X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FDynaLoader%2Fdl_dlopen.xs;h=66ee066adc40cec3fca45e788472c673467f9383;hb=1a95e36d92295cabb6c213a2f397c4cb7614d12c;hp=135f5112f214dbfef9def0ebdbe4cf1693259249;hpb=9d4ce9a5d50788ac8c636881861cb1c2ab45fc52;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/DynaLoader/dl_dlopen.xs b/ext/DynaLoader/dl_dlopen.xs index 135f511..66ee066 100644 --- a/ext/DynaLoader/dl_dlopen.xs +++ b/ext/DynaLoader/dl_dlopen.xs @@ -5,11 +5,13 @@ * Created: 10th July 1994 * * Modified: - * 15th July 1994 - Added code to explicitly save any error messages. - * 3rd August 1994 - Upgraded to v3 spec. - * 9th August 1994 - Changed to use IV - * 10th August 1994 - Tim Bunce: Added RTLD_LAZY, switchable debugging, - * basic FreeBSD support, removed ClearError + * 15th July 1994 - Added code to explicitly save any error messages. + * 3rd August 1994 - Upgraded to v3 spec. + * 9th August 1994 - Changed to use IV + * 10th August 1994 - Tim Bunce: Added RTLD_LAZY, switchable debugging, + * basic FreeBSD support, removed ClearError + * 29th Feburary 2000 - Alan Burlison: Added functionality to close dlopen'd + * files when the interpreter exits * */ @@ -37,6 +39,17 @@ RTLD_LAZY (==2) on Solaris 2. + dlclose + ------- + int + dlclose(handle) + void * handle; + + This function takes the handle returned by a previous invocation of + dlopen and closes the associated dynamic object file. It returns zero + on success, and non-zero on failure. + + dlsym ------ void * @@ -57,7 +70,7 @@ Returns a null-terminated string which describes the last error that occurred with either dlopen or dlsym. After each call to dlerror the error message will be reset to a null pointer. The - SaveError function is used to save the error as soo as it happens. + SaveError function is used to save the error as soon as it happens. Return Types @@ -99,7 +112,7 @@ SaveError("%s",dlerror()) ; Note that SaveError() takes a printf format string. Use a "%s" as - the first parameter if the error may contain and % characters. + the first parameter if the error may contain any % characters. */ @@ -142,12 +155,13 @@ BOOT: (void)dl_private_init(aTHX); -void * +void dl_load_file(filename, flags=0) char * filename int flags PREINIT: int mode = RTLD_LAZY; + void *handle; CODE: { #if defined(DLOPEN_WONT_DO_RELATIVE_PATHS) @@ -161,8 +175,11 @@ dl_load_file(filename, flags=0) } #endif #ifdef RTLD_NOW - if (dl_nonlazy) - mode = RTLD_NOW; + { + dMY_CXT; + if (dl_nonlazy) + mode = RTLD_NOW; + } #endif if (flags & 0x01) #ifdef RTLD_GLOBAL @@ -171,19 +188,35 @@ dl_load_file(filename, flags=0) Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename); #endif DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags)); - RETVAL = dlopen(filename, mode) ; - DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%lx\n", (unsigned long) RETVAL)); + handle = dlopen(filename, mode) ; + DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%lx\n", (unsigned long) handle)); ST(0) = sv_newmortal() ; - if (RETVAL == NULL) + if (handle == NULL) SaveError(aTHX_ "%s",dlerror()) ; else - sv_setiv( ST(0), PTR2IV(RETVAL)); + sv_setiv( ST(0), PTR2IV(handle)); } -void * + +int +dl_unload_file(libref) + void * libref + CODE: + DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_unload_file(%lx):\n", PTR2ul(libref))); + RETVAL = (dlclose(libref) == 0 ? 1 : 0); + if (!RETVAL) + SaveError(aTHX_ "%s", dlerror()) ; + DLDEBUG(2,PerlIO_printf(Perl_debug_log, " retval = %d\n", RETVAL)); + OUTPUT: + RETVAL + + +void dl_find_symbol(libhandle, symbolname) void * libhandle char * symbolname + PREINIT: + void *sym; CODE: #ifdef DLSYM_NEEDS_UNDERSCORE symbolname = Perl_form_nocontext("_%s", symbolname); @@ -191,19 +224,19 @@ dl_find_symbol(libhandle, symbolname) DLDEBUG(2, PerlIO_printf(Perl_debug_log, "dl_find_symbol(handle=%lx, symbol=%s)\n", (unsigned long) libhandle, symbolname)); - RETVAL = dlsym(libhandle, symbolname); + sym = dlsym(libhandle, symbolname); DLDEBUG(2, PerlIO_printf(Perl_debug_log, - " symbolref = %lx\n", (unsigned long) RETVAL)); + " symbolref = %lx\n", (unsigned long) sym)); ST(0) = sv_newmortal() ; - if (RETVAL == NULL) + if (sym == NULL) SaveError(aTHX_ "%s",dlerror()) ; else - sv_setiv( ST(0), PTR2IV(RETVAL)); + sv_setiv( ST(0), PTR2IV(sym)); void dl_undef_symbols() - PPCODE: + CODE: @@ -225,7 +258,8 @@ dl_install_xsub(perl_name, symref, filename="$Package") char * dl_error() CODE: - RETVAL = LastError ; + dMY_CXT; + RETVAL = dl_last_error ; OUTPUT: RETVAL