comparison 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
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
45 we'll have to look at how others have done similar things 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. */ 46 (e.g. Perl and Zsh 3.1), to avoid botching it up. */
47 47
48 #include <config.h> 48 #include <config.h>
49 #include "lisp.h" 49 #include "lisp.h"
50 #include "emacsfns.h"
51 #include "buffer.h" 50 #include "buffer.h"
52
53 #include <stdio.h>
54 #include "sysdll.h" 51 #include "sysdll.h"
55 #include <errno.h> 52 #include <errno.h>
56 53
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 }
57 61
58 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /* 62 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /*
59 Load LIBRARY as a shared object file. 63 Load LIBRARY as a shared object file.
60 64
61 After the LIBRARY is dynamically linked with the executable, the 65 After the LIBRARY is dynamically linked with the executable, the
70 */ 74 */
71 (library)) 75 (library))
72 { 76 {
73 /* This function can GC */ 77 /* This function can GC */
74 dll_handle *handle; 78 dll_handle *handle;
75 char *file; 79 CONST char *filename;
76 void (*function)();
77 80
78 CHECK_STRING (library); 81 CHECK_STRING (library);
79 library = Fexpand_file_name (library, Qnil); 82 library = Fexpand_file_name (library, Qnil);
80 83
81 file = XSTRING_DATA (library); 84 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (XSTRING_DATA (library), filename);
82 /* #### Is this right? */
83 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (file, file);
84 85
85 handle = dll_open (file); 86 handle = (dll_handle *) dll_open (filename);
86 if (handle == NULL) 87 if (handle == NULL)
87 { 88 {
88 signal_error (Qerror, 89 signal_error (Qerror,
89 list3 (build_translated_string ("Cannot load shared library"), 90 list3 (build_translated_string ("Cannot load shared library"),
90 library, build_translated_string (dll_error (handle)))); 91 library, build_translated_string (dll_error (handle))));
102 103
103 #### What if one of the first two functions signal an error? 104 #### What if one of the first two functions signal an error?
104 Should we take care to execute the other two? My fingers are 105 Should we take care to execute the other two? My fingers are
105 getting itchy! */ 106 getting itchy! */
106 107
107 function = dll_function (handle, "syms_of"); 108 maybe_call_library_function (handle, "syms_of");
108 if (function) 109 maybe_call_library_function (handle, "vars_of");
109 (*function) (); 110 maybe_call_library_function (handle, "complex_vars_of");
110
111 function = dll_function (handle, "vars_of");
112 if (function)
113 (*function) ();
114
115 function = dll_function (handle, "complex_vars_of");
116 if (function)
117 (*function) ();
118 111
119 return Qnil; 112 return Qnil;
120 } 113 }
121 114
122 void syms_of_dll () 115 void syms_of_dll ()