Skip to content
Tcl Source Code View Ticket
Login

View Ticket

setting tcl_libPath doesn't change encoding search path

Closed / Wont Fix463190ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 21 years ago
Descriptionplain2001-09-20 13:36:34
When looking for encodings, Tcl searches along the 
paths returned by TclGetLibraryPath(), which is stored 
in the C variable 'tclLibraryPathStr'.  If an 
application, extension or script wishes to augment the 
native set of encodings with some new encodings, Tcl 
provides no public way to achieve that.  The only 
access to this value is through:

"tclInt.h"
TclGetLibraryPath()
TclSetLibraryPath()

"in scripts"
$tcl_libPath  (but this is effectively read-only, 
since any changes to the variable have no effect on 
the C variable tclLibraryPathStr nor on the encoding 
search path).

A public way of either setting this search path or 
directly adding encodings should be provided in Tcl (I 
would lean towards the former).

I don't have a concrete proposal to make, since I'm 
not very familiar with this code, but it does seem 
like if my script wants to use its own new encoding, 
it ought to be able to do that without having to add 
the encoding to a pre-existing directory on 
$tcl_libPath (to which it might not have write access).
dgpplain2001-09-20 21:29:14
Logged In: YES 
user_id=80530

Moved to "Feature Requests".

I think this functionality could be provided by
a package making appropriate use of Tcl_CreateEncoding(),
right?  If so, I think some prototyping as a package
would be in order to work out the kinks before
modifying Tcl itself.  If the package is good enough,
modifying Tcl itself may not even be necessary.
dgpplain2001-09-20 21:39:01
Logged In: YES 
user_id=80530

OK, after reading Tcl_GetEncoding(3), my prior comment
might have slightly missed the mark.  The request here
is not for access to create a new encoding, which is
already provided by Tcl_CreateEncoding.

Instead it is access to influence the search path of
the dynamic loading of encoding files by 
Tcl_GetEncoding() that is sought.  There is a mechanism
provided for this as well:  lappend additional
directories onto the global list variable ::tcl_libPath.

And that is the point...  ah look he's getting it 
now!  The documented purpose of tcl_libPath is
to influence the search path of Tcl_GetEncoding(),
but it doesn't in fact have that influence.  And
that seems like a bug.  Putting it back...
dgp Ticket [463190ffff]: 3 changes [History diff]2001-09-20 21:40:05
vincentdarleyplain2001-09-20 21:45:24
Logged In: YES 
user_id=32170

Glad you got it!  I was just trying to write a more 
thorough explanation, but now it seems it boils down to

"setting tcl_libPath should adjust the encoding search 
path, but it doesn't"

and either the above should be fixed or some other way of 
setting the encoding search path should be provided.

thanks for taking a second look...
dgpplain2001-09-20 22:29:15
Logged In: YES 
user_id=80530

Just don't confuse my "getting it" with a commitment
to provide an immediate fix!  ;-)
vincentdarleyplain2002-02-05 22:53:23
Logged In: YES 
user_id=32170

Changed bug summary to clarify what the problem is.
dgpplain2002-02-23 06:41:34
Logged In: YES 
user_id=80530

I'm looking at this again, and it appears to me that
changing $tcl_libPath to affect loading of encodings
does not work, and never has worked.

Given that, I'm not inclined to make it work.  I'd
rather create something better.  The logic of having
any connection between the search paths for encoding
files and the value of some variable named tcl_libPath
is completely lost on me.  It feels like the auto_path
mistake all over again.

I'd much rather add a new subcommand to [encoding],
perhaps [encoding searchpath] and make that work
as a means to set/query the set of directories searched
for encoding data files.  That will require a TIP of
course.  Vince, interested in helping me work that out?
nobodyplain2002-02-25 16:35:16
Logged In: NO 

Sounds like a good plan to me.  Either way, it needs to be 
documented that $tcl_libPath is effectively read-only, for 
whatever it may be used.

I could help a bit, especially with testing, and especially 
in 2-3 weeks time...
hobbsplain2002-04-27 10:39:03
Logged In: YES 
user_id=72656

