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,
|
2011-02-12 12:25:18 +01:00
|
|
|
* 2003, 2008, 2009, 2010, 2011 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
|
|
|
|
|
|
2011-02-12 12:25:18 +01:00
|
|
|
#include <alloca.h>
|
2012-11-27 17:44:38 -05:00
|
|
|
#include <string.h>
|
2011-02-12 12:25:18 +01:00
|
|
|
|
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
|
|
|
|
2011-02-12 12:25:18 +01:00
|
|
|
#include <stdlib.h>
|
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"
|
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"
|
2012-11-27 17:44:38 -05:00
|
|
|
#include "libguile/gc.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.".
|
2002-06-30 20:34:38 +00:00
|
|
|
*/
|
2016-11-01 23:13:17 +01:00
|
|
|
static scm_i_pthread_mutex_t ltdl_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
2012-11-27 17:44:38 -05:00
|
|
|
|
|
|
|
|
/* LT_PATH_SEP-separated extension library search path, searched last */
|
|
|
|
|
static char *system_extensions_path;
|
|
|
|
|
|
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;
|
2010-03-17 00:51:22 +01:00
|
|
|
|
2012-11-27 17:44:38 -05:00
|
|
|
if (fname == NULL)
|
2010-03-17 00:51:22 +01:00
|
|
|
/* Return a handle for the program as a whole. */
|
|
|
|
|
handle = lt_dlopen (NULL);
|
2012-11-27 17:44:38 -05:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
handle = lt_dlopenext (fname);
|
2010-03-17 00:51:22 +01:00
|
|
|
|
2012-11-27 17:44:38 -05:00
|
|
|
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
|
|
|
|
|
= scm_gc_malloc_pointerless (strlen (system_extensions_path)
|
|
|
|
|
+ strlen (fname) + 2,
|
|
|
|
|
"dynl fname_attempt");
|
|
|
|
|
char *path; /* remaining path to search */
|
|
|
|
|
char *end; /* end of current path component */
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
/* Iterate over the components of SYSTEM_EXTENSIONS_PATH */
|
|
|
|
|
for (path = system_extensions_path;
|
|
|
|
|
*path != '\0';
|
|
|
|
|
path = (*end == '\0') ? end : (end + 1))
|
|
|
|
|
{
|
|
|
|
|
/* Find end of path component */
|
|
|
|
|
end = strchr (path, LT_PATHSEP_CHAR);
|
|
|
|
|
if (end == NULL)
|
|
|
|
|
end = strchr (path, '\0');
|
|
|
|
|
|
|
|
|
|
/* Skip empty path components */
|
|
|
|
|
if (path == end)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Construct FNAME_ATTEMPT, starting with path component */
|
|
|
|
|
s = fname_attempt;
|
|
|
|
|
memcpy (s, path, end - path);
|
|
|
|
|
s += end - path;
|
|
|
|
|
|
|
|
|
|
/* Append directory separator, but avoid duplicates */
|
|
|
|
|
if (s[-1] != '/'
|
|
|
|
|
#ifdef LT_DIRSEP_CHAR
|
|
|
|
|
&& s[-1] != LT_DIRSEP_CHAR
|
|
|
|
|
#endif
|
|
|
|
|
)
|
|
|
|
|
*s++ = '/';
|
|
|
|
|
|
|
|
|
|
/* Finally, append FNAME (including null terminator) */
|
|
|
|
|
strcpy (s, fname);
|
|
|
|
|
|
|
|
|
|
/* Try to load it, and terminate the search if successful */
|
|
|
|
|
handle = lt_dlopenext (fname_attempt);
|
|
|
|
|
if (handle != NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (handle == NULL)
|
2000-01-10 00:36:26 +00:00
|
|
|
{
|
2000-12-05 03:04:20 +00:00
|
|
|
SCM fn;
|
|
|
|
|
SCM msg;
|
|
|
|
|
|
2010-03-17 00:51:22 +01:00
|
|
|
fn = fname != NULL ? scm_from_locale_string (fname) : SCM_BOOL_F;
|
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
|
|
|
}
|
2010-03-17 00:51:22 +01:00
|
|
|
|
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 *
|
foreign.h presents a more pointer-centric interface
* libguile/foreign.c:
* libguile/foreign.h: Rework interface to be more pointer-centric.
Details are:
(SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the
pointer in a foreign is first-class. If it points to a native type
like uint32, then it still has a tag; but if it points to something
else, like a struct or a pointer or something, then its type is VOID
(i.e., void*).
(SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT.
(SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from
SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that
they only work with value types.
(SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign
pointer in question has a finalizer registered.
(SCM_FOREIGN_LEN): For void* pointers, optionally store the length in
bytes of the associated memory region.
(SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P.
(SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE.
(scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove
scm_c_from_foreign.
(scm_foreign_type): New accessor.
(scm_foreign_ref, scm_foreign_set_x): Take some optional args, used
when dereferencing void pointers.
* libguile/dynl.h:
* libguile/dynl.c (scm_dynamic_pointer): New function, used by
scm_dynamic_func. Adapt code to foreign.h changes.
* libguile/goops.c (scm_enable_primitive_generic_x)
(scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro.
* libguile/gsubr.c (create_gsubr): Adapt to API change.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer
directly, not indirected.
* libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr
pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change.
* libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-18 11:42:35 +01:00
|
|
|
sysdep_dynl_value (const char *symb, void *handle, const char *subr)
|
2000-01-10 00:36:26 +00:00
|
|
|
{
|
|
|
|
|
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)
|
2011-03-30 20:42:37 -07:00
|
|
|
scm_misc_error (subr, "Symbol not found: ~a",
|
|
|
|
|
scm_list_1 (scm_from_locale_string (symb)));
|
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
|
|
|
|
2012-11-27 17:44:38 -05:00
|
|
|
/* Initialize 'system_extensions_path' from
|
|
|
|
|
$GUILE_SYSTEM_EXTENSIONS_PATH, or if that's not set:
|
|
|
|
|
<SCM_LIB_DIR> <LT_PATHSEP_CHAR> <SCM_EXTENSIONS_DIR>.
|
|
|
|
|
|
|
|
|
|
'lt_dladdsearchdir' can't be used because it is searched before
|
|
|
|
|
the system-dependent search path, which is the one 'libtool
|
|
|
|
|
--mode=execute -dlopen' fiddles with (info "(libtool) Libltdl
|
|
|
|
|
Interface"). See
|
|
|
|
|
<http://lists.gnu.org/archive/html/guile-devel/2010-11/msg00095.html>.
|
|
|
|
|
|
|
|
|
|
The environment variables $LTDL_LIBRARY_PATH and $LD_LIBRARY_PATH
|
|
|
|
|
can't be used because they would be propagated to subprocesses
|
|
|
|
|
which may cause problems for other programs. See
|
|
|
|
|
<http://lists.gnu.org/archive/html/guile-devel/2012-09/msg00037.html> */
|
|
|
|
|
|
2009-10-13 11:31:02 +02:00
|
|
|
env = getenv ("GUILE_SYSTEM_EXTENSIONS_PATH");
|
2012-11-27 17:44:38 -05:00
|
|
|
if (env)
|
|
|
|
|
system_extensions_path = env;
|
2009-09-16 18:10:19 +02:00
|
|
|
else
|
2009-10-13 11:31:02 +02:00
|
|
|
{
|
2012-11-27 17:44:38 -05:00
|
|
|
system_extensions_path
|
|
|
|
|
= scm_gc_malloc_pointerless (strlen (SCM_LIB_DIR)
|
|
|
|
|
+ strlen (SCM_EXTENSIONS_DIR) + 2,
|
|
|
|
|
"system_extensions_path");
|
|
|
|
|
sprintf (system_extensions_path, "%s%c%s",
|
|
|
|
|
SCM_LIB_DIR, LT_PATHSEP_CHAR, SCM_EXTENSIONS_DIR);
|
2009-10-13 11:31:02 +02:00
|
|
|
}
|
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
|
|
|
{
|
2016-04-26 23:07:28 +02:00
|
|
|
scm_puts ("#<dynamic-object ", port);
|
2000-03-14 06:39:37 +00:00
|
|
|
scm_iprin1 (DYNL_FILENAME (exp), port, pstate);
|
|
|
|
|
if (DYNL_HANDLE (exp) == NULL)
|
2016-04-26 23:07:28 +02:00
|
|
|
scm_puts (" (unlinked)", port);
|
2016-04-26 23:01:14 +02:00
|
|
|
scm_putc ('>', port);
|
2000-03-14 06:39:37 +00:00
|
|
|
return 1;
|
1997-01-18 11:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
1999-06-21 15:16:54 +00:00
|
|
|
|
2010-03-17 00:51:22 +01:00
|
|
|
SCM_DEFINE (scm_dynamic_link, "dynamic-link", 0, 1, 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"
|
2010-03-17 00:51:22 +01:00
|
|
|
"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")
|
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);
|
2016-12-07 20:01:00 +01:00
|
|
|
scm_i_dynwind_pthread_mutex_lock (<dl_lock);
|
2010-03-17 00:51:22 +01:00
|
|
|
|
|
|
|
|
if (SCM_UNBNDP (filename))
|
|
|
|
|
file = NULL;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
file = scm_to_locale_string (filename);
|
|
|
|
|
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 ();
|
2010-03-17 00:51:22 +01:00
|
|
|
|
|
|
|
|
SCM_RETURN_NEWSMOB2 (scm_tc16_dynamic_obj,
|
|
|
|
|
SCM_UNBNDP (filename)
|
|
|
|
|
? SCM_UNPACK (SCM_BOOL_F) : 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);
|
2016-11-01 23:13:17 +01:00
|
|
|
|
|
|
|
|
scm_dynwind_begin (0);
|
2016-12-07 20:01:00 +01:00
|
|
|
scm_i_dynwind_pthread_mutex_lock (<dl_lock);
|
2000-05-04 08:07:18 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2016-11-01 23:13:17 +01:00
|
|
|
scm_dynwind_end ();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
Simplify the (system foreign) API.
Suggested by Neil Jerram.
* libguile/foreign.h (SCM_FOREIGN_TYPE, SCM_FOREIGN_VALUE_REF,
SCM_FOREIGN_VALUE_SET, SCM_FOREIGN_LEN, SCM_FOREIGN_TYPED_P,
SCM_FOREIGN_VALUE_P, SCM_VALIDATE_FOREIGN_VALUE, scm_foreign_set_x,
scm_foreign_type): Remove.
(scm_foreign_ref): Rename to...
(scm_foreign_address): ... this.
(scm_take_foreign_pointer): Update.
(SCM_FOREIGN_POINTER): Remove CTYPE argument. Update callers.
(scm_make_pointer): New declaration.
* libguile/foreign.c (scm_to_uintptr, scm_from_uintptr): New macros.
(scm_make_pointer): New function.
(scm_take_foreign_pointer): Remove TYPE and LEN arguments. Update
callers.
(scm_foreign_ref): Remove to...
(scm_foreign_address): ... this. Remove type-related code.
(scm_foreign_set_x): Remove.
(scm_foreign_to_bytevector): Change argument order; make LEN argument
compulsory.
(scm_i_foreign_print): Remove type printing.
(unpack): Remove foreign-type checking.
* libguile/deprecated.c (scm_dynamic_args_call): Update accordingly.
* libguile/dynl.c (scm_dynamic_pointer): Remove the TYPE and LEN
arguments; update callers. Update to the new foreign API.
* libguile/dynl.h (scm_dynamic_pointer): Update.
* libguile/gsubr.c (create_gsubr): Update to the new foreign API.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Ditto.
* libguile/snarf.h (SCM_IMMUTABLE_FOREIGN): Ditto.
* libguile/vm-i-system.c (subr_call): Ditto.
* module/system/foreign.scm (null-pointer?): New procedure.
* test-suite/standalone/test-ffi: Update to the new
`bytevector->foreign' signature.
* test-suite/tests/foreign.test ("null pointer")["null pointer
identity", "null-pointer? %null-pointer"]: New tests.
["foreign-set! other-null-pointer", "foreign->bytevector
other-null-pointer"]: Remove.
("make-pointer", "foreign<->bytevector"): New test prefixes.
2010-07-26 17:44:43 +02:00
|
|
|
SCM_DEFINE (scm_dynamic_pointer, "dynamic-pointer", 2, 0, 0,
|
|
|
|
|
(SCM name, SCM dobj),
|
2010-07-28 12:01:54 +02:00
|
|
|
"Return a ``wrapped pointer'' to the symbol @var{name}\n"
|
|
|
|
|
"in the shared object referred to by @var{dobj}. The returned\n"
|
|
|
|
|
"pointer points to a C object.\n\n"
|
2002-07-10 22:20:16 +00:00
|
|
|
"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.")
|
foreign.h presents a more pointer-centric interface
* libguile/foreign.c:
* libguile/foreign.h: Rework interface to be more pointer-centric.
Details are:
(SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the
pointer in a foreign is first-class. If it points to a native type
like uint32, then it still has a tag; but if it points to something
else, like a struct or a pointer or something, then its type is VOID
(i.e., void*).
(SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT.
(SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from
SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that
they only work with value types.
(SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign
pointer in question has a finalizer registered.
(SCM_FOREIGN_LEN): For void* pointers, optionally store the length in
bytes of the associated memory region.
(SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P.
(SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE.
(scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove
scm_c_from_foreign.
(scm_foreign_type): New accessor.
(scm_foreign_ref, scm_foreign_set_x): Take some optional args, used
when dereferencing void pointers.
* libguile/dynl.h:
* libguile/dynl.c (scm_dynamic_pointer): New function, used by
scm_dynamic_func. Adapt code to foreign.h changes.
* libguile/goops.c (scm_enable_primitive_generic_x)
(scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro.
* libguile/gsubr.c (create_gsubr): Adapt to API change.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer
directly, not indirected.
* libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr
pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change.
* libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-18 11:42:35 +01:00
|
|
|
#define FUNC_NAME s_scm_dynamic_pointer
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
foreign.h presents a more pointer-centric interface
* libguile/foreign.c:
* libguile/foreign.h: Rework interface to be more pointer-centric.
Details are:
(SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the
pointer in a foreign is first-class. If it points to a native type
like uint32, then it still has a tag; but if it points to something
else, like a struct or a pointer or something, then its type is VOID
(i.e., void*).
(SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT.
(SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from
SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that
they only work with value types.
(SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign
pointer in question has a finalizer registered.
(SCM_FOREIGN_LEN): For void* pointers, optionally store the length in
bytes of the associated memory region.
(SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P.
(SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE.
(scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove
scm_c_from_foreign.
(scm_foreign_type): New accessor.
(scm_foreign_ref, scm_foreign_set_x): Take some optional args, used
when dereferencing void pointers.
* libguile/dynl.h:
* libguile/dynl.c (scm_dynamic_pointer): New function, used by
scm_dynamic_func. Adapt code to foreign.h changes.
* libguile/goops.c (scm_enable_primitive_generic_x)
(scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro.
* libguile/gsubr.c (create_gsubr): Adapt to API change.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer
directly, not indirected.
* libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr
pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change.
* libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-18 11:42:35 +01:00
|
|
|
void *val;
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-10-30 11:42:26 +00:00
|
|
|
SCM_VALIDATE_STRING (1, name);
|
Simplify the (system foreign) API.
Suggested by Neil Jerram.
* libguile/foreign.h (SCM_FOREIGN_TYPE, SCM_FOREIGN_VALUE_REF,
SCM_FOREIGN_VALUE_SET, SCM_FOREIGN_LEN, SCM_FOREIGN_TYPED_P,
SCM_FOREIGN_VALUE_P, SCM_VALIDATE_FOREIGN_VALUE, scm_foreign_set_x,
scm_foreign_type): Remove.
(scm_foreign_ref): Rename to...
(scm_foreign_address): ... this.
(scm_take_foreign_pointer): Update.
(SCM_FOREIGN_POINTER): Remove CTYPE argument. Update callers.
(scm_make_pointer): New declaration.
* libguile/foreign.c (scm_to_uintptr, scm_from_uintptr): New macros.
(scm_make_pointer): New function.
(scm_take_foreign_pointer): Remove TYPE and LEN arguments. Update
callers.
(scm_foreign_ref): Remove to...
(scm_foreign_address): ... this. Remove type-related code.
(scm_foreign_set_x): Remove.
(scm_foreign_to_bytevector): Change argument order; make LEN argument
compulsory.
(scm_i_foreign_print): Remove type printing.
(unpack): Remove foreign-type checking.
* libguile/deprecated.c (scm_dynamic_args_call): Update accordingly.
* libguile/dynl.c (scm_dynamic_pointer): Remove the TYPE and LEN
arguments; update callers. Update to the new foreign API.
* libguile/dynl.h (scm_dynamic_pointer): Update.
* libguile/gsubr.c (create_gsubr): Update to the new foreign API.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Ditto.
* libguile/snarf.h (SCM_IMMUTABLE_FOREIGN): Ditto.
* libguile/vm-i-system.c (subr_call): Ditto.
* module/system/foreign.scm (null-pointer?): New procedure.
* test-suite/standalone/test-ffi: Update to the new
`bytevector->foreign' signature.
* test-suite/tests/foreign.test ("null pointer")["null pointer
identity", "null-pointer? %null-pointer"]: New tests.
["foreign-set! other-null-pointer", "foreign->bytevector
other-null-pointer"]: Remove.
("make-pointer", "foreign<->bytevector"): New test prefixes.
2010-07-26 17:44:43 +02:00
|
|
|
SCM_VALIDATE_SMOB (SCM_ARG2, dobj, dynamic_obj);
|
2010-03-17 00:06:13 +01:00
|
|
|
|
|
|
|
|
if (DYNL_HANDLE (dobj) == NULL)
|
2000-05-04 08:07:18 +00:00
|
|
|
SCM_MISC_ERROR ("Already unlinked: ~S", dobj);
|
2010-03-17 00:06:13 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *chars;
|
|
|
|
|
|
|
|
|
|
scm_dynwind_begin (0);
|
2016-12-07 20:01:00 +01:00
|
|
|
scm_i_dynwind_pthread_mutex_lock (<dl_lock);
|
2010-03-17 00:06:13 +01:00
|
|
|
chars = scm_to_locale_string (name);
|
|
|
|
|
scm_dynwind_free (chars);
|
|
|
|
|
val = sysdep_dynl_value (chars, DYNL_HANDLE (dobj), FUNC_NAME);
|
|
|
|
|
scm_dynwind_end ();
|
|
|
|
|
|
Use "pointer" instead of "foreign" when dealing with wrapped pointers.
* libguile/foreign.h (scm_t_foreign_finalizer): Rename to...
(scm_t_pointer_finalizer): ... this.
(SCM_FOREIGN_P): Rename to...
(SCM_POINTER_P): this.
(SCM_VALIDATE_FOREIGN): Rename to...
(SCM_VALIDATE_POINTER): ... this.
(SCM_FOREIGN_HAS_FINALIZER): Rename to...
(SCM_POINTER_HAS_FINALIZER): ... this.
(scm_take_foreign_pointer): Rename to...
(scm_from_pointer): ... this.
(scm_foreign_address): Rename to...
(scm_pointer_address): ... this.
(scm_foreign_to_bytevector): Rename to...
(scm_pointer_to_bytevector): ... this.
(scm_foreign_set_finalizer_x): Rename to...
(scm_set_pointer_finalizer_x): ... this.
(scm_bytevector_to_foreign): Rename to...
(scm_bytevector_to_pointer): ... this.
(scm_i_foreign_print): Rename to...
(scm_i_pointer_print): ... this.
* libguile/foreign.c: Update accordingly.
* libguile/tags.h (scm_tc7_foreign): Rename to...
(scm_tc7_pointer): ... this.
* libguile/foreign.c, libguile/deprecated.c, libguile/dynl.c,
libguile/evalext.c, libguile/gc.c, libguile/goops.c, libguile/gsubr.c,
libguile/gsubr.h, libguile/print.c, libguile/snarf.h,
libguile/vm-i-system.c, module/system/foreign.scm,
test-suite/standalone/test-ffi, test-suite/tests/foreign.test: Update
accordingly.
2010-07-27 14:54:53 +02:00
|
|
|
return scm_from_pointer (val, NULL);
|
2010-03-17 00:06:13 +01: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
|
|
|
|
foreign.h presents a more pointer-centric interface
* libguile/foreign.c:
* libguile/foreign.h: Rework interface to be more pointer-centric.
Details are:
(SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the
pointer in a foreign is first-class. If it points to a native type
like uint32, then it still has a tag; but if it points to something
else, like a struct or a pointer or something, then its type is VOID
(i.e., void*).
(SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT.
(SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from
SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that
they only work with value types.
(SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign
pointer in question has a finalizer registered.
(SCM_FOREIGN_LEN): For void* pointers, optionally store the length in
bytes of the associated memory region.
(SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P.
(SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE.
(scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove
scm_c_from_foreign.
(scm_foreign_type): New accessor.
(scm_foreign_ref, scm_foreign_set_x): Take some optional args, used
when dereferencing void pointers.
* libguile/dynl.h:
* libguile/dynl.c (scm_dynamic_pointer): New function, used by
scm_dynamic_func. Adapt code to foreign.h changes.
* libguile/goops.c (scm_enable_primitive_generic_x)
(scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro.
* libguile/gsubr.c (create_gsubr): Adapt to API change.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer
directly, not indirected.
* libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr
pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change.
* libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-18 11:42:35 +01:00
|
|
|
SCM_DEFINE (scm_dynamic_func, "dynamic-func", 2, 0, 0,
|
|
|
|
|
(SCM name, SCM dobj),
|
|
|
|
|
"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.")
|
|
|
|
|
#define FUNC_NAME s_scm_dynamic_func
|
|
|
|
|
{
|
Simplify the (system foreign) API.
Suggested by Neil Jerram.
* libguile/foreign.h (SCM_FOREIGN_TYPE, SCM_FOREIGN_VALUE_REF,
SCM_FOREIGN_VALUE_SET, SCM_FOREIGN_LEN, SCM_FOREIGN_TYPED_P,
SCM_FOREIGN_VALUE_P, SCM_VALIDATE_FOREIGN_VALUE, scm_foreign_set_x,
scm_foreign_type): Remove.
(scm_foreign_ref): Rename to...
(scm_foreign_address): ... this.
(scm_take_foreign_pointer): Update.
(SCM_FOREIGN_POINTER): Remove CTYPE argument. Update callers.
(scm_make_pointer): New declaration.
* libguile/foreign.c (scm_to_uintptr, scm_from_uintptr): New macros.
(scm_make_pointer): New function.
(scm_take_foreign_pointer): Remove TYPE and LEN arguments. Update
callers.
(scm_foreign_ref): Remove to...
(scm_foreign_address): ... this. Remove type-related code.
(scm_foreign_set_x): Remove.
(scm_foreign_to_bytevector): Change argument order; make LEN argument
compulsory.
(scm_i_foreign_print): Remove type printing.
(unpack): Remove foreign-type checking.
* libguile/deprecated.c (scm_dynamic_args_call): Update accordingly.
* libguile/dynl.c (scm_dynamic_pointer): Remove the TYPE and LEN
arguments; update callers. Update to the new foreign API.
* libguile/dynl.h (scm_dynamic_pointer): Update.
* libguile/gsubr.c (create_gsubr): Update to the new foreign API.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Ditto.
* libguile/snarf.h (SCM_IMMUTABLE_FOREIGN): Ditto.
* libguile/vm-i-system.c (subr_call): Ditto.
* module/system/foreign.scm (null-pointer?): New procedure.
* test-suite/standalone/test-ffi: Update to the new
`bytevector->foreign' signature.
* test-suite/tests/foreign.test ("null pointer")["null pointer
identity", "null-pointer? %null-pointer"]: New tests.
["foreign-set! other-null-pointer", "foreign->bytevector
other-null-pointer"]: Remove.
("make-pointer", "foreign<->bytevector"): New test prefixes.
2010-07-26 17:44:43 +02:00
|
|
|
return scm_dynamic_pointer (name, dobj);
|
foreign.h presents a more pointer-centric interface
* libguile/foreign.c:
* libguile/foreign.h: Rework interface to be more pointer-centric.
Details are:
(SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the
pointer in a foreign is first-class. If it points to a native type
like uint32, then it still has a tag; but if it points to something
else, like a struct or a pointer or something, then its type is VOID
(i.e., void*).
(SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT.
(SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from
SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that
they only work with value types.
(SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign
pointer in question has a finalizer registered.
(SCM_FOREIGN_LEN): For void* pointers, optionally store the length in
bytes of the associated memory region.
(SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P.
(SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE.
(scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove
scm_c_from_foreign.
(scm_foreign_type): New accessor.
(scm_foreign_ref, scm_foreign_set_x): Take some optional args, used
when dereferencing void pointers.
* libguile/dynl.h:
* libguile/dynl.c (scm_dynamic_pointer): New function, used by
scm_dynamic_func. Adapt code to foreign.h changes.
* libguile/goops.c (scm_enable_primitive_generic_x)
(scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro.
* libguile/gsubr.c (create_gsubr): Adapt to API change.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer
directly, not indirected.
* libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr
pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change.
* libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-18 11:42:35 +01:00
|
|
|
}
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
Use "pointer" instead of "foreign" when dealing with wrapped pointers.
* libguile/foreign.h (scm_t_foreign_finalizer): Rename to...
(scm_t_pointer_finalizer): ... this.
(SCM_FOREIGN_P): Rename to...
(SCM_POINTER_P): this.
(SCM_VALIDATE_FOREIGN): Rename to...
(SCM_VALIDATE_POINTER): ... this.
(SCM_FOREIGN_HAS_FINALIZER): Rename to...
(SCM_POINTER_HAS_FINALIZER): ... this.
(scm_take_foreign_pointer): Rename to...
(scm_from_pointer): ... this.
(scm_foreign_address): Rename to...
(scm_pointer_address): ... this.
(scm_foreign_to_bytevector): Rename to...
(scm_pointer_to_bytevector): ... this.
(scm_foreign_set_finalizer_x): Rename to...
(scm_set_pointer_finalizer_x): ... this.
(scm_bytevector_to_foreign): Rename to...
(scm_bytevector_to_pointer): ... this.
(scm_i_foreign_print): Rename to...
(scm_i_pointer_print): ... this.
* libguile/foreign.c: Update accordingly.
* libguile/tags.h (scm_tc7_foreign): Rename to...
(scm_tc7_pointer): ... this.
* libguile/foreign.c, libguile/deprecated.c, libguile/dynl.c,
libguile/evalext.c, libguile/gc.c, libguile/goops.c, libguile/gsubr.c,
libguile/gsubr.h, libguile/print.c, libguile/snarf.h,
libguile/vm-i-system.c, module/system/foreign.scm,
test-suite/standalone/test-ffi, test-suite/tests/foreign.test: Update
accordingly.
2010-07-27 14:54:53 +02:00
|
|
|
void (*fptr) (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
|
|
|
if (scm_is_string (func))
|
2000-03-14 06:39:37 +00:00
|
|
|
func = scm_dynamic_func (func, dobj);
|
Use "pointer" instead of "foreign" when dealing with wrapped pointers.
* libguile/foreign.h (scm_t_foreign_finalizer): Rename to...
(scm_t_pointer_finalizer): ... this.
(SCM_FOREIGN_P): Rename to...
(SCM_POINTER_P): this.
(SCM_VALIDATE_FOREIGN): Rename to...
(SCM_VALIDATE_POINTER): ... this.
(SCM_FOREIGN_HAS_FINALIZER): Rename to...
(SCM_POINTER_HAS_FINALIZER): ... this.
(scm_take_foreign_pointer): Rename to...
(scm_from_pointer): ... this.
(scm_foreign_address): Rename to...
(scm_pointer_address): ... this.
(scm_foreign_to_bytevector): Rename to...
(scm_pointer_to_bytevector): ... this.
(scm_foreign_set_finalizer_x): Rename to...
(scm_set_pointer_finalizer_x): ... this.
(scm_bytevector_to_foreign): Rename to...
(scm_bytevector_to_pointer): ... this.
(scm_i_foreign_print): Rename to...
(scm_i_pointer_print): ... this.
* libguile/foreign.c: Update accordingly.
* libguile/tags.h (scm_tc7_foreign): Rename to...
(scm_tc7_pointer): ... this.
* libguile/foreign.c, libguile/deprecated.c, libguile/dynl.c,
libguile/evalext.c, libguile/gc.c, libguile/goops.c, libguile/gsubr.c,
libguile/gsubr.h, libguile/print.c, libguile/snarf.h,
libguile/vm-i-system.c, module/system/foreign.scm,
test-suite/standalone/test-ffi, test-suite/tests/foreign.test: Update
accordingly.
2010-07-27 14:54:53 +02:00
|
|
|
SCM_VALIDATE_POINTER (SCM_ARG1, func);
|
2010-01-04 12:21:02 +01:00
|
|
|
|
Use "pointer" instead of "foreign" when dealing with wrapped pointers.
* libguile/foreign.h (scm_t_foreign_finalizer): Rename to...
(scm_t_pointer_finalizer): ... this.
(SCM_FOREIGN_P): Rename to...
(SCM_POINTER_P): this.
(SCM_VALIDATE_FOREIGN): Rename to...
(SCM_VALIDATE_POINTER): ... this.
(SCM_FOREIGN_HAS_FINALIZER): Rename to...
(SCM_POINTER_HAS_FINALIZER): ... this.
(scm_take_foreign_pointer): Rename to...
(scm_from_pointer): ... this.
(scm_foreign_address): Rename to...
(scm_pointer_address): ... this.
(scm_foreign_to_bytevector): Rename to...
(scm_pointer_to_bytevector): ... this.
(scm_foreign_set_finalizer_x): Rename to...
(scm_set_pointer_finalizer_x): ... this.
(scm_bytevector_to_foreign): Rename to...
(scm_bytevector_to_pointer): ... this.
(scm_i_foreign_print): Rename to...
(scm_i_pointer_print): ... this.
* libguile/foreign.c: Update accordingly.
* libguile/tags.h (scm_tc7_foreign): Rename to...
(scm_tc7_pointer): ... this.
* libguile/foreign.c, libguile/deprecated.c, libguile/dynl.c,
libguile/evalext.c, libguile/gc.c, libguile/goops.c, libguile/gsubr.c,
libguile/gsubr.h, libguile/print.c, libguile/snarf.h,
libguile/vm-i-system.c, module/system/foreign.scm,
test-suite/standalone/test-ffi, test-suite/tests/foreign.test: Update
accordingly.
2010-07-27 14:54:53 +02:00
|
|
|
fptr = SCM_POINTER_VALUE (func);
|
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
|
|
|
|
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:
|
|
|
|
|
*/
|