Handle valid symbols that are NULL correctly. (#385388, Felix Kater)
authorMatthias Clasen <mclasen@redhat.com>
Wed, 13 Dec 2006 15:41:22 +0000 (15:41 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 13 Dec 2006 15:41:22 +0000 (15:41 +0000)
2006-12-13  Matthias Clasen  <mclasen@redhat.com>

        * gmodule.c (g_module_open):
        * gmodule-dl.c (_g_module_symbol): Handle valid symbols
        that are NULL correctly.  (#385388, Felix Kater)

docs/reference/ChangeLog
docs/reference/glib/tmpl/modules.sgml
gmodule/ChangeLog
gmodule/gmodule-dl.c
gmodule/gmodule.c

index f1ce3652eafbcb81cee49cc0d6e3f8dd090b83c4..d728ed2cebf847ec43d99a68ba7a5583a8f0004a 100644 (file)
@@ -1,3 +1,7 @@
+2006-12-13  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/tmpl/modules.sgml: Point out that valid symbols may be NULL.
+
 2006-10-08  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/tmpl/unicode.sgml: Document GUnicodeType.
index 56aa90d3515f04bd792e4eeb8a19d927cac7c488..19deefe0fc45510c20ae909067519d44aa18322e 100644 (file)
@@ -71,6 +71,22 @@ just_say_hello (const char *filename, GError **error)
       return FALSE;
     }
 
+  if (say_hello == NULL)
+    {
+      g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN, "symbol say_hello is NULL");
+      if (!g_module_close (module))
+       g_warning ("&percnt;s: &percnt;s", filename, g_module_error (<!-- -->));
+      return FALSE;
+    }
+
+  if (say_hello == NULL)
+    {
+      g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN, "symbol say_hello is NULL");
+      if (!g_module_close (module))
+       g_warning ("&percnt;s: &percnt;s", filename, g_module_error (<!-- -->));
+      return FALSE;
+    }
+
   /* call our function in the module */
   say_hello ("Hello world!");
 
@@ -177,6 +193,12 @@ not supported on all platforms.
 <para>
 Gets a symbol pointer from a module.
 </para>
+<para>
+Note that a valid symbol can be %NULL.
+</para>
+<para>
+Note that a valid symbol can be %NULL.
+</para>
 
 @module: a #GModule.
 @symbol_name: the name of the symbol to find.
index 9090e2f539a8a653b9c62c0d280875cd701da3e0..819cb23fdaac421dca52c9be1255b204f776f88a 100644 (file)
@@ -1,3 +1,9 @@
+2006-12-13  Matthias Clasen  <mclasen@redhat.com>
+
+        * gmodule.c (g_module_open):
+        * gmodule-dl.c (_g_module_symbol): Handle valid symbols
+        that are NULL correctly.  (#385388, Felix Kater)
+
 Mon Sep 11 14:58:56 2006  Tim Janik  <timj@imendio.com>
 
        * gmodule.c: applied patch from Christian Persch to support
index 08f87f3b22fe3659c7b89a0fda61d5b70d4bd36f..ce3377767213d3ca419724b657ad3cdb47707165 100644 (file)
@@ -96,7 +96,7 @@ _g_module_open (const gchar *file_name,
   gpointer handle;
   
   handle = dlopen (file_name,
-       (bind_local ? 0 : RTLD_GLOBAL) | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
+                  (bind_local ? 0 : RTLD_GLOBAL) | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
   if (!handle)
     g_module_set_error (fetch_dlerror (TRUE));
   
@@ -140,10 +140,13 @@ _g_module_symbol (gpointer     handle,
                  const gchar *symbol_name)
 {
   gpointer p;
-  
+  gchar *msg;
+
+  fetch_dlerror (FALSE);
   p = dlsym (handle, symbol_name);
-  if (!p)
-    g_module_set_error (fetch_dlerror (FALSE));
+  msg = fetch_dlerror (FALSE);
+  if (msg)
+    g_module_set_error (msg);
   
   return p;
 }
index 0ff4eaa417d1763c8ef98ac629c8fd05ad021a24..75c4e709b53628ff266dfb4e8497847fe9bd2959 100644 (file)
@@ -477,7 +477,7 @@ g_module_open (const gchar    *file_name,
       modules = module;
       
       /* check initialization */
-      if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init))
+      if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL)
        check_failed = check_init (module);
       
       /* we don't call unload() if the initialization check failed. */