diff --git a/source/filters/filter-shape.cpp b/source/filters/filter-shape.cpp index 7fbd4941..7a68ff96 100644 --- a/source/filters/filter-shape.cpp +++ b/source/filters/filter-shape.cpp @@ -23,6 +23,7 @@ #include #include #include "strings.hpp" +#include "utility.hpp" // OBS #ifdef _MSC_VER diff --git a/source/plugin.hpp b/source/plugin.hpp index d66f6d42..58230876 100644 --- a/source/plugin.hpp +++ b/source/plugin.hpp @@ -43,46 +43,6 @@ #define P_LOG_INFO(...) P_LOG(LOG_INFO, __VA_ARGS__) #define P_LOG_DEBUG(...) P_LOG(LOG_DEBUG, __VA_ARGS__) -// Utility -#define vstr(s) dstr(s) -#define dstr(s) #s - -#ifndef __FUNCTION_NAME__ -#if defined(_WIN32) || defined(_WIN64) //WINDOWS -#define __FUNCTION_NAME__ __FUNCTION__ -#else //*NIX -#define __FUNCTION_NAME__ __func__ -#endif -#endif - -#ifdef __cplusplus -#define INITIALIZER(f) \ - static void f(void); \ - struct f##_t_ { \ - f##_t_(void) \ - { \ - f(); \ - } \ - }; \ - static f##_t_ f##_; \ - static void f(void) -#elif defined(_MSC_VER) -#pragma section(".CRT$XCU", read) -#define INITIALIZER2_(f, p) \ - static void f(void); \ - __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ - __pragma(comment(linker, "/include:" p #f "_")) static void f(void) -#ifdef _WIN64 -#define INITIALIZER(f) INITIALIZER2_(f, "") -#else -#define INITIALIZER(f) INITIALIZER2_(f, "_") -#endif -#else -#define INITIALIZER(f) \ - static void f(void) __attribute__((constructor)); \ - static void f(void) -#endif - // Initializer & Finalizer extern std::list> initializerFunctions; extern std::list> finalizerFunctions; diff --git a/source/utility.hpp b/source/utility.hpp index 7c0a0962..395078d2 100644 --- a/source/utility.hpp +++ b/source/utility.hpp @@ -44,3 +44,42 @@ typename std::enable_if::enable, Enum>::type oper struct enable_bitmask_operators { \ static const bool enable = true; \ }; + +#define vstr(s) dstr(s) +#define dstr(s) #s + +#ifndef __FUNCTION_NAME__ +#if defined(_WIN32) || defined(_WIN64) //WINDOWS +#define __FUNCTION_NAME__ __FUNCTION__ +#else //*NIX +#define __FUNCTION_NAME__ __func__ +#endif +#endif + +#ifdef __cplusplus +#define INITIALIZER(f) \ + static void f(void); \ + struct f##_t_ { \ + f##_t_(void) \ + { \ + f(); \ + } \ + }; \ + static f##_t_ f##_; \ + static void f(void) +#elif defined(_MSC_VER) +#pragma section(".CRT$XCU", read) +#define INITIALIZER2_(f, p) \ + static void f(void); \ + __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ + __pragma(comment(linker, "/include:" p #f "_")) static void f(void) +#ifdef _WIN64 +#define INITIALIZER(f) INITIALIZER2_(f, "") +#else +#define INITIALIZER(f) INITIALIZER2_(f, "_") +#endif +#else +#define INITIALIZER(f) \ + static void f(void) __attribute__((constructor)); \ + static void f(void) +#endif