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

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