Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 395b727b6253376bd8edc78473c19ed2710b821a
Ticket: 579617ffffffffffffffffffffffffffffffffff
encodings can't be found
User & Date: dgp on 2004-12-11 04:24:19
Changes

  1. icomment:
    Logged In: YES 
    user_id=80530
    
    
    In Tcl 8.5a2, Tcl_FindExecutable()
    and its components got a substantial
    rewrite.  The body of T_FE now
    clearly show the various things it does:
    {
        TclInitSubsystems();
        TclpSetInitialEncodings();
        TclpFindExecutable(argv0);
    }
    
    The TclInitSubsystems() call 
    represents the fundamental initialization
    of the Tcl library.  Without this call coming
    first, many of the routines (even public ones)
    of the Tcl library will fail or even crash.
    
    Currently there are two public routines
    that in turn call TclInitSubsystems,
    Tcl_FindExecutable() and Tcl_CreateInterp().
    Any code making calls into the Tcl library
    should be written so that its know one of these
    routines has been called first.
    
    It may be to our advantage to make
    TclInitSubsystems() itself a public
    routine (with the name Tcl_Initialize() ?)
    so that the responsibilities of callers
    are easier to describe (call Tcl_Initialize()
    first; call Tcl_Finalize() when the library
    won't be called anymore).
    
    After TclInitSubsystems() returns, all
    of Tcl's public routines should be
    "crash safe" when called according to
    their documentation.
    
    TclpSetInitialEncodings makes an
    attempt to initialize [encoding system]
    according to the environment of the
    process.  Its implementation is:
    {
        Tcl_DString encodingName;
        Tcl_SetSystemEncoding(NULL,
                TclpGetEncodingNameFromEnvironment(&encodingName));
        Tcl_DStringFree(&encodingName);
    }
    
    TclpSetInitialEncodings() might
    correctly initialize [encoding system],
    or it might not.  When it cannot, it will
    leave [encoding system] with the value
    of "identity".  Tclkit will face this situation,
    because at the time Tcl_FindExecutable
    is called, the *.enc files will not be found
    on the encoding search path yet.
    
    We should make
    TclpGetEncodingNameFromEnvironment()
    a public routine so that callers of the
    Tcl library can check at any time whether
    the value of [encoding system] agrees
    with what Tcl thinks the environment
    expects it to be.  With that routine public,
    Tclkit can easily repeat the [encoding system]
    initialization attempt after it is satisfied that
    a proper encoding search path is in place.
    
    Finally, TclpFindExecutable() performs
    the function of initializing [info nameofexecutable].
    The value is stored as a ProcessGlobalValue
    - a new kid of struct in the Tcl library - that automatically
    adapts itself to any changes in [encoding system].
    
    With Tcl 8.4, Tclkit's LibraryPathObjCmd had to
    make a second call to Tcl_FindExecutable to
    reset the proper encoding for the [info noe] value.
    That is no longer required, and in fact causes a
    problem.
    
    Startup sequence recommendation for Tclkit
    is now:
    
        TclInitSubsystems();
        TclSetEncodingSearchPath(Tcl_NewObj());
        Tcl_Main(...)
    
    and within LibraryPathObjCmd():
    
        Tcl_DString encodingName;
        TclSetEncodingSearchPath(objv[1]);
        Tcl_SetSystemEncoding(NULL,
                TclpGetEncodingNameFromEnvironment(&encodingName));
        Tcl_DStringFree(&encodingName);
    
    and within boot.tcl:
    
        libraryPath [file join [info library] encoding]
    
    Additional cosmetic change might be to rename
    [libraryPath] to [encodingPath] since that's what's
    really being set.
    
    Tcl should expose a script level command to allow
    setting of the encoding search path.  That might
    lead to a line in boot.tcl something like:
    
        encoding dirs [file join [info library] encoding]
    
    A re-attempt to set [encoding system] would then
    be needed, and that might mean exposing 
    TclpGetEncodingNameFromEnvironment at
    the script level as well.
    
    I think working source code changes for Tclkit 8.5a2
    have been fed back now.  Comments on continuing
    plans are invited.
    
    
    
  2. login: "dgp"
  3. mimetype: "text/plain"
  4. username: "dgp"