1996-12-08 16:52:38 +00:00
|
|
|
/* dynl.c - dynamic linking
|
|
|
|
|
*
|
* alist.c, arbiters.c, async.h, backtrace.h, boolean.c, chars.c,
chars.h, continuations.h, debug-malloc.h, dynl.c, feature.c,
feature.h, filesys.h, fluids.h, fports.h, gc_os_dep.c,
gdb_interface.h, gh_eval.c, gh_funcs.c, gh_io.c, gh_list.c,
gh_predicates.c, gsubr.c, gsubr.h, guardians.h,
guile-func-name-check.in, guile-snarf-docs-texi.in,
guile-snarf-docs.in, guile-snarf.awk.in, guile-snarf.in,
hashtab.h, iselect.h, keywords.h, lang.c, list.h, load.h,
objprop.c, objprop.h, options.c, options.h, random.h,
regex-posix.h, root.c, root.h, script.c, snarf.h, stackchk.c,
strerror.c, strop.h, strports.h, threads.h, values.c, values.h,
version.c, version.h: Updated copyright notice.
2001-07-19 21:08:49 +00:00
|
|
|
* Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
|
1996-12-08 16:52:38 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this software; see the file COPYING. If not, write to
|
1997-05-26 22:34:48 +00:00
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307 USA
|
1996-12-08 16:52:38 +00:00
|
|
|
*
|
|
|
|
|
* As a special exception, the Free Software Foundation gives permission
|
|
|
|
|
* for additional uses of the text contained in its release of GUILE.
|
|
|
|
|
*
|
|
|
|
|
* The exception is that, if you link the GUILE library with other files
|
|
|
|
|
* to produce an executable, this does not by itself cause the
|
|
|
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
|
|
|
* Your use of that executable is in no way restricted on account of
|
|
|
|
|
* linking the GUILE library code into it.
|
|
|
|
|
*
|
|
|
|
|
* This exception does not however invalidate any other reasons why
|
|
|
|
|
* the executable file might be covered by the GNU General Public License.
|
|
|
|
|
*
|
|
|
|
|
* This exception applies only to the code released by the
|
|
|
|
|
* Free Software Foundation under the name GUILE. If you copy
|
|
|
|
|
* code from other Free Software Foundation releases into a copy of
|
|
|
|
|
* GUILE, as the General Public License permits, the exception does
|
|
|
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
|
|
|
* anyone as to the status of such modified files, you must delete
|
|
|
|
|
* this exception notice from them.
|
|
|
|
|
*
|
|
|
|
|
* If you write modifications of your own for GUILE, it is your choice
|
|
|
|
|
* whether to permit this exception to apply to your modifications.
|
1997-05-26 22:34:48 +00:00
|
|
|
* If you do not wish that, delete this exception notice. */
|
1996-12-08 16:52:38 +00:00
|
|
|
|
1999-12-12 02:36:16 +00: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
|
|
|
|
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"
|
|
|
|
|
#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"
|
1999-12-18 23:33:15 +00:00
|
|
|
|
2000-01-10 00:36:26 +00:00
|
|
|
#ifdef DYNAMIC_LINKING
|
|
|
|
|
|
2000-06-02 23:33:10 +00:00
|
|
|
#include "libltdl/ltdl.h"
|
2000-01-10 00:36:26 +00:00
|
|
|
|
2002-06-30 20:34:38 +00:00
|
|
|
/* From the libtool manual: "Note that libltdl is not threadsafe,
|
|
|
|
|
i.e. a multithreaded application has to use a mutex for libltdl.".
|
|
|
|
|
|
|
|
|
|
Guile does not currently support pre-emptive threads, so there is
|
|
|
|
|
no mutex. Previously SCM_DEFER_INTS and SCM_ALLOW_INTS were used:
|
|
|
|
|
they are mentioned here in case somebody is grepping for thread
|
|
|
|
|
problems ;)
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
{
|
2000-03-14 06:39:37 +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;
|
|
|
|
|
|
|
|
|
|
fn = scm_makfrom0str (fname);
|
|
|
|
|
msg = scm_makfrom0str (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)
|
|
|
|
|
{
|
|
|
|
|
if (lt_dlclose ((lt_dlhandle) handle))
|
|
|
|
|
{
|
2000-03-14 06:39:37 +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;
|
|
|
|
|
|
|
|
|
|
fptr = lt_dlsym ((lt_dlhandle) handle, symb);
|
|
|
|
|
if (!fptr)
|
|
|
|
|
{
|
2000-03-14 06:39:37 +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 ()
|
|
|
|
|
{
|
|
|
|
|
lt_dlinit ();
|
|
|
|
|
}
|
|
|
|
|
|
1996-12-08 16:52:38 +00:00
|
|
|
#else
|
1997-01-20 19:11:41 +00:00
|
|
|
|
|
|
|
|
/* no dynamic linking available, throw errors. */
|
|
|
|
|
|
|
|
|
|
static void
|
1999-12-12 02:36:16 +00:00
|
|
|
sysdep_dynl_init (void)
|
1997-01-20 19:11:41 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1999-06-21 14:50:19 +00:00
|
|
|
no_dynl_error (const char *subr)
|
1997-01-20 19:11:41 +00:00
|
|
|
{
|
1997-06-16 19:09:11 +00:00
|
|
|
scm_misc_error (subr, "dynamic linking not available", SCM_EOL);
|
1997-01-20 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *
|
2000-05-18 08:47:52 +00:00
|
|
|
sysdep_dynl_link (const char *filename, const char *subr)
|
1997-01-20 19:11:41 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
no_dynl_error (subr);
|
|
|
|
|
return NULL;
|
1997-01-20 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1999-06-21 14:50:19 +00:00
|
|
|
sysdep_dynl_unlink (void *handle,
|
|
|
|
|
const char *subr)
|
1997-01-20 19:11:41 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
no_dynl_error (subr);
|
1997-01-20 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *
|
1999-06-21 14:50:19 +00:00
|
|
|
sysdep_dynl_func (const char *symbol,
|
|
|
|
|
void *handle,
|
|
|
|
|
const char *subr)
|
1997-01-20 19:11:41 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
no_dynl_error (subr);
|
|
|
|
|
return NULL;
|
1997-01-20 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
1997-01-18 11:40:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
scm_t_bits scm_tc16_dynamic_obj;
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2000-05-04 08:07:18 +00:00
|
|
|
#define DYNL_FILENAME(x) (SCM_CELL_OBJECT_1 (x))
|
|
|
|
|
#define DYNL_HANDLE(x) ((void *) SCM_CELL_WORD_2 (x))
|
|
|
|
|
#define SET_DYNL_HANDLE(x, v) (SCM_SET_CELL_WORD_2 ((x), (v)))
|
2000-03-14 06:39:37 +00:00
|
|
|
|
|
|
|
|
|
1997-01-18 11:40:31 +00:00
|
|
|
static SCM
|
2000-12-08 17:32:56 +00:00
|
|
|
dynl_obj_mark (SCM ptr)
|
1997-01-18 11:40:31 +00:00
|
|
|
{
|
2000-03-14 06:39:37 +00:00
|
|
|
return DYNL_FILENAME (ptr);
|
1997-07-18 14:31:06 +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),
|
|
|
|
|
"Open the dynamic library called @var{filename}. A library\n"
|
|
|
|
|
"handle representing the opened library is returned; this handle\n"
|
|
|
|
|
"should be used as the @var{dobj} argument to the following\n"
|
|
|
|
|
"functions.")
|
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;
|
1997-01-18 11:40:31 +00:00
|
|
|
|
2001-04-03 13:19:05 +00:00
|
|
|
SCM_VALIDATE_STRING (1, filename);
|
|
|
|
|
handle = sysdep_dynl_link (SCM_STRING_CHARS (filename), FUNC_NAME);
|
|
|
|
|
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),
|
* 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
|
|
|
"Return @code{#t} if @var{obj} is a dynamic library handle, or @code{#f}\n"
|
|
|
|
|
"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
|
|
|
{
|
2000-12-08 17:32:56 +00:00
|
|
|
return SCM_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),
|
2000-05-04 08:07:18 +00:00
|
|
|
"Unlink the indicated object file from the application. The\n"
|
2001-04-03 13:19:05 +00:00
|
|
|
"argument @var{dobj} must have been obtained by a call to\n"
|
2000-05-04 08:07:18 +00:00
|
|
|
"@code{dynamic-link}. After @code{dynamic-unlink} has been\n"
|
2001-04-03 13:19:05 +00:00
|
|
|
"called on @var{dobj}, its content is no longer accessible.")
|
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) {
|
|
|
|
|
SCM_MISC_ERROR ("Already unlinked: ~S", dobj);
|
|
|
|
|
} 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),
|
|
|
|
|
"Search the dynamic object @var{dobj} for the C function\n"
|
|
|
|
|
"indicated by the string @var{name} and return some Scheme\n"
|
|
|
|
|
"handle that can later be used with @code{dynamic-call} to\n"
|
|
|
|
|
"actually call the function.\n\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
|
|
|
"Regardless whether your C compiler prepends an underscore @samp{_} to\n"
|
|
|
|
|
"the global names in a program, you should @strong{not} include this\n"
|
|
|
|
|
"underscore in @var{function}. Guile knows whether the underscore is\n"
|
2000-08-11 15:12:37 +00:00
|
|
|
"needed or not and will add it 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-10-30 11:42:26 +00:00
|
|
|
/* The returned handle is formed by casting the address of the function to a
|
|
|
|
|
* long value and converting this to a scheme number
|
|
|
|
|
*/
|
|
|
|
|
|
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;
|
|
|
|
|
|
2000-10-30 11:42:26 +00:00
|
|
|
chars = SCM_STRING_CHARS (name);
|
2000-09-26 18:37:26 +00:00
|
|
|
func = (void (*) ()) sysdep_dynl_func (chars, DYNL_HANDLE (dobj), FUNC_NAME);
|
2000-05-04 08:07:18 +00:00
|
|
|
return scm_ulong2num ((unsigned long) func);
|
|
|
|
|
}
|
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) ();
|
|
|
|
|
|
2000-10-30 11:42:26 +00:00
|
|
|
if (SCM_STRINGP (func))
|
2000-03-14 06:39:37 +00:00
|
|
|
func = scm_dynamic_func (func, dobj);
|
|
|
|
|
fptr = (void (*) ()) SCM_NUM2ULONG (1, func);
|
|
|
|
|
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
|
|
|
|
2002-06-30 19:27:18 +00:00
|
|
|
/* return a newly allocated array of char pointers to each of the strings
|
|
|
|
|
in args, with a terminating NULL pointer. */
|
|
|
|
|
/* Note: a similar function is defined in posix.c, but we don't necessarily
|
|
|
|
|
want to export it. */
|
|
|
|
|
static char **allocate_string_pointers (SCM args, int *num_args_return)
|
|
|
|
|
{
|
|
|
|
|
char **result;
|
|
|
|
|
int n_args = scm_ilength (args);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
SCM_ASSERT (n_args >= 0, args, SCM_ARGn, "allocate_string_pointers");
|
|
|
|
|
result = (char **) scm_malloc ((n_args + 1) * sizeof (char *));
|
|
|
|
|
result[n_args] = NULL;
|
|
|
|
|
for (i = 0; i < n_args; i++)
|
|
|
|
|
{
|
|
|
|
|
SCM car = SCM_CAR (args);
|
|
|
|
|
|
|
|
|
|
if (!SCM_STRINGP (car))
|
|
|
|
|
{
|
|
|
|
|
free (result);
|
|
|
|
|
scm_wrong_type_arg ("allocate_string_pointers", SCM_ARGn, car);
|
|
|
|
|
}
|
|
|
|
|
result[i] = SCM_STRING_CHARS (SCM_CAR (args));
|
|
|
|
|
args = SCM_CDR (args);
|
|
|
|
|
}
|
|
|
|
|
*num_args_return = n_args;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2000-10-30 11:42:26 +00:00
|
|
|
if (SCM_STRINGP (func))
|
2000-03-14 06:39:37 +00:00
|
|
|
func = scm_dynamic_func (func, dobj);
|
|
|
|
|
|
|
|
|
|
fptr = (int (*) (int, char **)) SCM_NUM2ULONG (1, func);
|
2002-06-30 19:27:18 +00:00
|
|
|
argv = allocate_string_pointers (args, &argc);
|
|
|
|
|
/* if the procedure mutates its arguments, the original strings will be
|
|
|
|
|
changed -- in Guile 1.6 and earlier, this wasn't the case since a
|
|
|
|
|
new copy of each string was allocated. */
|
2000-03-14 06:39:37 +00:00
|
|
|
result = (*fptr) (argc, argv);
|
2002-06-30 19:27:18 +00:00
|
|
|
free (argv);
|
2000-03-14 06:39:37 +00:00
|
|
|
|
|
|
|
|
return SCM_MAKINUM (0L + 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_mark (scm_tc16_dynamic_obj, dynl_obj_mark);
|
|
|
|
|
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:
|
|
|
|
|
*/
|