annotate src/dll.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 8efd647ea9ca
children 6330739388db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
1 /* Lisp interface to dynamic loading.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
2 Copyright (C) 1998 Joshua Rowe.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
3 Additional cleanup by Hrvoje Niksic.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
4
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
5 This file is part of XEmacs.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
6
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
9 the Free Software Foundation; either version 2 of the License, or
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
10 (at your option) any later version.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
11
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
15 GNU General Public License for more details.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
16
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
18 along with this program; see the file COPYING. If not, write to
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
21
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
23
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
24 /* A shared object may have the following symbols defined:
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
25 syms_of
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
26 vars_of
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
27 complex_vars_of
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
28 They are called in that order. Each takes and returns void
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
29 arguments.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
30
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
31 All of this needs lots and LOTS of work. Some things to work on:
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
32
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
33 1) A good foreign interface. We probably need to get rid of
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
34 syms_of and similar junk, and define a more normal interfacing to
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
35 the outside world, e.g. an init_emacs_module() function. See below
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
36 for more discussion about it. Also, we need a modules/ directory
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
37 with a few nice sample modules, a sample Makefile, etc. so people
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
38 can start hacking.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
39
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
40 2) I'm getting coredumps very often -- practically every time I
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
41 compile without USE_MINIMAL_TAGBITS, and even with it sometimes. I
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
42 wasn't able to resolve these.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
43
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
44 3) All of this is sooo simple-minded. As it gets more complex,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
45 we'll have to look at how others have done similar things
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
46 (e.g. Perl and Zsh 3.1), to avoid botching it up. */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
47
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
48 #include <config.h>
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
49 #include "lisp.h"
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
50 #include "buffer.h"
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
51 #include "sysdll.h"
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
52 #include <errno.h>
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
53
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
54 static void
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
55 maybe_call_library_function (dll_handle *handle, CONST char *funcname)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
56 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
57 void (*function)(void) = (void (*)(void)) dll_function (handle, funcname);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
58 if (function)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
59 (*function) ();
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
60 }
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
61
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
62 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /*
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
63 Load LIBRARY as a shared object file.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
64
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
65 After the LIBRARY is dynamically linked with the executable, the
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
66 following functions are called:
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
67
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
68 syms_of(), containing definitions of symbols and subr's;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
69 vars_of(), containing definitions of variables;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
70 complex_vars_of(), containing complex definitions of variables.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
71
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
72 After this point, any lisp symbols defined in the shared object are
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
73 available for use.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
74 */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
75 (library))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
76 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
77 /* This function can GC */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
78 dll_handle *handle;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
79 CONST char *filename;
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
80
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
81 CHECK_STRING (library);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
82 library = Fexpand_file_name (library, Qnil);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
83
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
84 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (XSTRING_DATA (library), filename);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
85
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
86 handle = (dll_handle *) dll_open (filename);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
87 if (handle == NULL)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
88 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
89 signal_error (Qerror,
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
90 list3 (build_translated_string ("Cannot load shared library"),
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
91 library, build_translated_string (dll_error (handle))));
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
92 }
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
93
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
94 /* #### This looks unnecessary here, because at this time one
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
95 initialization function is fully sufficient. However, I am not
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
96 removing this support, since we may wish to add mechanisms for
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
97 static linking, which would have invoke these function via normal
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
98 paths.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
99
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
100 #### But then this is not sufficient, because one could as well
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
101 honor specifier_vars_of_foo(), etc. Maybe we should scrap it
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
102 after all.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
103
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
104 #### What if one of the first two functions signal an error?
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
105 Should we take care to execute the other two? My fingers are
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
106 getting itchy! */
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
107
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
108 maybe_call_library_function (handle, "syms_of");
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
109 maybe_call_library_function (handle, "vars_of");
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
110 maybe_call_library_function (handle, "complex_vars_of");
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
111
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
112 return Qnil;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
113 }
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
114
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
115 void syms_of_dll ()
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
116 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
117 DEFSUBR (Fdll_open);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
118 }