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