comparison src/emodules.c @ 1706:9fc738581a9d

[xemacs-hg @ 2003-09-22 03:21:12 by james] Remove GNU DLD support, fix the C++ build, make eval-related functions visible to modules, and fix minor Windows-related problems.
author james
date Mon, 22 Sep 2003 03:21:19 +0000
parents 64eaceca611d
children a8d8f419b459
comparison
equal deleted inserted replaced
1705:cdbc76885304 1706:9fc738581a9d
39 Lisp_Object Qmodule, Qunload_module, module_tag; 39 Lisp_Object Qmodule, Qunload_module, module_tag;
40 40
41 typedef struct _emodules_list 41 typedef struct _emodules_list
42 { 42 {
43 int used; /* Is this slot used? */ 43 int used; /* Is this slot used? */
44 char *soname; /* Name of the shared object loaded (full path) */ 44 CIbyte *soname; /* Name of the shared object loaded (full path) */
45 char *modname; /* The name of the module */ 45 CIbyte *modname; /* The name of the module */
46 char *modver; /* The module version string */ 46 CIbyte *modver; /* The module version string */
47 char *modtitle; /* How the module announces itself */ 47 CIbyte *modtitle; /* How the module announces itself */
48 void (*unload)(void); /* Module cleanup function to run before unloading */ 48 void (*unload)(void); /* Module cleanup function to run before unloading */
49 dll_handle dlhandle; /* Dynamic lib handle */ 49 dll_handle dlhandle; /* Dynamic lib handle */
50 } emodules_list; 50 } emodules_list;
51 51
52 static Lisp_Object Vmodule_extensions; 52 static Lisp_Object Vmodule_extensions;
54 static int emodules_depth; 54 static int emodules_depth;
55 static dll_handle dlhandle; 55 static dll_handle dlhandle;
56 static emodules_list *modules; 56 static emodules_list *modules;
57 static int modnum; 57 static int modnum;
58 58
59 static int find_make_module (const char *mod, const char *name, 59 static int find_make_module (const CIbyte *mod, const CIbyte *name,
60 const char *ver, int make_or_find); 60 const CIbyte *ver, int make_or_find);
61 static Lisp_Object module_load_unwind (Lisp_Object); 61 static Lisp_Object module_load_unwind (Lisp_Object);
62 static void attempt_module_delete (int mod); 62 static void attempt_module_delete (int mod);
63 63
64 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /* 64 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /*
65 Load in a C Emacs Extension module named FILE. 65 Load in a C Emacs Extension module named FILE.
89 Messages informing you of the progress of the load are displayed unless 89 Messages informing you of the progress of the load are displayed unless
90 the variable `load-modules-quietly' is non-NIL. 90 the variable `load-modules-quietly' is non-NIL.
91 */ 91 */
92 (file, name, version)) 92 (file, name, version))
93 { 93 {
94 char *mod, *mname, *mver; 94 CIbyte *mod, *mname, *mver;
95 int speccount = specpdl_depth(); 95 int speccount = specpdl_depth();
96 96
97 CHECK_STRING(file); 97 CHECK_STRING(file);
98 98
99 mod = (char *)XSTRING_DATA (file); 99 mod = (CIbyte *) XSTRING_DATA (file);
100 100
101 if (NILP (name)) 101 if (NILP (name))
102 mname = ""; 102 mname = "";
103 else 103 else
104 mname = (char *)XSTRING_DATA (name); 104 mname = (CIbyte *) XSTRING_DATA (name);
105 105
106 if (NILP (version)) 106 if (NILP (version))
107 mver = ""; 107 mver = "";
108 else 108 else
109 mver = (char *)XSTRING_DATA (version); 109 mver = (CIbyte *) XSTRING_DATA (version);
110 110
111 dlhandle = 0; 111 dlhandle = 0;
112 record_unwind_protect (module_load_unwind, make_int(modnum)); 112 record_unwind_protect (module_load_unwind, make_int(modnum));
113 emodules_load (mod, mname, mver); 113 emodules_load (mod, mname, mver);
114 unbind_to (speccount); 114 unbind_to (speccount);
129 soon as the last reference to symbols within the module is destroyed. 129 soon as the last reference to symbols within the module is destroyed.
130 */ 130 */
131 (file, name, version)) 131 (file, name, version))
132 { 132 {
133 int x; 133 int x;
134 char *mod, *mname, *mver; 134 CIbyte *mod, *mname, *mver;
135 Lisp_Object foundname = Qnil; 135 Lisp_Object foundname = Qnil;
136 struct gcpro gcpro1; 136 struct gcpro gcpro1;
137 137
138 CHECK_STRING(file); 138 CHECK_STRING(file);
139 139
140 GCPRO1 (foundname); 140 GCPRO1 (foundname);
141 if (locate_file (Vmodule_load_path, file, Vmodule_extensions, &foundname, 0) 141 if (locate_file (Vmodule_load_path, file, Vmodule_extensions, &foundname, 0)
142 < 0) 142 < 0)
143 return Qt; 143 return Qt;
144 mod = (char *)XSTRING_DATA (foundname); 144 mod = (CIbyte *) XSTRING_DATA (foundname);
145 UNGCPRO; 145 UNGCPRO;
146 146
147 if (NILP (name)) 147 if (NILP (name))
148 mname = ""; 148 mname = "";
149 else 149 else
150 mname = (char *)XSTRING_DATA (name); 150 mname = (CIbyte *) XSTRING_DATA (name);
151 151
152 if (NILP (version)) 152 if (NILP (version))
153 mver = ""; 153 mver = "";
154 else 154 else
155 mver = (char *)XSTRING_DATA (version); 155 mver = (CIbyte *) XSTRING_DATA (version);
156 156
157 x = find_make_module (mod, mname, mver, 1); 157 x = find_make_module (mod, mname, mver, 1);
158 if (x != -1) 158 if (x != -1)
159 { 159 {
160 if (modules[x].unload != NULL) 160 if (modules[x].unload != NULL)
202 202
203 return mlist; 203 return mlist;
204 } 204 }
205 205
206 static int 206 static int
207 find_make_module (const char *mod, const char *name, const char *ver, int mof) 207 find_make_module (const CIbyte *mod, const CIbyte *name, const CIbyte *ver,
208 int mof)
208 { 209 {
209 int i, fs = -1; 210 int i, fs = -1;
210 211
211 for (i = 0; i < modnum; i++) 212 for (i = 0; i < modnum; i++)
212 { 213 {
230 231
231 /* 232 /*
232 * We only get here if we haven't found a free slot and the module was 233 * We only get here if we haven't found a free slot and the module was
233 * not previously loaded. 234 * not previously loaded.
234 */ 235 */
235 if (modules == (emodules_list *)0) 236 if (modules == NULL)
236 modules = (emodules_list *) xmalloc (sizeof (emodules_list)); 237 modules = (emodules_list *) xmalloc (sizeof (emodules_list));
237 modnum++; 238 modnum++;
238 modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list)); 239 modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list));
239 240
240 fs = modnum - 1; 241 fs = modnum - 1;
322 * the error handler we take great care to close off the module chain before 323 * the error handler we take great care to close off the module chain before
323 * we call "error" and let the Fmodule_load unwind_protect() function handle 324 * we call "error" and let the Fmodule_load unwind_protect() function handle
324 * the cleaning up. 325 * the cleaning up.
325 */ 326 */
326 void 327 void
327 emodules_load(const char *module, const char *modname, const char *modver) 328 emodules_load (const CIbyte *module, const CIbyte *modname,
329 const CIbyte *modver)
328 { 330 {
329 Lisp_Object old_load_list; 331 Lisp_Object old_load_list;
330 Lisp_Object filename; 332 Lisp_Object filename;
331 Lisp_Object foundname, lisp_modname; 333 Lisp_Object foundname, lisp_modname;
332 int x, mpx; 334 int x, mpx;
333 char *soname; 335 CIbyte *soname;
334 const char **f; 336 const CIbyte **f;
335 const long *ellcc_rev; 337 const long *ellcc_rev;
336 char *mver, *mname, *mtitle, *symname; 338 CIbyte *mver, *mname, *mtitle, *symname;
337 void (*modload)(void) = 0; 339 void (*modload)(void) = 0;
338 void (*modsyms)(void) = 0; 340 void (*modsyms)(void) = 0;
339 void (*modvars)(void) = 0; 341 void (*modvars)(void) = 0;
340 void (*moddocs)(void) = 0; 342 void (*moddocs)(void) = 0;
341 void (*modunld)(void) = 0; 343 void (*modunld)(void) = 0;
346 foundname = Qnil; 348 foundname = Qnil;
347 349
348 emodules_depth++; 350 emodules_depth++;
349 dlhandle = 0; 351 dlhandle = 0;
350 352
351 if ((module == (const char *)0) || (module[0] == '\0')) 353 if (module == NULL || module[0] == '\0')
352 invalid_argument ("Empty module name", Qunbound); 354 invalid_argument ("Empty module name", Qunbound);
353 355
354 GCPRO4(filename, foundname, old_load_list, lisp_modname); 356 GCPRO4(filename, foundname, old_load_list, lisp_modname);
355 filename = build_string (module); 357 filename = build_string (module);
356 if (locate_file (Vmodule_load_path, filename, Vmodule_extensions, 358 if (locate_file (Vmodule_load_path, filename, Vmodule_extensions,
357 &foundname, 0) < 0) 359 &foundname, 0) < 0)
358 signal_error (Qdll_error, "Cannot open dynamic module", filename); 360 signal_error (Qdll_error, "Cannot open dynamic module", filename);
359 361
360 soname = (char *)ALLOCA (XSTRING_LENGTH (foundname) + 1); 362 LISP_STRING_TO_EXTERNAL (foundname, soname, Qfile_name);
361 strcpy (soname, (char *)XSTRING_DATA (foundname));
362 lisp_modname = call1 (Qfile_name_sans_extension, 363 lisp_modname = call1 (Qfile_name_sans_extension,
363 Ffile_name_nondirectory (foundname)); 364 Ffile_name_nondirectory (foundname));
364 365
365 dlhandle = dll_open (soname); 366 dlhandle = dll_open (foundname);
366 if (dlhandle == (dll_handle)0) 367 if (dlhandle == NULL)
367 { 368 {
368 Ibyte *dllerrint;
369
370 EXTERNAL_TO_C_STRING (dll_error (dlhandle), dllerrint, Qnative);
371 signal_error (Qdll_error, "Opening dynamic module", 369 signal_error (Qdll_error, "Opening dynamic module",
372 build_intstring (dllerrint)); 370 dll_error (dlhandle));
373 } 371 }
374 372
375 ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler"); 373 ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler");
376 if ((ellcc_rev == (const long *)0) || (*ellcc_rev <= 0)) 374 if (ellcc_rev == NULL || *ellcc_rev <= 0L)
377 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_compiler'", Qunbound); 375 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_compiler'", Qunbound);
378 if (*ellcc_rev > EMODULES_REVISION) 376 if (*ellcc_rev > EMODULES_REVISION)
379 signal_ferror (Qdll_error, "Invalid dynamic module: Unsupported version `%ld(%ld)'", *ellcc_rev, EMODULES_REVISION); 377 signal_ferror (Qdll_error, "Invalid dynamic module: Unsupported version `%ld(%ld)'", *ellcc_rev, EMODULES_REVISION);
380 378
381 f = (const char **)dll_variable (dlhandle, "emodule_name"); 379 f = (const CIbyte **) dll_variable (dlhandle, "emodule_name");
382 if ((f == (const char **)0) || (*f == (const char *)0)) 380 if (f == NULL || *f == NULL)
383 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_name'", Qunbound); 381 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_name'", Qunbound);
384 382
385 mname = (char *)ALLOCA (strlen (*f) + 1); 383 mname = (CIbyte *) ALLOCA (strlen (*f) + 1);
386 strcpy (mname, *f); 384 strcpy (mname, *f);
387 if (mname[0] == '\0') 385 if (mname[0] == '\0')
388 signal_error (Qdll_error, "Invalid dynamic module: Empty value for `emodule_name'", Qunbound); 386 signal_error (Qdll_error, "Invalid dynamic module: Empty value for `emodule_name'", Qunbound);
389 387
390 f = (const char **)dll_variable (dlhandle, "emodule_version"); 388 f = (const CIbyte **) dll_variable (dlhandle, "emodule_version");
391 if ((f == (const char **)0) || (*f == (const char *)0)) 389 if (f == NULL || *f == NULL)
392 signal_error (Qdll_error, "Missing symbol `emodule_version': Invalid dynamic module", Qunbound); 390 signal_error (Qdll_error, "Missing symbol `emodule_version': Invalid dynamic module", Qunbound);
393 391
394 mver = (char *)ALLOCA (strlen (*f) + 1); 392 mver = (CIbyte *) ALLOCA (strlen (*f) + 1);
395 strcpy (mver, *f); 393 strcpy (mver, *f);
396 394
397 f = (const char **)dll_variable (dlhandle, "emodule_title"); 395 f = (const CIbyte **) dll_variable (dlhandle, "emodule_title");
398 if ((f == (const char **)0) || (*f == (const char *)0)) 396 if (f == NULL || *f == NULL)
399 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_title'", Qunbound); 397 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_title'", Qunbound);
400 398
401 mtitle = (char *)ALLOCA (strlen (*f) + 1); 399 mtitle = (CIbyte *) ALLOCA (strlen (*f) + 1);
402 strcpy (mtitle, *f); 400 strcpy (mtitle, *f);
403 401
404 symname = (char *)ALLOCA (strlen (mname) + 15); 402 symname = (CIbyte *) ALLOCA (strlen (mname) + 15);
405 403
406 strcpy (symname, "modules_of_"); 404 strcpy (symname, "modules_of_");
407 strcat (symname, mname); 405 strcat (symname, mname);
408 modload = (void (*)(void))dll_function (dlhandle, symname); 406 modload = (void (*)(void))dll_function (dlhandle, symname);
409 /* 407 /*
412 */ 410 */
413 411
414 strcpy (symname, "syms_of_"); 412 strcpy (symname, "syms_of_");
415 strcat (symname, mname); 413 strcat (symname, mname);
416 modsyms = (void (*)(void))dll_function (dlhandle, symname); 414 modsyms = (void (*)(void))dll_function (dlhandle, symname);
417 if (modsyms == (void (*)(void))0) 415 if (modsyms == NULL)
418 { 416 {
419 missing_symbol: 417 missing_symbol:
420 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol", 418 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol",
421 build_string (symname)); 419 build_string (symname));
422 } 420 }
423 421
424 strcpy (symname, "vars_of_"); 422 strcpy (symname, "vars_of_");
425 strcat (symname, mname); 423 strcat (symname, mname);
426 modvars = (void (*)(void))dll_function (dlhandle, symname); 424 modvars = (void (*)(void))dll_function (dlhandle, symname);
427 if (modvars == (void (*)(void))0) 425 if (modvars == NULL)
428 goto missing_symbol; 426 goto missing_symbol;
429 427
430 strcpy (symname, "docs_of_"); 428 strcpy (symname, "docs_of_");
431 strcat (symname, mname); 429 strcat (symname, mname);
432 moddocs = (void (*)(void))dll_function (dlhandle, symname); 430 moddocs = (void (*)(void))dll_function (dlhandle, symname);
433 if (moddocs == (void (*)(void))0) 431 if (moddocs == NULL)
434 goto missing_symbol; 432 goto missing_symbol;
435 433
436 /* Now look for the optional unload function. */ 434 /* Now look for the optional unload function. */
437 strcpy (symname, "unload_"); 435 strcpy (symname, "unload_");
438 strcat (symname, mname); 436 strcat (symname, mname);
572 570
573 void 571 void
574 reinit_vars_of_module (void) 572 reinit_vars_of_module (void)
575 { 573 {
576 emodules_depth = 0; 574 emodules_depth = 0;
577 modules = (emodules_list *)0; 575 modules = NULL;
578 modnum = 0; 576 modnum = 0;
579 } 577 }
580 578
581 void 579 void
582 vars_of_module (void) 580 vars_of_module (void)