TIP #239: Enhance the 'load' Command
From: Jeff Hobbs (jeffh_at_activestate.com)
Date: 01/28/05
- Next message: Cameron Laird: "Re: Is there an easy way to check if a variable is a valid number in TCL?"
- Previous message: David N. Welton: "Re: Algebraic expression parser"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Jan 2005 17:28:28 +0000 (UTC)
TIP #239: ENHANCE THE 'LOAD' COMMAND
======================================
Version: $Revision: 1.1 $
Author: Jeff Hobbs <jeffh_at_activestate.com>
State: Draft
Type: Project
Tcl-Version: 8.5
Vote: Pending
Created: Wednesday, 26 January 2005
URL: http://purl.org/tcl/tip/239.html
WebEdit: http://purl.org/tcl/tip/edit/239
Post-History:
-------------------------------------------------------------------------
ABSTRACT
==========
This TIP proposes enhancing the Tcl *load* command with the ability to
load arbitrary libraries and functions.
RATIONALE
===========
The current Tcl *load* command limits itself operating within the
context of loading Tcl extension libraries and nothing else, even
though all the code is there for general library loading. With the
introduction of the VFS and more extensions having prerequisite library
dependencies, the ability to load arbitrary libraries would ease
development of StarKits with these extensions. It will also provide a
general mechanism to assist other developers get around the difficult
process of cross-platform library loading.
SPECIFICATION
===============
Current specification:
*load* /fileName/ ?/packageName/ ?/interp/??
Recommended specification:
*load* ?*-function* /funcName/? ?*-interp* /interp/? ?*-call*
/initName/? ?*--*? fileName
The *-interp* option takes the place of the optional final /interp/
argument.
The *-call* option replaces the /packageName/ argument. The user
specifies just the partial function name without the "_Init" or
"_SafeInit", as before. If the user specifies {}, no init call will be
made.
The *-function* option takes a C function name to find the symbol of
(via dlsym(), GetProcAddress(), or related function). If *-function* is
specified, *-call* and *-interp* are ignored and the return value is
the pointer location to the function, or 0 if it is not found. When
this is used, the library is not closed upon success, it remains open
until a call to *unload* is made.
An error is thrown if the library cannot be loaded.
I will also recommend obsoleting the existing *unload* call to use this
new functional spec style. Current spec, to be unsupported (it's new in
8.5):
*unload* /fileName/ ?/packageName/ ?/interp/??
New specification:
*unload* ?*-interp* /interp/? ?*-call* /uninitName/?
?*-nocomplain*? ?*-keeplibrary*? ?*--*? /fileName/
I think that C functions should be made available as well for
cross-platform access to the load functionality, but that is not
specified in this TIP. This would need to account for users that may
configure Tcl with --disable-load (does anybody need that anymore?).
EXAMPLES
==========
For a package in a starkit, tls example with shared OpenSSL library
shipped in package:
# $dir set by package mechanism
if {[package provide starkit] ne ""} {
load -call {} $dir/libopenssl.so
}
load $dir/libtls1.5.so
Another example would be Oratcl 4.3's use of dynamic Oracle library
callouts, which it has to do by hand due to the lack of this
functionality in the core.
REFERENCE IMPLEMENTATION
==========================
[To be uploaded to SourceForge and URL added to this TIP.]
COPYRIGHT
===========
This document has been placed in the public domain.
-------------------------------------------------------------------------
TIP AutoGenerator - written by Donal K. Fellows
[[Send Tcl/Tk announcements to tcl-announce@mitchell.org
Announcements archived at http://groups.yahoo.com/group/tcl_announce/
Send administrivia to tcl-announce-request@mitchell.org
Tcl/Tk at http://tcl.tk/ ]]
- Next message: Cameron Laird: "Re: Is there an easy way to check if a variable is a valid number in TCL?"
- Previous message: David N. Welton: "Re: Algebraic expression parser"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|