Author: Jan Nijtmans <[email protected]> State: Final Type: Project Vote: Done Tcl-Version: 9.0 Tcl-Branch: bug-ea39ab591e Vote-Summary: Accepted 7/0/1 Votes-For: AK, DP, JN, KW, KK, MC, SL Votes-Against: none Votes-Present: FV
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 algorithm becomes:
- If the filename starts with
lib, strip it.
- If the filename then starts with
tcl9, strip it.
- Take the characters following that, up to (but not including) the first character which is a (Unicode) digit or not a (Unicode) word.
- Convert those characters to (Unicode) Titlecase.
- The result will be the guessed
This is almost the same as the Tcl 8.x algorithm, the enhancement is that
the characters used in the filename are no longer limited to ASCII. For
example, a shared library
libπ.so will result in a prefix
Π, so the
Π_Init() will be called when loading this file.
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> ?<interp>?
load <fileName> [string totitle <prefix>] ?<interp>?
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.