annotate src/sysdll.c @ 1676:a72f7bf813c9

[xemacs-hg @ 2003-09-11 09:11:07 by crestani] 2003-09-11 Marcus Crestani <crestani@informatik.uni-tuebingen.de> * alloc.c: Clean up #ifdef USE_KKCC, move stack code to better position. Add lrecord_memory_descriptions table. (KKCC_GC_STACK_FULL): Replace functions with macros. (KKCC_GC_STACK_EMPTY): (kkcc_gc_stack_push): (kkcc_gc_stack_pop): (kkcc_gc_stack_push_lisp_object): (mark_object): Add #ifdef to remove unused code. (garbage_collect_1): Remove some #ifdefs. * dumper.c (pdump): Dump lrecord_memory_descriptions table. * lrecord.h: Add lrecord_memory_descriptions.
author crestani
date Thu, 11 Sep 2003 09:11:08 +0000
parents 64eaceca611d
children 9fc738581a9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* sysdll.c --- system dependent support for dynamic linked libraries
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Author: William Perry <wmperry@aventail.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
26 #include <stdlib.h>
1272
df61d2b1d4c3 [xemacs-hg @ 2003-02-07 21:40:22 by james]
james
parents: 880
diff changeset
27 #include "lisp.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "sysdll.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
30 #ifdef DLSYM_NEEDS_UNDERSCORE
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
31 #define MAYBE_PREPEND_UNDERSCORE(n) do { \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
32 char *buf = alloca_array (char, strlen (n) + 2); \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
33 *buf = '_'; \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
34 strcpy (buf + 1, n); \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
35 n = buf; \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
36 } while (0)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
37 #else
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
38 #define MAYBE_PREPEND_UNDERSCORE(n)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
39 #endif
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
40
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 /* This whole file is conditional upon HAVE_SHLIB */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #ifdef HAVE_SHLIB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 /* Thankfully, most systems follow the ELFish dlopen() method.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 442
diff changeset
46 #if defined(HAVE_DLOPEN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include <dlfcn.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #ifndef RTLD_LAZY
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
50 # ifdef DL_LAZY
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
51 # define RTLD_LAZY DL_LAZY
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
52 # else
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
53 # define RTLD_LAZY 1
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
54 # endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 452
diff changeset
57 #ifndef RTLD_NOW
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
58 # ifdef DL_NOW
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
59 # define RTLD_NOW DL_NOW
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
60 # else
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
61 # define RTLD_NOW 2
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
62 # endif
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 452
diff changeset
63 #endif
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 452
diff changeset
64
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
66 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
72 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 {
880
beddd25fe24a [xemacs-hg @ 2002-06-24 22:00:17 by youngs]
youngs
parents: 863
diff changeset
74 return (dll_handle) dlopen (fname, RTLD_NOW);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
80 return dlclose ((void *) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
84 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 {
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
86 MAYBE_PREPEND_UNDERSCORE (n);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
87 return (dll_func) dlsym ((void *) h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 dll_var
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
91 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 {
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
93 MAYBE_PREPEND_UNDERSCORE (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 return (dll_var)dlsym ((void *)h, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
97 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #if defined(HAVE_DLERROR) || defined(dlerror)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
101 return (const char *) dlerror ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 #elif defined(HAVE__DLERROR)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
103 return (const char *) _dlerror();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 return "Shared library error";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #elif defined(HAVE_SHL_LOAD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 /* This is the HP/UX version */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #include <dl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
113 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
119 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
121 /* shl_load will hang hard if passed a NULL fname. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
122 if (fname == NULL) return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
124 return (dll_handle) shl_load (fname, BIND_DEFERRED, 0L);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
130 return shl_unload ((shl_t) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
134 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 long handle = 0L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
138 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
141 return (dll_func) handle;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 dll_var
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
145 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 long handle = 0L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
149 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
152 return (dll_var) handle;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
155 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 /* #### WTF?! Shouldn't this at least attempt to get strerror or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 something? --hniksic */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 return "Generic shared library error";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
1596
0879be053100 [xemacs-hg @ 2003-07-30 18:32:22 by james]
james
parents: 1418
diff changeset
163 #elif defined(HAVE_DLD_INIT)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 #include <dld.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
166 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 char *real_exe = dld_find_executable (arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 int rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 rc = dld_init (real_exe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 if (rc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 dld_perror (exe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
181 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 rc = dld_link (fname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 if (rc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
187 return (dll_handle) 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 ** later on to free the file - you have to remember the filename and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 ** use that as the unlinker. We should eventually keep a linked list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ** of loaded modules and then use the node pointer as the unique id
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ** for the shared library. Wheeee. But not now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 DLL_FUNC
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
203 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
205 return dld_get_func (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 DLL_FUNC
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
209 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
211 return dld_get_symbol (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 }
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
213 #elif defined (WIN32_NATIVE) || defined (CYGWIN)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
214
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
215 #include "syswindows.h"
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
216 #include "sysfile.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
217
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
219 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
225 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 {
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
227 Ibyte *winfname, *unifname;
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
228 LOCAL_TO_WIN32_FILE_FORMAT ((char *) fname, winfname);
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
229 C_STRING_TO_TSTR (winfname, unifname);
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
230 return (dll_handle) qxeLoadLibrary (unifname);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 return FreeLibrary (h);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
240 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
242 return (dll_func) GetProcAddress (h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
246 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
248 return (dll_func) GetProcAddress (h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
251 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 {
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
254 /* Since nobody frees the returned string, I have to make this ugly hack. */
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
255 static char err[32] = "Windows DLL Error ";
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
256 snprintf (&err[18], 14, "%lu", GetLastError ());
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
257 return err;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 }
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
259 #elif defined(HAVE_DYLD)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
260 /* This section supports MacOSX dynamic libraries. Dynamically
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
261 loadable libraries must be compiled as bundles, not dynamiclibs.
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
262 */
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
263
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
264 #include <mach-o/dyld.h>
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
265
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
266 int
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
267 dll_init (const char *arg)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
268 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
269 return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
270 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
271
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
272 dll_handle
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
273 dll_open (const char *fname)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
274 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
275 NSObjectFileImage file;
1418
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
276 NSModule out;
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
277 NSObjectFileImageReturnCode ret =
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
278 NSCreateObjectFileImageFromFile(fname, &file);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
279 if (ret != NSObjectFileImageSuccess) {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
280 return NULL;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
281 }
1418
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
282 out = NSLinkModule(file, fname,
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
283 NSLINKMODULE_OPTION_BINDNOW |
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
284 NSLINKMODULE_OPTION_PRIVATE |
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
285 NSLINKMODULE_OPTION_RETURN_ON_ERROR);
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
286 return (dll_handle)out;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
287 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
288
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
289 int
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
290 dll_close (dll_handle h)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
291 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
292 return NSUnLinkModule((NSModule)h, NSUNLINKMODULE_OPTION_NONE);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
293 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
294
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
295 dll_func
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
296 dll_function (dll_handle h, const char *n)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
297 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
298 NSSymbol sym;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
299 MAYBE_PREPEND_UNDERSCORE (n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
300 sym = NSLookupSymbolInModule((NSModule)h, n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
301 if (sym == 0) return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
302 return (dll_func)NSAddressOfSymbol(sym);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
303 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
304
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
305 dll_var
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
306 dll_variable (dll_handle h, const char *n)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
307 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
308 NSSymbol sym;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
309 MAYBE_PREPEND_UNDERSCORE (n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
310 sym = NSLookupSymbolInModule((NSModule)h, n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
311 if (sym == 0) return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
312 return (dll_var)NSAddressOfSymbol(sym);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
313 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
314
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
315 const char *
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
316 dll_error (dll_handle h)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
317 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
318 NSLinkEditErrors c;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
319 int errorNumber;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
320 const char *fileNameWithError, *errorString;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
321 NSLinkEditError(&c, &errorNumber, &fileNameWithError, &errorString);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
322 return errorString;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
323 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 /* Catchall if we don't know about this systems method of dynamic loading */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
327 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
333 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
345 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
351 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
356 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 return "Shared libraries not implemented on this system";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 #endif /* System conditionals */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 #endif /* HAVE_SHLIB */