This is not necessarily the current version of this TIP.
|Version:||$Revision: 1.9 $|
|Author:||Kevin Kenny <kevin dot b dot kenny at gmail dot com>|
|Created:||Thursday, 01 October 2009|
This TIP proposes to promote the internal calls, TclLoadFile and TclpFindSymbol to the external API, making them available to C extensions. In addition, it proposes to introduce a Tcl_FSUnloadFile to the VFS layer, removing the weird duplicate client data from TclLoadFile and wrapping all necessary data into the Tcl_LoadHandle
In developing TDBC TIP #308, the author of this TIP was advised to look at the way that the 'oratcl' extension contrives to build on a system where Oracle is not installed as a model for TDBC extensions. Examination of the code revealed that it operates essentially by constructing at run time a Stubs table for the routines in the Oracle client library. There is a maze of #if directives selecting whether this process is accomplished by the system calls that manage Unix .so files (dlopen and friends), Windows .DLL files (LoadLibrary and related calls), HP-UX .shl files (shl_load, etc.), and so on.
Tcl already has functionality so that a caller can abstract away all this complexity. It provides the capability in the TclLoadFile call, but this call is MODULE_SCOPE and not exported even in the internal Stubs table. For this reason, it is entirely unavailable to TEA-compliant extensions.
If this call were available, it would be feasible, in the 8.6 time frame, to bundle all the database-specific TDBC drivers with the core TDBC distribution, since things could be set up so that they will build anywhere, even in the absence of the databases where they connect.
However, this call was never fully rationalized in the VFS world. Its strange API (with both a Tcl_LoadHandle and a ClientData, and a function pointer for unloading the library) is, as several reviewers pointed out, not somehting that we want to make available to general callers. Hence, a few more routines need rework.
The TclLoadFile call shall be renamed Tcl_LoadFile and exported in the external Stubs. Its call signature shall be changed to:
EXTERN int Tcl_LoadFile( Tcl_Interp *interp, Tcl_Obj *pathPtr, const char *symbols, int flags, void *procPtrs, Tcl_LoadHandle *handlePtr);
In this call, interp designates an interpreter for error reporting. pathPtr is an object containing the path of the library to be loaded. If pathPtr is a single name, the library search path of the current environment will be used to resolve it. The symbols array contains a NULL-terminated set of character strings that are the names of the imported symbols.
The return value of Tcl_LoadFile is a standard Tcl result code. If the result is TCL_ERROR, the interpreter result will contain an appropriate error message.
On return, Tcl_LoadFile fills in the block of memory commencing at the address given by procPtrs with the addresses that correspond to the names in symbols. If a name cannot be resolved in the given library, an error will be returned and all entries in procPtrs will be invalid. On a successful return, the loadHandle pointer will be a handle suitable for passing to Tcl_FindSymbol for resolving additional symbols in the library, or to Tcl_FSUnloadFile to unload the library.
The TclpFindSymbol call shall be renamed Tcl_FindSymbol and exported in the external Stubs. Its call signature shall be:
EXTERN void* Tcl_FindSymbol( Tcl_Interp *interp, Tcl_LoadHandle *loadHandle, const char *symbol);
This call searches for the given symbol in the already-loaded library identified by loadHandle. If the symbol is found, a pointer to its memory address is returned. Otherwise, NULL is returned, and an error message is left in interp (if interp is not NULL).
A new call, Tcl_FSUnloadFile shall be introduced and exported in the external Stubs.Its call signature shall be:
EXTERN int Tcl_FSUnloadFile( Tcl_Interp *interp, Tcl_LoadHandle *loadHandle);
This call unloads the library identified by loadHandle. It differs from the [unload] command in that no 'unload' procedure is called; the library is simply unloaded without first being given a chance to clean itself up. (This function is a lower-level interface used by [unload] as part of doing its work.) The return value is either TCL_OK or TCL_ERROR; when TCL_ERROR is returned, an appropriate message is left in the result of interp (if interp is not NULL).
The Tcl_LoadHandle object shall be represented internally by a structure, declared i