Mercurial > hg > xemacs-beta
comparison src/emodules.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children | 11054d720c21 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
47 static int emodules_depth; | 47 static int emodules_depth; |
48 static dll_handle dlhandle; | 48 static dll_handle dlhandle; |
49 static emodules_list *modules; | 49 static emodules_list *modules; |
50 static int modnum; | 50 static int modnum; |
51 | 51 |
52 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); |
53 static Lisp_Object module_load_unwind (Lisp_Object); | 53 static Lisp_Object module_load_unwind (Lisp_Object); |
54 static void attempt_module_delete (int mod); | 54 static void attempt_module_delete (int mod); |
55 | 55 |
56 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /* | 56 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /* |
57 Load in a C Emacs Extension module named FILE. | 57 Load in a C Emacs Extension module named FILE. |
182 | 182 |
183 return mlist; | 183 return mlist; |
184 } | 184 } |
185 | 185 |
186 static int | 186 static int |
187 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) |
188 { | 188 { |
189 int i, fs = -1; | 189 int i, fs = -1; |
190 | 190 |
191 for (i = 0; i < modnum; i++) | 191 for (i = 0; i < modnum; i++) |
192 { | 192 { |
211 /* | 211 /* |
212 * 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 |
213 * not previously loaded. | 213 * not previously loaded. |
214 */ | 214 */ |
215 if (modules == (emodules_list *)0) | 215 if (modules == (emodules_list *)0) |
216 modules = (emodules_list *) xmalloc (sizeof (emodules_list)); | 216 modules = (emodules_list *)xmalloc (sizeof(emodules_list)); |
217 modnum++; | 217 modnum++; |
218 modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list)); | 218 modules = xrealloc (modules, modnum * sizeof(emodules_list)); |
219 | 219 |
220 fs = modnum - 1; | 220 fs = modnum - 1; |
221 memset (&modules[fs], 0, sizeof(emodules_list)); | 221 memset (&modules[fs], 0, sizeof(emodules_list)); |
222 return fs; | 222 return fs; |
223 } | 223 } |
302 * 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 |
303 * 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 |
304 * the cleaning up. | 304 * the cleaning up. |
305 */ | 305 */ |
306 void | 306 void |
307 emodules_load(const char *module, const char *modname, const char *modver) | 307 emodules_load(CONST char *module, CONST char *modname, CONST char *modver) |
308 { | 308 { |
309 Lisp_Object filename; | 309 Lisp_Object filename; |
310 Lisp_Object foundname; | 310 Lisp_Object foundname; |
311 int fd, x, mpx; | 311 int fd, x, mpx; |
312 char *soname, *tmod; | 312 char *soname, *tmod; |
313 const char **f; | 313 CONST char **f; |
314 const long *ellcc_rev; | 314 CONST long *ellcc_rev; |
315 char *mver, *mname, *mtitle, *symname; | 315 char *mver, *mname, *mtitle, *symname; |
316 void (*modload)(void) = 0; | 316 void (*modload)(void) = 0; |
317 void (*modsyms)(void) = 0; | 317 void (*modsyms)(void) = 0; |
318 void (*modvars)(void) = 0; | 318 void (*modvars)(void) = 0; |
319 void (*moddocs)(void) = 0; | 319 void (*moddocs)(void) = 0; |
324 foundname = Qnil; | 324 foundname = Qnil; |
325 | 325 |
326 emodules_depth++; | 326 emodules_depth++; |
327 dlhandle = 0; | 327 dlhandle = 0; |
328 | 328 |
329 if ((module == (const char *)0) || (module[0] == '\0')) | 329 if ((module == (CONST char *)0) || (module[0] == '\0')) |
330 error ("Empty module name"); | 330 error ("Empty module name"); |
331 | 331 |
332 /* 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 |
333 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. */ |
334 tmod = (char *)alloca (strlen (module) + 1); | 334 tmod = (char *)alloca (strlen (module) + 1); |
348 | 348 |
349 dlhandle = dll_open (soname); | 349 dlhandle = dll_open (soname); |
350 if (dlhandle == (dll_handle)0) | 350 if (dlhandle == (dll_handle)0) |
351 error ("Opening dynamic module: %s", dll_error (dlhandle)); | 351 error ("Opening dynamic module: %s", dll_error (dlhandle)); |
352 | 352 |
353 ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler"); | 353 ellcc_rev = (CONST long *)dll_variable (dlhandle, "emodule_compiler"); |
354 if ((ellcc_rev == (const long *)0) || (*ellcc_rev <= 0)) | 354 if ((ellcc_rev == (CONST long *)0) || (*ellcc_rev <= 0)) |
355 error ("Missing symbol `emodule_compiler': Invalid dynamic module"); | 355 error ("Missing symbol `emodule_compiler': Invalid dynamic module"); |
356 if (*ellcc_rev > EMODULES_REVISION) | 356 if (*ellcc_rev > EMODULES_REVISION) |
357 error ("Unsupported version `%ld(%ld)': Invalid dynamic module", | 357 error ("Unsupported version `%ld(%ld)': Invalid dynamic module", |
358 *ellcc_rev, EMODULES_REVISION); | 358 *ellcc_rev, EMODULES_REVISION); |
359 | 359 |
360 f = (const char **)dll_variable (dlhandle, "emodule_name"); | 360 f = (CONST char **)dll_variable (dlhandle, "emodule_name"); |
361 if ((f == (const char **)0) || (*f == (const char *)0)) | 361 if ((f == (CONST char **)0) || (*f == (CONST char *)0)) |
362 error ("Missing symbol `emodule_name': Invalid dynamic module"); | 362 error ("Missing symbol `emodule_name': Invalid dynamic module"); |
363 | 363 |
364 mname = (char *)alloca (strlen (*f) + 1); | 364 mname = (char *)alloca (strlen (*f) + 1); |
365 strcpy (mname, *f); | 365 strcpy (mname, *f); |
366 if (mname[0] == '\0') | 366 if (mname[0] == '\0') |
367 error ("Empty value for `emodule_name': Invalid dynamic module"); | 367 error ("Empty value for `emodule_name': Invalid dynamic module"); |
368 | 368 |
369 f = (const char **)dll_variable (dlhandle, "emodule_version"); | 369 f = (CONST char **)dll_variable (dlhandle, "emodule_version"); |
370 if ((f == (const char **)0) || (*f == (const char *)0)) | 370 if ((f == (CONST char **)0) || (*f == (CONST char *)0)) |
371 error ("Missing symbol `emodule_version': Invalid dynamic module"); | 371 error ("Missing symbol `emodule_version': Invalid dynamic module"); |
372 | 372 |
373 mver = (char *)alloca (strlen (*f) + 1); | 373 mver = (char *)alloca (strlen (*f) + 1); |
374 strcpy (mver, *f); | 374 strcpy (mver, *f); |
375 | 375 |
376 f = (const char **)dll_variable (dlhandle, "emodule_title"); | 376 f = (CONST char **)dll_variable (dlhandle, "emodule_title"); |
377 if ((f == (const char **)0) || (*f == (const char *)0)) | 377 if ((f == (CONST char **)0) || (*f == (CONST char *)0)) |
378 error ("Missing symbol `emodule_title': Invalid dynamic module"); | 378 error ("Missing symbol `emodule_title': Invalid dynamic module"); |
379 | 379 |
380 mtitle = (char *)alloca (strlen (*f) + 1); | 380 mtitle = (char *)alloca (strlen (*f) + 1); |
381 strcpy (mtitle, *f); | 381 strcpy (mtitle, *f); |
382 | 382 |
476 modules[x].used = 1; | 476 modules[x].used = 1; |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 void | 480 void |
481 emodules_doc_subr(const char *symname, const char *doc) | 481 emodules_doc_subr(CONST char *symname, CONST char *doc) |
482 { | 482 { |
483 Bytecount len = strlen (symname); | 483 Bytecount len = strlen (symname); |
484 Lisp_Object sym = oblookup (Vobarray, (const Bufbyte *)symname, len); | 484 Lisp_Object sym = oblookup (Vobarray, (CONST Bufbyte *)symname, len); |
485 Lisp_Subr *subr; | 485 struct Lisp_Subr *subr; |
486 | 486 |
487 if (SYMBOLP(sym)) | 487 if (SYMBOLP(sym)) |
488 { | 488 { |
489 subr = XSUBR( XSYMBOL(sym)->function); | 489 subr = XSUBR( XSYMBOL(sym)->function); |
490 subr->doc = xstrdup (doc); | 490 subr->doc = xstrdup (doc); |
496 * look into this? | 496 * look into this? |
497 */ | 497 */ |
498 } | 498 } |
499 | 499 |
500 void | 500 void |
501 emodules_doc_sym (const char *symname, const char *doc) | 501 emodules_doc_sym (CONST char *symname, CONST char *doc) |
502 { | 502 { |
503 Bytecount len = strlen (symname); | 503 Bytecount len = strlen (symname); |
504 Lisp_Object sym = oblookup (Vobarray, (const Bufbyte *)symname, len); | 504 Lisp_Object sym = oblookup (Vobarray, (CONST Bufbyte *)symname, len); |
505 Lisp_Object docstr; | 505 Lisp_Object docstr; |
506 struct gcpro gcpro1; | 506 struct gcpro gcpro1; |
507 | 507 |
508 if (SYMBOLP(sym)) | 508 if (SYMBOLP(sym)) |
509 { | 509 { |
524 DEFSUBR(Funload_module); | 524 DEFSUBR(Funload_module); |
525 #endif | 525 #endif |
526 } | 526 } |
527 | 527 |
528 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 | |
537 vars_of_module (void) | 529 vars_of_module (void) |
538 { | 530 { |
539 reinit_vars_of_module (); | |
540 | |
541 DEFVAR_LISP ("module-version", &Vmodule_version /* | 531 DEFVAR_LISP ("module-version", &Vmodule_version /* |
542 Emacs dynamic loading mechanism version, as a string. | 532 Emacs dynamic loading mechanism version, as a string. |
543 | 533 |
544 This string is in the form XX.YY.ppp, where XX is the major version | 534 This string is in the form XX.YY.ppp, where XX is the major version |
545 number, YY is the minor version number, and ppp is the patch level. | 535 number, YY is the minor version number, and ppp is the patch level. |
546 This variable can be used to distinquish between different versions of | 536 This variable can be used to distinquish between different versions of |
547 the dynamic loading technology used in Emacs, if required. It is not | 537 the dynamic loading technology used in Emacs, if required. It is not |
548 a given that this value will be the same as the Emacs version number. | 538 a given that this value will be the same as the Emacs version number. |
549 */ ); | 539 */ ); |
550 Vmodule_version = build_string (EMODULES_VERSION); | 540 Vmodule_version = Fpurecopy (build_string (EMODULES_VERSION)); |
551 | 541 |
552 DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /* | 542 DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /* |
553 *Set to t if module loading is to be silent. | 543 *Set to t if module loading is to be silent. |
554 | 544 |
555 Normally, when loading dynamic modules, Emacs will inform you of its | 545 Normally, when loading dynamic modules, Emacs will inform you of its |
583 /* #### Export this to Lisp */ | 573 /* #### Export this to Lisp */ |
584 Vmodule_extensions = build_string (":.ell:.so:.dll"); | 574 Vmodule_extensions = build_string (":.ell:.so:.dll"); |
585 staticpro (&Vmodule_extensions); | 575 staticpro (&Vmodule_extensions); |
586 | 576 |
587 load_modules_quietly = 0; | 577 load_modules_quietly = 0; |
578 emodules_depth = 0; | |
579 modules = (emodules_list *)0; | |
580 modnum = 0; | |
588 Vmodule_load_path = Qnil; | 581 Vmodule_load_path = Qnil; |
589 Fprovide (intern ("modules")); | 582 Fprovide (intern ("modules")); |
590 } | 583 } |
591 | 584 |
592 #endif /* HAVE_SHLIB */ | 585 #endif /* HAVE_SHLIB */ |