summaryrefslogtreecommitdiffstats
path: root/unix/tclLoadDyld.c
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2002-07-17 20:00:44 (GMT)
committervincentdarley <vincentdarley>2002-07-17 20:00:44 (GMT)
commit7074d76f2ba74ea9a53f47fb4815145982285625 (patch)
tree7bf708f2c17514ad40291886268bc3cf73d95ddc /unix/tclLoadDyld.c
parent5625494c13f92f83294785e3691a89450f40c21a (diff)
downloadtcl-7074d76f2ba74ea9a53f47fb4815145982285625.zip
tcl-7074d76f2ba74ea9a53f47fb4815145982285625.tar.gz
tcl-7074d76f2ba74ea9a53f47fb4815145982285625.tar.bz2
load internals refactoring
Diffstat (limited to 'unix/tclLoadDyld.c')
-rw-r--r--unix/tclLoadDyld.c69
1 files changed, 28 insertions, 41 deletions
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c
index 8541416..9eefd91 100644
--- a/unix/tclLoadDyld.c
+++ b/unix/tclLoadDyld.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoadDyld.c,v 1.8 2002/02/25 15:21:59 das Exp $
+ * RCS: @(#) $Id: tclLoadDyld.c,v 1.9 2002/07/17 20:00:46 vincentdarley Exp $
*/
#include "tclInt.h"
@@ -40,17 +40,11 @@
*/
int
-TclpLoadFile(interp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr,
- clientDataPtr, unloadProcPtr)
+TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
Tcl_Interp *interp; /* Used for error reporting. */
Tcl_Obj *pathPtr; /* Name of the file containing the desired
- * code. */
- CONST 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
+ * code (UTF-8). */
+ TclLoadHandle *loadHandle; /* Filled with token for dynamically loaded
* file which will be passed back to
* (*unloadProcPtr)() to unload the file. */
Tcl_FSUnloadFileProc **unloadProcPtr;
@@ -58,9 +52,7 @@ TclpLoadFile(interp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr,
* function which should be used for
* this file. */
{
- NSSymbol symbol;
const struct mach_header *dyld_lib;
- Tcl_DString newName, ds;
char *native;
native = Tcl_FSGetNativePath(pathPtr);
@@ -75,46 +67,41 @@ TclpLoadFile(interp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr,
Tcl_AppendResult(interp, msg, (char *) NULL);
return TCL_ERROR;
}
-
+ *loadHandle = (TclLoadHandle)dyld_lib;
*unloadProcPtr = &TclpUnloadFile;
-
+ return TCL_OK;
+}
+
+Tcl_PackageInitProc*
+TclpFindSymbol(interp, loadHandle, symbol)
+ Tcl_Interp *interp;
+ TclLoadHandle loadHandle;
+ CONST char *symbol;
+{
+ NSSymbol nsSymbol;
+ CONST char *native;
+ Tcl_DString newName, ds;
+ Tcl_PackageInitProc* proc = NULL;
+ const struct mach_header *dyld_lib = (mach_header *)loadHandle;
/*
* dyld adds an underscore to the beginning of symbol names.
*/
- native = Tcl_UtfToExternalDString(NULL, sym1, -1, &ds);
+ native = Tcl_UtfToExternalDString(NULL, symbol, -1, &ds);
Tcl_DStringInit(&newName);
Tcl_DStringAppend(&newName, "_", 1);
native = Tcl_DStringAppend(&newName, native, -1);
- symbol = NSLookupSymbolInImage(dyld_lib, native,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- if(symbol) {
- *proc1Ptr = NSAddressOfSymbol(symbol);
- *clientDataPtr = NSModuleForSymbol(symbol);
- } else {
- *proc1Ptr=NULL;
- *clientDataPtr=NULL;
+ nsSymbol = NSLookupSymbolInImage(dyld_lib, native,
+ NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
+ NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+ if(nsSymbol) {
+ proc = NSAddressOfSymbol(nsSymbol);
+ /* *clientDataPtr = NSModuleForSymbol(nsSymbol); */
}
Tcl_DStringFree(&newName);
Tcl_DStringFree(&ds);
-
- native = Tcl_UtfToExternalDString(NULL, sym2, -1, &ds);
- Tcl_DStringInit(&newName);
- Tcl_DStringAppend(&newName, "_", 1);
- native = Tcl_DStringAppend(&newName, native, -1);
- symbol = NSLookupSymbolInImage(dyld_lib, native,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
- NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- if(symbol) {
- *proc2Ptr = NSAddressOfSymbol(symbol);
- } else {
- *proc2Ptr=NULL;
- }
- Tcl_DStringFree(&newName);
- Tcl_DStringFree(&ds);
-
- return TCL_OK;
+
+ return proc;
}
/*