428
|
1 /* emodules.c - Support routines for dynamic module loading
|
|
2 (C) Copyright 1998, 1999 J. Kean Johnston. All rights reserved.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 #include "emodules.h"
|
|
22 #include "sysdll.h"
|
|
23
|
|
24 #ifdef HAVE_SHLIB
|
|
25
|
|
26 /* CE-Emacs version number */
|
|
27 Lisp_Object Vmodule_version;
|
|
28
|
|
29 /* Do we do our work quietly? */
|
|
30 int load_modules_quietly;
|
|
31
|
996
|
32 /* Set this while unloading a module. This should NOT be made set by users,
|
|
33 as it allows the unbinding of symbol-value-forward variables. */
|
|
34 int unloading_module;
|
|
35
|
428
|
36 /* Load path */
|
|
37 Lisp_Object Vmodule_load_path;
|
564
|
38 Lisp_Object Qdll_error;
|
996
|
39 Lisp_Object Qmodule, Qunload_module, module_tag;
|
564
|
40
|
428
|
41 typedef struct _emodules_list
|
|
42 {
|
996
|
43 int used; /* Is this slot used? */
|
|
44 char *soname; /* Name of the shared object loaded (full path) */
|
|
45 char *modname; /* The name of the module */
|
|
46 char *modver; /* The module version string */
|
|
47 char *modtitle; /* How the module announces itself */
|
|
48 void (*unload)(void); /* Module cleanup function to run before unloading */
|
|
49 dll_handle dlhandle; /* Dynamic lib handle */
|
428
|
50 } emodules_list;
|
|
51
|
|
52 static Lisp_Object Vmodule_extensions;
|
|
53
|
|
54 static int emodules_depth;
|
|
55 static dll_handle dlhandle;
|
|
56 static emodules_list *modules;
|
|
57 static int modnum;
|
|
58
|
996
|
59 static int find_make_module (const char *mod, const char *name,
|
|
60 const char *ver, int make_or_find);
|
428
|
61 static Lisp_Object module_load_unwind (Lisp_Object);
|
|
62 static void attempt_module_delete (int mod);
|
|
63
|
|
64 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /*
|
|
65 Load in a C Emacs Extension module named FILE.
|
|
66 The optional NAME and VERSION are used to identify specific modules.
|
|
67
|
996
|
68 DO NOT USE THIS FUNCTION in your programs. Use `require' instead.
|
|
69
|
428
|
70 This function is similar in intent to `load' except that it loads in
|
|
71 pre-compiled C or C++ code, using dynamic shared objects. If NAME is
|
|
72 specified, then the module is only loaded if its internal name matches
|
|
73 the NAME specified. If VERSION is specified, then the module is only
|
|
74 loaded if it matches that VERSION. This function will check to make
|
|
75 sure that the same module is not loaded twice. Modules are searched
|
|
76 for in the same way as Lisp files, except that the valid file
|
1632
|
77 extensions are `.so', `.dll', `.ell', or `.dylib'.
|
428
|
78
|
|
79 All symbols in the shared module must be completely resolved in order
|
|
80 for this function to be successful. Any modules which the specified
|
|
81 FILE depends on will be automatically loaded. You can determine which
|
|
82 modules have been loaded as dynamic shared objects by examining the
|
|
83 return value of the function `list-modules'.
|
|
84
|
996
|
85 It is possible, although unwise, to unload modules using `unload-feature'.
|
442
|
86 The preferred mechanism for unloading or reloading modules is to quit
|
428
|
87 XEmacs, and then reload those new or changed modules that are required.
|
|
88
|
|
89 Messages informing you of the progress of the load are displayed unless
|
|
90 the variable `load-modules-quietly' is non-NIL.
|
|
91 */
|
444
|
92 (file, name, version))
|
428
|
93 {
|
|
94 char *mod, *mname, *mver;
|
|
95 int speccount = specpdl_depth();
|
|
96
|
|
97 CHECK_STRING(file);
|
|
98
|
|
99 mod = (char *)XSTRING_DATA (file);
|
|
100
|
|
101 if (NILP (name))
|
|
102 mname = "";
|
|
103 else
|
|
104 mname = (char *)XSTRING_DATA (name);
|
|
105
|
|
106 if (NILP (version))
|
|
107 mver = "";
|
|
108 else
|
|
109 mver = (char *)XSTRING_DATA (version);
|
|
110
|
|
111 dlhandle = 0;
|
|
112 record_unwind_protect (module_load_unwind, make_int(modnum));
|
|
113 emodules_load (mod, mname, mver);
|
771
|
114 unbind_to (speccount);
|
428
|
115
|
|
116 return Qt;
|
|
117 }
|
|
118
|
996
|
119 DEFUN ("unload-module", Funload_module, 1, 3, 0, /*
|
|
120 Unload a module previously loaded with load-module.
|
428
|
121
|
996
|
122 DO NOT USE THIS FUNCTION in your programs. Use `unload-feature' instead.
|
428
|
123
|
|
124 As with load-module, this function requires at least the module FILE, and
|
|
125 optionally the module NAME and VERSION to unload. It may not be possible
|
|
126 for the module to be unloaded from memory, as there may be Lisp objects
|
442
|
127 referring to variables inside the module code. However, once you have
|
428
|
128 requested a module to be unloaded, it will be unloaded from memory as
|
|
129 soon as the last reference to symbols within the module is destroyed.
|
|
130 */
|
444
|
131 (file, name, version))
|
428
|
132 {
|
|
133 int x;
|
|
134 char *mod, *mname, *mver;
|
996
|
135 Lisp_Object foundname = Qnil;
|
|
136 struct gcpro gcpro1;
|
428
|
137
|
|
138 CHECK_STRING(file);
|
|
139
|
996
|
140 GCPRO1 (foundname);
|
|
141 if (locate_file (Vmodule_load_path, file, Vmodule_extensions, &foundname, 0)
|
|
142 < 0)
|
|
143 return Qt;
|
|
144 mod = (char *)XSTRING_DATA (foundname);
|
|
145 UNGCPRO;
|
428
|
146
|
|
147 if (NILP (name))
|
|
148 mname = "";
|
|
149 else
|
|
150 mname = (char *)XSTRING_DATA (name);
|
|
151
|
|
152 if (NILP (version))
|
|
153 mver = "";
|
|
154 else
|
|
155 mver = (char *)XSTRING_DATA (version);
|
|
156
|
|
157 x = find_make_module (mod, mname, mver, 1);
|
|
158 if (x != -1)
|
996
|
159 {
|
|
160 if (modules[x].unload != NULL)
|
|
161 modules[x].unload ();
|
|
162 attempt_module_delete (x);
|
|
163 }
|
428
|
164 return Qt;
|
|
165 }
|
|
166
|
|
167 DEFUN ("list-modules", Flist_modules, 0, 0, "", /*
|
|
168 Produce a list of loaded dynamic modules.
|
|
169
|
|
170 This function will return a list of all the loaded dynamic modules.
|
|
171 Each element in the list is a list in the form (SONAME NAME VER DESC),
|
|
172 where SONAME is the name of the shared object that was loaded, NAME
|
|
173 is the internal module name, VER is the version of the module, and DESC
|
|
174 is how the module describes itself.
|
|
175
|
|
176 This function returns a list, so you will need to assign the return value
|
|
177 to a variable and then examine the variable with `describe-variable'.
|
|
178 For example:
|
|
179
|
|
180 (setq mylist (list-modules))
|
|
181 (describe-variable 'mylist)
|
|
182
|
|
183
|
|
184 NOTE: It is possible for the same module to be loaded more than once,
|
|
185 at different versions. However, you should never see the same module,
|
|
186 with the same name and version, loaded more than once. If you do, this
|
|
187 is a bug, and you are encouraged to report it.
|
|
188 */
|
|
189 ())
|
|
190 {
|
|
191 Lisp_Object mlist = Qnil;
|
|
192 int i;
|
|
193
|
|
194 for (i = 0; i < modnum; i++)
|
|
195 {
|
|
196 if (modules[i].used == 1)
|
|
197 mlist = Fcons (list4 (build_string (modules[i].soname),
|
|
198 build_string (modules[i].modname),
|
|
199 build_string (modules[i].modver),
|
|
200 build_string (modules[i].modtitle)), mlist);
|
|
201 }
|
|
202
|
|
203 return mlist;
|
|
204 }
|
|
205
|
|
206 static int
|
442
|
207 find_make_module (const char *mod, const char *name, const char *ver, int mof)
|
428
|
208 {
|
|
209 int i, fs = -1;
|
|
210
|
|
211 for (i = 0; i < modnum; i++)
|
|
212 {
|
|
213 if (fs == -1 && modules[i].used == 0)
|
|
214 fs = i;
|
|
215 if (strcmp (modules[i].soname, mod) == 0)
|
|
216 {
|
|
217 if (name && name[0] && strcmp (modules[i].modname, name))
|
|
218 continue;
|
|
219 if (ver && ver[0] && strcmp (modules[i].modver, ver))
|
|
220 continue;
|
|
221 return i; /* Found a match */
|
|
222 }
|
|
223 }
|
|
224
|
|
225 if (mof)
|
|
226 return fs;
|
|
227
|
|
228 if (fs != -1)
|
|
229 return fs; /* First free slot */
|
|
230
|
|
231 /*
|
442
|
232 * We only get here if we haven't found a free slot and the module was
|
428
|
233 * not previously loaded.
|
|
234 */
|
|
235 if (modules == (emodules_list *)0)
|
440
|
236 modules = (emodules_list *) xmalloc (sizeof (emodules_list));
|
428
|
237 modnum++;
|
440
|
238 modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list));
|
428
|
239
|
|
240 fs = modnum - 1;
|
|
241 memset (&modules[fs], 0, sizeof(emodules_list));
|
|
242 return fs;
|
|
243 }
|
|
244
|
|
245 static void
|
|
246 attempt_module_delete (int mod)
|
|
247 {
|
|
248 if (dll_close (modules[mod].dlhandle) == 0)
|
|
249 {
|
|
250 xfree (modules[mod].soname);
|
|
251 xfree (modules[mod].modname);
|
|
252 xfree (modules[mod].modver);
|
|
253 xfree (modules[mod].modtitle);
|
|
254 modules[mod].dlhandle = 0;
|
|
255 modules[mod].used = 0;
|
|
256 }
|
|
257 else if (modules[mod].used > 1)
|
|
258 modules[mod].used = 1; /* We couldn't delete it - it stays */
|
|
259 }
|
|
260
|
|
261 static Lisp_Object
|
|
262 module_load_unwind (Lisp_Object upto)
|
|
263 {
|
|
264 int x,l=0;
|
|
265
|
|
266 /*
|
|
267 * First close off the current handle if it is open.
|
|
268 */
|
|
269 if (dlhandle != 0)
|
|
270 dll_close (dlhandle);
|
|
271 dlhandle = 0;
|
|
272
|
|
273 if (CONSP (upto))
|
|
274 {
|
|
275 if (INTP (XCAR (upto)))
|
|
276 l = XINT (XCAR (upto));
|
853
|
277 free_cons (upto);
|
428
|
278 }
|
|
279 else
|
|
280 l = XINT (upto);
|
|
281
|
|
282 /*
|
|
283 * Here we need to go through and dlclose() (IN REVERSE ORDER!) any
|
|
284 * modules that were loaded as part of this load chain. We only mark
|
|
285 * the slots as closed if the dlclose() succeeds.
|
|
286 */
|
|
287 for (x = modnum-1; x >= l; x--)
|
|
288 {
|
|
289 if (modules[x].used > 1)
|
|
290 attempt_module_delete (x);
|
|
291 }
|
|
292 emodules_depth = 0;
|
|
293
|
|
294 return Qnil;
|
|
295 }
|
|
296
|
|
297 /*
|
|
298 * Do the actual grunt-work of loading in a module. We first try and
|
|
299 * dlopen() the module. If that fails, we have an error and we bail
|
|
300 * out immediately. If the dlopen() succeeds, we need to check for the
|
442
|
301 * existence of certain special symbols.
|
428
|
302 *
|
|
303 * All modules will have complete access to the variables and functions
|
|
304 * defined within XEmacs itself. It is up to the module to declare any
|
|
305 * variables or functions it uses, however. Modules will also have access
|
|
306 * to other functions and variables in other loaded modules, unless they
|
|
307 * are defined as STATIC.
|
|
308 *
|
|
309 * We need to be very careful with how we load modules. If we encounter an
|
|
310 * error along the way, we need to back out completely to the point at
|
442
|
311 * which the user started. Since we can be called recursively, we need to
|
428
|
312 * take care with marking modules as loaded. When we first start loading
|
|
313 * modules, we set the counter to zero. As we enter the function each time,
|
442
|
314 * we increment the counter, and before we leave we decrement it. When
|
428
|
315 * we get back down to 0, we know we are at the end of the chain and we
|
|
316 * can mark all the modules in the list as loaded.
|
|
317 *
|
|
318 * When we signal an error, we need to be sure to unwind all modules loaded
|
|
319 * thus far (but only for this module chain). It is assumed that if any
|
|
320 * modules in a chain fail, then they all do. This is logical, considering
|
442
|
321 * that the only time we recurse is when we have dependent modules. So in
|
428
|
322 * 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 * the cleaning up.
|
|
325 */
|
|
326 void
|
442
|
327 emodules_load(const char *module, const char *modname, const char *modver)
|
428
|
328 {
|
996
|
329 Lisp_Object old_load_list;
|
428
|
330 Lisp_Object filename;
|
996
|
331 Lisp_Object foundname, lisp_modname;
|
|
332 int x, mpx;
|
|
333 char *soname;
|
442
|
334 const char **f;
|
|
335 const long *ellcc_rev;
|
428
|
336 char *mver, *mname, *mtitle, *symname;
|
|
337 void (*modload)(void) = 0;
|
|
338 void (*modsyms)(void) = 0;
|
|
339 void (*modvars)(void) = 0;
|
|
340 void (*moddocs)(void) = 0;
|
996
|
341 void (*modunld)(void) = 0;
|
428
|
342 emodules_list *mp;
|
996
|
343 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
428
|
344
|
|
345 filename = Qnil;
|
|
346 foundname = Qnil;
|
|
347
|
|
348 emodules_depth++;
|
|
349 dlhandle = 0;
|
|
350
|
442
|
351 if ((module == (const char *)0) || (module[0] == '\0'))
|
563
|
352 invalid_argument ("Empty module name", Qunbound);
|
428
|
353
|
996
|
354 GCPRO4(filename, foundname, old_load_list, lisp_modname);
|
|
355 filename = build_string (module);
|
|
356 if (locate_file (Vmodule_load_path, filename, Vmodule_extensions,
|
|
357 &foundname, 0) < 0)
|
563
|
358 signal_error (Qdll_error, "Cannot open dynamic module", filename);
|
428
|
359
|
851
|
360 soname = (char *)ALLOCA (XSTRING_LENGTH (foundname) + 1);
|
428
|
361 strcpy (soname, (char *)XSTRING_DATA (foundname));
|
996
|
362 lisp_modname = call1 (Qfile_name_sans_extension,
|
|
363 Ffile_name_nondirectory (foundname));
|
428
|
364
|
|
365 dlhandle = dll_open (soname);
|
|
366 if (dlhandle == (dll_handle)0)
|
563
|
367 {
|
867
|
368 Ibyte *dllerrint;
|
563
|
369
|
|
370 EXTERNAL_TO_C_STRING (dll_error (dlhandle), dllerrint, Qnative);
|
|
371 signal_error (Qdll_error, "Opening dynamic module",
|
771
|
372 build_intstring (dllerrint));
|
563
|
373 }
|
428
|
374
|
442
|
375 ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler");
|
|
376 if ((ellcc_rev == (const long *)0) || (*ellcc_rev <= 0))
|
563
|
377 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_compiler'", Qunbound);
|
428
|
378 if (*ellcc_rev > EMODULES_REVISION)
|
563
|
379 signal_ferror (Qdll_error, "Invalid dynamic module: Unsupported version `%ld(%ld)'", *ellcc_rev, EMODULES_REVISION);
|
428
|
380
|
442
|
381 f = (const char **)dll_variable (dlhandle, "emodule_name");
|
|
382 if ((f == (const char **)0) || (*f == (const char *)0))
|
563
|
383 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_name'", Qunbound);
|
428
|
384
|
851
|
385 mname = (char *)ALLOCA (strlen (*f) + 1);
|
428
|
386 strcpy (mname, *f);
|
|
387 if (mname[0] == '\0')
|
563
|
388 signal_error (Qdll_error, "Invalid dynamic module: Empty value for `emodule_name'", Qunbound);
|
428
|
389
|
442
|
390 f = (const char **)dll_variable (dlhandle, "emodule_version");
|
|
391 if ((f == (const char **)0) || (*f == (const char *)0))
|
563
|
392 signal_error (Qdll_error, "Missing symbol `emodule_version': Invalid dynamic module", Qunbound);
|
428
|
393
|
851
|
394 mver = (char *)ALLOCA (strlen (*f) + 1);
|
428
|
395 strcpy (mver, *f);
|
|
396
|
442
|
397 f = (const char **)dll_variable (dlhandle, "emodule_title");
|
|
398 if ((f == (const char **)0) || (*f == (const char *)0))
|
563
|
399 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_title'", Qunbound);
|
428
|
400
|
851
|
401 mtitle = (char *)ALLOCA (strlen (*f) + 1);
|
428
|
402 strcpy (mtitle, *f);
|
|
403
|
851
|
404 symname = (char *)ALLOCA (strlen (mname) + 15);
|
428
|
405
|
|
406 strcpy (symname, "modules_of_");
|
|
407 strcat (symname, mname);
|
|
408 modload = (void (*)(void))dll_function (dlhandle, symname);
|
|
409 /*
|
442
|
410 * modload is optional. If the module doesn't require other modules it can
|
428
|
411 * be left out.
|
|
412 */
|
|
413
|
|
414 strcpy (symname, "syms_of_");
|
|
415 strcat (symname, mname);
|
|
416 modsyms = (void (*)(void))dll_function (dlhandle, symname);
|
|
417 if (modsyms == (void (*)(void))0)
|
563
|
418 {
|
|
419 missing_symbol:
|
|
420 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol",
|
|
421 build_string (symname));
|
|
422 }
|
428
|
423
|
|
424 strcpy (symname, "vars_of_");
|
|
425 strcat (symname, mname);
|
|
426 modvars = (void (*)(void))dll_function (dlhandle, symname);
|
|
427 if (modvars == (void (*)(void))0)
|
563
|
428 goto missing_symbol;
|
428
|
429
|
|
430 strcpy (symname, "docs_of_");
|
|
431 strcat (symname, mname);
|
|
432 moddocs = (void (*)(void))dll_function (dlhandle, symname);
|
|
433 if (moddocs == (void (*)(void))0)
|
563
|
434 goto missing_symbol;
|
428
|
435
|
996
|
436 /* Now look for the optional unload function. */
|
|
437 strcpy (symname, "unload_");
|
|
438 strcat (symname, mname);
|
|
439 modunld = (void (*)(void))dll_function (dlhandle, symname);
|
|
440
|
428
|
441 if (modname && modname[0] && strcmp (modname, mname))
|
563
|
442 signal_error (Qdll_error, "Module name mismatch", Qunbound);
|
428
|
443
|
|
444 if (modver && modver[0] && strcmp (modver, mver))
|
563
|
445 signal_error (Qdll_error, "Module version mismatch", Qunbound);
|
428
|
446
|
|
447 /*
|
|
448 * Attempt to make a new slot for this module. If this really is the
|
|
449 * first time we are loading this module, the used member will be 0.
|
|
450 * If that is non-zero, we know that we have a previously loaded module
|
442
|
451 * of the same name and version, and we don't need to go any further.
|
428
|
452 */
|
|
453 mpx = find_make_module (soname, mname, mver, 0);
|
|
454 mp = &modules[mpx];
|
|
455 if (mp->used > 0)
|
|
456 {
|
|
457 emodules_depth--;
|
|
458 dll_close (dlhandle);
|
806
|
459 dlhandle = 0; /* Zero this out before module_load_unwind runs */
|
428
|
460 return;
|
|
461 }
|
|
462
|
|
463 if (!load_modules_quietly)
|
|
464 message ("Loading %s v%s (%s)", mname, mver, mtitle);
|
|
465
|
|
466 /*
|
|
467 * We have passed the basic initialization, and can now add this
|
|
468 * module to the list of modules.
|
|
469 */
|
|
470 mp->used = emodules_depth + 1;
|
|
471 mp->soname = xstrdup (soname);
|
|
472 mp->modname = xstrdup (mname);
|
|
473 mp->modver = xstrdup (mver);
|
|
474 mp->modtitle = xstrdup (mtitle);
|
|
475 mp->dlhandle = dlhandle;
|
996
|
476 mp->unload = modunld;
|
428
|
477 dlhandle = 0;
|
|
478
|
996
|
479 old_load_list = Vcurrent_load_list;
|
|
480 Vcurrent_load_list = Qnil;
|
|
481 LOADHIST_ATTACH (lisp_modname);
|
|
482 LOADHIST_ATTACH (module_tag);
|
|
483
|
428
|
484 /*
|
|
485 * Now we need to call the module init function and perform the various
|
|
486 * startup tasks.
|
|
487 */
|
|
488 if (modload != 0)
|
|
489 (*modload)();
|
|
490
|
|
491 /*
|
|
492 * Now we can get the module to initialize its symbols, and then its
|
|
493 * variables, and lastly the documentation strings.
|
|
494 */
|
|
495 (*modsyms)();
|
|
496 (*modvars)();
|
|
497 (*moddocs)();
|
|
498
|
|
499 if (!load_modules_quietly)
|
|
500 message ("Loaded module %s v%s (%s)", mname, mver, mtitle);
|
|
501
|
996
|
502 Vload_history = Fcons (Fnreverse (Vcurrent_load_list), Vload_history);
|
|
503 Vcurrent_load_list = old_load_list;
|
|
504 UNGCPRO;
|
428
|
505
|
|
506 emodules_depth--;
|
|
507 if (emodules_depth == 0)
|
|
508 {
|
|
509 /*
|
|
510 * We have reached the end of the load chain. We now go through the
|
|
511 * list of loaded modules and mark all the valid modules as just
|
|
512 * that.
|
|
513 */
|
|
514 for (x = 0; x < modnum; x++)
|
|
515 if (modules[x].used > 1)
|
|
516 modules[x].used = 1;
|
|
517 }
|
|
518 }
|
|
519
|
|
520 void
|
442
|
521 emodules_doc_subr(const char *symname, const char *doc)
|
428
|
522 {
|
|
523 Bytecount len = strlen (symname);
|
867
|
524 Lisp_Object sym = oblookup (Vobarray, (const Ibyte *)symname, len);
|
440
|
525 Lisp_Subr *subr;
|
428
|
526
|
1632
|
527 /* Skip autoload cookies */
|
|
528 if (SYMBOLP (sym) && SUBRP (XSYMBOL (sym)->function))
|
428
|
529 {
|
1632
|
530 subr = XSUBR (XSYMBOL (sym)->function);
|
428
|
531 subr->doc = xstrdup (doc);
|
|
532 }
|
|
533 /*
|
|
534 * FIXME: I wish there was some way to avoid the xstrdup(). Is it
|
|
535 * possible to just set a pointer to the string, or somehow create a
|
|
536 * symbol whose value we can point to the constant string? Can someone
|
|
537 * look into this?
|
|
538 */
|
|
539 }
|
|
540
|
|
541 void
|
442
|
542 emodules_doc_sym (const char *symname, const char *doc)
|
428
|
543 {
|
|
544 Bytecount len = strlen (symname);
|
867
|
545 Lisp_Object sym = oblookup (Vobarray, (const Ibyte *)symname, len);
|
428
|
546 Lisp_Object docstr;
|
|
547 struct gcpro gcpro1;
|
|
548
|
|
549 if (SYMBOLP(sym))
|
|
550 {
|
|
551 docstr = build_string (doc);
|
|
552 GCPRO1(docstr);
|
|
553 Fput (sym, Qvariable_documentation, docstr);
|
|
554 UNGCPRO;
|
|
555 }
|
|
556 }
|
|
557
|
|
558
|
|
559 void
|
|
560 syms_of_module (void)
|
|
561 {
|
564
|
562 DEFERROR_STANDARD (Qdll_error, Qerror);
|
996
|
563 DEFSYMBOL (Qmodule);
|
|
564 DEFSYMBOL (Qunload_module);
|
428
|
565 DEFSUBR(Fload_module);
|
|
566 DEFSUBR(Flist_modules);
|
|
567 DEFSUBR(Funload_module);
|
996
|
568 module_tag = Fcons (Qmodule, Qnil);
|
|
569 staticpro (&module_tag);
|
|
570 Fput (Qunload_module, Qdisabled, Qt);
|
428
|
571 }
|
|
572
|
|
573 void
|
|
574 reinit_vars_of_module (void)
|
|
575 {
|
|
576 emodules_depth = 0;
|
|
577 modules = (emodules_list *)0;
|
|
578 modnum = 0;
|
|
579 }
|
|
580
|
|
581 void
|
|
582 vars_of_module (void)
|
|
583 {
|
|
584 reinit_vars_of_module ();
|
|
585
|
|
586 DEFVAR_LISP ("module-version", &Vmodule_version /*
|
|
587 Emacs dynamic loading mechanism version, as a string.
|
|
588
|
|
589 This string is in the form XX.YY.ppp, where XX is the major version
|
|
590 number, YY is the minor version number, and ppp is the patch level.
|
442
|
591 This variable can be used to distinguish between different versions of
|
428
|
592 the dynamic loading technology used in Emacs, if required. It is not
|
|
593 a given that this value will be the same as the Emacs version number.
|
|
594 */ );
|
|
595 Vmodule_version = build_string (EMODULES_VERSION);
|
|
596
|
|
597 DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /*
|
|
598 *Set to t if module loading is to be silent.
|
|
599
|
|
600 Normally, when loading dynamic modules, Emacs will inform you of its
|
|
601 progress, and will display the module name and version if the module
|
|
602 is loaded correctly. Setting this variable to `t' will suppress these
|
|
603 messages. This would normally only be done if `load-module' was being
|
|
604 called by a Lisp function.
|
|
605 */);
|
|
606
|
|
607 DEFVAR_LISP ("module-load-path", &Vmodule_load_path /*
|
|
608 *List of directories to search for dynamic modules to load.
|
|
609 Each element is a string (directory name) or nil (try default directory).
|
|
610
|
|
611 Note that elements of this list *may not* begin with "~", so you must
|
442
|
612 call `expand-file-name' on them before adding them to this list.
|
428
|
613
|
|
614 Initialized based on EMACSMODULEPATH environment variable, if any, otherwise
|
|
615 to default specified the file `paths.h' when XEmacs was built. If there
|
|
616 were no paths specified in `paths.h', then XEmacs chooses a default
|
|
617 value for this variable by looking around in the file-system near the
|
|
618 directory in which the XEmacs executable resides.
|
|
619
|
|
620 Due to the nature of dynamic modules, the path names should almost always
|
442
|
621 refer to architecture-dependent directories. It is unwise to attempt to
|
|
622 store dynamic modules in a heterogenous environment. Some environments
|
428
|
623 are similar enough to each other that XEmacs will be unable to determine
|
|
624 the correctness of a dynamic module, which can have unpredictable results
|
|
625 when a dynamic module is loaded.
|
|
626 */);
|
|
627
|
996
|
628 DEFVAR_BOOL ("unloading-module", &unloading_module /*
|
|
629 Used internally by `unload-feature'. Do not set this variable.
|
|
630 Danger, danger, Will Robinson!
|
|
631 */);
|
|
632
|
428
|
633 /* #### Export this to Lisp */
|
1381
|
634 Vmodule_extensions = list4 (build_string (".ell"),
|
996
|
635 build_string (".so"),
|
1381
|
636 build_string (".dll"),
|
|
637 build_string (".dylib"));
|
428
|
638 staticpro (&Vmodule_extensions);
|
|
639
|
|
640 load_modules_quietly = 0;
|
|
641 Vmodule_load_path = Qnil;
|
|
642 Fprovide (intern ("modules"));
|
|
643 }
|
|
644
|
|
645 #endif /* HAVE_SHLIB */
|