Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e875ed32f62955704c4bded7b39f2dea7faa581d
Ticket: 1256872fffffffffffffffffffffffffffffffff
Unicode support for Win32 (NT) console channels
User & Date: a_kovalenko on 2010-03-01 07:06:28
Changes

  1. icomment:
    As this artifact is still open, let me defend this implementation. My purpose is to ensure that it won't be rolled back for 8.6 as well.
    
    First, [fconfigure stdin -encoding utf8] didn't work before this patch, it just pretended to: utf-8 and a typical console codepage (whatever it be) have ASCII subset in common. Both with this patch and without it, the console channel after [fconfigure ... utf-8] is misconfigured, i.e. it cannot be used to input non-ascii characters correctly. The only difference is the amount of trouble caused by this misconfiguration.
    
    Mr. Hobbs seems to expect a solution that notices the upper-level -encoding reconfiguration on console channel and somehow takes it into account when the low-level I/O is done. If it's indeed the expected property of a "complete implementation", I would present an objection: no channel type ever worked this way, be it console channels or any other channels. The channel at the lowest level is a stream of bytes, and encoding translation is layered on top of it, but it doesn't affect the channel I/O behavior, ever. This principle was respected by Tcl from the very start of its unicode subsystem; it's also what extension and application developers do expect and will always expect.
    
    However, there is sometimes a reason for the channel type to influence _initial_ settings of the upper-level translation procedures: for example, TCP sockets require CR-LF line endings for most standard text-based network protocols. The same thing is true for the "unpatched" console channels: they preset the encoding to an autodetected codepage (result of GetConsoleCP); but they don't try to synchronize further channel encoding changes with console codepage. Once the channel is created, the application is free to fconfigure it to any encoding (breaking the correctness of translation, of course); if the console codepage is changed after the channel creation (exec cmd /c chcp...), the "real" low-level encoding and the tcl translation-level encoding are again out of sync.
    
    "Patched" implementation just detects and uses "unicode" as initial setting, exactly the same way as both implementations act on non-unicode systems, detecting non-unicode codepages. It doesn't prevent an application from altering it, even if it makes the channel unusable.
    
    To be short, I could say that [fconfigure stdin -encoding unicode] will hang the "unpatched" implementation and work with "patched" one: just the same as the reverse is true for -encoding utf-8 (which fact was the reason of rolling back this patch).
    
    There is, however, one possible compromise that may be added to my implementation to restore the backward compatibility, making the channel not-so-obviously-broken after encoding misconfiguration: I can use utf-8 as the "presented low-level" encoding on unicode systems, and do the utf8<->unicode translation during the I/O. This way, utf-8 will be set up as a channel encoding by default; if any application reconfigures the channel to utf-8 again, everything will work (not just pretend to); and if the channel is reconfigured to some wrong encoding being a superset of ASCII, the thing at least won't _hang_.
    
    Hereby I request comments from Mr. Hobbs, both of the current state of the patch and on the proposed improvement, on the possibility of backporting it again into 8.5 and 8.4 once the improvement is made, and on the plans for 8.6 (is it acceptable as is, or is it not rolled back only by accident? will it be acceptable if the change described above is made?).
    
    
  2. login: "a_kovalenko"
  3. mimetype: "text/plain"
  4. username: "a_kovalenko"