diff --git a/glib/glib-init.c b/glib/glib-init.c index 2e9428253..22be89108 100644 --- a/glib/glib-init.c +++ b/glib/glib-init.c @@ -342,12 +342,36 @@ glib_init (void) #ifdef G_PLATFORM_WIN32 +HMODULE glib_dll = NULL; + +static void +glib_win32_init (void) +{ + g_crash_handler_win32_init (); +#ifdef THREADS_WIN32 + g_thread_win32_init (); +#endif + + g_clock_win32_init (); + glib_init (); + /* must go after glib_init */ + g_console_win32_init (); +} + +static void +glib_win32_deinit (gboolean detach_thread) +{ +#ifdef THREADS_WIN32 + if (detach_thread) + g_thread_win32_process_detach (); +#endif + g_crash_handler_win32_deinit (); +} + BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); -HMODULE glib_dll; - BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, @@ -357,14 +381,7 @@ DllMain (HINSTANCE hinstDLL, { case DLL_PROCESS_ATTACH: glib_dll = hinstDLL; - g_crash_handler_win32_init (); - g_clock_win32_init (); -#ifdef THREADS_WIN32 - g_thread_win32_init (); -#endif - glib_init (); - /* must go after glib_init */ - g_console_win32_init (); + glib_win32_init (); break; case DLL_THREAD_DETACH: @@ -374,11 +391,7 @@ DllMain (HINSTANCE hinstDLL, break; case DLL_PROCESS_DETACH: -#ifdef THREADS_WIN32 - if (lpvReserved == NULL) - g_thread_win32_process_detach (); -#endif - g_crash_handler_win32_deinit (); + glib_win32_deinit (lpvReserved == NULL); break; default: @@ -389,7 +402,7 @@ DllMain (HINSTANCE hinstDLL, return TRUE; } -#elif defined (G_HAS_CONSTRUCTORS) +#elif defined(G_HAS_CONSTRUCTORS) /* && !G_PLATFORM_WIN32 */ #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(glib_init_ctor) @@ -402,6 +415,6 @@ glib_init_ctor (void) glib_init (); } -#else +#else /* !G_PLATFORM_WIN32 && !G_HAS_CONSTRUCTORS */ # error Your platform/compiler is missing constructor support -#endif +#endif /* G_PLATFORM_WIN32 */