Blame SOURCES/glib-prefer-constructors-over-DllMain.patch

2511a8
From bc90511c1eb333e26e0bc0eaee62375d0e788db6 Mon Sep 17 00:00:00 2001
2511a8
From: Erik van Pienbroek <epienbro@fedoraproject.org>
2511a8
Date: Tue, 16 Apr 2013 11:42:11 +0200
2511a8
Subject: [PATCH] win32: Prefer the use of constructors over DllMain
2511a8
2511a8
This prevents having to depend on DllMain in static libraries
2511a8
2511a8
Constructors are available in both the GCC build (GCC 2.7 and later)
2511a8
and the MSVC build (MSVC 2008 and later using _Pragma, earlier
2511a8
versions using #pragma)
2511a8
---
2511a8
 glib/glib-init.c | 22 ++++++++++++++--------
2511a8
 1 file changed, 14 insertions(+), 8 deletions(-)
2511a8
2511a8
diff --git a/glib/glib-init.c b/glib/glib-init.c
2511a8
index 0032ee8..dd6ccbf 100644
2511a8
--- a/glib/glib-init.c
2511a8
+++ b/glib/glib-init.c
2511a8
@@ -223,12 +223,14 @@ glib_init (void)
2511a8
 
2511a8
 #if defined (G_OS_WIN32)
2511a8
 
2511a8
+HMODULE glib_dll = NULL;
2511a8
+
2511a8
+#if defined (DLL_EXPORT)
2511a8
+
2511a8
 BOOL WINAPI DllMain (HINSTANCE hinstDLL,
2511a8
                      DWORD     fdwReason,
2511a8
                      LPVOID    lpvReserved);
2511a8
 
2511a8
-HMODULE glib_dll;
2511a8
-
2511a8
 BOOL WINAPI
2511a8
 DllMain (HINSTANCE hinstDLL,
2511a8
          DWORD     fdwReason,
beda90
@@ -238,14 +240,6 @@ DllMain (HINSTANCE hinstDLL,
2511a8
     {
2511a8
     case DLL_PROCESS_ATTACH:
2511a8
       glib_dll = hinstDLL;
beda90
-      g_crash_handler_win32_init ();
2511a8
-      g_clock_win32_init ();
2511a8
-#ifdef THREADS_WIN32
2511a8
-      g_thread_win32_init ();
2511a8
-#endif
2511a8
-      glib_init ();
beda90
-      /* must go after glib_init */
beda90
-      g_console_win32_init ();
2511a8
       break;
2511a8
 
2511a8
     case DLL_THREAD_DETACH:
2511a8
@@ -259,7 +256,10 @@ DllMain (HINSTANCE hinstDLL,
2511a8
   return TRUE;
2511a8
 }
2511a8
 
2511a8
-#elif defined (G_HAS_CONSTRUCTORS)
2511a8
+#endif /* defined (DLL_EXPORT) */
2511a8
+#endif /* defined (G_OS_WIN32) */
2511a8
+
2511a8
+#if defined (G_HAS_CONSTRUCTORS)
2511a8
 
2511a8
 #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
2511a8
 #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(glib_init_ctor)
beda90
@@ -269,7 +266,15 @@ G_DEFINE_CONSTRUCTOR(glib_init_ctor)
2511a8
 static void
2511a8
 glib_init_ctor (void)
2511a8
 {
2511a8
+#if defined (G_OS_WIN32)
2511a8
+  g_clock_win32_init ();
2511a8
+#ifdef THREADS_WIN32
2511a8
+  g_thread_win32_init ();
2511a8
+#endif /* defined (THREADS_WIN32) */
2511a8
+#endif /* defined (G_OS_WIN32) */
2511a8
   glib_init ();
beda90
+  /* must go after glib_init */
beda90
+  g_console_win32_init ();
2511a8
 }
beda90
beda90
 #else
2511a8
-- 
2511a8
1.8.2