diff options
Diffstat (limited to 'tcl/unix/tclLoadNext.c')
-rw-r--r-- | tcl/unix/tclLoadNext.c | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/tcl/unix/tclLoadNext.c b/tcl/unix/tclLoadNext.c index 41069413a56..db3c7154d52 100644 --- a/tcl/unix/tclLoadNext.c +++ b/tcl/unix/tclLoadNext.c @@ -20,17 +20,14 @@ /* *---------------------------------------------------------------------- * - * TclpLoadFile -- + * TclpDlopen -- * * Dynamically loads a binary code file into memory and returns - * the addresses of two procedures within that file, if they - * are defined. + * a handle to the new code. * * Results: * A standard Tcl completion code. If an error occurs, an error - * message is left in the interp's result. *proc1Ptr and *proc2Ptr - * are filled in with the addresses of the symbols given by - * *sym1 and *sym2, or NULL if those symbols can't be found. + * message is left in the interp's result. * * Side effects: * New code suddenly appears in memory. @@ -39,25 +36,25 @@ */ int -TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr, clientDataPtr) +TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr) Tcl_Interp *interp; /* Used for error reporting. */ - char *fileName; /* Name of the file containing the desired - * code. */ - char *sym1, *sym2; /* Names of two procedures to look up in - * the file's symbol table. */ - Tcl_PackageInitProc **proc1Ptr, **proc2Ptr; - /* Where to return the addresses corresponding - * to sym1 and sym2. */ - ClientData *clientDataPtr; /* Filled with token for dynamically loaded + Tcl_Obj *pathPtr; /* Name of the file containing the desired + * code (UTF-8). */ + Tcl_LoadHandle *loadHandle; /* Filled with token for dynamically loaded * file which will be passed back to - * TclpUnloadFile() to unload the file. */ + * (*unloadProcPtr)() to unload the file. */ + Tcl_FSUnloadFileProc **unloadProcPtr; + /* Filled with address of Tcl_FSUnloadFileProc + * function which should be used for + * this file. */ { struct mach_header *header; char *data; int len, maxlen; char *files[]={fileName,NULL}; NXStream *errorStream=NXOpenMemory(0,0,NX_READWRITE); - + char *fileName = Tcl_GetString(pathPtr); + if(!rld_load(errorStream,&header,files,NULL)) { NXGetMemoryBuffer(errorStream,&data,&len,&maxlen); Tcl_AppendResult(interp,"couldn't load file \"",fileName,"\": ",data,NULL); @@ -66,27 +63,45 @@ TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr, clientDataPtr) } NXCloseMemory(errorStream,NX_FREEBUFFER); - *proc1Ptr=NULL; - if(sym1) { - char sym[strlen(sym1)+2]; - sym[0]='_'; sym[1]=0; strcat(sym,sym1); - rld_lookup(NULL,sym,(unsigned long *)proc1Ptr); - } - - *proc2Ptr=NULL; - if(sym2) { - char sym[strlen(sym2)+2]; - sym[0]='_'; sym[1]=0; strcat(sym,sym2); - rld_lookup(NULL,sym,(unsigned long *)proc2Ptr); - } - *clientDataPtr = NULL; - + *loadHandle = (Tcl_LoadHandle)1; /* A dummy non-NULL value */ + *unloadProcPtr = &TclpUnloadFile; + return TCL_OK; } /* *---------------------------------------------------------------------- * + * TclpFindSymbol -- + * + * Looks up a symbol, by name, through a handle associated with + * a previously loaded piece of code (shared library). + * + * Results: + * Returns a pointer to the function associated with 'symbol' if + * it is found. Otherwise returns NULL and may leave an error + * message in the interp's result. + * + *---------------------------------------------------------------------- + */ +Tcl_PackageInitProc* +TclpFindSymbol(interp, loadHandle, symbol) + Tcl_Interp *interp; + Tcl_LoadHandle loadHandle; + CONST char *symbol; +{ + Tcl_PackageInitProc *proc=NULL; + if(symbol) { + char sym[strlen(symbol)+2]; + sym[0]='_'; sym[1]=0; strcat(sym,symbol); + rld_lookup(NULL,sym,(unsigned long *)&proc); + } + return proc; +} + +/* + *---------------------------------------------------------------------- + * * TclpUnloadFile -- * * Unloads a dynamically loaded binary code file from memory. @@ -103,9 +118,9 @@ TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr, clientDataPtr) */ void -TclpUnloadFile(clientData) - ClientData clientData; /* ClientData returned by a previous call - * to TclpLoadFile(). The clientData is +TclpUnloadFile(loadHandle) + Tcl_LoadHandle loadHandle; /* loadHandle returned by a previous call + * to TclpDlopen(). The loadHandle is * a token that represents the loaded * file. */ { @@ -133,11 +148,10 @@ TclpUnloadFile(clientData) int TclGuessPackageName(fileName, bufPtr) - char *fileName; /* Name of file containing package (already + CONST char *fileName; /* Name of file containing package (already * translated to local form if needed). */ Tcl_DString *bufPtr; /* Initialized empty dstring. Append * package name to this if possible. */ { return 0; } - |