Mercurial > hg > xemacs-beta
annotate src/sysdll.c @ 5090:0ca81354c4c7
Further frame-geometry cleanups
-------------------- ChangeLog entries follow: --------------------
man/ChangeLog addition:
2010-03-03 Ben Wing <ben@xemacs.org>
* internals/internals.texi (Intro to Window and Frame Geometry):
* internals/internals.texi (The Paned Area):
* internals/internals.texi (The Displayable Area):
Update to make note of e.g. the fact that the bottom gutter is
actually above the minibuffer.
src/ChangeLog addition:
2010-03-03 Ben Wing <ben@xemacs.org>
* emacs.c:
* emacs.c (assert_equal_failed):
* lisp.h:
* lisp.h (assert_equal):
New fun assert_equal, asserting that two values == each other, and
printing out both values upon failure.
* frame-gtk.c (gtk_initialize_frame_size):
* frame-impl.h:
* frame-impl.h (FRAME_TOP_INTERNAL_BORDER_START):
* frame-impl.h (FRAME_BOTTOM_INTERNAL_BORDER_START):
* frame-impl.h (FRAME_LEFT_INTERNAL_BORDER_START):
* frame-impl.h (FRAME_PANED_TOP_EDGE):
* frame-impl.h (FRAME_NONPANED_SIZE):
* frame-x.c (x_initialize_frame_size):
* frame.c:
* gutter.c (get_gutter_coords):
* gutter.c (calculate_gutter_size):
* gutter.h:
* gutter.h (WINDOW_REAL_TOP_GUTTER_BOUNDS):
* gutter.h (FRAME_TOP_GUTTER_BOUNDS):
* input-method-xlib.c:
* input-method-xlib.c (XIM_SetGeometry):
* redisplay-output.c (clear_left_border):
* redisplay-output.c (clear_right_border):
* redisplay-output.c (redisplay_output_pixmap):
* redisplay-output.c (redisplay_clear_region):
* redisplay-output.c (redisplay_clear_top_of_window):
* redisplay-output.c (redisplay_clear_to_window_end):
* redisplay-xlike-inc.c (XLIKE_clear_frame):
* redisplay.c:
* redisplay.c (UPDATE_CACHE_RETURN):
* redisplay.c (pixel_to_glyph_translation):
* toolbar.c (update_frame_toolbars_geometry):
* window.c (Fwindow_pixel_edges):
Get rid of some redundant macros. Consistently use the
FRAME_TOP_*_START, FRAME_RIGHT_*_END, etc. format. Rename
FRAME_*_BORDER_* to FRAME_*_INTERNAL_BORDER_*. Comment out
FRAME_BOTTOM_* for gutters and the paned area due to the
uncertainty over where the paned area actually begins. (Eventually
we should probably move the gutters outside the minibuffer so that
the paned area is contiguous.) Use FRAME_PANED_* more often in the
code to make things clearer.
Update the diagram to show that the bottom gutter is inside the
minibuffer (!) and that there are "junk boxes" when you have left
and/or right gutters (dead boxes that are mistakenly left uncleared,
unlike the corresponding scrollbar dead boxes). Update the text
appropriately to cover the bottom gutter position, etc.
Rewrite gutter-geometry code to use the FRAME_*_GUTTER_* in place of
equivalent expressions referencing other frame elements, to make the
code more portable in case we move around the gutter location.
Cleanup FRAME_*_GUTTER_BOUNDS() in gutter.h.
Add some #### GEOM! comments where I think code is incorrect --
typically, it wasn't fixed up properly when the gutter was added.
Some cosmetic changes.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 03 Mar 2010 05:07:47 -0600 |
parents | 4aebb0131297 |
children | f283b08ff0c9 |
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 { | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
80 soname = LISP_STRING_TO_EXTERNAL (fname, Qdll_filename_encoding); |
1706 | 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); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
96 next = ITEXT_TO_EXTERNAL (n, Qdll_function_name_encoding); |
4952
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); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
105 next = ITEXT_TO_EXTERNAL (n, Qdll_variable_name_encoding); |
4952
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 { | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
137 soname = LISP_STRING_TO_EXTERNAL (fname, Qdll_filename_encoding); |
1706 | 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 { |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
208 Extbyte *next = ITEXT_TO_EXTERNAL (n, Qmswindows_multibyte); |
4952
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 { |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
215 Extbyte *next = ITEXT_TO_EXTERNAL (n, Qmswindows_multibyte); |
4952
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 { | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
253 soname = LISP_STRING_TO_EXTERNAL (fname, Qdll_filename_encoding); |
1706 | 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 = |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
376 ITEXT_TO_EXTERNAL (symbol, Qdll_symbol_encoding); |
4952
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); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
401 next = ITEXT_TO_EXTERNAL (n, 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); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
443 next = ITEXT_TO_EXTERNAL (n, Qdll_variable_name_encoding); |
4952
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 { | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
474 soname = LISP_STRING_TO_EXTERNAL (fname, Qdll_filename_encoding); |
2078 | 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); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
490 next = ITEXT_TO_EXTERNAL (n, Qdll_function_name_encoding); |
4952
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); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
499 next = ITEXT_TO_EXTERNAL (n, Qdll_variable_name_encoding); |
4952
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 */ |