annotate src/dll.c @ 267:966663fcf606 r20-5b32

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