summaryrefslogtreecommitdiff
path: root/gmodule
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>2000-03-01 04:57:07 +0000
committerTim Janik <timj@src.gnome.org>2000-03-01 04:57:07 +0000
commitd568a76ae4976e0aa01e26e868121a07b4e91338 (patch)
treed1039190a0ad68b6d8359a1ede00bc1c35b87c1d /gmodule
parent549faafc021d87b1c4700294debdf3e4b85ed7e1 (diff)
downloadglib-d568a76ae4976e0aa01e26e868121a07b4e91338.tar.gz
do not return NULL symbols.
Wed Mar 1 05:34:47 2000 Tim Janik <timj@gtk.org> * gmodule-beos.c (_g_module_symbol): do not return NULL symbols. * gmodule-os2.c: removed NetBSD specific defines. (_g_module_self): set an error message for unsupported behaviour. * gmodule-beos.c: many coding style fixups. (_g_module_open): (_g_module_self): (_g_module_close): (_g_module_symbol): bunch of memory leaks plugged. * gmodule-dl.c: make sure the error message returned from dlerror() is always != NULL, by using a wrapper function fetch_dlerror(). based on a patch to fix _g_module_symbol() for NetBSD from Scott Presnell <srp@zgi.com>. * gmodule-dld.c: minor indentation. * gmodule-win32.c: minor cleanups. * merges from glib-1-2.
Diffstat (limited to 'gmodule')
-rw-r--r--gmodule/ChangeLog24
-rw-r--r--gmodule/gmodule-beos.c148
-rw-r--r--gmodule/gmodule-dl.c32
-rw-r--r--gmodule/gmodule-dld.c23
-rw-r--r--gmodule/gmodule-os2.c21
5 files changed, 158 insertions, 90 deletions
diff --git a/gmodule/ChangeLog b/gmodule/ChangeLog
index 040f881c9..f37adc135 100644
--- a/gmodule/ChangeLog
+++ b/gmodule/ChangeLog
@@ -1,3 +1,27 @@
+Wed Mar 1 05:34:47 2000 Tim Janik <timj@gtk.org>
+
+ * gmodule-beos.c (_g_module_symbol): do not return NULL symbols.
+
+ * gmodule-os2.c: removed NetBSD specific defines.
+ (_g_module_self): set an error message for unsupported behaviour.
+
+ * gmodule-beos.c: many coding style fixups.
+ (_g_module_open):
+ (_g_module_self):
+ (_g_module_close):
+ (_g_module_symbol): bunch of memory leaks plugged.
+
+ * gmodule-dl.c: make sure the error message returned from dlerror()
+ is always != NULL, by using a wrapper function fetch_dlerror(). based
+ on a patch to fix _g_module_symbol() for NetBSD from Scott Presnell
+ <srp@zgi.com>.
+
+ * gmodule-dld.c: minor indentation.
+
+ * gmodule-win32.c: minor cleanups.
+
+ * merges from glib-1-2.
+
2000-01-13 Martin Baulig <martin@home-of-linux.org>
* gmodule.c (g_module_open): Check whether `check_init' is not NULL
diff --git a/gmodule/gmodule-beos.c b/gmodule/gmodule-beos.c
index 8cc99b232..159d4f8a7 100644
--- a/gmodule/gmodule-beos.c
+++ b/gmodule/gmodule-beos.c
@@ -1,5 +1,5 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
- * Copyright (C) 1998 Tim Janik
+ * Copyright (C) 1998, 2000 Tim Janik
*
* BeOS GMODULE implementation
* Copyright (C) 1999 Richard Offer and Shawn T. Amundson (amundson@gtk.org)
@@ -55,18 +55,24 @@
/* --- functions --- */
static gpointer
-_g_module_open (const gchar *file_name,
- gboolean bind_lazy)
+_g_module_open (const gchar *file_name,
+ gboolean bind_lazy)
{
image_id handle;
handle = load_add_on (file_name);
- if (handle < B_OK) {
- g_module_set_error (g_strdup_printf("failed to load_add_on(%s), reason: %s",
- (gchar *) file_name, strerror(handle)));
- return NULL;
- }
-
+ if (handle < B_OK)
+ {
+ gchar *msg = g_strdup_printf ("failed to load_add_on(%s): %s",
+ file_name,
+ strerror (handle));
+
+ g_module_set_error (msg);
+ g_free (msg);
+
+ return NULL;
+ }
+
return (gpointer) handle;
}
@@ -76,81 +82,100 @@ _g_module_self (void)
image_info info;
int32 cookie = 0;
status_t status;
-
+
/* Is it always the first one? I'm guessing yes. */
- if ((status = get_next_image_info(0, &cookie, &info)) == B_OK)
+ status = get_next_image_info (0, &cookie, &info);
+ if (status == B_OK)
return (gpointer) info.id;
else
{
- g_module_set_error (g_strdup_printf("get_next_image_info() for self failed, reason: %s", strerror(status)));
+ gchar *msg = g_strdup_printf ("failed to get_next_image_info(self): %s",
+ strerror (status));
+
+ g_module_set_error (msg);
+ g_free (msg);
+
return NULL;
}
}
static void
-_g_module_close (gpointer handle,
- gboolean is_unref)
+_g_module_close (gpointer handle,
+ gboolean is_unref)
{
- image_info info;
- gchar *name;
-
- if (unload_add_on((image_id) handle) != B_OK)
- {
- /* Try and get the name of the image. */
- if (get_image_info((image_id) handle, &info) != B_OK)
- name = g_strdup("(unknown)");
- else
- name = g_strdup (info.name);
-
- g_module_set_error (g_strdup_printf("failed to unload_add_on(%s)",
- name));
- g_free (name);
- }
+ image_info info;
+ gchar *name;
+
+ if (unload_add_on ((image_id) handle) != B_OK)
+ {
+ gchar *msg;
+
+ /* Try and get the name of the image. */
+ if (get_image_info ((image_id) handle, &info) != B_OK)
+ name = g_strdup ("unknown");
+ else
+ name = g_strdup (info.name);
+
+ msg = g_strdup_printf ("failed to unload_add_on(%s): %s", name, strerror (status));
+ g_module_set_error (msg);
+ g_free (msg);
+ g_free (name);
+ }
}
static gpointer
-_g_module_symbol (gpointer handle,
- const gchar *symbol_name)
+_g_module_symbol (gpointer handle,
+ const gchar *symbol_name)
{
image_id id;
- gpointer p;
status_t status;
image_info info;
- gchar name[256];
- int32 name_len;
- int32 type;
- int32 n;
-
+ int32 type, name_len;
+ void *p;
+ gchar *msg, name[256];
+ gint n, l;
+
id = (image_id) handle;
-
- if ((status = get_image_info(id, &info)) != B_OK)
+
+ status = get_image_info (id, &info);
+ if (status != B_OK)
{
- g_module_set_error (g_strdup_printf("failed get_image_info(), reason: %s", strerror(status)));
+ msg = g_strdup_printf ("failed to get_image_info(): %s", strerror (status));
+ g_module_set_error (msg);
+ g_free (msg);
+
return NULL;
}
-
+
+ l = strlen (symbol_name);
name_len = 256;
type = B_SYMBOL_TYPE_ANY;
n = 0;
- while ((status = get_nth_image_symbol(id, n, name, &name_len, &type, (void **)&p)) == B_OK)
+ status = get_nth_image_symbol (id, n, name, &name_len, &type, &p);
+ while (status == B_OK)
{
- if (!strncmp (name, symbol_name, strlen(symbol_name)))
- {
- return p;
- }
-
- if (!strcmp (name, "_end"))
+ if (p && strncmp (name, symbol_name, l) == 0)
+ return p;
+
+ if (strcmp (name, "_end") == 0)
{
- g_module_set_error (g_strdup_printf("g_module_symbol(): no symbol matching '%s'", symbol_name));
- return NULL;
+ msg = g_strdup_printf ("unmatched symbol name `%s'", symbol_name);
+ g_module_set_error (msg);
+ g_free (msg);
+
+ return NULL;
}
-
+
name_len = 256;
type = B_SYMBOL_TYPE_ANY;
n++;
+ status = get_nth_image_symbol (id, n, name, &name_len, &type, &p);
}
-
- g_module_set_error (g_strdup_printf("failed get_image_symbol(%s), reason: %s", symbol_name, strerror(status)));
+
+ msg = g_strdup_printf ("failed to get_image_symbol(%s): %s", symbol_name, strerror (status));
+ g_module_set_error (msg);
+ g_free (msg);
+
return NULL;
}
@@ -158,13 +183,16 @@ static gchar*
_g_module_build_path (const gchar *directory,
const gchar *module_name)
{
- printf("WARNING: _g_module_build_path() untested!\n");
- if (directory && *directory) {
- if (strncmp (module_name, "lib", 3) == 0)
- return g_strconcat (directory, "/", module_name, NULL);
- else
- return g_strconcat (directory, "/lib", module_name, ".so", NULL);
- } else if (strncmp (module_name, "lib", 3) == 0)
+ g_warning ("_g_module_build_path() untested for BeOS!");
+
+ if (directory && *directory)
+ {
+ if (strncmp (module_name, "lib", 3) == 0)
+ return g_strconcat (directory, "/", module_name, NULL);
+ else
+ return g_strconcat (directory, "/lib", module_name, ".so", NULL);
+ }
+ else if (strncmp (module_name, "lib", 3) == 0)
return g_strdup (module_name);
else
return g_strconcat ("lib", module_name, ".so", NULL);
diff --git a/gmodule/gmodule-dl.c b/gmodule/gmodule-dl.c
index e8fb3f281..bbf76913b 100644
--- a/gmodule/gmodule-dl.c
+++ b/gmodule/gmodule-dl.c
@@ -1,5 +1,5 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
- * Copyright (C) 1998 Tim Janik
+ * Copyright (C) 1998, 2000 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -70,15 +70,25 @@
/* --- functions --- */
+static gchar*
+fetch_dlerror (void)
+{
+ gchar *msg = dlerror ();
+
+ /* make sure we always return an error message != NULL */
+
+ return msg ? msg : "unknown dl-error";
+}
+
static gpointer
-_g_module_open (const gchar *file_name,
- gboolean bind_lazy)
+_g_module_open (const gchar *file_name,
+ gboolean bind_lazy)
{
gpointer handle;
handle = dlopen (file_name, RTLD_GLOBAL | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
if (!handle)
- g_module_set_error (dlerror ());
+ g_module_set_error (fetch_dlerror ());
return handle;
}
@@ -94,14 +104,14 @@ _g_module_self (void)
handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY);
if (!handle)
- g_module_set_error (dlerror ());
+ g_module_set_error (fetch_dlerror ());
return handle;
}
static void
-_g_module_close (gpointer handle,
- gboolean is_unref)
+_g_module_close (gpointer handle,
+ gboolean is_unref)
{
/* are there any systems out there that have dlopen()/dlclose()
* without a reference count implementation?
@@ -111,19 +121,19 @@ _g_module_close (gpointer handle,
if (is_unref)
{
if (dlclose (handle) != 0)
- g_module_set_error (dlerror ());
+ g_module_set_error (fetch_dlerror ());
}
}
static gpointer
-_g_module_symbol (gpointer handle,
- const gchar *symbol_name)
+_g_module_symbol (gpointer handle,
+ const gchar *symbol_name)
{
gpointer p;
p = dlsym (handle, symbol_name);
if (!p)
- g_module_set_error (dlerror ());
+ g_module_set_error (fetch_dlerror ());
return p;
}
diff --git a/gmodule/gmodule-dld.c b/gmodule/gmodule-dld.c
index e8cf40d0d..1d1391aa2 100644
--- a/gmodule/gmodule-dld.c
+++ b/gmodule/gmodule-dld.c
@@ -1,5 +1,5 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
- * Copyright (C) 1998 Tim Janik
+ * Copyright (C) 1998, 2000 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -68,8 +68,8 @@
/* --- functions --- */
static gpointer
-_g_module_open (const gchar *file_name,
- gboolean bind_lazy)
+_g_module_open (const gchar *file_name,
+ gboolean bind_lazy)
{
shl_t shl_handle;
@@ -97,8 +97,8 @@ _g_module_self (void)
}
static void
-_g_module_close (gpointer handle,
- gboolean is_unref)
+_g_module_close (gpointer handle,
+ gboolean is_unref)
{
if (!is_unref)
{
@@ -108,13 +108,22 @@ _g_module_close (gpointer handle,
}
static gpointer
-_g_module_symbol (gpointer handle,
- const gchar *symbol_name)
+_g_module_symbol (gpointer handle,
+ const gchar *symbol_name)
{
gpointer p = NULL;
/* should we restrict lookups to TYPE_PROCEDURE?
*/
+ if (handle == PROG_HANDLE)
+ {
+ /* PROG_HANDLE will only lookup symbols in the program itself, not honouring
+ * libraries. passing NULL as a handle will also try to lookup the symbol
+ * in currently loaded libraries. fix pointed out and supplied by:
+ * David Gero <dgero@nortelnetworks.com>
+ */
+ handle = NULL;
+ }
if (shl_findsym ((shl_t*) &handle, symbol_name, TYPE_UNDEFINED, &p) != 0 ||
handle == NULL || p == NULL)
{
diff --git a/gmodule/gmodule-os2.c b/gmodule/gmodule-os2.c
index 7cfa720d3..d689a4202 100644
--- a/gmodule/gmodule-os2.c
+++ b/gmodule/gmodule-os2.c
@@ -1,5 +1,5 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
- * Copyright (C) 1998 Tim Janik
+ * Copyright (C) 1998, 2000 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -36,12 +36,8 @@
/* dlerror() is not implemented on all systems
*/
#ifndef G_MODULE_HAVE_DLERROR
-# ifdef __NetBSD__
-# define dlerror() g_strerror (errno)
-# else /* !__NetBSD__ */
/* could we rely on errno's state here? */
-# define dlerror() "unknown dl-error"
-# endif /* !__NetBSD__ */
+# define dlerror() "unknown dl-error"
#endif /* G_MODULE_HAVE_DLERROR */
/* some flags are missing on some systems, so we provide
@@ -92,15 +88,16 @@ _g_module_self (void)
* are required on some systems.
*/
-/* XXX, not supported */
+ /* XXX, not supported */
handle = NULL;
+ g_module_set_error ("module handle for self not supported");
return handle;
}
static void
-_g_module_close (gpointer handle,
- gboolean is_unref)
+_g_module_close (gpointer handle,
+ gboolean is_unref)
{
/* are there any systems out there that have dlopen()/dlclose()
* without a reference count implementation?
@@ -109,14 +106,14 @@ _g_module_close (gpointer handle,
if (is_unref)
{
-/* XXX, no return code */
+ /* XXX, no return code */
dlclose (handle);
}
}
static gpointer
-_g_module_symbol (gpointer handle,
- const gchar *symbol_name)
+_g_module_symbol (gpointer handle,
+ const gchar *symbol_name)
{
gpointer p;