os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclLoadNext.c
Update contrib.
4 * This procedure provides a version of the TclLoadFile that
5 * works with NeXTs rld_* dynamic loading. This file provided
6 * by Pedja Bogdanovich.
8 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * RCS: @(#) $Id: tclLoadNext.c,v 1.11 2002/10/10 12:25:53 vincentdarley Exp $
17 #include <mach-o/rld.h>
18 #include <streams/streams.h>
21 *----------------------------------------------------------------------
25 * Dynamically loads a binary code file into memory and returns
26 * a handle to the new code.
29 * A standard Tcl completion code. If an error occurs, an error
30 * message is left in the interp's result.
33 * New code suddenly appears in memory.
35 *----------------------------------------------------------------------
39 TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
40 Tcl_Interp *interp; /* Used for error reporting. */
41 Tcl_Obj *pathPtr; /* Name of the file containing the desired
43 Tcl_LoadHandle *loadHandle; /* Filled with token for dynamically loaded
44 * file which will be passed back to
45 * (*unloadProcPtr)() to unload the file. */
46 Tcl_FSUnloadFileProc **unloadProcPtr;
47 /* Filled with address of Tcl_FSUnloadFileProc
48 * function which should be used for
51 struct mach_header *header;
57 NXStream *errorStream = NXOpenMemory(0,0,NX_READWRITE);
59 fileName = Tcl_GetString(pathPtr);
62 * First try the full path the user gave us. This is particularly
63 * important if the cwd is inside a vfs, and we are trying to load
64 * using a relative path.
66 native = Tcl_FSGetNativePath(pathPtr);
67 files = {native,NULL};
69 result = rld_load(errorStream, &header, files, NULL);
73 * Let the OS loader examine the binary search path for
74 * whatever string the user gave us which hopefully refers
75 * to a file on the binary path
78 native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
79 files = {native,NULL};
80 result = rld_load(errorStream, &header, files, NULL);
87 NXGetMemoryBuffer(errorStream,&data,&len,&maxlen);
88 Tcl_AppendResult(interp, "couldn't load file \"",
89 fileName, "\": ", data, NULL);
90 NXCloseMemory(errorStream, NX_FREEBUFFER);
93 NXCloseMemory(errorStream, NX_FREEBUFFER);
95 *loadHandle = (Tcl_LoadHandle)1; /* A dummy non-NULL value */
96 *unloadProcPtr = &TclpUnloadFile;
102 *----------------------------------------------------------------------
106 * Looks up a symbol, by name, through a handle associated with
107 * a previously loaded piece of code (shared library).
110 * Returns a pointer to the function associated with 'symbol' if
111 * it is found. Otherwise returns NULL and may leave an error
112 * message in the interp's result.
114 *----------------------------------------------------------------------
117 TclpFindSymbol(interp, loadHandle, symbol)
119 Tcl_LoadHandle loadHandle;
122 Tcl_PackageInitProc *proc=NULL;
124 char sym[strlen(symbol)+2];
125 sym[0]='_'; sym[1]=0; strcat(sym,symbol);
126 rld_lookup(NULL,sym,(unsigned long *)&proc);
132 *----------------------------------------------------------------------
136 * Unloads a dynamically loaded binary code file from memory.
137 * Code pointers in the formerly loaded file are no longer valid
138 * after calling this function.
144 * Does nothing. Can anything be done?
146 *----------------------------------------------------------------------
150 TclpUnloadFile(loadHandle)
151 Tcl_LoadHandle loadHandle; /* loadHandle returned by a previous call
152 * to TclpDlopen(). The loadHandle is
153 * a token that represents the loaded
159 *----------------------------------------------------------------------
161 * TclGuessPackageName --
163 * If the "load" command is invoked without providing a package
164 * name, this procedure is invoked to try to figure it out.
167 * Always returns 0 to indicate that we couldn't figure out a
168 * package name; generic code will then try to guess the package
169 * from the file name. A return value of 1 would have meant that
170 * we figured out the package name and put it in bufPtr.
175 *----------------------------------------------------------------------
179 TclGuessPackageName(fileName, bufPtr)
180 CONST char *fileName; /* Name of file containing package (already
181 * translated to local form if needed). */
182 Tcl_DString *bufPtr; /* Initialized empty dstring. Append
183 * package name to this if possible. */