mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
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.
This commit is contained in:
parent
549faafc02
commit
d568a76ae4
@ -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>
|
2000-01-13 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
* gmodule.c (g_module_open): Check whether `check_init' is not NULL
|
* gmodule.c (g_module_open): Check whether `check_init' is not NULL
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* GMODULE - GLIB wrapper code for dynamic module loading
|
/* GMODULE - GLIB wrapper code for dynamic module loading
|
||||||
* Copyright (C) 1998 Tim Janik
|
* Copyright (C) 1998, 2000 Tim Janik
|
||||||
*
|
*
|
||||||
* BeOS GMODULE implementation
|
* BeOS GMODULE implementation
|
||||||
* Copyright (C) 1999 Richard Offer and Shawn T. Amundson (amundson@gtk.org)
|
* Copyright (C) 1999 Richard Offer and Shawn T. Amundson (amundson@gtk.org)
|
||||||
@ -55,18 +55,24 @@
|
|||||||
|
|
||||||
/* --- functions --- */
|
/* --- functions --- */
|
||||||
static gpointer
|
static gpointer
|
||||||
_g_module_open (const gchar *file_name,
|
_g_module_open (const gchar *file_name,
|
||||||
gboolean bind_lazy)
|
gboolean bind_lazy)
|
||||||
{
|
{
|
||||||
image_id handle;
|
image_id handle;
|
||||||
|
|
||||||
handle = load_add_on (file_name);
|
handle = load_add_on (file_name);
|
||||||
if (handle < B_OK) {
|
if (handle < B_OK)
|
||||||
g_module_set_error (g_strdup_printf("failed to load_add_on(%s), reason: %s",
|
{
|
||||||
(gchar *) file_name, strerror(handle)));
|
gchar *msg = g_strdup_printf ("failed to load_add_on(%s): %s",
|
||||||
return NULL;
|
file_name,
|
||||||
}
|
strerror (handle));
|
||||||
|
|
||||||
|
g_module_set_error (msg);
|
||||||
|
g_free (msg);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return (gpointer) handle;
|
return (gpointer) handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,81 +82,100 @@ _g_module_self (void)
|
|||||||
image_info info;
|
image_info info;
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
/* Is it always the first one? I'm guessing yes. */
|
/* 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;
|
return (gpointer) info.id;
|
||||||
else
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_g_module_close (gpointer handle,
|
_g_module_close (gpointer handle,
|
||||||
gboolean is_unref)
|
gboolean is_unref)
|
||||||
{
|
{
|
||||||
image_info info;
|
image_info info;
|
||||||
gchar *name;
|
gchar *name;
|
||||||
|
|
||||||
if (unload_add_on((image_id) handle) != B_OK)
|
if (unload_add_on ((image_id) handle) != B_OK)
|
||||||
{
|
{
|
||||||
/* Try and get the name of the image. */
|
gchar *msg;
|
||||||
if (get_image_info((image_id) handle, &info) != B_OK)
|
|
||||||
name = g_strdup("(unknown)");
|
/* Try and get the name of the image. */
|
||||||
else
|
if (get_image_info ((image_id) handle, &info) != B_OK)
|
||||||
name = g_strdup (info.name);
|
name = g_strdup ("unknown");
|
||||||
|
else
|
||||||
g_module_set_error (g_strdup_printf("failed to unload_add_on(%s)",
|
name = g_strdup (info.name);
|
||||||
name));
|
|
||||||
g_free (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
|
static gpointer
|
||||||
_g_module_symbol (gpointer handle,
|
_g_module_symbol (gpointer handle,
|
||||||
const gchar *symbol_name)
|
const gchar *symbol_name)
|
||||||
{
|
{
|
||||||
image_id id;
|
image_id id;
|
||||||
gpointer p;
|
|
||||||
status_t status;
|
status_t status;
|
||||||
image_info info;
|
image_info info;
|
||||||
gchar name[256];
|
int32 type, name_len;
|
||||||
int32 name_len;
|
void *p;
|
||||||
int32 type;
|
gchar *msg, name[256];
|
||||||
int32 n;
|
gint n, l;
|
||||||
|
|
||||||
id = (image_id) handle;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l = strlen (symbol_name);
|
||||||
name_len = 256;
|
name_len = 256;
|
||||||
type = B_SYMBOL_TYPE_ANY;
|
type = B_SYMBOL_TYPE_ANY;
|
||||||
n = 0;
|
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)))
|
if (p && strncmp (name, symbol_name, l) == 0)
|
||||||
|
return p;
|
||||||
|
|
||||||
|
if (strcmp (name, "_end") == 0)
|
||||||
{
|
{
|
||||||
return p;
|
msg = g_strdup_printf ("unmatched symbol name `%s'", symbol_name);
|
||||||
|
g_module_set_error (msg);
|
||||||
|
g_free (msg);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp (name, "_end"))
|
|
||||||
{
|
|
||||||
g_module_set_error (g_strdup_printf("g_module_symbol(): no symbol matching '%s'", symbol_name));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
name_len = 256;
|
name_len = 256;
|
||||||
type = B_SYMBOL_TYPE_ANY;
|
type = B_SYMBOL_TYPE_ANY;
|
||||||
n++;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,13 +183,16 @@ static gchar*
|
|||||||
_g_module_build_path (const gchar *directory,
|
_g_module_build_path (const gchar *directory,
|
||||||
const gchar *module_name)
|
const gchar *module_name)
|
||||||
{
|
{
|
||||||
printf("WARNING: _g_module_build_path() untested!\n");
|
g_warning ("_g_module_build_path() untested for BeOS!");
|
||||||
if (directory && *directory) {
|
|
||||||
if (strncmp (module_name, "lib", 3) == 0)
|
if (directory && *directory)
|
||||||
return g_strconcat (directory, "/", module_name, NULL);
|
{
|
||||||
else
|
if (strncmp (module_name, "lib", 3) == 0)
|
||||||
return g_strconcat (directory, "/lib", module_name, ".so", NULL);
|
return g_strconcat (directory, "/", module_name, NULL);
|
||||||
} else if (strncmp (module_name, "lib", 3) == 0)
|
else
|
||||||
|
return g_strconcat (directory, "/lib", module_name, ".so", NULL);
|
||||||
|
}
|
||||||
|
else if (strncmp (module_name, "lib", 3) == 0)
|
||||||
return g_strdup (module_name);
|
return g_strdup (module_name);
|
||||||
else
|
else
|
||||||
return g_strconcat ("lib", module_name, ".so", NULL);
|
return g_strconcat ("lib", module_name, ".so", NULL);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* GMODULE - GLIB wrapper code for dynamic module loading
|
/* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
@ -70,15 +70,25 @@
|
|||||||
|
|
||||||
|
|
||||||
/* --- functions --- */
|
/* --- 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
|
static gpointer
|
||||||
_g_module_open (const gchar *file_name,
|
_g_module_open (const gchar *file_name,
|
||||||
gboolean bind_lazy)
|
gboolean bind_lazy)
|
||||||
{
|
{
|
||||||
gpointer handle;
|
gpointer handle;
|
||||||
|
|
||||||
handle = dlopen (file_name, RTLD_GLOBAL | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
|
handle = dlopen (file_name, RTLD_GLOBAL | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
|
||||||
if (!handle)
|
if (!handle)
|
||||||
g_module_set_error (dlerror ());
|
g_module_set_error (fetch_dlerror ());
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@ -94,14 +104,14 @@ _g_module_self (void)
|
|||||||
|
|
||||||
handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY);
|
handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY);
|
||||||
if (!handle)
|
if (!handle)
|
||||||
g_module_set_error (dlerror ());
|
g_module_set_error (fetch_dlerror ());
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_g_module_close (gpointer handle,
|
_g_module_close (gpointer handle,
|
||||||
gboolean is_unref)
|
gboolean is_unref)
|
||||||
{
|
{
|
||||||
/* are there any systems out there that have dlopen()/dlclose()
|
/* are there any systems out there that have dlopen()/dlclose()
|
||||||
* without a reference count implementation?
|
* without a reference count implementation?
|
||||||
@ -111,19 +121,19 @@ _g_module_close (gpointer handle,
|
|||||||
if (is_unref)
|
if (is_unref)
|
||||||
{
|
{
|
||||||
if (dlclose (handle) != 0)
|
if (dlclose (handle) != 0)
|
||||||
g_module_set_error (dlerror ());
|
g_module_set_error (fetch_dlerror ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
_g_module_symbol (gpointer handle,
|
_g_module_symbol (gpointer handle,
|
||||||
const gchar *symbol_name)
|
const gchar *symbol_name)
|
||||||
{
|
{
|
||||||
gpointer p;
|
gpointer p;
|
||||||
|
|
||||||
p = dlsym (handle, symbol_name);
|
p = dlsym (handle, symbol_name);
|
||||||
if (!p)
|
if (!p)
|
||||||
g_module_set_error (dlerror ());
|
g_module_set_error (fetch_dlerror ());
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* GMODULE - GLIB wrapper code for dynamic module loading
|
/* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
@ -68,8 +68,8 @@
|
|||||||
|
|
||||||
/* --- functions --- */
|
/* --- functions --- */
|
||||||
static gpointer
|
static gpointer
|
||||||
_g_module_open (const gchar *file_name,
|
_g_module_open (const gchar *file_name,
|
||||||
gboolean bind_lazy)
|
gboolean bind_lazy)
|
||||||
{
|
{
|
||||||
shl_t shl_handle;
|
shl_t shl_handle;
|
||||||
|
|
||||||
@ -97,8 +97,8 @@ _g_module_self (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_g_module_close (gpointer handle,
|
_g_module_close (gpointer handle,
|
||||||
gboolean is_unref)
|
gboolean is_unref)
|
||||||
{
|
{
|
||||||
if (!is_unref)
|
if (!is_unref)
|
||||||
{
|
{
|
||||||
@ -108,13 +108,22 @@ _g_module_close (gpointer handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
_g_module_symbol (gpointer handle,
|
_g_module_symbol (gpointer handle,
|
||||||
const gchar *symbol_name)
|
const gchar *symbol_name)
|
||||||
{
|
{
|
||||||
gpointer p = NULL;
|
gpointer p = NULL;
|
||||||
|
|
||||||
/* should we restrict lookups to TYPE_PROCEDURE?
|
/* 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 ||
|
if (shl_findsym ((shl_t*) &handle, symbol_name, TYPE_UNDEFINED, &p) != 0 ||
|
||||||
handle == NULL || p == NULL)
|
handle == NULL || p == NULL)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* GMODULE - GLIB wrapper code for dynamic module loading
|
/* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
@ -36,12 +36,8 @@
|
|||||||
/* dlerror() is not implemented on all systems
|
/* dlerror() is not implemented on all systems
|
||||||
*/
|
*/
|
||||||
#ifndef G_MODULE_HAVE_DLERROR
|
#ifndef G_MODULE_HAVE_DLERROR
|
||||||
# ifdef __NetBSD__
|
|
||||||
# define dlerror() g_strerror (errno)
|
|
||||||
# else /* !__NetBSD__ */
|
|
||||||
/* could we rely on errno's state here? */
|
/* could we rely on errno's state here? */
|
||||||
# define dlerror() "unknown dl-error"
|
# define dlerror() "unknown dl-error"
|
||||||
# endif /* !__NetBSD__ */
|
|
||||||
#endif /* G_MODULE_HAVE_DLERROR */
|
#endif /* G_MODULE_HAVE_DLERROR */
|
||||||
|
|
||||||
/* some flags are missing on some systems, so we provide
|
/* some flags are missing on some systems, so we provide
|
||||||
@ -92,15 +88,16 @@ _g_module_self (void)
|
|||||||
* are required on some systems.
|
* are required on some systems.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* XXX, not supported */
|
/* XXX, not supported */
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
|
g_module_set_error ("module handle for self not supported");
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_g_module_close (gpointer handle,
|
_g_module_close (gpointer handle,
|
||||||
gboolean is_unref)
|
gboolean is_unref)
|
||||||
{
|
{
|
||||||
/* are there any systems out there that have dlopen()/dlclose()
|
/* are there any systems out there that have dlopen()/dlclose()
|
||||||
* without a reference count implementation?
|
* without a reference count implementation?
|
||||||
@ -109,14 +106,14 @@ _g_module_close (gpointer handle,
|
|||||||
|
|
||||||
if (is_unref)
|
if (is_unref)
|
||||||
{
|
{
|
||||||
/* XXX, no return code */
|
/* XXX, no return code */
|
||||||
dlclose (handle);
|
dlclose (handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
_g_module_symbol (gpointer handle,
|
_g_module_symbol (gpointer handle,
|
||||||
const gchar *symbol_name)
|
const gchar *symbol_name)
|
||||||
{
|
{
|
||||||
gpointer p;
|
gpointer p;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user