Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 46d34456e6e7fc64b45f01f3cd9979234725a9ba2e2dbad85ca99730d83542dd
Ticket: 3fc3287497a7e281b96661f883c20e0e74a0fca7
TclGetProcessGlobalValue encodes information twice on Windows
User & Date: ralfixx on 2024-05-22 17:22:07
Changes

  1. comment changed to:
    If the hostname on Windows contains an Umlaut, [info hostname] will return a different value when invoked for the second time:
    
        % tclsh8.6
        % info hostname
        foo-läptop
        % info hostname
        foo-läpt
    
    BUG: The second time, the hostname is encoded another time.
    
    Looking at the code for [info hostname] on Windows, it seems to me:
    
    - information is stored in global variable
        static ProcessGlobalValue hostName =
        	{0, 0, NULL, NULL, InitializeHostName, NULL, NULL};
      (win/tclWinSock.c)
      
    - the first time the information is retrieved by
      TclGetProcessGlobalValue(), it is initialized by a
      call to InitializeHostName(), which sets the encoding of the
      information to utf-8 after retrieving it from windows and converting
      it to utf-8
            *encodingPtr = Tcl_GetEncoding(NULL, "utf-8");
      (win/tclWinSock.c)
      
    - the next time the information is retrieved by
      TclGetProcessGlobalValue(), it sees that the encoding is non-NULL and
      compares it to the system encoding, which on Windows is not utf-8, but
      (in my case) cp1252.  So the information is converted again.
    
      TclGetProcessGlobalValue()
        ...
        if (pgvPtr->encoding) {
    	Tcl_Encoding current = Tcl_GetEncoding(NULL, NULL);
    
    	if (pgvPtr->encoding != current) {
    
    This is due to a wrong first argument to Tcl_UtfToExternalDString() 
    in TclGetProcessGlobalValue() in generic/tclUtil.c:
    
    #4287	    Tcl_UtfToExternalDString(pgvPtr->encoding, pgvPtr->value,
    		    pgvPtr->numBytes, &native);
    
    The first argument is the encoding to convert TO, not convert FROM.
    
    I first thought that TCL9 had this fixed by using NULL as first argument, but it actually hasn't.
    
    For a possible patch see next comment.
    
  2. login: "ralfixx"
  3. mimetype: "text/plain"