Collapse two almost identical structures into one:

* libltdl/lt_dlloader.h (lt_dlloader): Add next field.
* libltdl/ltdl.c (lt_user_dlloader): Remove entirely.  Change all
callers to use lt_dlloader instead.  Add a compatibility macro.
(lt_dlloader_add): Remove copy and allocate stage, just hook
directly into the loaders list.
This commit is contained in:
Gary V. Vaughan 2004-07-15 12:26:28 +00:00
parent 0d8529860b
commit 52de761d29
10 changed files with 63 additions and 80 deletions

View File

@ -1,3 +1,13 @@
2004-07-15 Gary V. Vaughan <gary@gnu.org>
Collapse two almost identical structures into one:
* libltdl/lt_dlloader.h (lt_dlloader): Add next field.
* libltdl/ltdl.c (lt_user_dlloader): Remove entirely. Change all
callers to use lt_dlloader instead. Add a compatibility macro.
(lt_dlloader_add): Remove copy and allocate stage, just hook
directly into the loaders list.
2004-07-15 Gary V. Vaughan <gary@gnu.org>
A cleaner way to access the private fields of an lt_dlhandle

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable dld_link_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -49,10 +49,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable dlopen_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -49,10 +49,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable dyld_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -51,10 +51,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable load_add_on_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -49,10 +49,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable loadlibrary_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -49,10 +49,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable preopen_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -51,10 +51,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
be fetched from the preloaded symbol list by lt_dlsym(): */
#define get_vtable shl_load_LTX_get_vtable
extern lt_user_dlloader *get_vtable (lt_user_data loader_data);
extern lt_dlloader *get_vtable (lt_user_data loader_data);
/* Boilerplate code to set up the vtable for hooking this loader into
@ -49,10 +49,10 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
/* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously)
change between loaders. */
lt_user_dlloader *
lt_dlloader *
get_vtable (lt_user_data loader_data)
{
static lt_user_dlloader *vtable = 0;
static lt_dlloader *vtable = 0;
if (!vtable)
{

View File

@ -35,15 +35,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
LT_BEGIN_C_DECLS
typedef struct lt_user_dlloader lt_user_dlloader;
typedef struct lt_dlloader lt_dlloader;
typedef void * lt_user_data;
typedef void * lt_module;
/* Type of a function to get a loader's vtable: */
typedef lt_user_dlloader *lt_get_vtable (lt_user_data loader_data);
typedef lt_dlloader *lt_get_vtable (lt_user_data loader_data);
/* Function pointer types for creating user defined module loaders: */
/* Function pointer types for module loader vtable entries: */
typedef int lt_dlloader_init (lt_user_data loader_data);
typedef int lt_dlloader_exit (lt_user_data loader_data);
typedef lt_module lt_module_open (lt_user_data loader_data,
@ -58,7 +57,10 @@ typedef enum {
LT_DLLOADER_PREPEND = 0, LT_DLLOADER_APPEND
} lt_dlloader_priority;
struct lt_user_dlloader {
/* This structure defines a module loader, as populated by the get_vtable
entry point of each loader. */
struct lt_dlloader {
lt_dlloader * next;
const char * name;
const char * sym_prefix;
lt_module_open * module_open;
@ -70,14 +72,19 @@ struct lt_user_dlloader {
lt_dlloader_priority priority;
};
LT_SCOPE lt_dlloader *lt_dlloader_next (lt_dlloader *place);
LT_SCOPE lt_dlloader *lt_dlloader_find (const char *loader_name);
LT_SCOPE const char *lt_dlloader_name (lt_dlloader *place);
LT_SCOPE lt_user_data *lt_dlloader_data (lt_dlloader *place);
LT_SCOPE int lt_dlloader_add
(const struct lt_user_dlloader *dlloader,
lt_user_data data);
LT_SCOPE int lt_dlloader_remove (const char *loader_name);
LT_SCOPE lt_dlloader * lt_dlloader_next (lt_dlloader *place);
LT_SCOPE lt_dlloader * lt_dlloader_find (const char *name);
LT_SCOPE const char * lt_dlloader_name (lt_dlloader *place);
LT_SCOPE lt_user_data * lt_dlloader_data (lt_dlloader *place);
LT_SCOPE int lt_dlloader_add (lt_dlloader *dlloader,
lt_user_data data);
LT_SCOPE int lt_dlloader_remove (const char *name);
/* --- Backwards source compatibility --- */
#define lt_user_dlloader lt_dlloader
LT_END_C_DECLS

View File

@ -57,23 +57,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
#define LT_SYMBOL_OVERHEAD 5
/* --- OPAQUE STRUCTURES DECLARED IN LTDL.H --- */
/* This structure is used for the list of registered loaders. */
struct lt_dlloader {
struct lt_dlloader *next;
const char *loader_name; /* identifying name for each loader */
const char *sym_prefix; /* prefix for symbols */
lt_module_open *module_open;
lt_module_close *module_close;
lt_find_sym *find_sym;
lt_dlloader_exit *dlloader_exit;
lt_user_data dlloader_data;
};
/* Various boolean flags can be stored in the flags field of an
lt_dlhandle_struct... */
#define LT_DLGET_FLAG(handle, flag) (((handle)->flags & (flag)) == (flag))
@ -177,7 +160,7 @@ loader_init_callback (lt_dlhandle handle)
static int
loader_init (lt_get_vtable *vtable_func, lt_user_data data)
{
lt_user_dlloader *vtable = 0;
lt_dlloader *vtable = 0;
int errors = 0;
if (vtable_func)
@ -216,7 +199,7 @@ loader_init (lt_get_vtable *vtable_func, lt_user_data data)
#define get_vtable preopen_LTX_get_vtable
#define preloaded_symbols LT_CONC3(lt_, LTDLOPEN, _LTX_preloaded_symbols)
extern lt_user_dlloader * get_vtable (lt_user_data data);
extern lt_dlloader * get_vtable (lt_user_data data);
extern lt_dlsymlist preloaded_symbols;
/* Initialize libltdl. */
@ -2138,11 +2121,10 @@ lt_dlcaller_get_data (lt_dlcaller_id key, lt_dlhandle handle)
int
lt_dlloader_add (const struct lt_user_dlloader *dlloader,
lt_user_data data)
lt_dlloader_add (lt_dlloader *dlloader, lt_user_data data)
{
int errors = 0;
lt_dlloader *node = 0, *ptr = 0;
lt_dlloader *ptr = 0;
if ((dlloader == 0) /* diagnose null parameters */
|| (dlloader->module_open == 0)
@ -2153,35 +2135,19 @@ lt_dlloader_add (const struct lt_user_dlloader *dlloader,
return 1;
}
/* Create a new dlloader node with copies of the user callbacks. */
node = lt__malloc (sizeof *node);
if (!node)
return 1;
/* There is no need to record the dlloader->dlloader_init function,
since we won't need it again. */
node->next = 0;
node->loader_name = dlloader->name;
node->sym_prefix = dlloader->sym_prefix;
node->module_open = dlloader->module_open;
node->module_close = dlloader->module_close;
node->find_sym = dlloader->find_sym;
node->dlloader_exit = dlloader->dlloader_exit;
node->dlloader_data = dlloader->dlloader_data;
switch (dlloader->priority)
{
case LT_DLLOADER_PREPEND:
/* Tack NODE on the front of the LOADERS list. */
node->next = loaders;
loaders = node;
dlloader->next = loaders;
loaders = dlloader;
break;
case LT_DLLOADER_APPEND:
/* Add NODE to the end of the LOADERS list. */
for (ptr = loaders; ptr->next; ptr = ptr->next)
/*NOWORK*/;
ptr->next = node;
ptr->next = dlloader;
break;
default:
@ -2194,9 +2160,9 @@ lt_dlloader_add (const struct lt_user_dlloader *dlloader,
}
int
lt_dlloader_remove (const char *loader_name)
lt_dlloader_remove (const char *name)
{
lt_dlloader *place = lt_dlloader_find (loader_name);
lt_dlloader *place = lt_dlloader_find (name);
lt_dlhandle handle;
int errors = 0;
@ -2227,7 +2193,7 @@ lt_dlloader_remove (const char *loader_name)
lt_dlloader *prev;
for (prev = loaders; prev->next; prev = prev->next)
{
if (streq (prev->next->loader_name, loader_name))
if (streq (prev->next->name, name))
{
break;
}
@ -2260,7 +2226,7 @@ lt_dlloader_name (lt_dlloader *place)
if (place)
{
name = place ? place->loader_name : 0;
name = place ? place->name : 0;
}
else
{
@ -2288,13 +2254,13 @@ lt_dlloader_data (lt_dlloader *place)
}
lt_dlloader *
lt_dlloader_find (const char *loader_name)
lt_dlloader_find (const char *name)
{
lt_dlloader *place = 0;
for (place = loaders; place; place = place->next)
{
if (streq (place->loader_name, loader_name))
if (streq (place->name, name))
{
break;
}