From 95ecc2d1a1731c7018cea1d11d1ad85a71629d21 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 5 Jun 2015 14:03:51 +0800 Subject: [PATCH] Port the library_init() constructor to MSVC. --- src/dispatch_common.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index 4e34d6e..e7979c9 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -120,6 +120,26 @@ #define GLES2_LIB "libGLESv2.so.2" #endif +#ifdef __GNUC__ +#define CONSTRUCT(_func) static void _func (void) __attribute__((constructor)); +#define DESTRUCT(_func) static void _func (void) __attribute__((destructor)); +#elif defined (_MSC_VER) && (_MSC_VER >= 1500) +#define CONSTRUCT(_func) \ + static void _func(void); \ + static int _func ## _wrapper(void) { _func(); return 0; } \ + __pragma(section(".CRT$XCU",read)) \ + __declspec(allocate(".CRT$XCU")) static int (* _array ## _func)(void) = _func ## _wrapper; + +#define DESTRUCT(_func) \ + static void _func(void); \ + static int _func ## _constructor(void) { atexit (_func); return 0; } \ + __pragma(section(".CRT$XCU",read)) \ + __declspec(allocate(".CRT$XCU")) static int (* _array ## _func)(void) = _func ## _constructor; + +#else +#error "You will need constructor support for your compiler" +#endif + struct api { #ifndef _WIN32 /** @@ -175,8 +195,7 @@ static EGLenum epoxy_egl_get_current_gl_context_api(void); #endif -static void -library_init(void) __attribute__((constructor)); +CONSTRUCT (library_init) static void library_init(void)