Improve error reporting: When g_module_open() fails, include the name of
authorTor Lillqvist <tml@novell.com>
Fri, 26 Sep 2008 09:16:25 +0000 (09:16 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Fri, 26 Sep 2008 09:16:25 +0000 (09:16 +0000)
2008-09-26  Tor Lillqvist  <tml@novell.com>

* gmodule-win32.c: Improve error reporting: When g_module_open()
fails, include the name of the module passed to LoadLibrary() in
what g_module_error() returns.

svn path=/trunk/; revision=7543

gmodule/ChangeLog
gmodule/gmodule-win32.c

index baf0578..1f6028d 100644 (file)
@@ -1,3 +1,9 @@
+2008-09-26  Tor Lillqvist  <tml@novell.com>
+
+       * gmodule-win32.c: Improve error reporting: When g_module_open()
+       fails, include the name of the module passed to LoadLibrary() in
+       what g_module_error() returns.
+
 2008-09-17  Matthias Clasen  <mclasen@redhat.com>
 
        * === Released 2.18.1 ===
index 7dba30e..98d3fb9 100644 (file)
 #endif
 
 static void
-set_error (void)
+set_error (const gchar *format,
+          ...)
 {
-  gchar *error = g_win32_error_message (GetLastError ());
+  gchar *error;
+  gchar *detail;
+  gchar *message;
+  va_list args;
 
-  g_module_set_error (error);
+  error = g_win32_error_message (GetLastError ());
+
+  va_start (args, format);
+  detail = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  message = g_strconcat (detail, error, NULL);
+
+  g_module_set_error (message);
+  g_free (message);
+  g_free (detail);
   g_free (error);
 }
 
@@ -70,7 +84,7 @@ _g_module_open (const gchar *file_name,
   g_free (wfilename);
       
   if (!handle)
-    set_error ();
+    set_error ("`%s': ", file_name);
 
   return handle;
 }
@@ -90,7 +104,7 @@ _g_module_close (gpointer handle,
 {
   if (handle != null_module_handle)
     if (!FreeLibrary (handle))
-      set_error ();
+      set_error ("");
 }
 
 static gpointer
@@ -219,7 +233,7 @@ _g_module_symbol (gpointer     handle,
     p = GetProcAddress (handle, symbol_name);
 
   if (!p)
-    set_error ();
+    set_error ("");
 
   return p;
 }