1996-12-08 16:52:38 +00:00
|
|
|
/* dynl.c - dynamic linking
|
|
|
|
|
*
|
2003-11-08 22:18:33 +00:00
|
|
|
* Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002,
|
2010-01-04 12:21:02 +01:00
|
|
|
* 2003, 2008, 2009, 2010 Free Software Foundation, Inc.
|
1996-12-08 16:52:38 +00:00
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
1996-12-08 16:52:38 +00:00
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
1996-12-08 16:52:38 +00:00
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
*/
|
1996-12-08 16:52:38 +00:00
|
|
|
|
1999-12-12 02:36:16 +00:00
|
|
|
|
|
|
|
|
|
2008-09-13 15:35:27 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-12-08 16:52:38 +00:00
|
|
|
/* "dynl.c" dynamically link&load object files.
|
|
|
|
|
Author: Aubrey Jaffer
|
|
|
|
|
Modified for libguile by Marius Vollmer */
|
|
|
|
|
|
1998-05-02 22:26:44 +00:00
|
|
|
#if 0 /* Disabled until we know for sure that it isn't needed */
|
1997-01-18 11:40:31 +00:00
|
|
|
/* XXX - This is only here to drag in a definition of __eprintf. This
|
|
|
|
|
is needed for proper operation of dynamic linking. The real
|
|
|
|
|
solution would probably be a shared libgcc. */
|
|
|
|
|
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maybe_drag_in_eprintf ()
|
|
|
|
|
{
|
|
|
|
|
assert (!maybe_drag_in_eprintf);
|
|
|
|
|
}
|
1998-05-02 22:26:44 +00:00
|
|
|
#endif
|
1997-01-18 11:40:31 +00:00
|
|
|
|
1997-01-20 19:11:41 +00:00
|
|
|
#include <stdio.h>
|
2001-01-26 17:30:54 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
#include "libguile/_scm.h"
|
2009-09-16 18:10:19 +02:00
|
|
|
#include "libguile/libpath.h"
|
2000-04-21 14:16:44 +00:00
|
|
|
#include "libguile/dynl.h"
|
|
|
|
|
#include "libguile/smob.h"
|
|
|
|
|
#include "libguile/keywords.h"
|
|
|
|
|
#include "libguile/ports.h"
|
|
|
|
|
#include "libguile/strings.h"
|
2001-06-03 23:31:14 +00:00
|
|
|
#include "libguile/deprecation.h"
|
2002-01-22 23:31:39 +00:00
|
|
|
#include "libguile/lang.h"
|
2000-04-21 14:16:44 +00:00
|
|
|
#include "libguile/validate.h"
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
#include "libguile/dynwind.h"
|
2010-01-04 12:21:02 +01:00
|
|
|
#include "libguile/foreign.h"
|
1999-12-18 23:33:15 +00:00
|
|
|
|
2004-10-22 13:01:59 +00:00
|
|
|
#include <ltdl.h>
|
2000-01-10 00:36:26 +00:00
|
|
|
|
2002-08-04 14:09:14 +00:00
|
|
|
/*
|
|
|
|
|
From the libtool manual: "Note that libltdl is not threadsafe,
|
|
|
|
|
i.e. a multithreaded application has to use a mutex for libltdl.".
|
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
Guile does not currently support pre-emptive threads, so there is no
|
|
|
|
|
mutex. Previously SCM_CRITICAL_SECTION_START and
|
|
|
|
|
SCM_CRITICAL_SECTION_END were used: they are mentioned here in case
|
|
|
|
|
somebody is grepping for thread problems ;)
|
2002-06-30 20:34:38 +00:00
|
|
|
*/
|
2005-03-30 18:32:19 +00:00
|
|
|
/* njrev: not threadsafe, protection needed as described above */
|
2002-06-30 20:34:38 +00:00
|
|
|
|
2000-01-10 00:36:26 +00:00
|
|
|
static void *
|
2000-05-18 08:47:52 +00:00
|
|
|
sysdep_dynl_link (const char *fname, const char *subr)
|
2000-01-10 00:36:26 +00:00
|
|
|
{
|
2004-10-22 13:01:59 +00:00
|
|
|
lt_dlhandle handle;
|
|
|
|
|
handle = lt_dlopenext (fname);
|
2000-01-10 00:36:26 +00:00
|
|
|
if (NULL == handle)
|
|
|
|
|
{
|
2000-12-05 03:04:20 +00:00
|
|
|
SCM fn;
|
|
|
|
|
SCM msg;
|
|
|
|
|
|
* strings.h, strings.c: (scm_i_string_chars, scm_i_string_length,
scm_i_string_writable_chars, scm_i_string_stop_writing): New, to
replace SCM_I_STRING_CHARS and SCM_I_STRING_LENGTH. Updated all
uses.
(scm_i_make_string, scm_c_make_string): New, to replace
scm_allocate_string. Updated all uses.
(SCM_STRINGP, SCM_STRING_CHARS, SCM_STRING_UCHARS,
SCM_STRING_LENGTH): Deprecated.
(scm_allocate_string, scm_take_str, scm_take0str, scm_mem2string,
scm_str2string, scm_makfrom0str, scm_makfrom0str_opt):
Discouraged. Replaced all uses with scm_from_locale_string or
similar, as appropriate.
(scm_c_string_length, scm_c_string_ref, scm_c_string_set_x,
scm_c_substring, scm_c_substring_shared, scm_c_substring_copy,
scm_substring_shared, scm_substring_copy): New.
* symbols.c, symbols.h (SCM_SYMBOLP, SCM_SYMBOL_FUNC,
SCM_SET_SYMBOL_FUNC, SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS,
SCM_SYMBOL_HASH, SCM_SYMBOL_INTERNED_P, scm_mem2symbol,
scm_str2symbol, scm_mem2uninterned_symbol): Discouraged.
(SCM_SYMBOL_LENGTH, SCM_SYMBOL_CHARS, scm_c_symbol2str):
Deprecated.
(SCM_MAKE_SYMBOL_TAG, SCM_SET_SYMBOL_LENGTH, SCM_SET_SYMBOL_CHARS,
SCM_PROP_SLOTS, SCM_SET_PROP_SLOTS): Removed.
(scm_is_symbol, scm_from_locale_symbol, scm_from_locale_symboln):
New, to replace scm_str2symbol and scm_mem2symbol, respectively.
Updated all uses.
(scm_gensym): Generate only the number suffix in the buffer, just
string-append the prefix.
2004-08-19 17:19:44 +00:00
|
|
|
fn = scm_from_locale_string (fname);
|
2004-10-22 13:01:59 +00:00
|
|
|
msg = scm_from_locale_string (lt_dlerror ());
|
* list.h (scm_list_1, scm_list_2, scm_list_3, scm_list_4, scm_list_5,
scm_list_n): New functions.
(SCM_LIST0, SCM_LIST1, SCM_LIST2, SCM_LIST3, SCM_LIST4, SCM_LIST5,
SCM_LIST6, SCM_LIST7, SCM_LIST8, SCM_LIST9, scm_listify): Deprecated.
(lots of files): Use the new functions.
* goops.c (CALL_GF1, CALL_GF2, CALL_GF3, CALL_GF4): Use scm_call_N.
* strings.c: #include "libguile/deprecation.h".
2001-06-28 01:11:59 +00:00
|
|
|
scm_misc_error (subr, "file: ~S, message: ~S", scm_list_2 (fn, msg));
|
2000-01-10 00:36:26 +00:00
|
|
|
}
|
|
|
|
|
return (void *) handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sysdep_dynl_unlink (void *handle, const char *subr)
|
|
|
|
|
{
|
2004-10-22 13:01:59 +00:00
|
|
|
if (lt_dlclose ((lt_dlhandle) handle))
|
2000-01-10 00:36:26 +00:00
|
|
|
{
|
2004-10-22 13:01:59 +00:00
|
|
|
scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
|
2000-01-10 00:36:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
sysdep_dynl_func (const char *symb, void *handle, const char *subr)
|
|
|
|
|
{
|
|
|
|
|
void *fptr;
|
|
|
|
|
|
2004-10-22 13:01:59 +00:00
|
|
|
fptr = lt_dlsym ((lt_dlhandle) handle, symb);
|
2000-01-10 00:36:26 +00:00
|
|
|
if (!fptr)
|
|
|
|
|
{
|
2004-10-22 13:01:59 +00:00
|
|
|
scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
|
2000-01-10 00:36:26 +00:00
|
|
|
}
|
|
|
|
|
return fptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sysdep_dynl_init ()
|
|
|
|
|
{
|
2009-09-16 18:10:19 +02:00
|
|
|
char *env;
|
|
|
|
|
|
2004-10-22 13:01:59 +00:00
|
|
|
lt_dlinit ();
|
2009-09-16 18:10:19 +02:00
|
|
|
|
2009-10-13 11:31:02 +02:00
|
|
|
env = getenv ("GUILE_SYSTEM_EXTENSIONS_PATH");
|
2009-09-16 18:10:19 +02:00
|
|
|
if (env && strcmp (env, "") == 0)
|
|
|
|
|
/* special-case interpret system-ltdl-path=="" as meaning no system path,
|
|
|
|
|
which is the case during the build */
|
|
|
|
|
;
|
|
|
|
|
else if (env)
|
2009-10-13 11:31:02 +02:00
|
|
|
/* FIXME: should this be a colon-separated path? Or is the only point to
|
|
|
|
|
allow the build system to turn off the installed extensions path? */
|
2009-09-16 18:10:19 +02:00
|
|
|
lt_dladdsearchdir (env);
|
|
|
|
|
else
|
2009-10-13 11:31:02 +02:00
|
|
|
{
|
|
|
|
|
lt_dladdsearchdir (SCM_LIB_DIR);
|
|
|
|
|
lt_dladdsearchdir (SCM_EXTENSIONS_DIR);
|
|
|
|
|
}
|
2000-01-10 00:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
scm_t_bits scm_tc16_dynamic_obj;
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2004-05-06 16:43:14 +00:00
|
|
|
#define DYNL_FILENAME SCM_SMOB_OBJECT
|
|
|
|
|
#define DYNL_HANDLE(x) ((void *) SCM_SMOB_DATA_2 (x))
|
2004-05-15 15:39:27 +00:00
|
|
|
#define SET_DYNL_HANDLE(x, v) (SCM_SET_SMOB_DATA_2 ((x), (scm_t_bits) (v)))
|
2000-03-14 06:39:37 +00:00
|
|
|
|
|
|
|
|
|
2000-12-08 17:32:56 +00:00
|
|
|
|
1997-01-18 11:40:31 +00:00
|
|
|
static int
|
2000-12-08 17:32:56 +00:00
|
|
|
dynl_obj_print (SCM exp, SCM port, scm_print_state *pstate)
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
scm_puts ("#<dynamic-object ", port);
|
|
|
|
|
scm_iprin1 (DYNL_FILENAME (exp), port, pstate);
|
|
|
|
|
if (DYNL_HANDLE (exp) == NULL)
|
|
|
|
|
scm_puts (" (unlinked)", port);
|
|
|
|
|
scm_putc ('>', port);
|
|
|
|
|
return 1;
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
1999-06-21 15:16:54 +00:00
|
|
|
|
2000-05-18 08:47:52 +00:00
|
|
|
SCM_DEFINE (scm_dynamic_link, "dynamic-link", 1, 0, 0,
|
2001-04-03 13:19:05 +00:00
|
|
|
(SCM filename),
|
2002-07-10 22:20:16 +00:00
|
|
|
"Find the shared object (shared library) denoted by\n"
|
|
|
|
|
"@var{filename} and link it into the running Guile\n"
|
|
|
|
|
"application. The returned\n"
|
|
|
|
|
"scheme object is a ``handle'' for the library which can\n"
|
|
|
|
|
"be passed to @code{dynamic-func}, @code{dynamic-call} etc.\n\n"
|
|
|
|
|
"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}.")
|
1999-12-12 02:36:16 +00:00
|
|
|
#define FUNC_NAME s_scm_dynamic_link
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
void *handle;
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
char *file;
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2006-01-29 00:23:28 +00:00
|
|
|
scm_dynwind_begin (0);
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
file = scm_to_locale_string (filename);
|
2006-01-29 00:23:28 +00:00
|
|
|
scm_dynwind_free (file);
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
handle = sysdep_dynl_link (file, FUNC_NAME);
|
2006-01-29 00:23:28 +00:00
|
|
|
scm_dynwind_end ();
|
2001-04-03 13:19:05 +00:00
|
|
|
SCM_RETURN_NEWSMOB2 (scm_tc16_dynamic_obj, SCM_UNPACK (filename), handle);
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
#undef FUNC_NAME
|
1997-01-18 11:40:31 +00:00
|
|
|
|
|
|
|
|
|
2000-01-05 19:05:23 +00:00
|
|
|
SCM_DEFINE (scm_dynamic_object_p, "dynamic-object?", 1, 0, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
(SCM obj),
|
2002-07-10 22:20:16 +00:00
|
|
|
"Return @code{#t} if @var{obj} is a dynamic object handle,\n"
|
|
|
|
|
"or @code{#f} otherwise.")
|
1999-12-12 02:36:16 +00:00
|
|
|
#define FUNC_NAME s_scm_dynamic_object_p
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2004-07-06 10:59:25 +00:00
|
|
|
return scm_from_bool (SCM_TYP16_PREDICATE (scm_tc16_dynamic_obj, obj));
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
#undef FUNC_NAME
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-05-04 08:07:18 +00:00
|
|
|
|
2000-01-05 19:05:23 +00:00
|
|
|
SCM_DEFINE (scm_dynamic_unlink, "dynamic-unlink", 1, 0, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
(SCM dobj),
|
2002-07-10 22:20:16 +00:00
|
|
|
"Unlink a dynamic object from the application, if possible. The\n"
|
|
|
|
|
"object must have been linked by @code{dynamic-link}, with \n"
|
|
|
|
|
"@var{dobj} the corresponding handle. After this procedure\n"
|
|
|
|
|
"is called, the handle can no longer be used to access the\n"
|
|
|
|
|
"object.")
|
1999-12-12 02:36:16 +00:00
|
|
|
#define FUNC_NAME s_scm_dynamic_unlink
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
/*fixme* GC-problem */
|
2000-05-04 08:07:18 +00:00
|
|
|
SCM_VALIDATE_SMOB (SCM_ARG1, dobj, dynamic_obj);
|
|
|
|
|
if (DYNL_HANDLE (dobj) == NULL) {
|
2003-11-08 22:18:01 +00:00
|
|
|
SCM_MISC_ERROR ("Already unlinked: ~S", scm_list_1 (dobj));
|
2000-05-04 08:07:18 +00:00
|
|
|
} else {
|
|
|
|
|
sysdep_dynl_unlink (DYNL_HANDLE (dobj), FUNC_NAME);
|
|
|
|
|
SET_DYNL_HANDLE (dobj, NULL);
|
|
|
|
|
return SCM_UNSPECIFIED;
|
|
|
|
|
}
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
#undef FUNC_NAME
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-05-04 08:07:18 +00:00
|
|
|
|
2000-01-05 19:05:23 +00:00
|
|
|
SCM_DEFINE (scm_dynamic_func, "dynamic-func", 2, 0, 0,
|
2000-10-30 11:42:26 +00:00
|
|
|
(SCM name, SCM dobj),
|
2002-07-10 22:20:16 +00:00
|
|
|
"Return a ``handle'' for the function @var{name} in the\n"
|
|
|
|
|
"shared object referred to by @var{dobj}. The handle\n"
|
|
|
|
|
"can be passed to @code{dynamic-call} to actually\n"
|
|
|
|
|
"call the function.\n\n"
|
|
|
|
|
"Regardless whether your C compiler prepends an underscore\n"
|
|
|
|
|
"@samp{_} to the global names in a program, you should\n"
|
|
|
|
|
"@strong{not} include this underscore in @var{name}\n"
|
|
|
|
|
"since it will be added automatically when necessary.")
|
1999-12-12 02:36:16 +00:00
|
|
|
#define FUNC_NAME s_scm_dynamic_func
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
void (*func) ();
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-10-30 11:42:26 +00:00
|
|
|
SCM_VALIDATE_STRING (1, name);
|
2000-03-14 06:39:37 +00:00
|
|
|
/*fixme* GC-problem */
|
2000-05-04 08:07:18 +00:00
|
|
|
SCM_VALIDATE_SMOB (SCM_ARG2, dobj, dynamic_obj);
|
|
|
|
|
if (DYNL_HANDLE (dobj) == NULL) {
|
|
|
|
|
SCM_MISC_ERROR ("Already unlinked: ~S", dobj);
|
|
|
|
|
} else {
|
2000-09-26 18:37:26 +00:00
|
|
|
char *chars;
|
|
|
|
|
|
2006-01-29 00:23:28 +00:00
|
|
|
scm_dynwind_begin (0);
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
chars = scm_to_locale_string (name);
|
2006-01-29 00:23:28 +00:00
|
|
|
scm_dynwind_free (chars);
|
* numbers.h, numbers.c, discouraged.h, discouraged.c (scm_short2num,
scm_ushort2num, scm_int2num, scm_uint2num, scm_long2num,
scm_ulong2num, scm_size2num, scm_ptrdiff2num, scm_num2short,
scm_num2ushort, scm_num2int, scm_num2uint, scm_num2long,
scm_num2ulong, scm_num2size, scm_num2ptrdiff, scm_long_long2num,
scm_ulong_long2num, scm_num2long_long, scm_num2ulong_long):
Discouraged by moving to discouraged.h and discouraged.c and
reimplementing in terms of scm_from_* and scm_to_*. Changed all uses
to the new scm_from_* and scm_to_* functions.
2004-08-02 16:14:04 +00:00
|
|
|
func = (void (*) ()) sysdep_dynl_func (chars, DYNL_HANDLE (dobj),
|
|
|
|
|
FUNC_NAME);
|
2006-01-29 00:23:28 +00:00
|
|
|
scm_dynwind_end ();
|
2010-01-04 12:21:02 +01:00
|
|
|
return scm_c_from_foreign (SCM_FOREIGN_TYPE_POINTER, &func, 0, NULL);
|
2000-05-04 08:07:18 +00:00
|
|
|
}
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
#undef FUNC_NAME
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-05-04 08:07:18 +00:00
|
|
|
|
2000-01-05 19:05:23 +00:00
|
|
|
SCM_DEFINE (scm_dynamic_call, "dynamic-call", 2, 0, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
(SCM func, SCM dobj),
|
2002-07-09 22:40:03 +00:00
|
|
|
"Call a C function in a dynamic object. Two styles of\n"
|
|
|
|
|
"invocation are supported:\n\n"
|
|
|
|
|
"@itemize @bullet\n"
|
|
|
|
|
"@item @var{func} can be a function handle returned by\n"
|
|
|
|
|
"@code{dynamic-func}. In this case @var{dobj} is\n"
|
|
|
|
|
"ignored\n"
|
|
|
|
|
"@item @var{func} can be a string with the name of the\n"
|
|
|
|
|
"function to call, with @var{dobj} the handle of the\n"
|
|
|
|
|
"dynamic object in which to find the function.\n"
|
|
|
|
|
"This is equivalent to\n"
|
|
|
|
|
"@smallexample\n\n"
|
|
|
|
|
"(dynamic-call (dynamic-func @var{func} @var{dobj}) #f)\n"
|
|
|
|
|
"@end smallexample\n"
|
|
|
|
|
"@end itemize\n\n"
|
|
|
|
|
"In either case, the function is passed no arguments\n"
|
|
|
|
|
"and its return value is ignored.")
|
1999-12-12 02:36:16 +00:00
|
|
|
#define FUNC_NAME s_scm_dynamic_call
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
void (*fptr) ();
|
|
|
|
|
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
if (scm_is_string (func))
|
2000-03-14 06:39:37 +00:00
|
|
|
func = scm_dynamic_func (func, dobj);
|
2010-01-04 12:21:02 +01:00
|
|
|
SCM_VALIDATE_FOREIGN_TYPED (SCM_ARG1, func, POINTER);
|
|
|
|
|
|
|
|
|
|
fptr = SCM_FOREIGN_OBJECT_REF (func, void*);
|
2000-03-14 06:39:37 +00:00
|
|
|
fptr ();
|
|
|
|
|
return SCM_UNSPECIFIED;
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
#undef FUNC_NAME
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-01-05 19:05:23 +00:00
|
|
|
SCM_DEFINE (scm_dynamic_args_call, "dynamic-args-call", 3, 0, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
(SCM func, SCM dobj, SCM args),
|
2001-04-03 13:19:05 +00:00
|
|
|
"Call the C function indicated by @var{func} and @var{dobj},\n"
|
|
|
|
|
"just like @code{dynamic-call}, but pass it some arguments and\n"
|
|
|
|
|
"return its return value. The C function is expected to take\n"
|
|
|
|
|
"two arguments and return an @code{int}, just like @code{main}:\n"
|
* alist.c, chars.c, debug.c, dynl.c, dynwind.c, error.c, eval.c,
evalext.c, filesys.c, gc.c, hash.c, hashtab.c, ioext.c,
keywords.c, list.c, load.c, macros.c, net_db.c, numbers.c,
objprop.c, ports.c, posix.c, print.c, procprop.c, procs.c,
ramap.c, regex-posix.c, root.c, scmsigs.c, simpos.c, socket.c,
stacks.c, stime.c, strings.c, strop.c, strports.c, struct.c,
symbols.c, throw.c, unif.c, vectors.c, version.c, vports.c,
weaks.c: Converted docstrings to ANSI C format.
2000-01-18 11:24:03 +00:00
|
|
|
"@smallexample\n"
|
|
|
|
|
"int c_func (int argc, char **argv);\n"
|
|
|
|
|
"@end smallexample\n\n"
|
2001-04-03 13:19:05 +00:00
|
|
|
"The parameter @var{args} must be a list of strings and is\n"
|
|
|
|
|
"converted into an array of @code{char *}. The array is passed\n"
|
|
|
|
|
"in @var{argv} and its size in @var{argc}. The return value is\n"
|
|
|
|
|
"converted to a Scheme number and returned from the call to\n"
|
|
|
|
|
"@code{dynamic-args-call}.")
|
1999-12-12 02:36:16 +00:00
|
|
|
#define FUNC_NAME s_scm_dynamic_args_call
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
int (*fptr) (int argc, char **argv);
|
|
|
|
|
int result, argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
if (scm_is_string (func))
|
2000-03-14 06:39:37 +00:00
|
|
|
func = scm_dynamic_func (func, dobj);
|
2010-01-04 12:21:02 +01:00
|
|
|
SCM_VALIDATE_FOREIGN_TYPED (SCM_ARG1, func, POINTER);
|
2000-03-14 06:39:37 +00:00
|
|
|
|
2010-01-04 12:21:02 +01:00
|
|
|
fptr = SCM_FOREIGN_OBJECT_REF (func, void*);
|
* stime.c, socket.c, simpos.c, procs.c, posix.c, ports.c,
net_db.c, fports.c, filesys.c, eval.c, deprecation.c, dynl.c:
Replaced uses of SCM_STRING_CHARS with proper uses of
scm_to_locale_string. Replaced SCM_STRINGP with scm_is_string.
Replaced scm_mem2string with scm_from_locale_string.
* simpos.c, posix.c (allocate_string_pointers, environ_list_to_c):
Removed, replaced all uses with scm_i_allocate_string_pointers.
2004-08-10 14:08:02 +00:00
|
|
|
|
|
|
|
|
argv = scm_i_allocate_string_pointers (args);
|
|
|
|
|
for (argc = 0; argv[argc]; argc++)
|
|
|
|
|
;
|
2000-03-14 06:39:37 +00:00
|
|
|
result = (*fptr) (argc, argv);
|
|
|
|
|
|
2004-07-23 15:43:02 +00:00
|
|
|
return scm_from_int (result);
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
#undef FUNC_NAME
|
1997-01-18 11:40:31 +00:00
|
|
|
|
1996-12-08 16:52:38 +00:00
|
|
|
void
|
|
|
|
|
scm_init_dynamic_linking ()
|
|
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
scm_tc16_dynamic_obj = scm_make_smob_type ("dynamic-object", 0);
|
2000-12-08 17:32:56 +00:00
|
|
|
scm_set_smob_print (scm_tc16_dynamic_obj, dynl_obj_print);
|
2000-03-14 06:39:37 +00:00
|
|
|
sysdep_dynl_init ();
|
2000-04-21 14:16:44 +00:00
|
|
|
#include "libguile/dynl.x"
|
1996-12-08 16:52:38 +00:00
|
|
|
}
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Local Variables:
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
End:
|
|
|
|
|
*/
|