summaryrefslogtreecommitdiff
path: root/libguile/dynl.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-03-17 00:51:22 +0100
committerLudovic Courtès <ludo@gnu.org>2010-03-17 00:54:01 +0100
commitd12f974b4389f11a2f5fe47f6ca786514cb3bbc9 (patch)
treecdcf0debe7eebfd49d60410509f30d570ec8f619 /libguile/dynl.c
parentdd1464bf38c5e2dc71652b62f63e4bcf93179a14 (diff)
downloadguile-d12f974b4389f11a2f5fe47f6ca786514cb3bbc9.tar.gz
Change `dynamic-link' to return a global handle when the argument is omitted.
* libguile/dynl.c (sysdep_dynl_link): Handle FNAME == NULL. (scm_dynamic_link): Make argument optional. Adjust body accordingly. * test-suite/standalone/test-ffi (global, strerror, strlen): New bindings. Add test for these bindings. * doc/ref/api-modules.texi (Low level dynamic linking): Update description of `dynamic-link'.
Diffstat (limited to 'libguile/dynl.c')
-rw-r--r--libguile/dynl.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/libguile/dynl.c b/libguile/dynl.c
index 91d4ea135..a204e93d7 100644
--- a/libguile/dynl.c
+++ b/libguile/dynl.c
@@ -77,16 +77,23 @@ static void *
sysdep_dynl_link (const char *fname, const char *subr)
{
lt_dlhandle handle;
- handle = lt_dlopenext (fname);
+
+ if (fname != NULL)
+ handle = lt_dlopenext (fname);
+ else
+ /* Return a handle for the program as a whole. */
+ handle = lt_dlopen (NULL);
+
if (NULL == handle)
{
SCM fn;
SCM msg;
- fn = scm_from_locale_string (fname);
+ fn = fname != NULL ? scm_from_locale_string (fname) : SCM_BOOL_F;
msg = scm_from_locale_string (lt_dlerror ());
scm_misc_error (subr, "file: ~S, message: ~S", scm_list_2 (fn, msg));
}
+
return (void *) handle;
}
@@ -155,7 +162,7 @@ dynl_obj_print (SCM exp, SCM port, scm_print_state *pstate)
}
-SCM_DEFINE (scm_dynamic_link, "dynamic-link", 1, 0, 0,
+SCM_DEFINE (scm_dynamic_link, "dynamic-link", 0, 1, 0,
(SCM filename),
"Find the shared object (shared library) denoted by\n"
"@var{filename} and link it into the running Guile\n"
@@ -165,18 +172,33 @@ SCM_DEFINE (scm_dynamic_link, "dynamic-link", 1, 0, 0,
"Searching for object files is system dependent. Normally,\n"
"if @var{filename} does have an explicit directory it will\n"
"be searched for in locations\n"
- "such as @file{/usr/lib} and @file{/usr/local/lib}.")
+ "such as @file{/usr/lib} and @file{/usr/local/lib}.\n\n"
+ "When @var{filename} is omitted, a @dfn{global symbol handle} is\n"
+ "returned. This handle provides access to the symbols\n"
+ "available to the program at run-time, including those exported\n"
+ "by the program itself and the shared libraries already loaded.\n")
#define FUNC_NAME s_scm_dynamic_link
{
void *handle;
char *file;
scm_dynwind_begin (0);
- file = scm_to_locale_string (filename);
- scm_dynwind_free (file);
+
+ if (SCM_UNBNDP (filename))
+ file = NULL;
+ else
+ {
+ file = scm_to_locale_string (filename);
+ scm_dynwind_free (file);
+ }
+
handle = sysdep_dynl_link (file, FUNC_NAME);
scm_dynwind_end ();
- SCM_RETURN_NEWSMOB2 (scm_tc16_dynamic_obj, SCM_UNPACK (filename), handle);
+
+ SCM_RETURN_NEWSMOB2 (scm_tc16_dynamic_obj,
+ SCM_UNBNDP (filename)
+ ? SCM_UNPACK (SCM_BOOL_F) : SCM_UNPACK (filename),
+ handle);
}
#undef FUNC_NAME