I like the 'encoding path' idea as well (came to the same 
conclusion myself when playing around in there).  The whole 
hard-coded encoding stuff is bad.  Note that the path 
should be absolute - none of this auto-appending 'encoding' 
onto it as is currently done.
vincentdarleyplain2002-04-30 00:29:36
Logged In: YES 
user_id=32170

Some rather odd obserations about tclEncodings.c, which 
should probably be fixed/resolved at the same time:

tclEncodings.c and tclUnixTest.c both set and get the value 
of the C
variable tclDefaultEncodingDir, and tclBasic.c frees up any 
memory
associated with tclDefaultEncodingDir.  There are also 
public APIs
'Tcl_GetDefaultEncodingDir()', 'Tcl_SetDefaultEncodingDir
()'.

However, that C variable is not actually /used/ anywhere in 
Tcl for
anything, and certainly not as a 'default encoding 
directory'!
techentinplain2004-05-05 23:40:04
Logged In: YES 
user_id=43494

Tclkit workaround:

If you're trying to add encodings for tclkit, see 
http://wiki.tcl.tk/RegisterNewEncodingsAtRuntime which 
explains how to copy encoding files int $tcl_library at run time.
dkfplain2004-05-06 16:16:59
Logged In: YES 
user_id=79902

I have yet to see an [encoding path] TIP.  Is there a likely
horizon for this document being submitted?
vincentdarleyplain2004-05-06 19:45:50
Logged In: YES 
user_id=32170

For my part, I have no plans to submit such a TIP -- Vince.
dgp Ticket [463190ffff]: 1 change [History diff]2004-05-06 23:14:57
hobbsplain2004-05-06 23:20:03
Logged In: YES 
user_id=72656

There should be no expectation that setting a magic var
changes the encoding path in Tcl currently.  However, I do
plan a TIP for 8.5 of the form 'encoding path(s)|dirs', as
it is the Right Thing.
vincentdarleyplain2004-05-07 02:27:33
Logged In: YES 
user_id=32170

Jeff: the Tcl documentation says:

"When \fBTcl_GetEncoding\fR encounters an encoding
\fIname\fR that has not
been loaded, it attempts to load an encoding file called
\fIname\fB.enc\fR
from the \fBencoding\fR subdirectory of each directory
specified in the
library path \fB$tcl_libPath\fR.  If the encoding file
exists, but is
malformed, an error message will be left in \fIinterp\fR.
"

that certainly gives me the expectation that setting this
var will change the current Tcl encoding path.  That's not
to say this behaviour is good, or that 'encoding
path(s)|dirs' is bad, just that Tcl does not follow its
current documentation.
hobbsplain2004-05-07 02:58:50
Logged In: YES 
user_id=72656

You have to make some assumptions that you are allowed to
set tcl_libPath in the first place, but the real problem is
that comment is wrong in just about every aspect.  The
tcl_libPath should not be considered a valid var, should not
exist, and will likely be removed in any future version
because it's a bogus red herring.

What actually happens is that tcl_libPath is set to the
internal library path on startup, and never referred to
again.  It is a for-reference-only variable.  In that way
the docs are correct, it's the assumption that setting
tcl_libPath affects anything that is invalid.

Which of course leads to a better question ... do we just
want to manage the encoding directory, or allow some
Tcl-level access to read *and* set the library path?
dgpplain2004-06-17 03:52:22
Logged In: YES 
user_id=80530


The false claims have been removed
from the Encoding.3 documentation.

A soon-to-be-written TIP will offer
a new method for scripts to control
the search path for *.enc files.
nobodyplain2005-08-08 17:52:02
Logged In: NO 

In Tcl 8.5, I see "unsupported::EncodingDirs" as a new
command. Is the plan (as per the 1 year old comment below)
to write a new TIP to expose this?
dgpplain2005-08-08 20:18:29
Logged In: YES 
user_id=80530


yes.

feel free to use the [::tcl::unsupported]
version for now, and report any trouble
with it.
Log in (anonymous is fine) to add a comment.