* objects.c, objects.h (scm_mcache_lookup_cmethod): Moved here
[bpt/guile.git] / libguile / dynl-dld.c
1 /* dynl-dld.c - dynamic linking with dld
2 *
3 * Copyright (C) 1990-1997 Free Software Foundation, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
19 *
20 * As a special exception, the Free Software Foundation gives permission
21 * for additional uses of the text contained in its release of GUILE.
22 *
23 * The exception is that, if you link the GUILE library with other files
24 * to produce an executable, this does not by itself cause the
25 * resulting executable to be covered by the GNU General Public License.
26 * Your use of that executable is in no way restricted on account of
27 * linking the GUILE library code into it.
28 *
29 * This exception does not however invalidate any other reasons why
30 * the executable file might be covered by the GNU General Public License.
31 *
32 * This exception applies only to the code released by the
33 * Free Software Foundation under the name GUILE. If you copy
34 * code from other Free Software Foundation releases into a copy of
35 * GUILE, as the General Public License permits, the exception does
36 * not apply to the code that you add in this way. To avoid misleading
37 * anyone as to the status of such modified files, you must delete
38 * this exception notice from them.
39 *
40 * If you write modifications of your own for GUILE, it is your choice
41 * whether to permit this exception to apply to your modifications.
42 * If you do not wish that, delete this exception notice. */
43
44 /* "dynl.c" dynamically link&load object files.
45 Author: Aubrey Jaffer
46 Modified for libguile by Marius Vollmer */
47
48 #include "dld.h"
49
50 static void listundef SCM_P ((void));
51
52 static void
53 listundefs ()
54 {
55 int i;
56 char **undefs = dld_list_undefined_sym();
57 puts(" undefs:");
58 for(i = dld_undefined_sym_count;i--;) {
59 putc('"', stdout);
60 fputs(undefs[i], stdout);
61 puts("\"");
62 }
63 free(undefs);
64 }
65
66 static void *
67 sysdep_dynl_link (fname, int flags, subr)
68 const char *fname;
69 int flags;
70 const char *subr;
71 {
72 int status;
73
74 status = dld_link (fname);
75 if (status)
76 {
77 SCM_ALLOW_INTS;
78 scm_misc_error (subr, dld_strerror (status), SCM_EOL);
79 }
80 return fname;
81 }
82
83 static void
84 sysdep_dynl_unlink (handle, subr)
85 void *handle;
86 const char *subr;
87 {
88 int status;
89
90 status = dld_unlink_by_file ((char *)fname, 1);
91 if (status)
92 {
93 SCM_ALLOW_INTS;
94 scm_misc_error (s_dynamic_unlink, dld_strerror (status), SCM_EOL);
95 }
96 }
97
98 static void *
99 sysdep_dynl_func (symb, handle, subr)
100 const char *symb;
101 void *handle;
102 const char *subr;
103 {
104 void *func;
105
106 func = (void *) dld_get_func (func);
107 if (func == 0)
108 scm_misc_error (subr, dld_strerror (dld_errno), SCM_EOL);
109 if (!dld_function_executable_p (func)) {
110 listundefs ();
111 SCM_ALLOW_INTS;
112 scm_misc_error (subr, "unresolved symbols remain", SCM_EOL);
113 }
114 return func;
115 }
116
117 static void
118 sysdep_dynl_init ()
119 {
120 #ifndef RTL
121 if (!execpath)
122 execpath = dld_find_executable (SCM_CHARS (SCM_CAR (progargs)));
123 if (dld_init (SCM_CHARS (SCM_CAR (progargs)))) {
124 dld_perror("DLD");
125 return;
126 }
127 #endif
128
129 #ifdef DLD_DYNCM /* XXX - what's this? */
130 add_feature("dld:dyncm");
131 #endif
132 }