Skip to content
Tcl Source Code History Of Ticket 218434
Login

History Of Ticket 218434

Artifacts Associated With Ticket 218434

  1. Ticket change [57ad384f72] (rid 117663) by nobody on 2000-10-26 00:57:33:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 6096 Bug
      Version: 8.2.1
      SubmitDate: '2000-08-09'
      LastModified: '2000-08-10'
      Severity: SER
      Status: Closed
      Submitter: techsupp
      ChangedBy: ericm
      RelatedBugIDs: 3345
      OS: Digital Unix
      OSVersion: Tru64 UNIX Version 5.1
      Machine: Digital Personal WorkStation 500au (Alpha)
      FixedDate: '2000-10-25'
      ClosedDate: '2000-08-10'
      
      
      Name:
      
      Rigoberto Corujo
      
      
      Extensions:
      
      TclX 8.1
      
      
      ReproducibleScript:
      
      When running Extended Tcl on Tru64 UNIX with a dechanzi Chinese locale, the output of the following command is not properly displayed.  That is, some of the date output contains "?" characters.
      
      
      $ tcl
      
      tcl>puts "[fmtclock [getclock]]"
      
      
      This is because the output of "fmtclock" is not UTF-8 encoded, but "puts", or rather the "WriteChars()" routine that implements the "puts" command, expects the string it is processing to be UTF-8 encoded.  Running the following command produces the correct output, however, which means that "puts" needs to be fixed.
      
      
      $ tcl
      
      tcl>fmtclock [getclock]
      
      
      The "WriteChars()" routine ("./tcl8.2/generic/tclIO.c") should accept strings that are UTF-8 encoded and strings that are locally encoded.  If the string is already locally encoded, then it should not try to do the UTF-8 to local encoding.
      
      
      ObservedBehavior:
      
      Some question marks ("?") are displayed in the date string that is output.
      
      
      DesiredBehavior:
      
      The output of
      
      
      tcl>puts "[fmtclock [getclock]]"
      
      
      should be the same as
      
      
      tcl>fmtclock [getclock]
      
      
      Since the output is in Chinese I will not show it here as it will likely not display properly on a browser.
      
      
      Patch:
      
      One of our I18N engineers provided the following patch as a workaround, but cautioned that a more comprehensive solution is needed which requires knoUTF-8 and non-UTF-8 strings get passed among the different modules.
      
      
      $ diff -c tclIO.c.old tclIO.c.new > tclIO.c.patch 
      
      $ cat tclIO.c.patch
      
      *** tclIO.c.old Wed Aug  2 08:43:52 2000
      
      --- tclIO.c.new Wed Aug  2 08:43:57 2000
      
      ***************
      
      *** 2984,2990 ****
      
      --- 2984,3001 ----
      
            int dstWrote, dstLen, stageLen, stageMax, stageRead;
      
            Tcl_Encoding encoding;
      
            char safe[BUFFER_PADDING];
      
      + #ifndef       NO_DEC_I18N
      
      +     extern int Tcl_IsWellFormUtf8(uchar_t *, int) ;
      
      
      +     /*
      
      +      * QAR 81435
      
      +      * Assume string is in native encoding if it is not a well-form
      
      +      * UTF-8 sequence.
      
      +      */
      
      +     if (!Tcl_IsWellFormUtf8((uchar_t *)src, srcLen))
      
      +       return(WriteBytes(chanPtr, src, srcLen)) ;
      
      + #endif
      
      + 
      
            total = 0;
      
            sawLF = 0;
      
            savedLF = 0;
      
      
      $ diff -c tclUtf.c.old tclUtf.c.new > tclIO.c.patch
      
      $ cat tclIO.c.patch
      
      *** tclUtf.c.old        Wed Aug  2 08:45:31 2000
      
      --- tclUtf.c.new        Wed Aug  2 08:45:38 2000
      
      ***************
      
      *** 1581,1583 ****
      
      --- 1581,1621 ----
      
      
            return (((ALPHA_BITS | DIGIT_BITS | CONNECTOR_BITS) >> category) & 1);
      
        }
      
      + 
      
      + 
      
      
      + #ifndef       NO_DEC_I18N
      
      + /*
      
      +  *----------------------------------------------------------------------
      
      +  *
      
      +  * Tcl_IsWellFormUtf8
      
      +  *
      
      +  *    Test if a string is a well-form UTF-8 sequence.
      
      +  *
      
      +  * Results:
      
      +  *    Returns 1 if string is a well-form UTF-8 sequence.
      
      +  *
      
      +  * Side effects:
      
      +  *    None.
      
      +  *
      
      +  *----------------------------------------------------------------------
      
      +  */
      
      + #define       TCL_VALID_UTF8_NONFIRSTBYTE(b)  (((b) & 0xc0) == 0x80)
      
      + int
      
      + Tcl_IsWellFormUtf8(uchar_t *str, int length)
      
      + {
      
      +     int ch, len ;
      
      + 
      
      +     while (length-- > 0)
      
      +     {
      
      +       ch = *str++ ;
      
      +       if (isascii(ch))
      
      +           continue ;
      
      +       if ((len = totalBytes[ch] - 1) <= 0)
      
      +           return(0) ; /* Invalid UTF-8 sequence */
      
      +       while (len-- > 0)
      
      +           if (!TCL_VALID_UTF8_NONFIRSTBYTE(*str++))
      
      +               return(0) ;
      
      +     }
      
      +     return(1) ;       /* Well-form UTF-8 sequence */
      
      + }
      
      + #endif
      
      
      PatchFiles:
      
      ./tcl8.2/generic/tclIO.c
      
          ./tcl8.2/generic/tclUtf.c
      
      
      
      
      As was discussed in the newsgroup, [puts] should not have to handle non-UTF-8 strings, as it is part of the "API contract" that WriteChars is given UTF-8 strings.
      
      So it is fair to say that the problem should be solved in [fmtclock]; however, that doesn't really give the whole story.  Since TclX 7.5, [fmtclock] has simply been an alias to [clock format].  There was a bug in [clock format] that caused it to return non-UTF-8 strings, which only showed up when used in locales like the one you used.  This bug was corrected for 8.4a1, and the fix was backported for 8.3.2.  I suggest that you upgrade your Tcl installation to that version.
      
         Eric Melski                            The Other Tcl Guy
         ericm at ajubasolutions.com            Ajuba Solutions
      
      -- 08/10/2000 ericm
      
      
      
    4. foundin initialized to: "obsolete: 8.2.1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "69. Other"
    10. title initialized to: ""puts" does not work with non UTF-8 strings"
    11. type initialized to: "Bug"
  2. Ticket change [c5996248c5] (rid 112027) by welch on 2000-10-26 08:22:15:

    1. closedate changed to: "2000-10-26T01:22:15"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  3. Ticket change [4b6b4301d9] (rid 126710) by dgp on 2001-04-19 04:15:11:

    1. closedate changed to: "2001-04-18T21:15:11"
    2. closer changed to: "dgp"
    3. subsystem changed to: "06. Time Measurement"
    4. title changed to: ""puts" does not work with non UTF-8 strings"