os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclLoadShl.c
Update contrib.
4 * This procedure provides a version of the TclLoadFile that works
5 * with the "shl_load" and "shl_findsym" library procedures for
6 * dynamic loading (e.g. for HP machines).
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: tclLoadShl.c,v 1.13.2.1 2005/10/05 04:23:56 hobbs Exp $
19 * On some HP machines, dl.h defines EXTERN; remove that definition.
29 *----------------------------------------------------------------------
33 * Dynamically loads a binary code file into memory and returns
34 * a handle to the new code.
37 * A standard Tcl completion code. If an error occurs, an error
38 * message is left in the interp's result.
41 * New code suddenly appears in memory.
43 *----------------------------------------------------------------------
47 TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
48 Tcl_Interp *interp; /* Used for error reporting. */
49 Tcl_Obj *pathPtr; /* Name of the file containing the desired
51 Tcl_LoadHandle *loadHandle; /* Filled with token for dynamically loaded
52 * file which will be passed back to
53 * (*unloadProcPtr)() to unload the file. */
54 Tcl_FSUnloadFileProc **unloadProcPtr;
55 /* Filled with address of Tcl_FSUnloadFileProc
56 * function which should be used for
61 char *fileName = Tcl_GetString(pathPtr);
64 * The flags below used to be BIND_IMMEDIATE; they were changed at
65 * the suggestion of Wolfgang Kechel (wolfgang@prs.de): "This
66 * enables verbosity for missing symbols when loading a shared lib
67 * and allows to load libtk8.0.sl into tclsh8.0 without problems.
68 * In general, this delays resolving symbols until they are actually
69 * needed. Shared libs do no longer need all libraries linked in
70 * when they are build."
75 * First try the full path the user gave us. This is particularly
76 * important if the cwd is inside a vfs, and we are trying to load
77 * using a relative path.
79 native = Tcl_FSGetNativePath(pathPtr);
80 handle = shl_load(native, BIND_DEFERRED|BIND_VERBOSE, 0L);
84 * Let the OS loader examine the binary search path for
85 * whatever string the user gave us which hopefully refers
86 * to a file on the binary path
89 native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
90 handle = shl_load(native,
91 BIND_DEFERRED|BIND_VERBOSE|DYNAMIC_PATH, 0L);
96 Tcl_AppendResult(interp, "couldn't load file \"", fileName,
97 "\": ", Tcl_PosixError(interp), (char *) NULL);
100 *loadHandle = (Tcl_LoadHandle) handle;
101 *unloadProcPtr = &TclpUnloadFile;
106 *----------------------------------------------------------------------
110 * Looks up a symbol, by name, through a handle associated with
111 * a previously loaded piece of code (shared library).
114 * Returns a pointer to the function associated with 'symbol' if
115 * it is found. Otherwise returns NULL and may leave an error
116 * message in the interp's result.
118 *----------------------------------------------------------------------
121 TclpFindSymbol(interp, loadHandle, symbol)
123 Tcl_LoadHandle loadHandle;
127 Tcl_PackageInitProc *proc=NULL;
128 shl_t handle = (shl_t)loadHandle;
130 * Some versions of the HP system software still use "_" at the
131 * beginning of exported symbols while others don't; try both
132 * forms of each name.
135 if (shl_findsym(&handle, symbol, (short) TYPE_PROCEDURE, (void *) &proc)
137 Tcl_DStringInit(&newName);
138 Tcl_DStringAppend(&newName, "_", 1);
139 Tcl_DStringAppend(&newName, symbol, -1);
140 if (shl_findsym(&handle, Tcl_DStringValue(&newName),
141 (short) TYPE_PROCEDURE, (void *) &proc) != 0) {
144 Tcl_DStringFree(&newName);
150 *----------------------------------------------------------------------
154 * Unloads a dynamically loaded binary code file from memory.
155 * Code pointers in the formerly loaded file are no longer valid
156 * after calling this function.
162 * Code removed from memory.
164 *----------------------------------------------------------------------
168 TclpUnloadFile(loadHandle)
169 Tcl_LoadHandle loadHandle; /* loadHandle returned by a previous call
170 * to TclpDlopen(). The loadHandle is
171 * a token that represents the loaded
176 handle = (shl_t) loadHandle;
181 *----------------------------------------------------------------------
183 * TclGuessPackageName --
185 * If the "load" command is invoked without providing a package
186 * name, this procedure is invoked to try to figure it out.
189 * Always returns 0 to indicate that we couldn't figure out a
190 * package name; generic code will then try to guess the package
191 * from the file name. A return value of 1 would have meant that
192 * we figured out the package name and put it in bufPtr.
197 *----------------------------------------------------------------------
201 TclGuessPackageName(fileName, bufPtr)
202 CONST char *fileName; /* Name of file containing package (already
203 * translated to local form if needed). */
204 Tcl_DString *bufPtr; /* Initialized empty dstring. Append
205 * package name to this if possible. */