132 lines
2.8 KiB
Diff
132 lines
2.8 KiB
Diff
--- origsrc/glib-2.38.2/gmodule/gmodule-win32.c 2014-03-11 21:19:04.000809400 -0500
|
|
+++ src/glib-2.38.2/gmodule/gmodule-win32.c 2014-03-11 21:18:51.717249600 -0500
|
|
@@ -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,24 @@ set_error (const gchar *format,
|
|
g_free (error);
|
|
}
|
|
|
|
+#endif
|
|
+
|
|
/* --- functions --- */
|
|
static gpointer
|
|
_g_module_open (const gchar *file_name,
|
|
gboolean bind_lazy,
|
|
gboolean bind_local)
|
|
{
|
|
- HINSTANCE handle;
|
|
- wchar_t *wfilename;
|
|
#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 ? 0 : 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);
|
|
|
|
handle = LoadLibraryW (wfilename);
|
|
@@ -85,6 +104,7 @@ _g_module_open (const gchar *file_name,
|
|
|
|
if (!handle)
|
|
set_error ("'%s': ", file_name);
|
|
+#endif
|
|
|
|
return handle;
|
|
}
|
|
@@ -95,16 +115,41 @@ static gpointer null_module_handle = &du
|
|
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 +195,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)
|
|
@@ -160,6 +212,7 @@ _g_module_symbol (gpointer handle,
|
|
|
|
if (!p)
|
|
set_error ("");
|
|
+#endif
|
|
|
|
return p;
|
|
}
|