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 "buffer.h"
|
|
51 #include "sysdll.h"
|
|
52 #include <errno.h>
|
|
53
|
272
|
54 static void
|
|
55 maybe_call_library_function (dll_handle *handle, CONST char *funcname)
|
|
56 {
|
|
57 void (*function)(void) = (void (*)(void)) dll_function (handle, funcname);
|
|
58 if (function)
|
|
59 (*function) ();
|
|
60 }
|
265
|
61
|
|
62 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /*
|
|
63 Load LIBRARY as a shared object file.
|
|
64
|
|
65 After the LIBRARY is dynamically linked with the executable, the
|
|
66 following functions are called:
|
|
67
|
|
68 syms_of(), containing definitions of symbols and subr's;
|
|
69 vars_of(), containing definitions of variables;
|
|
70 complex_vars_of(), containing complex definitions of variables.
|
|
71
|
|
72 After this point, any lisp symbols defined in the shared object are
|
|
73 available for use.
|
|
74 */
|
|
75 (library))
|
|
76 {
|
|
77 /* This function can GC */
|
|
78 dll_handle *handle;
|
272
|
79 CONST char *filename;
|
265
|
80
|
|
81 CHECK_STRING (library);
|
|
82 library = Fexpand_file_name (library, Qnil);
|
|
83
|
272
|
84 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (XSTRING_DATA (library), filename);
|
265
|
85
|
272
|
86 handle = (dll_handle *) dll_open (filename);
|
265
|
87 if (handle == NULL)
|
|
88 {
|
|
89 signal_error (Qerror,
|
|
90 list3 (build_translated_string ("Cannot load shared library"),
|
|
91 library, build_translated_string (dll_error (handle))));
|
|
92 }
|
|
93
|
|
94 /* #### This looks unnecessary here, because at this time one
|
|
95 initialization function is fully sufficient. However, I am not
|
|
96 removing this support, since we may wish to add mechanisms for
|
|
97 static linking, which would have invoke these function via normal
|
|
98 paths.
|
|
99
|
|
100 #### But then this is not sufficient, because one could as well
|
|
101 honor specifier_vars_of_foo(), etc. Maybe we should scrap it
|
|
102 after all.
|
|
103
|
|
104 #### What if one of the first two functions signal an error?
|
|
105 Should we take care to execute the other two? My fingers are
|
|
106 getting itchy! */
|
|
107
|
272
|
108 maybe_call_library_function (handle, "syms_of");
|
|
109 maybe_call_library_function (handle, "vars_of");
|
|
110 maybe_call_library_function (handle, "complex_vars_of");
|
265
|
111
|
|
112 return Qnil;
|
|
113 }
|
|
114
|
|
115 void syms_of_dll ()
|
|
116 {
|
|
117 DEFSUBR (Fdll_open);
|
|
118 }
|