summaryrefslogtreecommitdiffstats
path: root/unix/tclLoadDyld.c
diff options
context:
space:
mode:
authordas <das>2001-11-23 01:39:42 (GMT)
committerdas <das>2001-11-23 01:39:42 (GMT)
commit54c5936b6021be7a0d149ce218e7bba30faf984e (patch)
tree979fa41979efaf22cb7e936f182fc2a2d165e934 /unix/tclLoadDyld.c
parent5bf5a16c3a6e83b4297123ae905297ac723f7f81 (diff)
downloadtcl-54c5936b6021be7a0d149ce218e7bba30faf984e.zip
tcl-54c5936b6021be7a0d149ce218e7bba30faf984e.tar.gz
tcl-54c5936b6021be7a0d149ce218e7bba30faf984e.tar.bz2
*unix/Makefile.in:
*unix/configure.in: *unix/install-sh: *unix/mkLinks: *unix/mkLinks.tcl: *unix/tclLoadDyld.c: *unix/tclMtherr.c: Mac OSX support: build system, dynamic code loading and support for case-insensitive filesystems in mkLinks (patch #435258)
Diffstat (limited to 'unix/tclLoadDyld.c')
-rw-r--r--unix/tclLoadDyld.c97
1 files changed, 44 insertions, 53 deletions
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c
index 3fde4b9..e62a8b2 100644
--- a/unix/tclLoadDyld.c
+++ b/unix/tclLoadDyld.c
@@ -2,17 +2,16 @@
* tclLoadDyld.c --
*
* This procedure provides a version of the TclLoadFile that
- * works with NeXT/Apple's dyld dynamic loading. This file
+ * works with Apple's dyld dynamic loading. This file
* provided by Wilfredo Sanchez (wsanchez@apple.com).
- * The works on Mac OS X and Mac OS X Server.
- * It should work with OpenStep, but it's not been tried.
+ * This works on Mac OS X.
*
* Copyright (c) 1995 Apple Computer, Inc.
*
* 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.5 2001/09/28 01:21:53 dgp Exp $
+ * RCS: @(#) $Id: tclLoadDyld.c,v 1.6 2001/11/23 01:40:10 das Exp $
*/
#include "tclInt.h"
@@ -58,63 +57,55 @@ TclpLoadFile(interp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr,
* function which should be used for
* this file. */
{
- NSObjectFileImageReturnCode err;
- NSObjectFileImage image;
- NSModule module;
- NSSymbol symbol;
- char *name;
+ NSSymbol symbol;
+ enum DYLD_BOOL dyld_return;
+ Tcl_DString newName, ds;
+ char *native;
- char *fileName = Tcl_GetString(pathPtr);
- err = NSCreateObjectFileImageFromFile(fileName, &image);
- if (err != NSObjectFileImageSuccess) {
- switch (err) {
- case NSObjectFileImageFailure:
- Tcl_SetResult(interp, "dyld: general failure", TCL_STATIC);
- break;
- case NSObjectFileImageInappropriateFile:
- Tcl_SetResult(interp, "dyld: inappropriate Mach-O file",
- TCL_STATIC);
- break;
- case NSObjectFileImageArch:
- Tcl_SetResult(interp,
- "dyld: inappropriate Mach-O architecture", TCL_STATIC);
- break;
- case NSObjectFileImageFormat:
- Tcl_SetResult(interp, "dyld: invalid Mach-O file format",
- TCL_STATIC);
- break;
- case NSObjectFileImageAccess:
- Tcl_SetResult(interp, "dyld: permission denied", TCL_STATIC);
- break;
- default:
- Tcl_SetResult(interp, "dyld: unknown failure", TCL_STATIC);
- break;
- }
+ native = Tcl_FSGetNativePath(pathPtr);
+ dyld_return = NSAddLibrary(native);
+
+ if (dyld_return != TRUE) {
+ Tcl_AppendResult(interp, "dyld: couldn't add library \"",
+ Tcl_GetString(pathPtr),
+ "\": ", Tcl_PosixError(interp), (char *) NULL);
return TCL_ERROR;
}
- module = NSLinkModule(image, fileName, TRUE);
+ *unloadProcPtr = &TclpUnloadFile;
- if (module == NULL) {
- Tcl_SetResult(interp, "dyld: falied to link module", TCL_STATIC);
- return TCL_ERROR;
- }
+ /*
+ * dyld adds an underscore to the beginning of symbol names.
+ */
- name = (char*)malloc(sizeof(char)*(strlen(sym1)+2));
- sprintf(name, "_%s", sym1);
- symbol = NSLookupAndBindSymbol(name);
- free(name);
- *proc1Ptr = NSAddressOfSymbol(symbol);
+ native = Tcl_UtfToExternalDString(NULL, sym1, -1, &ds);
+ Tcl_DStringInit(&newName);
+ Tcl_DStringAppend(&newName, "_", 1);
+ native = Tcl_DStringAppend(&newName, native, -1);
+ if(NSIsSymbolNameDefined(native)) {
+ symbol = NSLookupAndBindSymbol(native);
+ *proc1Ptr = NSAddressOfSymbol(symbol);
+ *clientDataPtr = NSModuleForSymbol(symbol);
+ } else {
+ *proc1Ptr=NULL;
+ *clientDataPtr=NULL;
+ }
+ Tcl_DStringFree(&newName);
+ Tcl_DStringFree(&ds);
- name = (char*)malloc(sizeof(char)*(strlen(sym2)+2));
- sprintf(name, "_%s", sym2);
- symbol = NSLookupAndBindSymbol(name);
- free(name);
- *proc2Ptr = NSAddressOfSymbol(symbol);
+ native = Tcl_UtfToExternalDString(NULL, sym2, -1, &ds);
+ Tcl_DStringInit(&newName);
+ Tcl_DStringAppend(&newName, "_", 1);
+ native = Tcl_DStringAppend(&newName, native, -1);
+ if(NSIsSymbolNameDefined(native)) {
+ symbol = NSLookupAndBindSymbol(native);
+ *proc2Ptr = NSAddressOfSymbol(symbol);
+ } else {
+ *proc2Ptr=NULL;
+ }
+ Tcl_DStringFree(&newName);
+ Tcl_DStringFree(&ds);
- *clientDataPtr = module;
- *unloadProcPtr = &TclpUnloadFile;
-
return TCL_OK;
}