1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: mod_raw.cc,v 1.9 2000-12-07 15:03:57 obachman Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: machine depend code for dynamic modules |
---|
7 | * |
---|
8 | * Provides: dynl_open() |
---|
9 | * dynl_sym() |
---|
10 | * dynl_error() |
---|
11 | * dunl_close() |
---|
12 | */ |
---|
13 | |
---|
14 | #include "mod2.h" |
---|
15 | #include "static.h" |
---|
16 | #ifdef HAVE_STATIC |
---|
17 | #undef HAVE_DL |
---|
18 | #endif |
---|
19 | |
---|
20 | #if defined(HAVE_DL) |
---|
21 | #include "mod_raw.h" |
---|
22 | #include "febase.h" |
---|
23 | |
---|
24 | /***************************************************************************** |
---|
25 | * |
---|
26 | * General section |
---|
27 | * These are just wrappers around the repsective dynl_* calls |
---|
28 | * which look for the binary in the bin_dir of Singular and ommit warnings if |
---|
29 | * somethings goes wrong |
---|
30 | * |
---|
31 | *****************************************************************************/ |
---|
32 | static BOOLEAN warn_handle = FALSE; |
---|
33 | static BOOLEAN warn_proc = FALSE; |
---|
34 | #ifndef DL_TAIL |
---|
35 | #define DL_TAIL "so" |
---|
36 | #endif |
---|
37 | |
---|
38 | void* dynl_open_binary_warn(char* binary_name) |
---|
39 | { |
---|
40 | void* handle = NULL; |
---|
41 | const char* bin_dir = feGetResource('b'); |
---|
42 | if (bin_dir != NULL) |
---|
43 | { |
---|
44 | char path_name[MAXPATHLEN]; |
---|
45 | sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, binary_name, |
---|
46 | DL_TAIL); |
---|
47 | handle = dynl_open(path_name); |
---|
48 | if (handle == NULL && ! warn_handle) |
---|
49 | { |
---|
50 | Warn("Could not open dynamic library: %s", path_name); |
---|
51 | Warn("Error message from system: %s", dynl_error()); |
---|
52 | Warn("Singular will work properly, but much slower."); |
---|
53 | Warn("See the INSTALL section in the Singular manual for details."); |
---|
54 | warn_handle = TRUE; |
---|
55 | } |
---|
56 | } |
---|
57 | return handle; |
---|
58 | } |
---|
59 | |
---|
60 | void* dynl_sym_warn(void* handle, char* proc) |
---|
61 | { |
---|
62 | void *proc_ptr = NULL; |
---|
63 | if (handle != NULL) |
---|
64 | { |
---|
65 | proc_ptr = dynl_sym(handle, proc); |
---|
66 | if (proc_ptr == NULL && ! warn_proc) |
---|
67 | { |
---|
68 | Warn("Could load a procedure from a dynamic library"); |
---|
69 | Warn("Error message from system: %s", dynl_error()); |
---|
70 | Warn("Singular will work properly, but much slower."); |
---|
71 | Warn("See the INSTALL section in the Singular manual for details."); |
---|
72 | warn_proc = TRUE; |
---|
73 | } |
---|
74 | } |
---|
75 | return proc_ptr; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | /***************************************************************************** |
---|
80 | * SECTION ix86-linux / alpha-linux * |
---|
81 | *****************************************************************************/ |
---|
82 | #if defined(ix86_Linux) || defined(DecAlpha_Linux) || defined(ix86_Linux_libc5) |
---|
83 | #include <dlfcn.h> |
---|
84 | |
---|
85 | void *dynl_open( |
---|
86 | char *filename /* I: filename to load */ |
---|
87 | ) |
---|
88 | { |
---|
89 | return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL)); |
---|
90 | } |
---|
91 | |
---|
92 | void *dynl_sym(void *handle, char *symbol) |
---|
93 | { |
---|
94 | return(dlsym(handle, symbol)); |
---|
95 | } |
---|
96 | |
---|
97 | int dynl_close (void *handle) |
---|
98 | { |
---|
99 | return(dlclose (handle)); |
---|
100 | } |
---|
101 | |
---|
102 | const char *dynl_error() |
---|
103 | { |
---|
104 | return(dlerror()); |
---|
105 | } |
---|
106 | #endif /* ix86_Linux */ |
---|
107 | |
---|
108 | /***************************************************************************** |
---|
109 | * SECTION HPUX-9/10 * |
---|
110 | *****************************************************************************/ |
---|
111 | #if defined(HPUX_9) || defined(HPUX_10) |
---|
112 | #include <dl.h> |
---|
113 | |
---|
114 | typedef char *((*func_ptr) ()); |
---|
115 | |
---|
116 | void *dynl_open(char *filename) |
---|
117 | { |
---|
118 | shl_t handle = shl_load(filename, BIND_DEFERRED, 0); |
---|
119 | |
---|
120 | return ((void *) handle); |
---|
121 | } |
---|
122 | |
---|
123 | void *dynl_sym(void *handle, char *symbol) |
---|
124 | { |
---|
125 | func_ptr f; |
---|
126 | |
---|
127 | if (shl_findsym((shl_t *) & handle, symbol, TYPE_PROCEDURE, &f) == -1) |
---|
128 | { |
---|
129 | if (shl_findsym((shl_t *) & handle, symbol, TYPE_UNDEFINED, &f) == -1) |
---|
130 | { |
---|
131 | f = (func_ptr) NULL; |
---|
132 | } |
---|
133 | } |
---|
134 | return (f); |
---|
135 | } |
---|
136 | |
---|
137 | int dynl_close (void *handle) |
---|
138 | { |
---|
139 | shl_unload((shl_t) handle); |
---|
140 | return(0); |
---|
141 | } |
---|
142 | |
---|
143 | const char *dynl_error() |
---|
144 | { |
---|
145 | static char errmsg[] = "shl_load failed"; |
---|
146 | |
---|
147 | return errmsg; |
---|
148 | } |
---|
149 | #endif /* HPUX_9 or HPUX_10 */ |
---|
150 | |
---|
151 | /***************************************************************************** |
---|
152 | * SECTION 68k-MPW * |
---|
153 | *****************************************************************************/ |
---|
154 | #ifdef 68k_MPW |
---|
155 | /* # include <> */ |
---|
156 | |
---|
157 | void *dynl_open(char *filename) |
---|
158 | { |
---|
159 | return(NULL); |
---|
160 | } |
---|
161 | |
---|
162 | void *dynl_sym(void *handle, char *symbol) |
---|
163 | { |
---|
164 | return(NULL); |
---|
165 | } |
---|
166 | |
---|
167 | int dynl_close (void *handle) |
---|
168 | { |
---|
169 | return(0); |
---|
170 | } |
---|
171 | |
---|
172 | const char *dynl_error() |
---|
173 | { |
---|
174 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
175 | |
---|
176 | return errmsg; |
---|
177 | } |
---|
178 | # endif /* 68k_MPW */ |
---|
179 | |
---|
180 | |
---|
181 | /***************************************************************************** |
---|
182 | * SECTION AIX-4 * |
---|
183 | *****************************************************************************/ |
---|
184 | #ifdef AIX_4 |
---|
185 | /* # include <> */ |
---|
186 | |
---|
187 | void *dynl_open(char *filename) |
---|
188 | { |
---|
189 | return(NULL); |
---|
190 | } |
---|
191 | |
---|
192 | void *dynl_sym(void *handle, char *symbol) |
---|
193 | { |
---|
194 | return(NULL); |
---|
195 | } |
---|
196 | |
---|
197 | int dynl_close (void *handle) |
---|
198 | { |
---|
199 | return(0); |
---|
200 | } |
---|
201 | |
---|
202 | const char *dynl_error() |
---|
203 | { |
---|
204 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
205 | |
---|
206 | return errmsg; |
---|
207 | } |
---|
208 | # endif /* AIX_4 */ |
---|
209 | |
---|
210 | /***************************************************************************** |
---|
211 | * SECTION IRIX-6 * |
---|
212 | *****************************************************************************/ |
---|
213 | #ifdef IRIX_6 |
---|
214 | /* # include <> */ |
---|
215 | |
---|
216 | void *dynl_open(char *filename) |
---|
217 | { |
---|
218 | return(NULL); |
---|
219 | } |
---|
220 | |
---|
221 | void *dynl_sym(void *handle, char *symbol) |
---|
222 | { |
---|
223 | return(NULL); |
---|
224 | } |
---|
225 | |
---|
226 | int dynl_close (void *handle) |
---|
227 | { |
---|
228 | return(0); |
---|
229 | } |
---|
230 | |
---|
231 | const char *dynl_error() |
---|
232 | { |
---|
233 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
234 | |
---|
235 | return errmsg; |
---|
236 | } |
---|
237 | # endif /* IRIX_6 */ |
---|
238 | |
---|
239 | /***************************************************************************** |
---|
240 | * SECTION Sun3OS-4 * |
---|
241 | *****************************************************************************/ |
---|
242 | #ifdef Sun3OS_4 |
---|
243 | /* # include <> */ |
---|
244 | |
---|
245 | void *dynl_open(char *filename) |
---|
246 | { |
---|
247 | return(NULL); |
---|
248 | } |
---|
249 | |
---|
250 | void *dynl_sym(void *handle, char *symbol) |
---|
251 | { |
---|
252 | return(NULL); |
---|
253 | } |
---|
254 | |
---|
255 | int dynl_close (void *handle) |
---|
256 | { |
---|
257 | return(0); |
---|
258 | } |
---|
259 | |
---|
260 | const char *dynl_error() |
---|
261 | { |
---|
262 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
263 | |
---|
264 | return errmsg; |
---|
265 | } |
---|
266 | #endif /* Sun3OS_4 */ |
---|
267 | |
---|
268 | /***************************************************************************** |
---|
269 | * SECTION SunOS-4/5 * |
---|
270 | *****************************************************************************/ |
---|
271 | #if defined(SunOS_4) || defined(SunOS_5) |
---|
272 | /* # include <> */ |
---|
273 | |
---|
274 | void *dynl_open(char *filename) |
---|
275 | { |
---|
276 | return(NULL); |
---|
277 | } |
---|
278 | |
---|
279 | void *dynl_sym(void *handle, char *symbol) |
---|
280 | { |
---|
281 | return(NULL); |
---|
282 | } |
---|
283 | |
---|
284 | int dynl_close (void *handle) |
---|
285 | { |
---|
286 | return(0); |
---|
287 | } |
---|
288 | |
---|
289 | const char *dynl_error() |
---|
290 | { |
---|
291 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
292 | |
---|
293 | return errmsg; |
---|
294 | } |
---|
295 | #endif /* SunOS_4 or SunOS_5 */ |
---|
296 | |
---|
297 | /***************************************************************************** |
---|
298 | * SECTION ix86-win * |
---|
299 | *****************************************************************************/ |
---|
300 | #ifdef ix86_win |
---|
301 | /* # include <> */ |
---|
302 | |
---|
303 | void *dynl_open(char *filename) |
---|
304 | { |
---|
305 | return(NULL); |
---|
306 | } |
---|
307 | |
---|
308 | void *dynl_sym(void *handle, char *symbol) |
---|
309 | { |
---|
310 | return(NULL); |
---|
311 | } |
---|
312 | |
---|
313 | int dynl_close (void *handle) |
---|
314 | { |
---|
315 | return(0); |
---|
316 | } |
---|
317 | |
---|
318 | const char *dynl_error() |
---|
319 | { |
---|
320 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
321 | |
---|
322 | return errmsg; |
---|
323 | } |
---|
324 | #endif /* ix86_win */ |
---|
325 | |
---|
326 | /***************************************************************************** |
---|
327 | * SECTION ppc-MPW * |
---|
328 | *****************************************************************************/ |
---|
329 | #ifdef ppc_MPW |
---|
330 | /* # include <> */ |
---|
331 | |
---|
332 | void *dynl_open(char *filename) |
---|
333 | { |
---|
334 | return(NULL); |
---|
335 | } |
---|
336 | |
---|
337 | void *dynl_sym(void *handle, char *symbol) |
---|
338 | { |
---|
339 | return(NULL); |
---|
340 | } |
---|
341 | |
---|
342 | int dynl_close (void *handle) |
---|
343 | { |
---|
344 | return(0); |
---|
345 | } |
---|
346 | |
---|
347 | const char *dynl_error() |
---|
348 | { |
---|
349 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
350 | return errmsg; |
---|
351 | } |
---|
352 | # endif /* ppc_MPW */ |
---|
353 | |
---|
354 | |
---|
355 | #endif /* HAVE_DL */ |
---|