Mercurial > hg > xemacs-beta
comparison src/emodules.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | aabb7f5b1c81 |
children | 697ef44129c6 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
40 char *modver; /* The version that the module is at */ | 40 char *modver; /* The version that the module is at */ |
41 char *modtitle; /* How the module announces itself */ | 41 char *modtitle; /* How the module announces itself */ |
42 dll_handle dlhandle; /* Dynamic lib handle */ | 42 dll_handle dlhandle; /* Dynamic lib handle */ |
43 } emodules_list; | 43 } emodules_list; |
44 | 44 |
45 static Lisp_Object Vmodule_extensions; | |
46 | |
45 static int emodules_depth; | 47 static int emodules_depth; |
46 static dll_handle dlhandle; | 48 static dll_handle dlhandle; |
47 static emodules_list *modules; | 49 static emodules_list *modules; |
48 static int modnum; | 50 static int modnum; |
49 | 51 |
50 static int find_make_module (CONST char *mod, CONST char *name, CONST char *ver, int make_or_find); | 52 static int find_make_module (const char *mod, const char *name, const char *ver, int make_or_find); |
51 static Lisp_Object module_load_unwind (Lisp_Object); | 53 static Lisp_Object module_load_unwind (Lisp_Object); |
52 static void attempt_module_delete (int mod); | 54 static void attempt_module_delete (int mod); |
53 | 55 |
54 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /* | 56 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /* |
55 Load in a C Emacs Extension module named FILE. | 57 Load in a C Emacs Extension module named FILE. |
180 | 182 |
181 return mlist; | 183 return mlist; |
182 } | 184 } |
183 | 185 |
184 static int | 186 static int |
185 find_make_module (CONST char *mod, CONST char *name, CONST char *ver, int mof) | 187 find_make_module (const char *mod, const char *name, const char *ver, int mof) |
186 { | 188 { |
187 int i, fs = -1; | 189 int i, fs = -1; |
188 | 190 |
189 for (i = 0; i < modnum; i++) | 191 for (i = 0; i < modnum; i++) |
190 { | 192 { |
209 /* | 211 /* |
210 * We only get here if we havent found a free slot and the module was | 212 * We only get here if we havent found a free slot and the module was |
211 * not previously loaded. | 213 * not previously loaded. |
212 */ | 214 */ |
213 if (modules == (emodules_list *)0) | 215 if (modules == (emodules_list *)0) |
214 modules = (emodules_list *)xmalloc (sizeof(emodules_list)); | 216 modules = (emodules_list *) xmalloc (sizeof (emodules_list)); |
215 modnum++; | 217 modnum++; |
216 modules = xrealloc (modules, modnum * sizeof(emodules_list)); | 218 modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list)); |
217 | 219 |
218 fs = modnum - 1; | 220 fs = modnum - 1; |
219 memset (&modules[fs], 0, sizeof(emodules_list)); | 221 memset (&modules[fs], 0, sizeof(emodules_list)); |
220 return fs; | 222 return fs; |
221 } | 223 } |
300 * the error handler we take great care to close off the module chain before | 302 * the error handler we take great care to close off the module chain before |
301 * we call "error" and let the Fmodule_load unwind_protect() function handle | 303 * we call "error" and let the Fmodule_load unwind_protect() function handle |
302 * the cleaning up. | 304 * the cleaning up. |
303 */ | 305 */ |
304 void | 306 void |
305 emodules_load(CONST char *module, CONST char *modname, CONST char *modver) | 307 emodules_load(const char *module, const char *modname, const char *modver) |
306 { | 308 { |
307 Lisp_Object filename; | 309 Lisp_Object filename; |
308 Lisp_Object foundname; | 310 Lisp_Object foundname; |
309 int fd, x, mpx; | 311 int fd, x, mpx; |
310 char *soname, *tmod; | 312 char *soname, *tmod; |
311 CONST char **f; | 313 const char **f; |
312 CONST long *ellcc_rev; | 314 const long *ellcc_rev; |
313 char *mver, *mname, *mtitle, *symname; | 315 char *mver, *mname, *mtitle, *symname; |
314 void (*modload)(void) = 0; | 316 void (*modload)(void) = 0; |
315 void (*modsyms)(void) = 0; | 317 void (*modsyms)(void) = 0; |
316 void (*modvars)(void) = 0; | 318 void (*modvars)(void) = 0; |
317 void (*moddocs)(void) = 0; | 319 void (*moddocs)(void) = 0; |
322 foundname = Qnil; | 324 foundname = Qnil; |
323 | 325 |
324 emodules_depth++; | 326 emodules_depth++; |
325 dlhandle = 0; | 327 dlhandle = 0; |
326 | 328 |
327 if ((module == (CONST char *)0) || (module[0] == '\0')) | 329 if ((module == (const char *)0) || (module[0] == '\0')) |
328 error ("Empty module name"); | 330 error ("Empty module name"); |
329 | 331 |
330 /* This is to get around the fact that build_string() is not declared | 332 /* This is to get around the fact that build_string() is not declared |
331 as taking a const char * as an argument. I HATE compiler warnings. */ | 333 as taking a const char * as an argument. I HATE compiler warnings. */ |
332 tmod = (char *)alloca (strlen (module) + 1); | 334 tmod = (char *)alloca (strlen (module) + 1); |
333 strcpy (tmod, module); | 335 strcpy (tmod, module); |
334 | 336 |
335 GCPRO2(filename, foundname); | 337 GCPRO2(filename, foundname); |
336 filename = build_string (tmod); | 338 filename = build_string (tmod); |
337 fd = locate_file(Vmodule_load_path, filename, ":.ell:.so:.dll", &foundname, -1); | 339 fd = locate_file(Vmodule_load_path, filename, Vmodule_extensions, |
340 &foundname, -1); | |
338 UNGCPRO; | 341 UNGCPRO; |
339 | 342 |
340 if (fd < 0) | 343 if (fd < 0) |
341 signal_simple_error ("Cannot open dynamic module", filename); | 344 signal_simple_error ("Cannot open dynamic module", filename); |
342 | 345 |
345 | 348 |
346 dlhandle = dll_open (soname); | 349 dlhandle = dll_open (soname); |
347 if (dlhandle == (dll_handle)0) | 350 if (dlhandle == (dll_handle)0) |
348 error ("Opening dynamic module: %s", dll_error (dlhandle)); | 351 error ("Opening dynamic module: %s", dll_error (dlhandle)); |
349 | 352 |
350 ellcc_rev = (CONST long *)dll_variable (dlhandle, "emodule_compiler"); | 353 ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler"); |
351 if ((ellcc_rev == (CONST long *)0) || (*ellcc_rev <= 0)) | 354 if ((ellcc_rev == (const long *)0) || (*ellcc_rev <= 0)) |
352 error ("Missing symbol `emodule_compiler': Invalid dynamic module"); | 355 error ("Missing symbol `emodule_compiler': Invalid dynamic module"); |
353 if (*ellcc_rev > EMODULES_REVISION) | 356 if (*ellcc_rev > EMODULES_REVISION) |
354 error ("Unsupported version `%ld(%ld)': Invalid dynamic module", | 357 error ("Unsupported version `%ld(%ld)': Invalid dynamic module", |
355 *ellcc_rev, EMODULES_REVISION); | 358 *ellcc_rev, EMODULES_REVISION); |
356 | 359 |
357 f = (CONST char **)dll_variable (dlhandle, "emodule_name"); | 360 f = (const char **)dll_variable (dlhandle, "emodule_name"); |
358 if ((f == (CONST char **)0) || (*f == (CONST char *)0)) | 361 if ((f == (const char **)0) || (*f == (const char *)0)) |
359 error ("Missing symbol `emodule_name': Invalid dynamic module"); | 362 error ("Missing symbol `emodule_name': Invalid dynamic module"); |
360 | 363 |
361 mname = (char *)alloca (strlen (*f) + 1); | 364 mname = (char *)alloca (strlen (*f) + 1); |
362 strcpy (mname, *f); | 365 strcpy (mname, *f); |
363 if (mname[0] == '\0') | 366 if (mname[0] == '\0') |
364 error ("Empty value for `emodule_name': Invalid dynamic module"); | 367 error ("Empty value for `emodule_name': Invalid dynamic module"); |
365 | 368 |
366 f = (CONST char **)dll_variable (dlhandle, "emodule_version"); | 369 f = (const char **)dll_variable (dlhandle, "emodule_version"); |
367 if ((f == (CONST char **)0) || (*f == (CONST char *)0)) | 370 if ((f == (const char **)0) || (*f == (const char *)0)) |
368 error ("Missing symbol `emodule_version': Invalid dynamic module"); | 371 error ("Missing symbol `emodule_version': Invalid dynamic module"); |
369 | 372 |
370 mver = (char *)alloca (strlen (*f) + 1); | 373 mver = (char *)alloca (strlen (*f) + 1); |
371 strcpy (mver, *f); | 374 strcpy (mver, *f); |
372 | 375 |
373 f = (CONST char **)dll_variable (dlhandle, "emodule_title"); | 376 f = (const char **)dll_variable (dlhandle, "emodule_title"); |
374 if ((f == (CONST char **)0) || (*f == (CONST char *)0)) | 377 if ((f == (const char **)0) || (*f == (const char *)0)) |
375 error ("Missing symbol `emodule_title': Invalid dynamic module"); | 378 error ("Missing symbol `emodule_title': Invalid dynamic module"); |
376 | 379 |
377 mtitle = (char *)alloca (strlen (*f) + 1); | 380 mtitle = (char *)alloca (strlen (*f) + 1); |
378 strcpy (mtitle, *f); | 381 strcpy (mtitle, *f); |
379 | 382 |
473 modules[x].used = 1; | 476 modules[x].used = 1; |
474 } | 477 } |
475 } | 478 } |
476 | 479 |
477 void | 480 void |
478 emodules_doc_subr(CONST char *symname, CONST char *doc) | 481 emodules_doc_subr(const char *symname, const char *doc) |
479 { | 482 { |
480 Bytecount len = strlen (symname); | 483 Bytecount len = strlen (symname); |
481 Lisp_Object sym = oblookup (Vobarray, (CONST Bufbyte *)symname, len); | 484 Lisp_Object sym = oblookup (Vobarray, (const Bufbyte *)symname, len); |
482 struct Lisp_Subr *subr; | 485 Lisp_Subr *subr; |
483 | 486 |
484 if (SYMBOLP(sym)) | 487 if (SYMBOLP(sym)) |
485 { | 488 { |
486 subr = XSUBR( XSYMBOL(sym)->function); | 489 subr = XSUBR( XSYMBOL(sym)->function); |
487 subr->doc = xstrdup (doc); | 490 subr->doc = xstrdup (doc); |
493 * look into this? | 496 * look into this? |
494 */ | 497 */ |
495 } | 498 } |
496 | 499 |
497 void | 500 void |
498 emodules_doc_sym (CONST char *symname, CONST char *doc) | 501 emodules_doc_sym (const char *symname, const char *doc) |
499 { | 502 { |
500 Bytecount len = strlen (symname); | 503 Bytecount len = strlen (symname); |
501 Lisp_Object sym = oblookup (Vobarray, (CONST Bufbyte *)symname, len); | 504 Lisp_Object sym = oblookup (Vobarray, (const Bufbyte *)symname, len); |
502 Lisp_Object docstr; | 505 Lisp_Object docstr; |
503 struct gcpro gcpro1; | 506 struct gcpro gcpro1; |
504 | 507 |
505 if (SYMBOLP(sym)) | 508 if (SYMBOLP(sym)) |
506 { | 509 { |
521 DEFSUBR(Funload_module); | 524 DEFSUBR(Funload_module); |
522 #endif | 525 #endif |
523 } | 526 } |
524 | 527 |
525 void | 528 void |
529 reinit_vars_of_module (void) | |
530 { | |
531 emodules_depth = 0; | |
532 modules = (emodules_list *)0; | |
533 modnum = 0; | |
534 } | |
535 | |
536 void | |
526 vars_of_module (void) | 537 vars_of_module (void) |
527 { | 538 { |
539 reinit_vars_of_module (); | |
540 | |
528 DEFVAR_LISP ("module-version", &Vmodule_version /* | 541 DEFVAR_LISP ("module-version", &Vmodule_version /* |
529 Emacs dynamic loading mechanism version, as a string. | 542 Emacs dynamic loading mechanism version, as a string. |
530 | 543 |
531 This string is in the form XX.YY.ppp, where XX is the major version | 544 This string is in the form XX.YY.ppp, where XX is the major version |
532 number, YY is the minor version number, and ppp is the patch level. | 545 number, YY is the minor version number, and ppp is the patch level. |
533 This variable can be used to distinquish between different versions of | 546 This variable can be used to distinquish between different versions of |
534 the dynamic loading technology used in Emacs, if required. It is not | 547 the dynamic loading technology used in Emacs, if required. It is not |
535 a given that this value will be the same as the Emacs version number. | 548 a given that this value will be the same as the Emacs version number. |
536 */ ); | 549 */ ); |
537 Vmodule_version = Fpurecopy (build_string (EMODULES_VERSION)); | 550 Vmodule_version = build_string (EMODULES_VERSION); |
538 | 551 |
539 DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /* | 552 DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /* |
540 *Set to t if module loading is to be silent. | 553 *Set to t if module loading is to be silent. |
541 | 554 |
542 Normally, when loading dynamic modules, Emacs will inform you of its | 555 Normally, when loading dynamic modules, Emacs will inform you of its |
565 are similar enough to each other that XEmacs will be unable to determine | 578 are similar enough to each other that XEmacs will be unable to determine |
566 the correctness of a dynamic module, which can have unpredictable results | 579 the correctness of a dynamic module, which can have unpredictable results |
567 when a dynamic module is loaded. | 580 when a dynamic module is loaded. |
568 */); | 581 */); |
569 | 582 |
583 /* #### Export this to Lisp */ | |
584 Vmodule_extensions = build_string (":.ell:.so:.dll"); | |
585 staticpro (&Vmodule_extensions); | |
586 | |
570 load_modules_quietly = 0; | 587 load_modules_quietly = 0; |
571 emodules_depth = 0; | |
572 modules = (emodules_list *)0; | |
573 modnum = 0; | |
574 Vmodule_load_path = Qnil; | 588 Vmodule_load_path = Qnil; |
575 Fprovide (intern ("modules")); | 589 Fprovide (intern ("modules")); |
576 } | 590 } |
577 | 591 |
578 #endif /* HAVE_SHLIB */ | 592 #endif /* HAVE_SHLIB */ |