annotate src/dll.c @ 276:6330739388db r21-0b36

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