Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl_CreateInterp() needs initialized encoding search path

Closed / Fixed9b2e63636199b969e480a2a5fdba09588b0f0170Created 13 years agoUpdated 13 years ago
Descriptionwiki2013-06-26 07:41:10
Starting with Tcl 8.5 (Actually, [tip.tcl.tk/59|TIP #59]) Tcl_CreateInterp() needs the encodings to be initialized. This makes it impossible to implement a VFS using scripts. Thinking about it, it's a design error in TIP #59, but that's easy to conclude afterwards. Fixing this would prevent the need for a double TclInitSubsystems() call in tclMain.c: one in Tcl_FindExecutable(), one on Tcl_CreateInterp().
Referenced by3
jan.nijtmanswiki2013-06-26 07:45:05

Proposed solution in [06020a12ac]

jan.nijtmanswiki2013-06-27 09:11:52

Fixed in core-8-5-branch [341f682e08] and trunk [6189063c4d], with more comments and using a Byte Array in stead of a String to store unencoded configuration values (Good suggestion by Andreas Kupries, thanks!)

jan.nijtmans Closed ticket [9b2e636361]. [History diff]2013-06-27 09:16:04
dgpplain2013-07-05 16:00:13
Related issue is [983509].

Reviewing the patch now.  Wondering whether
ProcessGlobalValue is a useful tool here.
dgpplain2013-07-05 16:53:26
Yes this change is a fix for [983509] (why isn't
this a link?).

PGV is not helpful here.  These values are stored
per-interp, so a process-global thing isn't useful.

So this patch is a good one.

I don't think the description is as helpful as
it ought to be, since the notion of "initialized
encodings" covers multiple stages.

The first stage is the call to TclInitEncodingSubsystem(),
which is called by TclInitSubsystems() which in turn is
called early by Tcl_CreateInterp(), so that level of 
initialization is always complete and not an issue.  This
means the core machinery is set up and the set of built-in
encodings (identity, utf-8, unicode, iso8859-1) is ready
to go.

The second stage is the call to TclpSetInitialEncodings()
which this patch delays until after Tcl_CreateInterp() is
complete.  The only thing functionally that call does is 
to (try to) set the value of [encoding system] to match
the value it detects the environment expects it to have.
Since the workings of Tcl_RegisterConfig() don't make use
of the system encoding, the direct effect of that routine
doesn't really matter here.

The third stage is getting the [encoding dirs] search path
set up to locate where the *.enc files are actually stored.
This isn't done explicitly by Tcl initialization.  Instead
either the first [encoding dirs] command in init.tcl or
the first attempt to use an encoding that is not built-in
will cause the default search path to be established by the
routine InitializeEncodingSearchPath().  In some embedding
scenarios -- notably kit things that store *.enc in a 
script-powered VFS -- this default path won't be a successful
one, and a later [encoding dirs $path] will need to establish
a fully working encoding system.

It's the third stage that's really the issue here, so I revised
the Title to make that more clear.
dgpplain2013-07-05 17:14:26
All that said, I think Twylite is correct
and we'd be better off doing what we can
to establish that the value of CFG_ENCODING
when we build Tcl is the name of one of
the built-in encodings.  That's already true
on many platforms.  That's a fairly straightforward
first step toward the more radical redesign where
we deny the use of CFG_ENCODING completely, and
just demand conformance to a particular encoding
in the built-in set, likely utf-8.
Log in (anonymous is fine) to add a comment.