From: Jim I. <ji...@ap...> - 2002-02-15 18:42:33
|
Daniel, This looks great. I am not that upset about not supporting 10.0 for=20 Tcl. There are a bunch of Apps (including Office) that only support=20 10.1. And 10.1 is SO much better... People can always check out the=20 old version if they really must support 10.0 for some reason. So check=20= it into the head. You can check stuff into the macosx-8-4-branch too,=20= right? If so, feel free to check it in there, otherwise I will figure=20= out why you can't. Thanks for hacking on this. Jim On Friday, February 15, 2002, at 05:18 AM, Daniel A. Steffen wrote: > At 21:39 +1100 on 15/2/02, Daniel A. Steffen wrote: > >> probably we should rewrite tclLoadDyld.c using the 10.1 >> TwoLevelNamespaces API anyway. > > I took a stab at this, c.f. below. (based on tclLoadDyld.c from the > tip of core-8-3-1-branch) > > works well, doesn't fail on nonexistent files, searches > DYLD_LIBRARY_PATH etc. Howver, it probably requires 10.1, > <mach-o/dyld.h> is unclear on this (Jim?), so it might not be > appropriate for core-8-3-1-branch ? > > If I don't hear any objections, I'll check a CONSTified version into > the HEAD though. > > Cheers, > > Daniel > > -------------------------- paste into=20 > tclLoadDyld.c -------------------------- > > #include "tclInt.h" > #include "tclPort.h" > #include <mach-o/dyld.h> > > /* > = *---------------------------------------------------------------------- > * > * TclpLoadFile -- > * > * Dynamically loads a binary code file into memory and returns > * the addresses of two procedures within that file, if they > * are defined. > * > * Results: > * A standard Tcl completion code. If an error occurs, an error > * message is left in the interpreter's result. *proc1Ptr and=20 > *proc2Ptr > * are filled in with the addresses of the symbols given by > * *sym1 and *sym2, or NULL if those symbols can't be found. > * > * Side effects: > * New code suddenly appears in memory. > * > = *---------------------------------------------------------------------- > */ > > int > TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr,=20 > clientDataPtr) > 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=20 > loaded > * file which will be passed back to > * TclpUnloadFile() to unload the file. = */ > { > NSSymbol symbol; > const struct mach_header *dyld_lib; > Tcl_DString newName, ds; > char *native; > > native =3D Tcl_UtfToExternalDString(NULL, fileName, -1, &ds); > dyld_lib =3D NSAddImage(native, > NSADDIMAGE_OPTION_WITH_SEARCHING | > NSADDIMAGE_OPTION_RETURN_ON_ERROR); > Tcl_DStringFree(&ds); > =A0=A0 > if (!dyld_lib) { > NSLinkEditErrors editError; > char *name, *msg; > NSLinkEditError(&editError, &errno, &name, &msg); > Tcl_AppendResult(interp, msg, (char *) NULL); > return TCL_ERROR; > } > > /* > * dyld adds an underscore to the beginning of symbol names. > */ > > native =3D Tcl_UtfToExternalDString(NULL, sym1, -1, &ds); > Tcl_DStringInit(&newName); > Tcl_DStringAppend(&newName, "_", 1); > native =3D Tcl_DStringAppend(&newName, native, -1); > symbol =3D NSLookupSymbolInImage(dyld_lib, native, > NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | > NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); > if(symbol) { > *proc1Ptr =3D NSAddressOfSymbol(symbol); > *clientDataPtr =3D NSModuleForSymbol(symbol); > } else { > *proc1Ptr=3DNULL; > *clientDataPtr=3DNULL; > } > Tcl_DStringFree(&newName); > Tcl_DStringFree(&ds); > > native =3D Tcl_UtfToExternalDString(NULL, sym2, -1, &ds); > Tcl_DStringInit(&newName); > Tcl_DStringAppend(&newName, "_", 1); > native =3D Tcl_DStringAppend(&newName, native, -1); > symbol =3D NSLookupSymbolInImage(dyld_lib, native, > NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | > NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); > if(symbol) { > *proc2Ptr =3D NSAddressOfSymbol(symbol); > } else { > *proc2Ptr=3DNULL; > } > Tcl_DStringFree(&newName); > Tcl_DStringFree(&ds); > =A0=A0 > return TCL_OK; > } > > ------------------------ end paste into=20 > tclLoadDyld.c ------------------------- > > > -- > ** Daniel A. Steffen ** "And now to something completely > ** Department of Mathematics ** different" Monty Python > ** Macquarie University ** <mailto:st...@ma...> > ** NSW 2109 Australia ** = <http://www.maths.mq.edu.au/~steffen/> > -- Jim Ingham ji...@ap... Developer Tools - gdb Apple Computer |