From: Perl 5 Porters Date: Wed, 10 Jul 1996 23:26:01 +0000 (+0000) Subject: Add NeXTSTEP/OPENSTEP 4 support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6bcbf1c78e6914b11d9eab7c9a121914d1ffd63;p=p5sagit%2Fp5-mst-13.2.git Add NeXTSTEP/OPENSTEP 4 support --- diff --git a/ext/DynaLoader/dl_next.xs b/ext/DynaLoader/dl_next.xs index 33a4100..9e98d56 100644 --- a/ext/DynaLoader/dl_next.xs +++ b/ext/DynaLoader/dl_next.xs @@ -31,9 +31,12 @@ Anno Siegel */ +#if NS_TARGET_MAJOR >= 4 +#else /* include these before perl headers */ #include #include +#endif #include "EXTERN.h" #include "perl.h" @@ -47,15 +50,105 @@ Anno Siegel static char * dl_last_error = (char *) 0; static AV *dl_resolve_using = Nullav; -NXStream * -OpenError() +static char *dlerror() +{ + return dl_last_error; +} + +int dlclose(handle) /* stub only */ +void *handle; +{ + return 0; +} + +#if NS_TARGET_MAJOR >= 4 +#import + +enum dyldErrorSource +{ + OFImage, +}; + +static void TranslateError + (const char *path, enum dyldErrorSource type, int number) +{ + char errorBuffer[128]; + unsigned int index; + static char *OFIErrorStrings[] = + { + "%s(%d): Object Image Load Failure\n", + "%s(%d): Object Image Load Success\n", + "%s(%d): Not an recognisable object file\n", + "%s(%d): No valid architecture\n", + "%s(%d): Object image has an invalid format\n", + "%s(%d): Invalid access (permissions?)\n", + "%s(%d): Unknown error code from NSCreateObjectFileImageFromFile\n", + }; +#define NUM_OFI_ERRORS (sizeof(OFIErrorStrings) / sizeof(OFIErrorStrings[0])) + + if ( dl_last_error ) { + safefree(dl_last_error); + } + switch (type) + { + case OFImage: + index = number; + if (index > NUM_OFI_ERRORS - 1) + index = NUM_OFI_ERRORS - 1; + sprintf(errorBuffer, OFIErrorStrings[index], path, number); + break; + + default: + sprintf(errorBuffer, "%s(%d): Totally unknown error type %d\n", + path, number, type); + break; + } + dl_last_error = safemalloc(strlen(errorBuffer)+1); + strcpy(dl_last_error, errorBuffer); +} + +static char *dlopen(char *path, int mode /* mode is ignored */) +{ + int dyld_result; + NSObjectFileImage ofile; + NSModule handle = NULL; + + dyld_result = NSCreateObjectFileImageFromFile(path, &ofile); + if (dyld_result != NSObjectFileImageSuccess) + TranslateError(path, OFImage, dyld_result); + else + { + // NSLinkModule will cause the run to abort on any link error's + // not very friendly but the error recovery functionality is limited. + handle = NSLinkModule(ofile, path, TRUE); + } + + return handle; +} + +void * +dlsym(handle, symbol) +void *handle; +char *symbol; +{ + void *addr; + + if (NSIsSymbolNameDefined(symbol)) + addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol)); + else + addr = NULL; + + return addr; +} + +#else /* NS_TARGET_MAJOR <= 3 */ + +static NXStream *OpenError(void) { return NXOpenMemory( (char *) 0, 0, NX_WRITEONLY); } -void -TransferError( s) -NXStream *s; +static void TransferError(NXStream *s) { char *buffer; int len, maxlen; @@ -68,24 +161,14 @@ NXStream *s; strcpy(dl_last_error, buffer); } -void -CloseError( s) -NXStream *s; +static void CloseError(NXStream *s) { if ( s ) { NXCloseMemory( s, NX_FREEBUFFER); } } -char *dlerror() -{ - return dl_last_error; -} - -char * -dlopen(path, mode) -char * path; -int mode; /* mode is ignored */ +static char *dlopen(char *path, int mode /* mode is ignored */) { int rld_success; NXStream *nxerr; @@ -120,13 +203,6 @@ int mode; /* mode is ignored */ return result; } -int -dlclose(handle) /* stub only */ -void *handle; -{ - return 0; -} - void * dlsym(handle, symbol) void *handle; @@ -144,6 +220,8 @@ char *symbol; return (void*) symref; } +#endif /* NS_TARGET_MAJOR >= 4 */ + /* ----- code from dl_dlopen.xs below here ----- */ @@ -182,6 +260,10 @@ dl_find_symbol(libhandle, symbolname) void * libhandle char * symbolname CODE: +#if NS_TARGET_MAJOR >= 4 + char symbolname_buf[1024]; + symbolname = dl_add_underscore(symbolname, symbolname_buf); +#endif DLDEBUG(2,fprintf(stderr,"dl_find_symbol(handle=%x, symbol=%s)\n", libhandle, symbolname)); RETVAL = dlsym(libhandle, symbolname);