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.
This commit is contained in:
Tim Janik 2000-03-01 04:53:47 +00:00 committed by Tim Janik
parent 47e9e8475c
commit 6fbe816b6b
5 changed files with 71 additions and 31 deletions

View File

@ -1,3 +1,25 @@
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.
Sat Feb 19 19:43:29 2000 Tim Janik <timj@gtk.org>
* testgmodule.c (main): added test to check that not yet bound symbols

View File

@ -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;
}

View File

@ -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,8 +108,8 @@ _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;

View File

@ -1,5 +1,7 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998 Tim Janik
* Copyright (C) 1998, 2000 Tim Janik
*
* WIN32 GMODULE implementation
* Copyright (C) 1998 Tor Lillqvist
*
* This library is free software; you can redistribute it and/or
@ -34,15 +36,16 @@
/* --- functions --- */
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy)
_g_module_open (const gchar *file_name,
gboolean bind_lazy)
{
HINSTANCE handle;
handle = LoadLibrary (file_name);
if (!handle)
{
char error[100];
gchar error[100];
sprintf (error, "Error code %d", GetLastError ());
g_module_set_error (error);
}
@ -58,7 +61,8 @@ _g_module_self (void)
handle = GetModuleHandle (NULL);
if (!handle)
{
char error[100];
gchar error[100];
sprintf (error, "Error code %d", GetLastError ());
g_module_set_error (error);
}
@ -67,30 +71,33 @@ _g_module_self (void)
}
static void
_g_module_close (gpointer handle,
gboolean is_unref)
_g_module_close (gpointer handle,
gboolean is_unref)
{
if (!FreeLibrary (handle))
{
char error[100];
gchar error[100];
sprintf (error, "Error code %d", GetLastError ());
g_module_set_error (error);
}
}
static gpointer
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
{
gpointer p;
p = GetProcAddress (handle, symbol_name);
if (!p)
{
char error[100];
gchar error[100];
sprintf (error, "Error code %d", GetLastError ());
g_module_set_error (error);
}
return p;
}
@ -99,7 +106,7 @@ _g_module_build_path (const gchar *directory,
const gchar *module_name)
{
gint k;
k = strlen (module_name);
if (directory && *directory)
if (k > 4 && g_strcasecmp (module_name + k - 4, ".dll") == 0)

View File

@ -382,7 +382,7 @@ g_module_symbol (GModule *module,
*symbol = _g_module_symbol (module->handle, symbol_name);
#endif /* !G_MODULE_NEED_USCORE */
module_error = g_module_error();
module_error = g_module_error ();
if (module_error)
{
gchar *error;
@ -391,6 +391,7 @@ g_module_symbol (GModule *module,
g_module_set_error (error);
g_free (error);
*symbol = NULL;
return FALSE;
}