1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Implement ltdl-like directory search for modules

Search LTDL_LIBRARY_PATH and LD_LIBRARY_PATH before
the system extensions path.

* dynl.c (sysdep_dynl_link_search): new procedure
  (sysdep_dynl_link): search library paths
This commit is contained in:
Mike Gran 2020-03-24 14:55:21 -07:00
parent f6373cf69f
commit bcce103393

View file

@ -67,24 +67,15 @@ static scm_i_pthread_mutex_t ltdl_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
static char *system_extensions_path; static char *system_extensions_path;
static void * static void *
sysdep_dynl_link (const char *fname, const char *subr) sysdep_dynl_link_search (const char *fname, const char *subr, char *library_path)
{ {
GModule *handle; GModule *handle = NULL;
/* Try the literal filename first or, if NULL, the program itself */ if (library_path == NULL || strlen(library_path) == 0)
handle = g_module_open (fname, 0); return NULL;
if (handle == NULL
#ifdef LT_DIRSEP_CHAR
&& strchr (fname, LT_DIRSEP_CHAR) == NULL
#endif
&& strchr (fname, '/') == NULL)
{
/* FNAME contains no directory separators and was not in the
usual library search paths, so now we search for it in
SYSTEM_EXTENSIONS_PATH. */
char *fname_attempt char *fname_attempt
= scm_gc_malloc_pointerless (strlen (system_extensions_path) = scm_gc_malloc_pointerless (strlen (library_path)
+ strlen (fname) + 2, + strlen (fname) + 2,
"dynl fname_attempt"); "dynl fname_attempt");
char *path; /* remaining path to search */ char *path; /* remaining path to search */
@ -92,7 +83,7 @@ sysdep_dynl_link (const char *fname, const char *subr)
char *s; char *s;
/* Iterate over the components of SYSTEM_EXTENSIONS_PATH */ /* Iterate over the components of SYSTEM_EXTENSIONS_PATH */
for (path = system_extensions_path; for (path = library_path;
*path != '\0'; *path != '\0';
path = (*end == '\0') ? end : (end + 1)) path = (*end == '\0') ? end : (end + 1))
{ {
@ -126,6 +117,38 @@ sysdep_dynl_link (const char *fname, const char *subr)
if (handle != NULL) if (handle != NULL)
break; break;
} }
return handle;
}
static void *
sysdep_dynl_link (const char *fname, const char *subr)
{
GModule *handle;
/* Try the literal filename first or, if NULL, the program itself */
handle = g_module_open (fname, 0);
if (handle == NULL && fname != NULL
#ifdef LT_DIRSEP_CHAR
&& strchr (fname, LT_DIRSEP_CHAR) == NULL
#endif
&& strchr (fname, '/') == NULL)
{
/* FNAME contains no directory separators and was not in the
usual library search paths, so now we search for it in
LTDL_LIBRARY_PATH, LD_LIBRARY_PATH, and SYSTEM_EXTENSIONS_PATH. */
handle = sysdep_dynl_link_search (fname, subr, getenv("LTDL_LIBRARY_PATH"));
if (!handle)
handle = sysdep_dynl_link_search (fname, subr, getenv("LD_LIBRARY_PATH"));
if (!handle)
handle = sysdep_dynl_link_search (fname, subr, system_extensions_path);
if (!handle)
{
SCM fn;
fn = fname != NULL ? scm_from_locale_string (fname) : SCM_BOOL_F;
scm_misc_error (subr, "module ~S not found in search paths", scm_list_1 (fn));
}
} }
if (handle == NULL) if (handle == NULL)
@ -135,7 +158,7 @@ sysdep_dynl_link (const char *fname, const char *subr)
fn = fname != NULL ? scm_from_locale_string (fname) : SCM_BOOL_F; fn = fname != NULL ? scm_from_locale_string (fname) : SCM_BOOL_F;
msg = scm_from_locale_string (g_module_error ()); msg = scm_from_locale_string (g_module_error ());
scm_misc_error (subr, "file: ~S, message: ~S", scm_list_2 (fn, msg)); scm_misc_error (subr, "module ~S not found, message: ~S", scm_list_2 (fn, msg));
} }
return (void *) handle; return (void *) handle;