X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fsysdll.c;h=fc1d877d3af33e53ba136b32d1d8f147150d2890;hb=bc741487551598b72717ccde638419f56cd4e16e;hp=1e2807ca94504d7a4bb4bfc6c8466f4facea7d80;hpb=0c693dc08f0794304711787b2eb47c144ea4bef1;p=chise%2Fxemacs-chise.git diff --git a/src/sysdll.c b/src/sysdll.c index 1e2807c..fc1d877 100644 --- a/src/sysdll.c +++ b/src/sysdll.c @@ -24,6 +24,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #endif #include +#include "lisp.h" #include "sysdll.h" /* This whole file is conditional upon HAVE_SHLIB */ @@ -31,6 +32,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA /* Thankfully, most systems follow the ELFish dlopen() method. */ + #if defined(HAVE_DLOPEN) #include @@ -38,8 +40,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # define RTLD_LAZY 1 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */ -#ifndef RTLD_GLOBAL -# define RTLD_GLOBAL 0 +#ifndef RTLD_NOW +# define RTLD_NOW 2 #endif int @@ -48,10 +50,11 @@ dll_init (const char *arg) return 0; } + dll_handle dll_open (const char *fname) { - return (dll_handle) dlopen (fname, RTLD_LAZY | RTLD_GLOBAL); + return (dll_handle) dlopen (fname, RTLD_NOW); } int @@ -150,7 +153,7 @@ dll_error (dll_handle h) return "Generic shared library error"; } -#elif defined(HAVE_INIT_DLD) +#elif defined(HAVE_DLD_INIT) #include int dll_init (const char *arg) @@ -241,8 +244,85 @@ dll_error (dll_handle h) { 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 + +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; + } + return (dll_handle)NSLinkModule(file, fname, + NSLINKMODULE_OPTION_BINDNOW | + NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); +} + +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; +#ifdef DLSYM_NEEDS_UNDERSCORE + char *buf = alloca_array (char, strlen (n) + 2); + *buf = '_'; + strcpy (buf + 1, n); + n = buf; +#endif + 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; +#ifdef DLSYM_NEEDS_UNDERSCORE + char *buf = alloca_array (char, strlen (n) + 2); + *buf = '_'; + strcpy (buf + 1, n); + n = buf; +#endif + 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 */ +/* Catchall if we don't know about this system's method of dynamic loading */ int dll_init (const char *arg) {