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
|
276
|
24 /* A shared object must have the symbol `emacs_initialize' defined.
|
|
25 It should contain initialization of functions, symbols, etc. and
|
|
26 their loading into Lisp-land. The function will be called without
|
|
27 arguments and is not expected to return any.
|
265
|
28
|
|
29 All of this needs lots and LOTS of work. Some things to work on:
|
|
30
|
276
|
31 1) A good foreign interface. This is probably tough, because it
|
|
32 implies drawing a new border between "external" and "internal"
|
|
33 stuff (traditionally, Lisp code was external, while C was
|
|
34 internal). Also, we need a modules/ directory with a few nice
|
|
35 sample modules, a sample Makefile, etc. so people can start
|
|
36 hacking.
|
265
|
37
|
276
|
38 2) All of this is sooo simple-minded. As it gets more complex,
|
265
|
39 we'll have to look at how others have done similar things
|
276
|
40 (e.g. Perl 5 and Zsh 3.1), to avoid botching it up. */
|
265
|
41
|
|
42 #include <config.h>
|
|
43 #include "lisp.h"
|
|
44 #include "buffer.h"
|
|
45 #include "sysdll.h"
|
|
46 #include <errno.h>
|
|
47
|
|
48 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /*
|
|
49 Load LIBRARY as a shared object file.
|
|
50
|
|
51 After the LIBRARY is dynamically linked with the executable, the
|
276
|
52 `emacs_initialize' function will be called without arguments. It
|
|
53 should define all the symbols, subr's and variables the module
|
|
54 introduces.
|
265
|
55
|
|
56 After this point, any lisp symbols defined in the shared object are
|
|
57 available for use.
|
|
58 */
|
|
59 (library))
|
|
60 {
|
|
61 /* This function can GC */
|
|
62 dll_handle *handle;
|
276
|
63 void (*function) (void);
|
272
|
64 CONST char *filename;
|
265
|
65
|
|
66 CHECK_STRING (library);
|
|
67 library = Fexpand_file_name (library, Qnil);
|
|
68
|
272
|
69 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (XSTRING_DATA (library), filename);
|
265
|
70
|
272
|
71 handle = (dll_handle *) dll_open (filename);
|
265
|
72 if (handle == NULL)
|
|
73 {
|
|
74 signal_error (Qerror,
|
|
75 list3 (build_translated_string ("Cannot load shared library"),
|
|
76 library, build_translated_string (dll_error (handle))));
|
|
77 }
|
|
78
|
276
|
79 /* #### Perhaps emacs_initialize() should return a Lisp_Object, so
|
|
80 we can return it? */
|
265
|
81
|
276
|
82 function = (void (*)(void)) dll_function (handle, "emacs_initialize");
|
|
83 if (!function)
|
|
84 signal_simple_error ("Shared library does not define `emacs_initialize'",
|
|
85 library);
|
|
86 (*function) ();
|
265
|
87
|
|
88 return Qnil;
|
|
89 }
|
|
90
|
|
91 void syms_of_dll ()
|
|
92 {
|
|
93 DEFSUBR (Fdll_open);
|
|
94 }
|