Mercurial > hg > xemacs-beta
annotate src/sysdll.c @ 4953:304aebb79cd3
function renamings to track names of char typedefs
-------------------- ChangeLog entries follow: --------------------
man/ChangeLog addition:
2010-01-27 Ben Wing <ben@xemacs.org>
* internals/internals.texi (lrecords):
* internals/internals.texi (The DFC API):
* internals/internals.texi (Conversion to and from External Data):
* internals/internals.texi (Mule-izing Code):
* internals/internals.texi (Pervasive changes throughout XEmacs sources):
* internals/internals.texi (Ben's README):
* internals/internals.texi (Future Work -- Localized Text/Messages):
* emodules.texi (Defining Variables):
Rename:
write_c_string -> write_cistring
build_intstring -> build_istring
build_string -> build_cistring
build_ext_string -> build_extstring
make_ext_string -> make_extstring
buffer_insert_c_string -> buffer_insert_ascstring
intern_int -> intern_istring
See comment in src/ChangeLog about this.
modules/ChangeLog addition:
2010-01-27 Ben Wing <ben@xemacs.org>
* postgresql/postgresql.c (print_pgconn):
* postgresql/postgresql.c (print_pgresult):
* postgresql/postgresql.c (Fpq_conn_defaults):
* postgresql/postgresql.c (Fpq_pgconn):
* postgresql/postgresql.c (Fpq_res_status):
* postgresql/postgresql.c (Fpq_result_error_message):
* postgresql/postgresql.c (Fpq_fname):
* postgresql/postgresql.c (Fpq_get_value):
* postgresql/postgresql.c (Fpq_cmd_status):
* postgresql/postgresql.c (Fpq_cmd_tuples):
* postgresql/postgresql.c (Fpq_notifies):
* postgresql/postgresql.c (Fpq_get_line):
* postgresql/postgresql.c (Fpq_get_line_async):
* postgresql/postgresql.c (FROB):
* postgresql/postgresql.c (init_postgresql_from_environment):
* ldap/eldap.c:
* ldap/eldap.c (Fldap_open):
* ldap/eldap.c (Fldap_search_basic):
* canna/canna_api.c:
* canna/canna_api.c (make_euc_string):
Rename:
write_c_string -> write_cistring
build_intstring -> build_istring
build_string -> build_cistring
build_ext_string -> build_extstring
make_ext_string -> make_extstring
buffer_insert_c_string -> buffer_insert_ascstring
intern_int -> intern_istring
See comment in src/ChangeLog about this.
src/ChangeLog addition:
2010-01-27 Ben Wing <ben@xemacs.org>
* .gdbinit.in.in:
* README:
* abbrev.c (write_abbrev):
* abbrev.c (describe_abbrev):
* alloc.c (make_extstring):
* alloc.c (build_istring):
* alloc.c (build_cistring):
* alloc.c (build_ascstring):
* alloc.c (build_extstring):
* alloc.c (build_msg_istring):
* alloc.c (build_defer_istring):
* buffer.c (Fgenerate_new_buffer_name):
* buffer.c (init_buffer_2):
* console-tty.c (tty_init_console):
* console-x.c (get_display_arg_connection):
* console-x.c (x_perhaps_init_unseen_key_defaults):
* database.c (dbm_map):
* database.c (dbm_get):
* database.c (berkdb_get):
* database.c (berkdb_map):
* device-gtk.c (FROB_PIXMAP):
* device-gtk.c (Fgtk_style_info):
* device-msw.c (msprinter_default_printer):
* device-msw.c (sync_printer_with_devmode):
* device-x.c (coding_system_of_xrm_database):
* device-x.c (x_init_device):
* device-x.c (signal_if_x_error):
* device-x.c (Fx_get_resource):
* device-x.c (Fx_server_vendor):
* device-x.c (Fx_get_font_path):
* dialog-x.c (maybe_run_dbox_text_callback):
* doc.c (extract_object_file_name):
* doc.c (unparesseuxify_doc_string):
* doc.c (get_doc_string):
* doc.c (get_object_file_name):
* doc.c (Fdocumentation):
* doc.c (Fsnarf_documentation):
* doc.c (Fsubstitute_command_keys):
* editfns.c (init_editfns):
* editfns.c (Ftemp_directory):
* editfns.c (Fuser_login_name):
* editfns.c (Fuser_real_login_name):
* editfns.c (Fuser_home_directory):
* editfns.c (Fformat_time_string):
* editfns.c (Fcurrent_time_string):
* editfns.c (Fcurrent_time_zone):
* emacs.c:
* emacs.c (main_1):
* emodules.c (Flist_modules):
* emodules.c (emodules_load):
* emodules.c (emodules_doc_sym):
* emodules.c (vars_of_module):
* event-Xt.c (x_has_keysym):
* event-gtk.c (emacs_gtk_format_magic_event):
* event-gtk.c (dragndrop_data_received):
* event-gtk.c (gtk_reset_key_mapping):
* event-msw.c (mswindows_dde_callback):
* event-msw.c (mswindows_wnd_proc):
* faces.c (complex_vars_of_faces):
* file-coding.c (find_coding_system):
* file-coding.c (setup_eol_coding_systems):
* file-coding.c (make_coding_system_1):
* file-coding.c (snarf_coding_system):
* fileio.c:
* fileio.c (lisp_strerror):
* fileio.c (Ffile_name_directory):
* fileio.c (Ffile_name_as_directory):
* fileio.c (Fdirectory_file_name):
* fileio.c (if):
* fileio.c (Ffile_symlink_p):
* fileio.c (Fencrypt_string):
* fileio.c (Fdecrypt_string):
* filelock.c (lock_file):
* filelock.c (Ffile_locked_p):
* floatfns.c (matherr):
* font-mgr.c (build_fcapi_string):
* font-mgr.c (make_xlfd_font_regexp):
* frame-msw.c (mswindows_window_id):
* frame-msw.c (mswindows_frame_property):
* frame-x.c:
* frame-x.c (color_to_string):
* frame-x.c (maybe_set_frame_title_format):
* frame-x.c (x_cde_transfer_callback):
* frame-x.c (Fx_window_id):
* glade.c (connector):
* glade.c (Fglade_xml_textdomain):
* glade.c (syms_of_glade):
* glyphs-eimage.c (jpeg_instantiate):
* glyphs-eimage.c (png_instantiate):
* glyphs-eimage.c (tiff_instantiate):
* glyphs-gtk.c (font_instantiate):
* glyphs-gtk.c (BUILD_GLYPH_INST):
* glyphs-x.c (x_locate_pixmap_file):
* glyphs-x.c (font_instantiate):
* glyphs-x.c (x_widget_property):
* glyphs-x.c (BUILD_GLYPH_INST):
* glyphs.c (print_image_instance):
* glyphs.c (bitmap_to_lisp_data):
* glyphs.c (pixmap_to_lisp_data):
* gpmevent.c (turn_off_gpm):
* gpmevent.c (Fgpm_enabled_p):
* gpmevent.c (Fgpm_enable):
* gtk-glue.c (__make_string_mapper):
* gtk-glue.c (xemacs_gtklist_to_list):
* gtk-xemacs.c (FROB_FACE):
* gtk-xemacs.c (xemacs_gtk_convert_color):
* hpplay.c (player_error_internal):
* hpplay.c (myHandler):
* insdel.c (buffer_insert_ascstring_1):
* insdel.h:
* insdel.h (buffer_insert_ascstring):
* intl.c (Fcurrent_locale):
* intl.c (Fset_current_locale):
* keymap.c (make_key_description):
* keymap.c (Ftext_char_description):
* keymap.c (describe_command):
* keymap.c (describe_map):
* lisp.h:
* lread.c:
* lread.c (locate_file_in_directory_mapper):
* lread.c (locate_file_construct_suffixed_files_mapper):
* mule-charset.c (Fmake_charset):
* nt.c (Fmswindows_short_file_name):
* nt.c (Fmswindows_long_file_name):
* objects-gtk.c (__get_gtk_font_truename):
* objects-gtk.c (__gtk_font_list_internal):
* objects-msw.c (font_enum_callback_2):
* objects-msw.c (create_hfont_from_font_spec):
* objects-msw.c (mswindows_font_list):
* objects-msw.c (mswindows_font_spec_matches_charset_stage_2):
* objects-tty.c (tty_initialize_font_instance):
* objects-x.c (x_font_truename):
* objects-x.c (x_font_instance_truename):
* objects-x.c (x_font_instance_properties):
* objects-x.c (x_font_list):
* print.c (write_cistring):
* print.c (print_vector_internal):
* print.c (print_cons):
* process-nt.c (nt_canonicalize_host_name):
* process-unix.c (unix_create_process):
* process-unix.c (unix_canonicalize_host_name):
* process.c (status_message):
* process.c (status_notify):
* process.c (init_xemacs_process):
* process.c (syms_of_process):
* redisplay-tty.c (term_get_fkeys_1):
* redisplay-tty.c (CONDITIONAL_REASSIGN):
* search.c (compile_pattern_1):
* select-common.h (selection_data_to_lisp_data):
* select-gtk.c (atom_to_symbol):
* select-gtk.c (PROCESSING_GTK_CODE):
* select-msw.c (mswindows_get_foreign_selection):
* select-x.c (x_atom_to_symbol):
* select-x.c (Fx_get_cutbuffer_internal):
* symbols.c (intern_istring):
* symbols.c (intern):
* symbols.c (intern_converting_underscores_to_dashes):
* symbols.c (Fintern):
* sysdep.c (init_system_name):
* sysdll.c (dll_error):
* sysdll.c (dll_open):
* syswindows.h:
* syswindows.h (build_tstr_string):
* tests.c (DFC_CHECK_LENGTH):
* tests.c (DFC_CHECK_CONTENT):
* tests.c (DFC_RESULT_PASS):
* tests.c (Ftest_data_format_conversion):
* text.c:
* text.c (new_dfc_convert_now_damn_it):
* text.h:
* text.h (build_wext_string):
* tooltalk.c (tt_build_c_string):
* tooltalk.c (Ftooltalk_default_procid):
* tooltalk.c (Ftooltalk_default_session):
* tooltalk.c (init_tooltalk):
* ui-byhand.c (Fgtk_clist_get_text):
* ui-byhand.c (Fgtk_clist_get_pixtext):
* ui-byhand.c (Fgtk_label_get):
* ui-byhand.c (Fgtk_notebook_query_tab_label_packing):
* ui-gtk.c (emacs_gtk_object_printer):
* ui-gtk.c (emacs_gtk_boxed_printer):
* ui-gtk.c (gtk_type_to_lisp):
* ui-gtk.c (symbol_to_enum):
* ui-gtk.c (enum_to_symbol):
* unexaix.c (report_error):
* unexaix.c (ERROR0):
* unexec.c (report_error):
* unexec.c (ERROR0):
* unicode.c (unicode_to_ichar):
* win32.c (tstr_to_local_file_format):
* win32.c (Fmswindows_cygwin_to_win32_path):
* win32.c (struct read_link_hash):
* xemacs.def.in.in:
Rename:
write_c_string -> write_cistring
build_intstring -> build_istring
build_string -> build_cistring
build_ext_string -> build_extstring
make_ext_string -> make_extstring
buffer_insert_c_string -> buffer_insert_ascstring
intern_int -> intern_istring
These functions have been renamed so that the naming harmonizes
with the typedefs for strings: `cistring' along with CIbyte *,
`istring' along with Ibyte *, `extstring' along with Extbyte *,
`ascstring' along with Ascbyte *.
Also make buffer_insert_ascstring take Ascbyte * and assert
that its argument is ASCII.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 27 Jan 2010 00:35:36 -0600 |
parents | 19a72041c5ed |
children | 4aebb0131297 |
rev | line source |
---|---|
428 | 1 /* sysdll.c --- system dependent support for dynamic linked libraries |
2 Copyright (C) 1998 Free Software Foundation, Inc. | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3 Copyright (C) 2010 Ben Wing. |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
4 |
428 | 5 Author: William Perry <wmperry@aventail.com> |
6 | |
7 This file is part of XEmacs. | |
8 | |
9 XEmacs is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
11 Free Software Foundation; either version 2, or (at your option) any | |
12 later version. | |
13 | |
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with XEmacs; see the file COPYING. If not, write to the Free | |
21 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
22 02111-1307, USA. */ | |
23 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
24 /* This file has been Mule-ized, Ben Wing, 1-26-10. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
25 |
428 | 26 #ifdef HAVE_CONFIG_H |
27 #include <config.h> | |
28 #endif | |
29 | |
430 | 30 #include <stdlib.h> |
1272 | 31 #include "lisp.h" |
428 | 32 #include "sysdll.h" |
33 | |
1383 | 34 #ifdef DLSYM_NEEDS_UNDERSCORE |
35 #define MAYBE_PREPEND_UNDERSCORE(n) do { \ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
36 Ibyte *buf = alloca_array (Ibyte, qxestrlen (n) + 2); \ |
1383 | 37 *buf = '_'; \ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
38 qxestrcpy (buf + 1, n); \ |
1383 | 39 n = buf; \ |
40 } while (0) | |
41 #else | |
42 #define MAYBE_PREPEND_UNDERSCORE(n) | |
43 #endif | |
44 | |
428 | 45 /* This whole file is conditional upon HAVE_SHLIB */ |
46 #ifdef HAVE_SHLIB | |
47 | |
48 /* Thankfully, most systems follow the ELFish dlopen() method. | |
49 */ | |
452 | 50 #if defined(HAVE_DLOPEN) |
428 | 51 #include <dlfcn.h> |
52 | |
53 #ifndef RTLD_LAZY | |
1383 | 54 # ifdef DL_LAZY |
55 # define RTLD_LAZY DL_LAZY | |
56 # else | |
57 # define RTLD_LAZY 1 | |
58 # endif | |
428 | 59 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */ |
60 | |
863 | 61 #ifndef RTLD_NOW |
1383 | 62 # ifdef DL_NOW |
63 # define RTLD_NOW DL_NOW | |
64 # else | |
65 # define RTLD_NOW 2 | |
66 # endif | |
863 | 67 #endif |
68 | |
428 | 69 dll_handle |
1706 | 70 dll_open (Lisp_Object fname) |
428 | 71 { |
1706 | 72 Extbyte *soname; |
73 | |
74 if (NILP (fname)) | |
75 { | |
76 soname = NULL; | |
77 } | |
78 else | |
79 { | |
80 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding); | |
81 } | |
82 return (dll_handle) dlopen (soname, RTLD_NOW); | |
428 | 83 } |
84 | |
85 int | |
86 dll_close (dll_handle h) | |
87 { | |
442 | 88 return dlclose ((void *) h); |
428 | 89 } |
90 | |
91 dll_func | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
92 dll_function (dll_handle h, const Ibyte *n) |
428 | 93 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
94 Extbyte *next; |
1383 | 95 MAYBE_PREPEND_UNDERSCORE (n); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
96 C_STRING_TO_EXTERNAL (n, next, Qdll_function_name_encoding); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
97 return (dll_func) dlsym ((void *) h, next); |
428 | 98 } |
99 | |
100 dll_var | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
101 dll_variable (dll_handle h, const Ibyte *n) |
428 | 102 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
103 Extbyte *next; |
1383 | 104 MAYBE_PREPEND_UNDERSCORE (n); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
105 C_STRING_TO_EXTERNAL (n, next, Qdll_variable_name_encoding); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
106 return (dll_var)dlsym ((void *)h, next); |
428 | 107 } |
108 | |
1706 | 109 Lisp_Object |
1811 | 110 dll_error () |
428 | 111 { |
1706 | 112 const Extbyte *msg; |
428 | 113 #if defined(HAVE_DLERROR) || defined(dlerror) |
1706 | 114 msg = (const Extbyte *) dlerror (); |
428 | 115 #elif defined(HAVE__DLERROR) |
1706 | 116 msg = (const Extbyte *) _dlerror(); |
428 | 117 #else |
1706 | 118 msg = (const Extbyte *) "Shared library error"; |
428 | 119 #endif |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
120 return build_extstring (msg, Qerror_message_encoding); |
428 | 121 } |
122 | |
123 #elif defined(HAVE_SHL_LOAD) | |
124 /* This is the HP/UX version */ | |
125 #include <dl.h> | |
126 dll_handle | |
1706 | 127 dll_open (Lisp_Object fname) |
428 | 128 { |
1706 | 129 Extbyte *soname; |
428 | 130 |
1706 | 131 if (NILP (fname)) |
132 { | |
133 soname = NULL; | |
134 } | |
135 else | |
136 { | |
137 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding); | |
138 } | |
139 return (dll_handle) shl_load (soname, BIND_DEFERRED, 0L); | |
428 | 140 } |
141 | |
142 int | |
143 dll_close (dll_handle h) | |
144 { | |
442 | 145 return shl_unload ((shl_t) h); |
428 | 146 } |
147 | |
148 dll_func | |
1706 | 149 dll_function (dll_handle h, const CIbyte *n) |
428 | 150 { |
151 long handle = 0L; | |
152 | |
442 | 153 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle)) |
428 | 154 return NULL; |
155 | |
442 | 156 return (dll_func) handle; |
428 | 157 } |
158 | |
159 dll_var | |
1706 | 160 dll_variable (dll_handle h, const CIbyte *n) |
428 | 161 { |
162 long handle = 0L; | |
163 | |
442 | 164 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle)) |
428 | 165 return NULL; |
166 | |
442 | 167 return (dll_var) handle; |
428 | 168 } |
169 | |
1706 | 170 Lisp_Object |
1811 | 171 dll_error () |
428 | 172 { |
173 /* #### WTF?! Shouldn't this at least attempt to get strerror or | |
174 something? --hniksic */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
175 return build_ascstring ("Generic shared library error"); |
428 | 176 } |
177 | |
1632 | 178 #elif defined (WIN32_NATIVE) || defined (CYGWIN) |
442 | 179 |
1632 | 180 #include "syswindows.h" |
181 #include "sysfile.h" | |
442 | 182 |
428 | 183 dll_handle |
1706 | 184 dll_open (Lisp_Object fname) |
428 | 185 { |
1706 | 186 Extbyte *soname; |
187 | |
188 if (NILP (fname)) | |
189 { | |
190 soname = NULL; | |
191 } | |
192 else | |
193 { | |
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
3841
diff
changeset
|
194 LISP_LOCAL_FILE_FORMAT_TO_TSTR (fname, soname); |
1706 | 195 } |
196 return (dll_handle) qxeLoadLibrary (soname); | |
428 | 197 } |
198 | |
199 int | |
200 dll_close (dll_handle h) | |
201 { | |
1706 | 202 return FreeLibrary ((HMODULE) h); |
428 | 203 } |
204 | |
205 dll_func | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
206 dll_function (dll_handle h, const Ibyte *n) |
428 | 207 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
208 Extbyte *next = NEW_C_STRING_TO_EXTERNAL (n, Qmswindows_multibyte); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
209 return (dll_func) GetProcAddress ((HINSTANCE) h, next); |
428 | 210 } |
211 | |
212 dll_func | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
213 dll_variable (dll_handle h, const Ibyte *n) |
428 | 214 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
215 Extbyte *next = NEW_C_STRING_TO_EXTERNAL (n, Qmswindows_multibyte); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
216 return (dll_func) GetProcAddress ((HINSTANCE) h, next); |
428 | 217 } |
218 | |
1706 | 219 Lisp_Object |
1811 | 220 dll_error () |
428 | 221 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
222 Ascbyte err[32]; |
1706 | 223 snprintf (err, 32, "Windows DLL Error %lu", GetLastError ()); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
224 return build_ascstring (err); |
428 | 225 } |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
226 #elif defined (HAVE_DYLD) |
1383 | 227 /* This section supports MacOSX dynamic libraries. Dynamically |
228 loadable libraries must be compiled as bundles, not dynamiclibs. | |
229 */ | |
230 | |
231 #include <mach-o/dyld.h> | |
232 | |
233 dll_handle | |
1706 | 234 dll_open (Lisp_Object fname) |
1383 | 235 { |
1706 | 236 Extbyte *soname; |
1383 | 237 NSObjectFileImage file; |
1418 | 238 NSModule out; |
1706 | 239 NSObjectFileImageReturnCode ret; |
240 | |
2855 | 241 /* |
242 * MacOS X dll support is for bundles, not the current executable, so return | |
243 * NULL is this case. However, dll_function() uses a special hack where a | |
244 * NULL handle can be used to find executable symbols. This satisfies the | |
245 * needs of ui-gtk.c but is not a general solution. | |
246 */ | |
1706 | 247 if (NILP (fname)) |
248 { | |
2855 | 249 return NULL; |
1706 | 250 } |
251 else | |
252 { | |
253 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding); | |
254 } | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
255 ret = NSCreateObjectFileImageFromFile (soname, &file); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
256 if (ret != NSObjectFileImageSuccess) |
1383 | 257 return NULL; |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
258 out = NSLinkModule (file, soname, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
259 NSLINKMODULE_OPTION_BINDNOW | |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
260 NSLINKMODULE_OPTION_PRIVATE | |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
261 NSLINKMODULE_OPTION_RETURN_ON_ERROR); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
262 return (dll_handle) out; |
1383 | 263 } |
264 | |
265 int | |
266 dll_close (dll_handle h) | |
267 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
268 return NSUnLinkModule ((NSModule) h, NSUNLINKMODULE_OPTION_NONE); |
1383 | 269 } |
270 | |
1851 | 271 /* Given an address, return the mach_header for the image containing it |
272 * or zero if the given address is not contained in any loaded images. | |
273 * | |
274 * Note: image_for_address(), my_find_image() and search_linked_libs() are | |
275 * based on code from the dlcompat library | |
276 * (http://www.opendarwin.org/projects/dlcompat). | |
277 */ | |
278 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
279 static const struct mach_header * |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
280 image_for_address (void *address) |
1851 | 281 { |
282 unsigned long i; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
283 unsigned long count = _dyld_image_count (); |
3841 | 284 const struct mach_header *mh = 0; |
1851 | 285 |
286 for (i = 0; i < count; i++) | |
287 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
288 unsigned long addr = (unsigned long) address - |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
289 _dyld_get_image_vmaddr_slide (i); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
290 mh = _dyld_get_image_header (i); |
1851 | 291 |
292 if (mh) | |
293 { | |
294 struct load_command *lc = | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
295 (struct load_command *) ((Rawbyte *) mh + |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
296 sizeof(struct mach_header)); |
1851 | 297 unsigned long j; |
298 | |
299 for (j = 0; j < mh->ncmds; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
300 j++, lc = (struct load_command *) ((Rawbyte *)lc + lc->cmdsize)) |
1851 | 301 { |
302 if (LC_SEGMENT == lc->cmd && | |
303 addr >= ((struct segment_command *)lc)->vmaddr && | |
304 addr < | |
305 ((struct segment_command *)lc)->vmaddr + | |
306 ((struct segment_command *)lc)->vmsize) | |
307 { | |
308 goto image_found; | |
309 } | |
310 } | |
311 } | |
312 | |
313 mh = 0; | |
314 } | |
315 | |
316 image_found: | |
317 return mh; | |
318 } | |
319 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
320 static const struct mach_header * |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
321 my_find_image (const char *name) |
1851 | 322 { |
323 const struct mach_header *mh = (struct mach_header *) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
324 NSAddImage (name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED | |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
325 NSADDIMAGE_OPTION_RETURN_ON_ERROR); |
1851 | 326 |
327 if (!mh) | |
328 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
329 int count = _dyld_image_count (); |
1851 | 330 int j; |
331 | |
332 for (j = 0; j < count; j++) | |
333 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
334 const char *id = _dyld_get_image_name (j); |
1851 | 335 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
336 if (!strcmp (id, name)) |
1851 | 337 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
338 mh = _dyld_get_image_header (j); |
1851 | 339 break; |
340 } | |
341 } | |
342 } | |
343 | |
344 return mh; | |
345 } | |
346 | |
347 /* | |
348 * dyld adds libraries by first adding the directly dependant libraries in | |
349 * link order, and then adding the dependencies for those libraries, so we | |
350 * should do the same... but we don't bother adding the extra dependencies, if | |
351 * the symbols are neither in the loaded image nor any of it's direct | |
352 * dependencies, then it probably isn't there. | |
353 */ | |
354 static NSSymbol | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
355 search_linked_libs (const struct mach_header * mh, const Ibyte *symbol) |
1851 | 356 { |
2054 | 357 unsigned long n; |
1851 | 358 NSSymbol nssym = 0; |
359 | |
360 struct load_command *lc = | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
361 (struct load_command *) ((Rawbyte *) mh + sizeof (struct mach_header)); |
1851 | 362 |
363 for (n = 0; n < mh->ncmds; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
364 n++, lc = (struct load_command *) ((Rawbyte *) lc + lc->cmdsize)) |
1851 | 365 { |
366 if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) | |
367 { | |
368 struct mach_header *wh; | |
369 | |
370 if ((wh = (struct mach_header *) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
371 my_find_image((Rawbyte *) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
372 (((struct dylib_command *) lc)-> |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
373 dylib.name.offset + (Rawbyte *) lc)))) |
1851 | 374 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
375 Extbyte *symext = |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
376 NEW_C_STRING_TO_EXTERNAL (symbol, Qdll_symbol_encoding); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
377 if (NSIsSymbolNameDefinedInImage (wh, symext)) |
1851 | 378 { |
379 nssym = | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
380 NSLookupSymbolInImage |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
381 (wh, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
382 symext, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
383 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
384 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); |
1851 | 385 break; |
386 } | |
387 } | |
388 } | |
389 } | |
390 | |
391 return nssym; | |
392 } | |
393 | |
1383 | 394 dll_func |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
395 dll_function (dll_handle h, const Ibyte *n) |
1383 | 396 { |
1851 | 397 NSSymbol sym = 0; |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
398 Extbyte *next; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
399 |
1383 | 400 MAYBE_PREPEND_UNDERSCORE (n); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
401 C_STRING_TO_EXTERNAL (n, next, Qdll_function_name_encoding); |
1851 | 402 |
403 /* NULL means the program image and shared libraries, not bundles. */ | |
404 | |
405 if (h == NULL) | |
406 { | |
407 /* NOTE: This assumes that this function is included in the main program | |
408 and not in a shared library. */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
409 const struct mach_header* my_mh = |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
410 image_for_address ((void*) &dll_function); |
1851 | 411 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
412 if (NSIsSymbolNameDefinedInImage (my_mh, next)) |
1851 | 413 { |
414 sym = | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
415 NSLookupSymbolInImage |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
416 (my_mh, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
417 next, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
418 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
419 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); |
1851 | 420 } |
421 | |
422 if (!sym) | |
423 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
424 sym = search_linked_libs (my_mh, n); |
1851 | 425 } |
426 } | |
427 else | |
428 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
429 sym = NSLookupSymbolInModule ((NSModule)h, next); |
1851 | 430 } |
431 | |
432 if (sym == 0) return 0; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
433 return (dll_func) NSAddressOfSymbol (sym); |
1851 | 434 } |
1383 | 435 |
436 dll_var | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
437 dll_variable (dll_handle h, const Ibyte *n) |
1383 | 438 { |
439 NSSymbol sym; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
440 Extbyte *next; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
441 |
1383 | 442 MAYBE_PREPEND_UNDERSCORE (n); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
443 C_STRING_TO_EXTERNAL (n, next, Qdll_variable_name_encoding); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
444 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
445 sym = NSLookupSymbolInModule ((NSModule) h, n); |
1383 | 446 if (sym == 0) return 0; |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
447 return (dll_var) NSAddressOfSymbol (sym); |
1383 | 448 } |
449 | |
1706 | 450 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
451 dll_error (void) |
1383 | 452 { |
453 NSLinkEditErrors c; | |
454 int errorNumber; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
455 const Extbyte *fileNameWithError, *errorString; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
456 NSLinkEditError (&c, &errorNumber, &fileNameWithError, &errorString); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
457 return build_extstring (errorString, Qerror_message_encoding); |
1383 | 458 } |
2078 | 459 #elif HAVE_LTDL |
460 /* Libtool's libltdl */ | |
461 #include <ltdl.h> | |
462 | |
463 dll_handle | |
464 dll_open (Lisp_Object fname) | |
465 { | |
466 Extbyte *soname; | |
467 | |
468 if (NILP (fname)) | |
469 { | |
470 soname = NULL; | |
471 } | |
472 else | |
473 { | |
474 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding); | |
475 } | |
476 return (dll_handle) lt_dlopen (soname); | |
477 } | |
478 | |
479 int | |
480 dll_close (dll_handle h) | |
481 { | |
482 return lt_dlclose ((lt_dlhandle) h); | |
483 } | |
484 | |
485 dll_func | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
486 dll_function (dll_handle h, const Ibyte *n) |
2078 | 487 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
488 Extbyte *next; |
2078 | 489 MAYBE_PREPEND_UNDERSCORE (n); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
490 C_STRING_TO_EXTERNAL (n, next, Qdll_function_name_encoding); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
491 return (dll_func) lt_dlsym ((lt_dlhandle) h, next); |
2078 | 492 } |
493 | |
494 dll_var | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
495 dll_variable (dll_handle h, const Ibyte *n) |
2078 | 496 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
497 Extbyte *next; |
2078 | 498 MAYBE_PREPEND_UNDERSCORE (n); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
499 C_STRING_TO_EXTERNAL (n, next, Qdll_variable_name_encoding); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
500 return (dll_var) lt_dlsym ((lt_dlhandle) h, next); |
2078 | 501 } |
502 | |
503 Lisp_Object | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
504 dll_error (void) |
2078 | 505 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
506 return build_extstring (lt_dlerror (), Qerror_message_encoding); |
2078 | 507 } |
428 | 508 #else |
1706 | 509 /* Catchall if we don't know about this system's method of dynamic loading */ |
428 | 510 dll_handle |
1706 | 511 dll_open (Lisp_Object fname) |
428 | 512 { |
513 return NULL; | |
514 } | |
515 | |
516 int | |
517 dll_close (dll_handle h) | |
518 { | |
519 return 0; | |
520 } | |
521 | |
522 dll_func | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
523 dll_function (dll_handle h, const Ibyte *n) |
428 | 524 { |
525 return NULL; | |
526 } | |
527 | |
528 dll_func | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
529 dll_variable (dll_handle h, const Ibyte *n) |
428 | 530 { |
531 return NULL; | |
532 } | |
533 | |
1706 | 534 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
535 dll_error (void) |
428 | 536 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
537 return build_ascstring ("Shared libraries not implemented on this system"); |
428 | 538 } |
539 #endif /* System conditionals */ | |
540 | |
541 #endif /* HAVE_SHLIB */ |