Go to the first, previous, next, last section, table of contents.
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:
lt_dlinfo
is used to store information about a module.
The filename attribute is a null-terminated character string of
the real module file name. If the module is a libtool module then
name is its module name (e.g. "libfoo"
for
"dir/libfoo.la"
), otherwise it is set to NULL
. The
ref_count attribute is a reference counter that describes how
often the same module is currently loaded.
The following function will return a pointer to libltdl's internal copy of this structure for the given handle:
NULL
on failure.
Furthermore, in order to save you from having to keep a list of the handles of all the modules you have loaded, these functions allow you to iterate over libltdl's list of loaded modules:
lt_dlforeach
.
As soon as func returns a non-zero value for one of the handles,
lt_dlforeach
will stop calling func and immediately return 1.
Otherwise 0 is returned.
NULL
, and the next one on subsequent calls.
If place is the last element in the list of loaded modules, this
function returns NULL
.
Of course, you would still need to maintain your own list of loaded module handles to parallel the list maintained by libltdl if there are any other data that you need to associate with each handle for the purposes of your application. However, if you use the following API calls to associate your application data with individual module handles as they are loaded there is actually no need to do that. You must first obtain a unique caller id from libltdl which you subsequently use to retrieve the data you stored earlier. This allows for different libraries that each wish to store their own data against loaded modules to do so without interfering with one another's data.
lt_dlerror()
.
For example, to correctly remove some associated data:
lt_ptr stale = lt_dlcaller_set_data (key, handle, 0); if (stale == NULL) { char *error_msg = lt_dlerror (); if (error_msg != NULL) { my_error_handler (error_msg); return STATUS_FAILED; } } else { free (stale); }
NULL
if there is none.
The preceding functions can be combined with lt_dlforeach
to
implement search and apply operations without the need for your
application to track the modules that have been loaded and unloaded:
int my_dlcaller_callback (lt_dlhandle handle, lt_ptr key_ptr) { struct my_module_data *my_data; my_data = lt_dlcaller_get_data (handle, (lt_dlcaller_id) *key_ptr); return process (my_data); } int my_dlcaller_foreach (lt_dlcaller_id key) { lt_dlforeach (my_dlcaller_callback, (lt_ptr) &key); }
Go to the first, previous, next, last section, table of contents.