From ea1512221b376246c28f69fea3b4c163e578f543 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 13 Dec 2006 15:41:22 +0000 Subject: [PATCH] Handle valid symbols that are NULL correctly. (#385388, Felix Kater) 2006-12-13 Matthias Clasen * gmodule.c (g_module_open): * gmodule-dl.c (_g_module_symbol): Handle valid symbols that are NULL correctly. (#385388, Felix Kater) --- docs/reference/ChangeLog | 4 ++++ docs/reference/glib/tmpl/modules.sgml | 22 ++++++++++++++++++++++ gmodule/ChangeLog | 6 ++++++ gmodule/gmodule-dl.c | 11 +++++++---- gmodule/gmodule.c | 2 +- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index f1ce365..d728ed2 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2006-12-13 Matthias Clasen + + * glib/tmpl/modules.sgml: Point out that valid symbols may be NULL. + 2006-10-08 Matthias Clasen * glib/tmpl/unicode.sgml: Document GUnicodeType. diff --git a/docs/reference/glib/tmpl/modules.sgml b/docs/reference/glib/tmpl/modules.sgml index 56aa90d..19deefe 100644 --- a/docs/reference/glib/tmpl/modules.sgml +++ b/docs/reference/glib/tmpl/modules.sgml @@ -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 ("%s: %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 ("%s: %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. Gets a symbol pointer from a module. + +Note that a valid symbol can be %NULL. + + +Note that a valid symbol can be %NULL. + @module: a #GModule. @symbol_name: the name of the symbol to find. diff --git a/gmodule/ChangeLog b/gmodule/ChangeLog index 9090e2f..819cb23 100644 --- a/gmodule/ChangeLog +++ b/gmodule/ChangeLog @@ -1,3 +1,9 @@ +2006-12-13 Matthias Clasen + + * 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 * gmodule.c: applied patch from Christian Persch to support diff --git a/gmodule/gmodule-dl.c b/gmodule/gmodule-dl.c index 08f87f3..ce33777 100644 --- a/gmodule/gmodule-dl.c +++ b/gmodule/gmodule-dl.c @@ -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; } diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c index 0ff4eaa..75c4e70 100644 --- a/gmodule/gmodule.c +++ b/gmodule/gmodule.c @@ -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. */ -- 2.7.4