summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-07-10 23:26:01 +0000
committerCharles Bailey <bailey@genetics.upenn.edu>1996-07-10 23:26:01 +0000
commitd6bcbf1c78e6914b11d9eab7c9a121914d1ffd63 (patch)
treef5e33616ab2b04e6d294b8d7f4a53c0bd2e5e9b7 /ext
parentd2cedf73b8eb6fdc231c00e6da4718c055e8fd2c (diff)
downloadperl-d6bcbf1c78e6914b11d9eab7c9a121914d1ffd63.tar.gz
Add NeXTSTEP/OPENSTEP 4 support
Diffstat (limited to 'ext')
-rw-r--r--ext/DynaLoader/dl_next.xs130
1 files changed, 106 insertions, 24 deletions
diff --git a/ext/DynaLoader/dl_next.xs b/ext/DynaLoader/dl_next.xs
index 33a41003ef..9e98d562e0 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 <mach-o/rld.h>
#include <streams/streams.h>
+#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 <mach-o/dyld.h>
+
+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);