Mercurial > hg > xemacs-beta
changeset 1383:517919955e3f
[xemacs-hg @ 2003-03-26 04:22:47 by james]
Add Andrew Begel's support for MacOS X dynamic bundles. Also some minor
tweaks to sysdll.c to enhance compatibility and clarity.
author | james |
---|---|
date | Wed, 26 Mar 2003 04:22:49 +0000 |
parents | 134a4093b1e7 |
children | 72bc4b7c2480 |
files | src/ChangeLog src/config.h.in src/sysdll.c |
diffstat | 3 files changed, 101 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Tue Mar 25 23:45:45 2003 +0000 +++ b/src/ChangeLog Wed Mar 26 04:22:49 2003 +0000 @@ -1,3 +1,15 @@ +2003-03-25 Jerry James <james@xemacs.org> + + * config.h.in: Add HAVE_DYLD to indicate Darwin/MacOSX dynamic + linking (from Andrew Begel). + * sysdll.c: Factor common code into MAYBE_PREPEND_UNDERSCORE. + Try DL_LAZY and DL_NOW if RTLD_LAZY and RTLD_NOW are undefined. + Add Andrew Begel's support for loading bundles using the + Darwin/MacOSX native API. + * sysdll.c (dll_function): Use MAYBE_PREPEND_UNDERSCORE. + * sysdll.c (dll_variable): Ditto. + * sysdll.c (dll_open): Minor whitespace fix. + 2003-03-25 Andrew Begel <abegel@cs.berkeley.edu> * emodules.c (vars_of_module): Add .dylib as an acceptable shared
--- a/src/config.h.in Tue Mar 25 23:45:45 2003 +0000 +++ b/src/config.h.in Wed Mar 26 04:22:49 2003 +0000 @@ -304,6 +304,7 @@ #undef HAVE_SHL_LOAD #undef HAVE_DLD_INIT #undef HAVE_SHLIB +#undef HAVE_DYLD #undef DLSYM_NEEDS_UNDERSCORE #undef HAVE_LIBINTL
--- a/src/sysdll.c Tue Mar 25 23:45:45 2003 +0000 +++ b/src/sysdll.c Wed Mar 26 04:22:49 2003 +0000 @@ -27,6 +27,17 @@ #include "lisp.h" #include "sysdll.h" +#ifdef DLSYM_NEEDS_UNDERSCORE +#define MAYBE_PREPEND_UNDERSCORE(n) do { \ + char *buf = alloca_array (char, strlen (n) + 2); \ + *buf = '_'; \ + strcpy (buf + 1, n); \ + n = buf; \ +} while (0) +#else +#define MAYBE_PREPEND_UNDERSCORE(n) +#endif + /* This whole file is conditional upon HAVE_SHLIB */ #ifdef HAVE_SHLIB @@ -36,11 +47,19 @@ #include <dlfcn.h> #ifndef RTLD_LAZY -# define RTLD_LAZY 1 +# ifdef DL_LAZY +# define RTLD_LAZY DL_LAZY +# else +# define RTLD_LAZY 1 +# endif #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */ #ifndef RTLD_NOW -# define RTLD_NOW 2 +# ifdef DL_NOW +# define RTLD_NOW DL_NOW +# else +# define RTLD_NOW 2 +# endif #endif int @@ -64,24 +83,14 @@ dll_func dll_function (dll_handle h, const char *n) { -#ifdef DLSYM_NEEDS_UNDERSCORE - char *buf = alloca_array (char, strlen (n) + 2); - *buf = '_'; - strcpy (buf + 1, n); - n = buf; -#endif + MAYBE_PREPEND_UNDERSCORE (n); return (dll_func) dlsym ((void *) h, n); } dll_var dll_variable (dll_handle h, const char *n) { -#ifdef DLSYM_NEEDS_UNDERSCORE - char *buf = alloca_array (char, strlen (n) + 2); - *buf = '_'; - strcpy (buf + 1, n); - n = buf; -#endif + MAYBE_PREPEND_UNDERSCORE (n); return (dll_var)dlsym ((void *)h, n); } @@ -112,7 +121,7 @@ /* shl_load will hang hard if passed a NULL fname. */ if (fname == NULL) return NULL; - return (dll_handle) shl_load (fname, BIND_DEFERRED,0L); + return (dll_handle) shl_load (fname, BIND_DEFERRED, 0L); } int @@ -242,6 +251,70 @@ { return "Windows DLL Error"; } +#elif defined(HAVE_DYLD) +/* This section supports MacOSX dynamic libraries. Dynamically + loadable libraries must be compiled as bundles, not dynamiclibs. +*/ + +#include <mach-o/dyld.h> + +int +dll_init (const char *arg) +{ + return 0; +} + +dll_handle +dll_open (const char *fname) +{ + NSObjectFileImage file; + NSObjectFileImageReturnCode ret = + NSCreateObjectFileImageFromFile(fname, &file); + if (ret != NSObjectFileImageSuccess) { + return NULL; + } + NSModule out = NSLinkModule(file, fname, + NSLINKMODULE_OPTION_BINDNOW | + NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + return (dll_handle)out; +} + +int +dll_close (dll_handle h) +{ + return NSUnLinkModule((NSModule)h, NSUNLINKMODULE_OPTION_NONE); +} + +dll_func +dll_function (dll_handle h, const char *n) +{ + NSSymbol sym; + MAYBE_PREPEND_UNDERSCORE (n); + sym = NSLookupSymbolInModule((NSModule)h, n); + if (sym == 0) return 0; + return (dll_func)NSAddressOfSymbol(sym); +} + +dll_var +dll_variable (dll_handle h, const char *n) +{ + NSSymbol sym; + MAYBE_PREPEND_UNDERSCORE (n); + sym = NSLookupSymbolInModule((NSModule)h, n); + if (sym == 0) return 0; + return (dll_var)NSAddressOfSymbol(sym); +} + +const char * +dll_error (dll_handle h) +{ + NSLinkEditErrors c; + int errorNumber; + const char *fileNameWithError, *errorString; + NSLinkEditError(&c, &errorNumber, &fileNameWithError, &errorString); + return errorString; +} #else /* Catchall if we don't know about this systems method of dynamic loading */ int