Files
MSYS2-packages/glib2/2.24.1-gmodule.patch
2013-11-06 11:32:10 +04:00

133 lines
2.6 KiB
Diff

--- src/glib-2.38.1/gmodule/gmodule-win32.c.orig 2013-08-08 14:00:40.000000000 +0400
+++ src/glib-2.38.1/gmodule/gmodule-win32.c 2013-11-05 23:23:51.213200000 +0400
@@ -38,8 +38,23 @@
#include <tlhelp32.h>
#ifdef G_WITH_CYGWIN
-#include <sys/cygwin.h>
-#endif
+#include <dlfcn.h>
+
+static gchar*
+fetch_dlerror (gboolean replace_null)
+{
+ gchar *msg = dlerror ();
+
+ /* make sure we always return an error message != NULL, if
+ * expected to do so. */
+
+ if (!msg && replace_null)
+ return "unknown dl-error";
+
+ return msg;
+}
+
+#else
static void
set_error (const gchar *format,
@@ -64,20 +79,28 @@
g_free (error);
}
+#endif
+
/* --- functions --- */
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local)
{
+#ifdef G_WITH_CYGWIN
+ gpointer handle;
+
+ handle = dlopen (file_name,
+ (bind_local ? 0 : RTLD_GLOBAL) | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
+ if (!handle)
+ g_module_set_error (fetch_dlerror (TRUE));
+#else
HINSTANCE handle;
wchar_t *wfilename;
-#ifdef G_WITH_CYGWIN
gchar tmp[MAX_PATH];
cygwin_conv_to_win32_path(file_name, tmp);
file_name = tmp;
-#endif
wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL);
handle = LoadLibraryW (wfilename);
@@ -85,7 +108,7 @@
if (!handle)
set_error ("'%s': ", file_name);
-
+#endif
return handle;
}
@@ -95,16 +118,41 @@
static gpointer
_g_module_self (void)
{
+#ifdef G_WITH_CYGWIN
+ gpointer handle;
+
+ /* to query symbols from the program itself, special link options
+ * are required on some systems.
+ */
+
+ 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
+ /* are there any systems out there that have dlopen()/dlclose()
+ * without a reference count implementation?
+ */
+ is_unref |= 1;
+
+ if (is_unref)
+ 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
@@ -150,6 +198,13 @@
{
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)
@@ -160,6 +215,7 @@
if (!p)
set_error ("");
+#endif
return p;
}