--- origsrc/glib-2.56.4/gmodule/gmodule-win32.c 2018-08-15 12:22:08.000000000 -0400 +++ src/glib-2.56.4/gmodule/gmodule-win32.c 2020-05-23 08:29:18.332616700 -0400 @@ -37,7 +37,20 @@ #ifdef G_WITH_CYGWIN #include -#endif +#include + +static gchar* +fetch_dlerror (gboolean replace_null) +{ + gchar *msg = dlerror (); + + if (!msg && replace_null) + return "unknown dl-error"; + + return msg; +} + +#else static void set_error (const gchar *format, @@ -62,22 +75,26 @@ set_error (const gchar *format, g_free (error); } +#endif /* G_WITH_CYGWIN */ + /* --- functions --- */ static gpointer _g_module_open (const gchar *file_name, gboolean bind_lazy, gboolean bind_local) { - HINSTANCE handle; - wchar_t *wfilename; DWORD old_mode; BOOL success; #ifdef G_WITH_CYGWIN - gchar tmp[MAX_PATH]; + gpointer handle; - cygwin_conv_to_win32_path(file_name, tmp); - file_name = tmp; -#endif + handle = dlopen (file_name, + (bind_local ? RTLD_LOCAL : RTLD_GLOBAL) | (bind_lazy ? RTLD_LAZY : RTLD_NOW)); + if (!handle) + g_module_set_error (fetch_dlerror (TRUE)); +#else + HINSTANCE handle; + wchar_t *wfilename; wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL); /* suppress error dialog */ @@ -91,26 +108,44 @@ _g_module_open (const gchar *file_name, if (!handle) set_error ("'%s': ", file_name); +#endif return handle; } +#ifndef G_WITH_CYGWIN static gint dummy; static gpointer null_module_handle = &dummy; +#endif static gpointer _g_module_self (void) { +#ifdef G_WITH_CYGWIN + gpointer handle; + + handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY); + if (!handle) + g_module_set_error (fetch_dlerror (TRUE)); + + return handle; +#else return null_module_handle; +#endif } static void _g_module_close (gpointer handle, gboolean is_unref) { +#ifdef G_WITH_CYGWIN + if (dlclose (handle) != 0) + g_module_set_error (fetch_dlerror (TRUE)); +#else if (handle != null_module_handle) if (!FreeLibrary (handle)) set_error (""); +#endif } static gpointer @@ -129,8 +164,19 @@ find_in_any_module_using_toolhelp (const if (Module32First (snapshot, &me32)) { do { - if ((p = GetProcAddress (me32.hModule, symbol_name)) != NULL) - break; + if ((p = GetProcAddress (me32.hModule, symbol_name)) != NULL) { +#ifdef G_WITH_CYGWIN + /* if symbol is found in another module, we probably do not want it */ + ssize_t size = cygwin_conv_path (CCP_WIN_A_TO_POSIX, me32.szExePath, NULL, 0); + char *posix = (char *) alloca (size); + cygwin_conv_path (CCP_WIN_A_TO_POSIX, me32.szExePath, posix, size); + if (g_strstr_len (posix, size, "/usr/lib") + || g_strstr_len (posix, size, "/usr/local/lib")) + p = NULL; + else +#endif + break; + } } while (Module32Next (snapshot, &me32)); } @@ -156,6 +202,13 @@ _g_module_symbol (gpointer handle, { gpointer p; +#ifdef G_WITH_CYGWIN + p = dlsym (handle, symbol_name); + if (!p) + p = find_in_any_module (symbol_name); + if (!p) + g_module_set_error (fetch_dlerror (FALSE)); +#else if (handle == null_module_handle) { if ((p = GetProcAddress (GetModuleHandle (NULL), symbol_name)) == NULL) @@ -166,6 +219,7 @@ _g_module_symbol (gpointer handle, if (!p) set_error (""); +#endif return p; }