Author: Jan Nijtmans <[email protected]> State: Draft Type: Project Tcl-Version: 9.0 Tcl-Branch: bug-ea39ab591e
The "load" command, and its supporting C API is quite misleading. For example
the 3th argument of "load" is case-insensitive: It is converted to Titlecase,
_Init is attached to it, then the C-function in the
shared library with this name is called. No package handling is done,
still the 3th argument of "load" is called "packageName".
See also bug report ea39ab591e: Tcl_StaticPackage allows case sensitvity; [load] prevents it which describes in better wordings what's wrong.
This TIP proposes to get rid of the case-insensitivity of the "load"
command, except in the guessing of the
prefix from the filename.
In order to distinguish libraries from packages (libraries are
available globally while package are per interpreter), a number
of renamings will be done.
In Tcl 8.7, rename
Tcl_LibraryUnloadProc. Also add the following defines in
#define Tcl_PackageInitProc Tcl_LibraryInitProc #define Tcl_PackageUnloadProc Tcl_LibraryUnloadProc #define Tcl_StaticPackage Tcl_StaticLibraryThis way, the new names of the functions already can be used in Tcl 8.7, but the functionality stays the same. Hopefully those new names make it clear that those functions take part in the
loadmechanism, not the
In Tcl 9.0, if the "load" command's 3th parameter is missing, this parameter is guessed from the filename. Starting with Tcl 9.0, a Unicode TitleCase will be used, not a ASCII one. The full algorith becomes:
- If the filename starts with
lib, strip it.
- If the filename then starts with
tcl9, strip it.
- Take all (Unicode) alphabetical characters following that, convert to (Unicode) titlecase.
- The result will be the guessed
This is almost the same as the Tcl 8.x algorithm, the
enhancement is that all Unicode characters can be used
in the filename. For example, a shared library
will result in a prefix
Π, so the initialization function
Π_Init() will be called.
When using Tcl 9.0, the following existing library names will be changed:
This makes it possible to install Tk 8.7 in the same directory when compiled for Tcl 8.7 resp 9.0. Since the filename is different, the pkgIndex.tcl file can load the correct Tk library no matter Tcl 8.7 or 9.0 is doing the call. (Of course, Tk 8.7 needs to be compiled twice then, once with Tcl 8.7 headers, once with Tcl 9.0 headers)
Implementation is in Tcl (and Tk) branch bug-ea39ab591e.
This is not compatible with Tcl 8.x, but there is a simple way to make code compatible with both Tcl 8.x and 9.0: Just replace all "load" invocations:
load <fileName> <prefix>
load <fileName> [string totitle <prefix>].
Of course, if the 3th argument of
load already is in Titlecase
(it usually is) nothing needs to be done.
This document has been placed in the public domain.