#endif
#include <stdlib.h>
+#include "lisp.h"
#include "sysdll.h"
/* This whole file is conditional upon HAVE_SHLIB */
#ifdef HAVE_SHLIB
/* Thankfully, most systems follow the ELFish dlopen() method.
-** HAVE__DLOPEN is lame, but SCO has their dl* functions as _dl*, and
-** unless you include dlfcn.h you don't get the macros to mask them, and
-** autoconf fails to find them. No longer true as of 5.0.5.
-**
-** Anybody who wants to use this on SCO needs to have their configure.in
-** look for _dlopen() as well as dlopen()
*/
-#if defined(HAVE_DLOPEN) || defined(HAVE__DLOPEN) || defined(HAVE_DLFCN_H)
+
+#if defined(HAVE_DLOPEN)
#include <dlfcn.h>
#ifndef RTLD_LAZY
# 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
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
return "Generic shared library error";
}
-#elif defined(HAVE_INIT_DLD)
+#elif defined(HAVE_DLD_INIT)
#include <dld.h>
int
dll_init (const char *arg)
{
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;
+ }
+ 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)
{