From cf9089f5ec802af897520d5bcb5376f7b6899416 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Fri, 17 Aug 2012 11:37:04 -0700 Subject: [PATCH] glib: Fix static usage of glib on win32 When glib is built static, the threads and clock code are not initialized since DllMain is never run. Instead, initialize them from the glib constructor. https://bugzilla.gnome.org/show_bug.cgi?id=678387 --- glib-patches/patchlist | 1 + glib-patches/win32-static-init.patch | 32 ++++++++++++++++++++++++++++ glib/glib/glib-init.c | 8 +++++++ 3 files changed, 41 insertions(+) create mode 100644 glib-patches/win32-static-init.patch diff --git a/glib-patches/patchlist b/glib-patches/patchlist index 065bb5c..52bb331 100644 --- a/glib-patches/patchlist +++ b/glib-patches/patchlist @@ -6,3 +6,4 @@ no-pkg-config.patch no-gettext.patch cross-compiling.patch static-only.patch +win32-static-init.patch diff --git a/glib-patches/win32-static-init.patch b/glib-patches/win32-static-init.patch new file mode 100644 index 0000000..ae5af1e --- /dev/null +++ b/glib-patches/win32-static-init.patch @@ -0,0 +1,32 @@ +When glib is built static, the threads and clock code are not +initialized since DllMain is never run. Instead, initialize them from +the glib constructor. + +https://bugzilla.gnome.org/show_bug.cgi?id=678387 + +diff --git a/glib/glib/glib-init.c b/glib/glib/glib-init.c +index f4edd5c..3ec89a0 100644 +--- a/glib/glib/glib-init.c ++++ b/glib/glib/glib-init.c +@@ -225,6 +225,10 @@ glib_init (void) + + HMODULE glib_dll; + ++#endif ++ ++#if defined (G_OS_WIN32) && !defined (GLIB_STATIC_COMPILATION) ++ + BOOL WINAPI + DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, +@@ -261,6 +265,10 @@ G_DEFINE_CONSTRUCTOR(glib_init_ctor) + static void + glib_init_ctor (void) + { ++#ifdef G_OS_WIN32 ++ g_clock_win32_init (); ++ g_thread_win32_init (); ++#endif + glib_init (); + } + diff --git a/glib/glib/glib-init.c b/glib/glib/glib-init.c index f4edd5c..3ec89a0 100644 --- a/glib/glib/glib-init.c +++ b/glib/glib/glib-init.c @@ -225,6 +225,10 @@ glib_init (void) HMODULE glib_dll; +#endif + +#if defined (G_OS_WIN32) && !defined (GLIB_STATIC_COMPILATION) + BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, @@ -261,6 +265,10 @@ G_DEFINE_CONSTRUCTOR(glib_init_ctor) static void glib_init_ctor (void) { +#ifdef G_OS_WIN32 + g_clock_win32_init (); + g_thread_win32_init (); +#endif glib_init (); }