From 3f92e1cc895e42fb2c9abac4a2f976db3c6c0f61 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 24 Mar 2019 21:10:20 +0100 Subject: [PATCH] utility: Move helper macros As not everything in the plugin needs to use these, they have no place in the plugin header, and thus are now in utility.hpp --- source/filters/filter-shape.cpp | 1 + source/plugin.hpp | 40 --------------------------------- source/utility.hpp | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 40 deletions(-) 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