From 8bd0890c7ba838e8c979578cf9dc13118bdffee0 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Thu, 8 Jul 2004 09:35:51 +0000 Subject: [PATCH] * libltdl/ltdl.h (lt_dlinfo): Move private module field to here... * libltdl/ltdl.c (lt_dlhandle_struct): ...from here. Changed all callers. * libltdl/loader-loadlibrary.c (sys_wll_open): Use new inteface to scan loaded handle->info.module fields for previously loaded modules. * doc/libtool.texi (User defined module data): Document changes to the interface. * NEWS: Updated. Reported by Chuck Wilson --- ChangeLog | 13 +++++++++++++ NEWS | 1 + doc/libtool.texi | 7 +++++-- libltdl/loader-loadlibrary.c | 12 +++++------- libltdl/ltdl.c | 11 +++++------ libltdl/ltdl.h | 10 ++++++---- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10fb8d91..b96dd09a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2004-07-08 Gary V. Vaughan + + * libltdl/ltdl.h (lt_dlinfo): Move private module field to here... + * libltdl/ltdl.c (lt_dlhandle_struct): ...from here. Changed all + callers. + * libltdl/loader-loadlibrary.c (sys_wll_open): Use new inteface to + scan loaded handle->info.module fields for previously loaded + modules. + * doc/libtool.texi (User defined module data): Document changes to + the interface. + * NEWS: Updated. + Reported by Chuck Wilson + 2004-07-07 Brad * m4/libtool.m4: Fixes for the OpenBSD support diff --git a/NEWS b/NEWS index bf4ab10c..d18a3395 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,7 @@ New in 1.5b: 2004-??-??; CVS version 1.5a, Libtool team: The symbols are deprecated but exported for backwards compatibility. * libltdl no longer uses lt_dlmalloc, lt_dlrealloc and lt_dlfree. The symbols are still exported for backwards compatibility. +* The lt_dlinfo struct has a new module field that can be used by dlloaders. * libltdl no longer supports pre-c89 compilers. Some of the pre89 portability functions had compile time bugs in them anyway, so you guys can't have been using it :-) diff --git a/doc/libtool.texi b/doc/libtool.texi index b3c4cd41..9afdd3aa 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -3329,14 +3329,17 @@ Some of the internal information about each loaded module that is maintained by libltdl is available to the user, in the form of this structure: -@deftypefn {Type} {struct} lt_dlinfo @{ @w{char *@var{filename};} @w{char *@var{name};} @w{int @var{ref_count};} @} +@deftypefn {Type} {struct} lt_dlinfo @{ @w{char *@var{filename};} @w{char *@var{name};} @w{int @var{ref_count};} @w{lt_module @var{module};}@} @code{lt_dlinfo} is used to store information about a module. The @var{filename} attribute is a null-terminated character string of the real module file name. If the module is a libtool module then @var{name} is its module name (e.g. @code{"libfoo"} for @code{"dir/libfoo.la"}), otherwise it is set to @code{NULL}. The @var{ref_count} attribute is a reference counter that describes how -often the same module is currently loaded. +often the same module is currently loaded. @var{module} is the +dlloader's internal handle for the native module, and can be used, for +example, by a loader to check whether @var{module} has already been +loaded to save loading it again. @end deftypefn The following function will return a pointer to libltdl's internal copy diff --git a/libltdl/loader-loadlibrary.c b/libltdl/loader-loadlibrary.c index 8e56e40d..535ebc1a 100644 --- a/libltdl/loader-loadlibrary.c +++ b/libltdl/loader-loadlibrary.c @@ -38,7 +38,7 @@ static lt_dlhandle handles; static lt_module sys_wll_open (lt_user_data loader_data, const char *filename) { - lt_dlhandle cur; + lt_dlhandle cur = 0; lt_module module = 0; const char *errormsg = 0; char *searchname = 0; @@ -92,21 +92,19 @@ sys_wll_open (lt_user_data loader_data, const char *filename) We check whether LoadLibrary is returning a handle to an already loaded module, and simulate failure if we find one. */ - cur = handles; - while (cur) + while (cur = lt_dlhandle_next (cur)) { - if (!cur->module) + const lt_dlinfo *info = lt_dlgetinfo (cur); + if (!info->module) { cur = 0; break; } - if (cur->module == module) + if (info->module == module) { break; } - - cur = cur->next; } if (cur || !module) diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 3ab2719d..81c801bd 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -91,7 +91,6 @@ struct lt_dlhandle_struct { lt_dlinfo info; int depcount; /* number of dependencies */ lt_dlhandle *deplibs; /* dependencies */ - lt_module module; /* system module handle */ void * system; /* system specific data */ lt_caller_data *caller_data; /* per caller associated data */ int flags; /* various boolean stats */ @@ -404,9 +403,9 @@ tryall_dlopen (lt_dlhandle *handle, const char *filename) { lt_user_data data = loader->dlloader_data; - cur->module = loader->module_open (data, filename); + cur->info.module = loader->module_open (data, filename); - if (cur->module != 0) + if (cur->info.module != 0) { break; } @@ -1712,7 +1711,7 @@ lt_dlclose (lt_dlhandle handle) handles = handle->next; } - errors += handle->loader->module_close (data, handle->module); + errors += handle->loader->module_close (data, handle->info.module); errors += unload_deplibs(handle); /* It is up to the callers to free the data itself. */ @@ -1795,7 +1794,7 @@ lt_dlsym (lt_dlhandle handle, const char *symbol) strcat(sym, symbol); /* try "modulename_LTX_symbol" */ - address = handle->loader->find_sym (data, handle->module, sym); + address = handle->loader->find_sym (data, handle->info.module, sym); if (address) { if (sym != lsym) @@ -1818,7 +1817,7 @@ lt_dlsym (lt_dlhandle handle, const char *symbol) strcpy(sym, symbol); } - address = handle->loader->find_sym (data, handle->module, sym); + address = handle->loader->find_sym (data, handle->info.module, sym); if (sym != lsym) { FREE (sym); diff --git a/libltdl/ltdl.h b/libltdl/ltdl.h index fcf076b5..bf907f4d 100644 --- a/libltdl/ltdl.h +++ b/libltdl/ltdl.h @@ -1,5 +1,5 @@ /* ltdl.h -- generic dlopen functions - Copyright (C) 1998-2000 Free Software Foundation, Inc. + Copyright (C) 1998-2000, 2004 Free Software Foundation, Inc. Originally by Thomas Tanner NOTE: The canonical source of this file is maintained with the @@ -32,6 +32,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #include #include +#include LT_BEGIN_C_DECLS @@ -101,10 +102,11 @@ LT_SCOPE int lt_dlpreload_default (const lt_dlsymlist *preloaded); /* Read only information pertaining to a loaded module. */ typedef struct { - char *filename; /* file name */ - char *name; /* module name */ - int ref_count; /* number of times lt_dlopened minus + char * filename; /* file name */ + char * name; /* module name */ + int ref_count; /* number of times lt_dlopened minus number of times lt_dlclosed. */ + lt_module module; /* system module handle */ } lt_dlinfo; LT_SCOPE const lt_dlinfo *lt_dlgetinfo (lt_dlhandle handle);