os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclLoadDld.c
Update contrib.
4 * This procedure provides a version of the TclLoadFile that
5 * works with the "dld_link" and "dld_get_func" library procedures
6 * for dynamic loading. It has been tested on Linux 1.1.95 and
7 * dld-3.2.7. This file probably isn't needed anymore, since it
8 * makes more sense to use "dl_open" etc.
10 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
12 * See the file "license.terms" for information on usage and redistribution
13 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 * RCS: @(#) $Id: tclLoadDld.c,v 1.12 2002/10/10 12:25:53 vincentdarley Exp $
22 * In some systems, like SunOS 4.1.3, the RTLD_NOW flag isn't defined
23 * and this argument to dlopen must always be 1.
31 *----------------------------------------------------------------------
35 * Dynamically loads a binary code file into memory and returns
36 * a handle to the new code.
39 * A standard Tcl completion code. If an error occurs, an error
40 * message is left in the interp's result.
43 * New code suddenly appears in memory.
45 *----------------------------------------------------------------------
49 TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
50 Tcl_Interp *interp; /* Used for error reporting. */
51 Tcl_Obj *pathPtr; /* Name of the file containing the desired
53 Tcl_LoadHandle *loadHandle; /* Filled with token for dynamically loaded
54 * file which will be passed back to
55 * (*unloadProcPtr)() to unload the file. */
56 Tcl_FSUnloadFileProc **unloadProcPtr;
57 /* Filled with address of Tcl_FSUnloadFileProc
58 * function which should be used for
61 static int firstTime = 1;
67 * The dld package needs to know the pathname to the tcl binary.
68 * If that's not known, return an error.
72 if (tclExecutableName == NULL) {
74 "don't know name of application binary file, so can't initialize dynamic loader",
78 returnCode = dld_init(tclExecutableName);
79 if (returnCode != 0) {
80 Tcl_AppendResult(interp,
81 "initialization failed for dynamic loader: ",
82 dld_strerror(returnCode), (char *) NULL);
88 fileName = Tcl_GetString(pathPtr);
91 * First try the full path the user gave us. This is particularly
92 * important if the cwd is inside a vfs, and we are trying to load
93 * using a relative path.
95 native = Tcl_FSGetNativePath(pathPtr);
96 returnCode = dld_link(native);
98 if (returnCode != 0) {
100 native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
101 returnCode = dld_link(native);
102 Tcl_DStringFree(&ds);
105 if (returnCode != 0) {
106 Tcl_AppendResult(interp, "couldn't load file \"",
108 dld_strerror(returnCode), (char *) NULL);
111 *loadHandle = (Tcl_LoadHandle) strcpy(
112 (char *) ckalloc((unsigned) (strlen(fileName) + 1)), fileName);
113 *unloadProcPtr = &TclpUnloadFile;
118 *----------------------------------------------------------------------
122 * Looks up a symbol, by name, through a handle associated with
123 * a previously loaded piece of code (shared library).
126 * Returns a pointer to the function associated with 'symbol' if
127 * it is found. Otherwise returns NULL and may leave an error
128 * message in the interp's result.
130 *----------------------------------------------------------------------
133 TclpFindSymbol(interp, loadHandle, symbol)
135 Tcl_LoadHandle loadHandle;
138 return (Tcl_PackageInitProc *) dld_get_func(symbol);
142 *----------------------------------------------------------------------
146 * Unloads a dynamically loaded binary code file from memory.
147 * Code pointers in the formerly loaded file are no longer valid
148 * after calling this function.
154 * Code removed from memory.
156 *----------------------------------------------------------------------
160 TclpUnloadFile(loadHandle)
161 Tcl_LoadHandle loadHandle; /* loadHandle returned by a previous call
162 * to TclpDlopen(). The loadHandle is
163 * a token that represents the loaded
168 handle = (char *) loadHandle;
169 dld_unlink_by_file(handle, 0);
174 *----------------------------------------------------------------------
176 * TclGuessPackageName --
178 * If the "load" command is invoked without providing a package
179 * name, this procedure is invoked to try to figure it out.
182 * Always returns 0 to indicate that we couldn't figure out a
183 * package name; generic code will then try to guess the package
184 * from the file name. A return value of 1 would have meant that
185 * we figured out the package name and put it in bufPtr.
190 *----------------------------------------------------------------------
194 TclGuessPackageName(fileName, bufPtr)
195 CONST char *fileName; /* Name of file containing package (already
196 * translated to local form if needed). */
197 Tcl_DString *bufPtr; /* Initialized empty dstring. Append
198 * package name to this if possible. */