diff options
Diffstat (limited to 'byterun/unix.c')
-rw-r--r-- | byterun/unix.c | 119 |
1 files changed, 2 insertions, 117 deletions
diff --git a/byterun/unix.c b/byterun/unix.c index f7e3f6326..b0e606ccc 100644 --- a/byterun/unix.c +++ b/byterun/unix.c @@ -26,9 +26,7 @@ #include <fcntl.h> #include "config.h" #ifdef SUPPORT_DYNAMIC_LINKING -#ifdef HAS_NSLINKMODULE -#include <mach-o/dyld.h> -#elif defined(__CYGWIN32__) +#ifdef __CYGWIN32__ #include "flexdll.h" #else #include <dlfcn.h> @@ -170,120 +168,7 @@ char * caml_search_dll_in_path(struct ext_table * path, char * name) } #ifdef SUPPORT_DYNAMIC_LINKING -#ifdef HAS_NSLINKMODULE -/* Use MacOSX bundles */ - -static char *dlerror_string = "No error"; - -/* Need to emulate dlopen behaviour by caching open libraries */ -typedef struct bundle_entry { - struct bundle_entry *next; - char *name; - void *handle; - int count; -} entry_t; - -entry_t bundle_list = {NULL,NULL,NULL,0}; - -entry_t *caml_lookup_bundle(const char *name) -{ - entry_t *current = bundle_list.next, *last = &bundle_list; - - while (current !=NULL) { - if (!strcmp(name,current->name)) - return current; - last = current; - current = current->next; - } - current = (entry_t*) malloc(sizeof(entry_t)+strlen(name)+1); - current->name = (char*)(current+1); - strcpy(current->name, name); - current->count = 0; - current->next = NULL; - last->next = current; - return current; -} - -void * caml_dlopen(char * libname, int for_execution, int global) -{ - NSObjectFileImage image; - entry_t *bentry = caml_lookup_bundle(libname); - NSObjectFileImageReturnCode retCode; - void *result = NULL; - - if (bentry->count > 0) - return bentry->handle; - - retCode = NSCreateObjectFileImageFromFile(libname, &image); - switch (retCode) { - case NSObjectFileImageSuccess: - dlerror_string = NULL; - result = (void*)NSLinkModule(image, libname, NSLINKMODULE_OPTION_BINDNOW - | NSLINKMODULE_OPTION_RETURN_ON_ERROR); - if (result != NULL) { - bentry->count++; - bentry->handle = result; - } - else NSDestroyObjectFileImage(image); - break; - case NSObjectFileImageAccess: - dlerror_string = "cannot access this bundle"; break; - case NSObjectFileImageArch: - dlerror_string = "this bundle has wrong CPU architecture"; break; - case NSObjectFileImageFormat: - case NSObjectFileImageInappropriateFile: - dlerror_string = "this file is not a proper bundle"; break; - default: - dlerror_string = "could not read object file"; break; - } - return result; -} - -void caml_dlclose(void * handle) -{ - entry_t *current = bundle_list.next; - int close = 1; - - dlerror_string = NULL; - while (current != NULL) { - if (current->handle == handle) { - current->count--; - close = (current->count == 0); - break; - } - current = current->next; - } - if (close) - NSUnLinkModule((NSModule)handle, NSUNLINKMODULE_OPTION_NONE); -} - -void * caml_dlsym(void * handle, char * name) -{ - NSSymbol sym; - char _name[1000] = "_"; - strncat (_name, name, 998); - dlerror_string = NULL; - sym = NSLookupSymbolInModule((NSModule)handle, _name); - if (sym != NULL) return NSAddressOfSymbol(sym); - else return NULL; -} - -void * caml_globalsym(char * name) -{ - return NULL; -} - -char * caml_dlerror(void) -{ - NSLinkEditErrors c; - int errnum; - const char *fileName, *errorString; - if (dlerror_string != NULL) return dlerror_string; - NSLinkEditError(&c,&errnum,&fileName,&errorString); - return (char *) errorString; -} - -#elif defined(__CYGWIN32__) +#ifdef __CYGWIN32__ /* Use flexdll */ void * caml_dlopen(char * libname, int for_execution, int global) |