265
|
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) I'm getting coredumps very often -- practically every time I
|
|
41 compile without USE_MINIMAL_TAGBITS, and even with it sometimes. I
|
|
42 wasn't able to resolve these.
|
|
43
|
|
44 3) All of this is sooo simple-minded. As it gets more complex,
|
|
45 we'll have to look at how others have done similar things
|
|
46 (e.g. Perl and Zsh 3.1), to avoid botching it up. */
|
|
47
|
|
48 #include <config.h>
|
|
49 #include "lisp.h"
|
|
50 #include "emacsfns.h"
|
|
51 #include "buffer.h"
|
|
52
|
|
53 #include <stdio.h>
|
|
54 #include "sysdll.h"
|
|
55 #include <errno.h>
|
|
56
|
|
57
|
|
58 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /*
|
|
59 Load LIBRARY as a shared object file.
|
|
60
|
|
61 After the LIBRARY is dynamically linked with the executable, the
|
|
62 following functions are called:
|
|
63
|
|
64 syms_of(), containing definitions of symbols and subr's;
|
|
65 vars_of(), containing definitions of variables;
|
|
66 complex_vars_of(), containing complex definitions of variables.
|
|
67
|
|
68 After this point, any lisp symbols defined in the shared object are
|
|
69 available for use.
|
|
70 */
|
|
71 (library))
|
|
72 {
|
|
73 /* This function can GC */
|
|
74 dll_handle *handle;
|
|
75 char *file;
|
|
76 void (*function)();
|
|
77
|
|
78 CHECK_STRING (library);
|
|
79 library = Fexpand_file_name (library, Qnil);
|
|
80
|
|
81 file = XSTRING_DATA (library);
|
|
82 /* #### Is this right? */
|
|
83 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (file, file);
|
|
84
|
|
85 handle = dll_open (file);
|
|
86 if (handle == NULL)
|
|
87 {
|
|
88 signal_error (Qerror,
|
|
89 list3 (build_translated_string ("Cannot load shared library"),
|
|
90 library, build_translated_string (dll_error (handle))));
|
|
91 }
|
|
92
|
|
93 /* #### This looks unnecessary here, because at this time one
|
|
94 initialization function is fully sufficient. However, I am not
|
|
95 removing this support, since we may wish to add mechanisms for
|
|
96 static linking, which would have invoke these function via normal
|
|
97 paths.
|
|
98
|
|
99 #### But then this is not sufficient, because one could as well
|
|
100 honor specifier_vars_of_foo(), etc. Maybe we should scrap it
|
|
101 after all.
|
|
102
|
|
103 #### What if one of the first two functions signal an error?
|
|
104 Should we take care to execute the other two? My fingers are
|
|
105 getting itchy! */
|
|
106
|
|
107 function = dll_function (handle, "syms_of");
|
|
108 if (function)
|
|
109 (*function) ();
|
|
110
|
|
111 function = dll_function (handle, "vars_of");
|
|
112 if (function)
|
|
113 (*function) ();
|
|
114
|
|
115 function = dll_function (handle, "complex_vars_of");
|
|
116 if (function)
|
|
117 (*function) ();
|
|
118
|
|
119 return Qnil;
|
|
120 }
|
|
121
|
|
122 void syms_of_dll ()
|
|
123 {
|
|
124 DEFSUBR (Fdll_open);
|
|
125 }
|