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
|
1750
|
24 /* Load path */
|
|
25 static Lisp_Object Vmodule_load_path;
|
|
26
|
|
27 /* Module lFile extensions */
|
|
28 static Lisp_Object Vmodule_extensions;
|
|
29
|
428
|
30 #ifdef HAVE_SHLIB
|
|
31
|
|
32 /* CE-Emacs version number */
|
|
33 Lisp_Object Vmodule_version;
|
|
34
|
|
35 /* Do we do our work quietly? */
|
|
36 int load_modules_quietly;
|
|
37
|
996
|
38 /* Set this while unloading a module. This should NOT be made set by users,
|
|
39 as it allows the unbinding of symbol-value-forward variables. */
|
|
40 int unloading_module;
|
|
41
|
564
|
42 Lisp_Object Qdll_error;
|
996
|
43 Lisp_Object Qmodule, Qunload_module, module_tag;
|
564
|
44
|
428
|
45 typedef struct _emodules_list
|
|
46 {
|
996
|
47 int used; /* Is this slot used? */
|
1706
|
48 CIbyte *soname; /* Name of the shared object loaded (full path) */
|
|
49 CIbyte *modname; /* The name of the module */
|
|
50 CIbyte *modver; /* The module version string */
|
|
51 CIbyte *modtitle; /* How the module announces itself */
|
996
|
52 void (*unload)(void); /* Module cleanup function to run before unloading */
|
|
53 dll_handle dlhandle; /* Dynamic lib handle */
|
428
|
54 } emodules_list;
|
|
55
|
|
56 static int emodules_depth;
|
|
57 static dll_handle dlhandle;
|
|
58 static emodules_list *modules;
|
|
59 static int modnum;
|
|
60
|
1706
|
61 static int find_make_module (const CIbyte *mod, const CIbyte *name,
|
|
62 const CIbyte *ver, int make_or_find);
|
428
|
63 static Lisp_Object module_load_unwind (Lisp_Object);
|
|
64 static void attempt_module_delete (int mod);
|
|
65
|
|
66 DEFUN ("load-module", Fload_module, 1, 3, "FLoad dynamic module: ", /*
|
|
67 Load in a C Emacs Extension module named FILE.
|
|
68 The optional NAME and VERSION are used to identify specific modules.
|
|
69
|
996
|
70 DO NOT USE THIS FUNCTION in your programs. Use `require' instead.
|
|
71
|
428
|
72 This function is similar in intent to `load' except that it loads in
|
|
73 pre-compiled C or C++ code, using dynamic shared objects. If NAME is
|
|
74 specified, then the module is only loaded if its internal name matches
|
|
75 the NAME specified. If VERSION is specified, then the module is only
|
|
76 loaded if it matches that VERSION. This function will check to make
|
|
77 sure that the same module is not loaded twice. Modules are searched
|
|
78 for in the same way as Lisp files, except that the valid file
|
1632
|
79 extensions are `.so', `.dll', `.ell', or `.dylib'.
|
428
|
80
|
|
81 All symbols in the shared module must be completely resolved in order
|
|
82 for this function to be successful. Any modules which the specified
|
|
83 FILE depends on will be automatically loaded. You can determine which
|
|
84 modules have been loaded as dynamic shared objects by examining the
|
|
85 return value of the function `list-modules'.
|
|
86
|
996
|
87 It is possible, although unwise, to unload modules using `unload-feature'.
|
442
|
88 The preferred mechanism for unloading or reloading modules is to quit
|
428
|
89 XEmacs, and then reload those new or changed modules that are required.
|
|
90
|
|
91 Messages informing you of the progress of the load are displayed unless
|
|
92 the variable `load-modules-quietly' is non-NIL.
|
|
93 */
|
444
|
94 (file, name, version))
|
428
|
95 {
|
1706
|
96 CIbyte *mod, *mname, *mver;
|
428
|
97 int speccount = specpdl_depth();
|
|
98
|
|
99 CHECK_STRING(file);
|
|
100
|
1706
|
101 mod = (CIbyte *) XSTRING_DATA (file);
|
428
|
102
|
|
103 if (NILP (name))
|
|
104 mname = "";
|
|
105 else
|
1706
|
106 mname = (CIbyte *) XSTRING_DATA (name);
|
428
|
107
|
|
108 if (NILP (version))
|
|
109 mver = "";
|
|
110 else
|
1706
|
111 mver = (CIbyte *) XSTRING_DATA (version);
|
428
|
112
|
|
113 dlhandle = 0;
|
|
114 record_unwind_protect (module_load_unwind, make_int(modnum));
|
|
115 emodules_load (mod, mname, mver);
|
771
|
116 unbind_to (speccount);
|
428
|
117
|
|
118 return Qt;
|
|
119 }
|
|
120
|
996
|
121 DEFUN ("unload-module", Funload_module, 1, 3, 0, /*
|
|
122 Unload a module previously loaded with load-module.
|
428
|
123
|
996
|
124 DO NOT USE THIS FUNCTION in your programs. Use `unload-feature' instead.
|
428
|
125
|
|
126 As with load-module, this function requires at least the module FILE, and
|
|
127 optionally the module NAME and VERSION to unload. It may not be possible
|
|
128 for the module to be unloaded from memory, as there may be Lisp objects
|
442
|
129 referring to variables inside the module code. However, once you have
|
428
|
130 requested a module to be unloaded, it will be unloaded from memory as
|
|
131 soon as the last reference to symbols within the module is destroyed.
|
|
132 */
|
444
|
133 (file, name, version))
|
428
|
134 {
|
|
135 int x;
|
1706
|
136 CIbyte *mod, *mname, *mver;
|
996
|
137 Lisp_Object foundname = Qnil;
|
|
138 struct gcpro gcpro1;
|
428
|
139
|
|
140 CHECK_STRING(file);
|
|
141
|
996
|
142 GCPRO1 (foundname);
|
|
143 if (locate_file (Vmodule_load_path, file, Vmodule_extensions, &foundname, 0)
|
|
144 < 0)
|
|
145 return Qt;
|
1706
|
146 mod = (CIbyte *) XSTRING_DATA (foundname);
|
996
|
147 UNGCPRO;
|
428
|
148
|
|
149 if (NILP (name))
|
|
150 mname = "";
|
|
151 else
|
1706
|
152 mname = (CIbyte *) XSTRING_DATA (name);
|
428
|
153
|
|
154 if (NILP (version))
|
|
155 mver = "";
|
|
156 else
|
1706
|
157 mver = (CIbyte *) XSTRING_DATA (version);
|
428
|
158
|
|
159 x = find_make_module (mod, mname, mver, 1);
|
|
160 if (x != -1)
|
996
|
161 {
|
|
162 if (modules[x].unload != NULL)
|
|
163 modules[x].unload ();
|
|
164 attempt_module_delete (x);
|
|
165 }
|
428
|
166 return Qt;
|
|
167 }
|
|
168
|
|
169 DEFUN ("list-modules", Flist_modules, 0, 0, "", /*
|
|
170 Produce a list of loaded dynamic modules.
|
|
171
|
|
172 This function will return a list of all the loaded dynamic modules.
|
|
173 Each element in the list is a list in the form (SONAME NAME VER DESC),
|
|
174 where SONAME is the name of the shared object that was loaded, NAME
|
|
175 is the internal module name, VER is the version of the module, and DESC
|
|
176 is how the module describes itself.
|
|
177
|
|
178 This function returns a list, so you will need to assign the return value
|
|
179 to a variable and then examine the variable with `describe-variable'.
|
|
180 For example:
|
|
181
|
|
182 (setq mylist (list-modules))
|
|
183 (describe-variable 'mylist)
|
|
184
|
|
185
|
|
186 NOTE: It is possible for the same module to be loaded more than once,
|
|
187 at different versions. However, you should never see the same module,
|
|
188 with the same name and version, loaded more than once. If you do, this
|
|
189 is a bug, and you are encouraged to report it.
|
|
190 */
|
|
191 ())
|
|
192 {
|
|
193 Lisp_Object mlist = Qnil;
|
|
194 int i;
|
|
195
|
|
196 for (i = 0; i < modnum; i++)
|
|
197 {
|
|
198 if (modules[i].used == 1)
|
|
199 mlist = Fcons (list4 (build_string (modules[i].soname),
|
|
200 build_string (modules[i].modname),
|
|
201 build_string (modules[i].modver),
|
|
202 build_string (modules[i].modtitle)), mlist);
|
|
203 }
|
|
204
|
|
205 return mlist;
|
|
206 }
|
|
207
|
|
208 static int
|
1706
|
209 find_make_module (const CIbyte *mod, const CIbyte *name, const CIbyte *ver,
|
|
210 int mof)
|
428
|
211 {
|
|
212 int i, fs = -1;
|
|
213
|
|
214 for (i = 0; i < modnum; i++)
|
|
215 {
|
|
216 if (fs == -1 && modules[i].used == 0)
|
|
217 fs = i;
|
|
218 if (strcmp (modules[i].soname, mod) == 0)
|
|
219 {
|
|
220 if (name && name[0] && strcmp (modules[i].modname, name))
|
|
221 continue;
|
|
222 if (ver && ver[0] && strcmp (modules[i].modver, ver))
|
|
223 continue;
|
|
224 return i; /* Found a match */
|
|
225 }
|
|
226 }
|
|
227
|
|
228 if (mof)
|
|
229 return fs;
|
|
230
|
|
231 if (fs != -1)
|
|
232 return fs; /* First free slot */
|
|
233
|
|
234 /*
|
442
|
235 * We only get here if we haven't found a free slot and the module was
|
428
|
236 * not previously loaded.
|
|
237 */
|
1706
|
238 if (modules == NULL)
|
440
|
239 modules = (emodules_list *) xmalloc (sizeof (emodules_list));
|
428
|
240 modnum++;
|
440
|
241 modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list));
|
428
|
242
|
|
243 fs = modnum - 1;
|
|
244 memset (&modules[fs], 0, sizeof(emodules_list));
|
|
245 return fs;
|
|
246 }
|
|
247
|
|
248 static void
|
|
249 attempt_module_delete (int mod)
|
|
250 {
|
|
251 if (dll_close (modules[mod].dlhandle) == 0)
|
|
252 {
|
1726
|
253 xfree (modules[mod].soname, CIbyte *);
|
|
254 xfree (modules[mod].modname, CIbyte *);
|
|
255 xfree (modules[mod].modver, CIbyte *);
|
|
256 xfree (modules[mod].modtitle, CIbyte *);
|
428
|
257 modules[mod].dlhandle = 0;
|
|
258 modules[mod].used = 0;
|
|
259 }
|
|
260 else if (modules[mod].used > 1)
|
|
261 modules[mod].used = 1; /* We couldn't delete it - it stays */
|
|
262 }
|
|
263
|
|
264 static Lisp_Object
|
|
265 module_load_unwind (Lisp_Object upto)
|
|
266 {
|
|
267 int x,l=0;
|
|
268
|
|
269 /*
|
|
270 * First close off the current handle if it is open.
|
|
271 */
|
|
272 if (dlhandle != 0)
|
|
273 dll_close (dlhandle);
|
|
274 dlhandle = 0;
|
|
275
|
|
276 if (CONSP (upto))
|
|
277 {
|
|
278 if (INTP (XCAR (upto)))
|
|
279 l = XINT (XCAR (upto));
|
853
|
280 free_cons (upto);
|
428
|
281 }
|
|
282 else
|
|
283 l = XINT (upto);
|
|
284
|
|
285 /*
|
|
286 * Here we need to go through and dlclose() (IN REVERSE ORDER!) any
|
|
287 * modules that were loaded as part of this load chain. We only mark
|
|
288 * the slots as closed if the dlclose() succeeds.
|
|
289 */
|
|
290 for (x = modnum-1; x >= l; x--)
|
|
291 {
|
|
292 if (modules[x].used > 1)
|
|
293 attempt_module_delete (x);
|
|
294 }
|
|
295 emodules_depth = 0;
|
|
296
|
|
297 return Qnil;
|
|
298 }
|
|
299
|
|
300 /*
|
|
301 * Do the actual grunt-work of loading in a module. We first try and
|
|
302 * dlopen() the module. If that fails, we have an error and we bail
|
|
303 * out immediately. If the dlopen() succeeds, we need to check for the
|
442
|
304 * existence of certain special symbols.
|
428
|
305 *
|
|
306 * All modules will have complete access to the variables and functions
|
|
307 * defined within XEmacs itself. It is up to the module to declare any
|
|
308 * variables or functions it uses, however. Modules will also have access
|
|
309 * to other functions and variables in other loaded modules, unless they
|
|
310 * are defined as STATIC.
|
|
311 *
|
|
312 * We need to be very careful with how we load modules. If we encounter an
|
|
313 * error along the way, we need to back out completely to the point at
|
442
|
314 * which the user started. Since we can be called recursively, we need to
|
428
|
315 * take care with marking modules as loaded. When we first start loading
|
|
316 * modules, we set the counter to zero. As we enter the function each time,
|
442
|
317 * we increment the counter, and before we leave we decrement it. When
|
428
|
318 * we get back down to 0, we know we are at the end of the chain and we
|
|
319 * can mark all the modules in the list as loaded.
|
|
320 *
|
|
321 * When we signal an error, we need to be sure to unwind all modules loaded
|
|
322 * thus far (but only for this module chain). It is assumed that if any
|
|
323 * modules in a chain fail, then they all do. This is logical, considering
|
442
|
324 * that the only time we recurse is when we have dependent modules. So in
|
428
|
325 * the error handler we take great care to close off the module chain before
|
|
326 * we call "error" and let the Fmodule_load unwind_protect() function handle
|
|
327 * the cleaning up.
|
|
328 */
|
|
329 void
|
1706
|
330 emodules_load (const CIbyte *module, const CIbyte *modname,
|
|
331 const CIbyte *modver)
|
428
|
332 {
|
996
|
333 Lisp_Object old_load_list;
|
428
|
334 Lisp_Object filename;
|
996
|
335 Lisp_Object foundname, lisp_modname;
|
|
336 int x, mpx;
|
1706
|
337 CIbyte *soname;
|
|
338 const CIbyte **f;
|
442
|
339 const long *ellcc_rev;
|
1706
|
340 CIbyte *mver, *mname, *mtitle, *symname;
|
428
|
341 void (*modload)(void) = 0;
|
|
342 void (*modsyms)(void) = 0;
|
|
343 void (*modvars)(void) = 0;
|
|
344 void (*moddocs)(void) = 0;
|
996
|
345 void (*modunld)(void) = 0;
|
428
|
346 emodules_list *mp;
|
996
|
347 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
428
|
348
|
|
349 filename = Qnil;
|
|
350 foundname = Qnil;
|
|
351
|
|
352 emodules_depth++;
|
|
353 dlhandle = 0;
|
|
354
|
1706
|
355 if (module == NULL || module[0] == '\0')
|
563
|
356 invalid_argument ("Empty module name", Qunbound);
|
428
|
357
|
996
|
358 GCPRO4(filename, foundname, old_load_list, lisp_modname);
|
|
359 filename = build_string (module);
|
|
360 if (locate_file (Vmodule_load_path, filename, Vmodule_extensions,
|
|
361 &foundname, 0) < 0)
|
563
|
362 signal_error (Qdll_error, "Cannot open dynamic module", filename);
|
428
|
363
|
1706
|
364 LISP_STRING_TO_EXTERNAL (foundname, soname, Qfile_name);
|
996
|
365 lisp_modname = call1 (Qfile_name_sans_extension,
|
|
366 Ffile_name_nondirectory (foundname));
|
428
|
367
|
1706
|
368 dlhandle = dll_open (foundname);
|
|
369 if (dlhandle == NULL)
|
563
|
370 {
|
|
371 signal_error (Qdll_error, "Opening dynamic module",
|
1706
|
372 dll_error (dlhandle));
|
563
|
373 }
|
428
|
374
|
442
|
375 ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler");
|
1706
|
376 if (ellcc_rev == NULL || *ellcc_rev <= 0L)
|
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
|
1706
|
381 f = (const CIbyte **) dll_variable (dlhandle, "emodule_name");
|
|
382 if (f == NULL || *f == NULL)
|
563
|
383 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_name'", Qunbound);
|
428
|
384
|
1706
|
385 mname = (CIbyte *) 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
|
1706
|
390 f = (const CIbyte **) dll_variable (dlhandle, "emodule_version");
|
|
391 if (f == NULL || *f == NULL)
|
563
|
392 signal_error (Qdll_error, "Missing symbol `emodule_version': Invalid dynamic module", Qunbound);
|
428
|
393
|
1706
|
394 mver = (CIbyte *) ALLOCA (strlen (*f) + 1);
|
428
|
395 strcpy (mver, *f);
|
|
396
|
1706
|
397 f = (const CIbyte **) dll_variable (dlhandle, "emodule_title");
|
|
398 if (f == NULL || *f == NULL)
|
563
|
399 signal_error (Qdll_error, "Invalid dynamic module: Missing symbol `emodule_title'", Qunbound);
|
428
|
400
|
1706
|
401 mtitle = (CIbyte *) ALLOCA (strlen (*f) + 1);
|
428
|
402 strcpy (mtitle, *f);
|
|
403
|
1706
|
404 symname = (CIbyte *) 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);
|
1706
|
417 if (modsyms == NULL)
|
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);
|
1706
|
427 if (modvars == NULL)
|
563
|
428 goto missing_symbol;
|
428
|
429
|
|
430 strcpy (symname, "docs_of_");
|
|
431 strcat (symname, mname);
|
|
432 moddocs = (void (*)(void))dll_function (dlhandle, symname);
|
1706
|
433 if (moddocs == NULL)
|
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;
|
1706
|
577 modules = NULL;
|
428
|
578 modnum = 0;
|
|
579 }
|
|
580
|
1750
|
581 #endif /* HAVE_SHLIB */
|
|
582
|
428
|
583 void
|
|
584 vars_of_module (void)
|
|
585 {
|
1750
|
586 #ifdef HAVE_SHLIB
|
|
587 Fprovide (intern ("modules"));
|
|
588
|
428
|
589 reinit_vars_of_module ();
|
|
590
|
|
591 DEFVAR_LISP ("module-version", &Vmodule_version /*
|
|
592 Emacs dynamic loading mechanism version, as a string.
|
|
593
|
|
594 This string is in the form XX.YY.ppp, where XX is the major version
|
|
595 number, YY is the minor version number, and ppp is the patch level.
|
442
|
596 This variable can be used to distinguish between different versions of
|
428
|
597 the dynamic loading technology used in Emacs, if required. It is not
|
|
598 a given that this value will be the same as the Emacs version number.
|
|
599 */ );
|
|
600 Vmodule_version = build_string (EMODULES_VERSION);
|
|
601
|
|
602 DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /*
|
|
603 *Set to t if module loading is to be silent.
|
|
604
|
|
605 Normally, when loading dynamic modules, Emacs will inform you of its
|
|
606 progress, and will display the module name and version if the module
|
|
607 is loaded correctly. Setting this variable to `t' will suppress these
|
|
608 messages. This would normally only be done if `load-module' was being
|
|
609 called by a Lisp function.
|
|
610 */);
|
1733
|
611 load_modules_quietly = 0;
|
428
|
612
|
1750
|
613 DEFVAR_BOOL ("unloading-module", &unloading_module /*
|
|
614 Used internally by `unload-feature'. Do not set this variable.
|
|
615 Danger, danger, Will Robinson!
|
|
616 */);
|
|
617 unloading_module = 0;
|
|
618
|
|
619 #endif /* HAVE_SHLIB */
|
|
620
|
428
|
621 DEFVAR_LISP ("module-load-path", &Vmodule_load_path /*
|
|
622 *List of directories to search for dynamic modules to load.
|
|
623 Each element is a string (directory name) or nil (try default directory).
|
|
624
|
|
625 Note that elements of this list *may not* begin with "~", so you must
|
442
|
626 call `expand-file-name' on them before adding them to this list.
|
428
|
627
|
|
628 Initialized based on EMACSMODULEPATH environment variable, if any, otherwise
|
|
629 to default specified the file `paths.h' when XEmacs was built. If there
|
|
630 were no paths specified in `paths.h', then XEmacs chooses a default
|
|
631 value for this variable by looking around in the file-system near the
|
|
632 directory in which the XEmacs executable resides.
|
|
633
|
|
634 Due to the nature of dynamic modules, the path names should almost always
|
442
|
635 refer to architecture-dependent directories. It is unwise to attempt to
|
|
636 store dynamic modules in a heterogenous environment. Some environments
|
428
|
637 are similar enough to each other that XEmacs will be unable to determine
|
|
638 the correctness of a dynamic module, which can have unpredictable results
|
|
639 when a dynamic module is loaded.
|
|
640 */);
|
1733
|
641 Vmodule_load_path = Qnil;
|
428
|
642
|
1733
|
643 DEFVAR_LISP ("module-extensions", &Vmodule_extensions /*
|
|
644 *List of filename extensions to use when searching for dynamic modules.
|
|
645 */);
|
|
646 Vmodule_extensions = list5 (build_string (".ell"),
|
996
|
647 build_string (".so"),
|
1381
|
648 build_string (".dll"),
|
1733
|
649 build_string (".dylib"),
|
|
650 build_string (""));
|
428
|
651 }
|