X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=src%2Fsysdll.c;h=fc1d877d3af33e53ba136b32d1d8f147150d2890;hp=bc911c422ed38afda0ffb3c510c4ba2975ce73b6;hb=de1ec4b272dfa3f9ef2c9ae28a9ba67170d24da5;hpb=d81014e89b5102527e5b50aac62edeed2955671d diff --git a/src/sysdll.c b/src/sysdll.c index bc911c4..fc1d877 100644 --- a/src/sysdll.c +++ b/src/sysdll.c @@ -32,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 @@ -49,6 +50,7 @@ dll_init (const char *arg) return 0; } + dll_handle dll_open (const char *fname) { @@ -151,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) @@ -242,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) {