utility: Add initializer functions

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-07-07 12:57:30 +02:00
parent c5d81e41a6
commit 99003d5193
+28 -3
View File
@@ -15,8 +15,6 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#ifndef OBS_FFMPEG_UTILITY_HPP
#define OBS_FFMPEG_UTILITY_HPP
#pragma once #pragma once
#include "version.hpp" #include "version.hpp"
@@ -45,4 +43,31 @@
#define vstr(s) dstr(s) #define vstr(s) dstr(s)
#define dstr(s) #s #define dstr(s) #s
#endif OBS_FFMPEG_UTILITY_HPP // Initializer
#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