TIP #239: Enhance the 'load' Command

From: Jeff Hobbs (jeffh_at_activestate.com)
Date: 01/28/05


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/ ]]



Relevant Pages

  • Re: finding tk version in Matrix 10.6
    ... But in a normal Tcl shell you would use 'package require Tk' to load ... If you simply want to use load and its the same command as in a normal ... can't invoke "winfo" command: application has been destroyed ...
    (comp.lang.tcl)
  • Re: loading a tcl file
    ... > I've been dabbling in tcl for a while, but I'm still *very* new to it. ... > which I can load up and run using the graphical interface to load tcl ... > if there was a quick way to load the file from the tkconsole command ...
    (comp.lang.tcl)
  • loading a tcl file
    ... I've been dabbling in tcl for a while, but I'm still *very* new to it. ... which I can load up and run using the graphical interface to load tcl ... if there was a quick way to load the file from the tkconsole command ...
    (comp.lang.tcl)
  • Re: Dynamic Linking and Loading in an odd way
    ... it must be able to load either or both on demand. ... | yet I want to be able to create new libraries and functions without ... at coding time what that list file name is. ... If you are implementing a dynamic command facility in your ...
    (comp.unix.programmer)
  • Re: I cannot understand this Tcl syntax ...
    ... if this code works, you can be sure it's a command, since the first word on a line in TCL is always a command. ... Did you use the source command to load additional TCL files? ... There are tons of places where a proc or command can hide. ...
    (comp.lang.tcl)