.
D 2014-09-12T18:35:44.939
L Encoding\sLoading
P f03b40cdd3e63f29d7ae94b64206c52aab1a87b7
U dgp
W 3375
<h1>Source Files</h1>
* portions of [/finfo?name=generic/tclEncoding.c|tclEncoding.c]
<h1>Public Interface</h1>
* Tcl_GetEncodingSearchPath
* Tcl_SetEncodingSearchPath
* Tcl_GetDefaultEncodingDir
* Tcl_SetDefaultEncodingDir
<h1>Private Interface</h1>
* TclGetLibraryPath
<h1>Directly Depends On Public Interface</h1>
* [Encoding System]
* [list Object Type]
* [Tcl_Obj System]
* [Pathname Management]
* [File System Access]
* [Allocation]
* [dict Object Type]
* [Channel System]
<h1>Directly Depends On Private Interface of</h1>
* [Global Values]
* [Initialization, Library, Autoloader]
* [Pathname Management]
<h1>Discussion</h1>
This module includes the code that goes out and searches the <b>encoding dirs</b>
search path to find <i>*.enc</i> files that holds data to define additional encodings.
The circularity problem is that both querying a file system and reading data in from
a file potentially make use of encodings, and might run aground if they need an
encoding that's not already available.
The way out of this dilemma comes in several parts, some already in place. First,
we make sure that handling of the <b>utf-8</b> encoding is built-in to Tcl, with
no need to bring data in from a file first. That's the foundation of the bootstrap.
Then we define that all <i>*.enc</i> files must be stored in the <b>utf-8</b>
encoding. This relieves all concern about the channel read operation.
We still have to query the filesystem. Here is where Tcl's virtual filesystem architecture
holds the key. Each Tcl_Filesystem can define a <b>Tcl_FSCreateInternalRepProc</b>
to generate the data format it needs (and may cache) to interact with whatever backing system
it is using to implement the filesystem. In the current implementation, the unix native
filesystem uses the routine <b>TclNativeCreateNativeRep</b> to perform this function,
and it in turn calls <b>Tcl_UtfToExternalDString</b> to apply the system encoding to
get something suitable for passing to <b>TclOSOpen</b>. That closes the cycle.
(Note that Windows doesn't put in place any similar cycle. It makes no call back into
the [Encoding System]. Maybe once it did, but no more.)
So long as Tcl believes the system encoding is <b>utf-8</b> there's no problem, and
that's a common environment on unix systems. But we are vulnerable to trouble with
other values for the system encoding. The solution requires breaking out of this mistaken
concept of a system encoding. There's no such thing. At this point, we do not care what
encoding <i>the system</i> uses, whatever that means. We specifically want to know
how to convert Tcl path values into values this native filesystem can understand. That's
a property of each Tcl_Filesystem, not <i>the system</i> in any more general sense.
So the proper placement of the burden is in each Tcl_Filesystem, and the
<b>Tcl_FSCreateInternalRepProc</b>. It must supply for itself any encoding knowledge.
If it wishes to use the [Encoding System] facilities, that's fine, but for any non-foundational
encoding, it will have to be able to supply the encoding(s) it needs with <b>Tcl_CreateEncoding</b>
calls.
<b>TclGetLibraryPath</b> appears to exist only for internal stubs compat.
Otherwise it could be a file static routine.
Z d3d4e74639b14c3f6eba30fcbf0ff653