3 * Platform: NeXT NS 3.2
4 * Author: Anno Siegel (siegel@zrz.TU-Berlin.DE)
5 * Based on: dl_dlopen.xs by Paul Marquess
6 * Created: Aug 15th, 1994
11 And Gandalf said: 'Many folk like to know beforehand what is to
12 be set on the table; but those who have laboured to prepare the
13 feast like to keep their secret; for wonder makes the words of
19 dl_next.xs is itself a port from dl_dlopen.xs by Paul Marquess. It
20 should not be used as a base for further ports though it may be used
21 as an example for how dl_dlopen.xs can be ported to other platforms.
23 The method used here is just to supply the sun style dlopen etc.
24 functions in terms of NeXTs rld_*. The xs code proper is unchanged
27 The port could use some streamlining. For one, error handling could
38 #include "dlutils.c" /* SaveError() etc */
41 #include <mach-o/rld.h>
42 #include <streams/streams.h>
44 static char * dl_last_error = (char *) 0;
49 return NXOpenMemory( (char *) 0, 0, NX_WRITEONLY);
59 if ( dl_last_error ) {
60 safefree(dl_last_error);
62 NXGetMemoryBuffer(s, &buffer, &len, &maxlen);
63 dl_last_error = safemalloc(len);
64 strcpy(dl_last_error, buffer);
72 NXCloseMemory( s, NX_FREEBUFFER);
84 int mode; /* mode is ignored */
87 NXStream *nxerr = OpenError();
93 av_resolve = GvAVn(gv_fetchpv(
94 "DynaLoader::dl_resolve_using", FALSE, SVt_PVAV));
95 psize = AvFILL(av_resolve) + 3;
96 p = (char **) safemalloc(psize * sizeof(char*));
98 for(i=1; i<psize-1; i++) {
99 p[i] = SvPVx(*av_fetch(av_resolve, i-1, TRUE), na);
102 rld_success = rld_load(nxerr, (struct mach_header **)0, p,
108 TransferError(nxerr);
116 dlclose(handle) /* stub only */
123 dlsym(handle, symbol)
127 NXStream *nxerr = OpenError();
129 unsigned long symref = 0;
131 sprintf(symbuf, "_%s", symbol);
132 if (!rld_lookup(nxerr, symbuf, &symref)) {
133 TransferError(nxerr);
136 return (void*) symref;
140 /* ----- code from dl_dlopen.xs below here ----- */
146 (void)dl_generic_private_init();
149 MODULE = DynaLoader PACKAGE = DynaLoader
152 (void)dl_private_init();
157 dl_load_file(filename)
161 DLDEBUG(1,fprintf(stderr,"dl_load_file(%s):\n", filename));
162 RETVAL = dlopen(filename, mode) ;
163 DLDEBUG(2,fprintf(stderr," libref=%x\n", RETVAL));
164 ST(0) = sv_newmortal() ;
166 SaveError("%s",dlerror()) ;
168 sv_setiv( ST(0), (IV)RETVAL);
172 dl_find_symbol(libhandle, symbolname)
176 DLDEBUG(2,fprintf(stderr,"dl_find_symbol(handle=%x, symbol=%s)\n",
177 libhandle, symbolname));
178 RETVAL = dlsym(libhandle, symbolname);
179 DLDEBUG(2,fprintf(stderr," symbolref = %x\n", RETVAL));
180 ST(0) = sv_newmortal() ;
182 SaveError("%s",dlerror()) ;
184 sv_setiv( ST(0), (IV)RETVAL);
193 # These functions should not need changing on any platform:
196 dl_install_xsub(perl_name, symref, filename="$Package")
201 DLDEBUG(2,fprintf(stderr,"dl_install_xsub(name=%s, symref=%x)\n",
203 ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)())symref, filename)));