245
|
1 /* Lisp interface to dynamic loading.
|
|
2 Copyright (C) 1998 Joshua Rowe.
|
|
3 Additional cleanup by Hrvoje Niksic.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 This program is free software; you can redistribute it and/or modify
|
|
8 it under the terms of the GNU General Public License as published by
|
|
9 the Free Software Foundation; either version 2 of the License, or
|
|
10 (at your option) any later version.
|
|
11
|
|
12 This program is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with this program; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* A shared object may have the following symbols defined:
|
|
25 syms_of
|
|
26 vars_of
|
|
27 complex_vars_of
|
|
28 They are called in that order. Each takes and returns void
|
|
29 arguments.
|
|
30
|
|
31 All of this needs lots and LOTS of work. Some things to work on:
|
|
32
|
|
33 1) A good foreign interface. We probably need to get rid of
|
|
34 syms_of and similar junk, and define a more normal interfacing to
|
|
35 the outside world, e.g. an init_emacs_module() function. See below
|
|
36 for more discussion about it. Also, we need a modules/ directory
|
|
37 with a few nice sample modules, a sample Makefile, etc. so people
|
|
38 can start hacking.
|
|
39
|
|
40 2) Compatibility concerns. There are systems without dynamic
|
|
41 libraries (Ultrix, to name one). OK, scrap them, but not all
|
|
42 systems out there use the exact dlopen() interface that this file
|
|
43 uses. Bill Perry said he had ready Makefiles for 14 or so systems
|
|
44 to do this sort of things portably. Check it out. Or, use Gordon
|
|
45 Matzigkeit's libtool.
|
|
46
|
|
47 3) I'm getting coredumps very often -- practically every time I
|
|
48 compile without USE_MINIMAL_TAGBITS, and even with it sometimes. I
|
|
49 wasn't able to resolve these.
|
|
50
|
|
51 4) All of this is sooo simple-minded. As it gets more complex,
|
|
52 we'll have to look at how others have done similar things
|
|
53 (e.g. Perl and Zsh 3.1), to avoid botching it up. */
|
|
54
|
|
55 #include <config.h>
|
|
56 #include "lisp.h"
|
|
57 #include "emacsfns.h"
|
|
58 #include "buffer.h"
|
|
59
|
|
60 #include <stdio.h>
|
|
61 #include <dlfcn.h>
|
|
62 #include <errno.h>
|
|
63
|
|
64
|
|
65 DEFUN ("dl-open", Fdl_open, 1, 1, "FShared object: ", /*
|
|
66 Load LIBRARY as a shared object file.
|
|
67
|
|
68 After the LIBRARY is dynamically linked with the executable, the
|
|
69 following functions are called:
|
|
70
|
|
71 syms_of(), containing definitions of symbols and subr's;
|
|
72 vars_of(), containing definitions of variables;
|
|
73 complex_vars_of(), containing complex definitions of variables.
|
|
74
|
|
75 After this point, any lisp symbols defined in the shared object are
|
|
76 available for use.
|
|
77 */
|
|
78 (library))
|
|
79 {
|
|
80 /* This function can GC */
|
|
81 void *handle;
|
|
82 char *file;
|
|
83 void (*function)();
|
|
84
|
|
85 CHECK_STRING (library);
|
|
86 library = Fexpand_file_name (library, Qnil);
|
|
87
|
|
88 file = XSTRING_DATA (library);
|
|
89 /* #### Is this right? */
|
|
90 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (file, file);
|
|
91
|
|
92 handle = dlopen (file, RTLD_LAZY);
|
|
93 if (handle == NULL)
|
|
94 {
|
|
95 signal_error (Qerror,
|
|
96 list3 (build_translated_string ("Cannot load shared library"),
|
|
97 library, build_translated_string (dlerror ())));
|
|
98 }
|
|
99
|
|
100 /* #### This looks unnecessary here, because at this time one
|
|
101 initialization function is fully sufficient. However, I am not
|
|
102 removing this support, since we may wish to add mechanisms for
|
|
103 static linking, which would have invoke these function via normal
|
|
104 paths.
|
|
105
|
|
106 #### But then this is not sufficient, because one could as well
|
|
107 honor specifier_vars_of_foo(), etc. Maybe we should scrap it
|
|
108 after all.
|
|
109
|
|
110 #### What if one of the first two functions signal an error?
|
|
111 Should we take care to execute the other two? My fingers are
|
|
112 getting itchy! */
|
|
113
|
|
114 function = dlsym (handle, "syms_of");
|
|
115 if (function)
|
|
116 {
|
|
117 function ();
|
|
118 }
|
|
119
|
|
120 function = dlsym (handle, "vars_of");
|
|
121 if (function)
|
|
122 {
|
|
123 function ();
|
|
124 }
|
|
125
|
|
126 function = dlsym (handle, "complex_vars_of");
|
|
127 if (function)
|
|
128 {
|
|
129 function ();
|
|
130 }
|
|
131
|
|
132 return Qnil;
|
|
133 }
|
|
134
|
|
135 void syms_of_dlopen ()
|
|
136 {
|
|
137 DEFSUBR (Fdl_open);
|
|
138 }
|