Artifacts Associated With Ticket 141c6f5621
Ticket change [362267ca82] (rid 198798) by pooryorick on 2022-03-07 00:07:06:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
When the following script is evaluated in a core_8_branch build, the total length of the string containing a single character is reported as 2, the length of the first character is reported as 2, and the length of the next character is reported as 0: <code><verbatim> set string \Uade19 puts [list string length [string length $string]] puts [string length [string index $string 0]] puts [string length [string index $string 1]] </verbatim></code>
- is_private initialized to: "0"
- login: "pooryorick"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "pooryorick"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
[string length] reports a length of 2 for a single character
- type initialized to: "Bug"
Ticket change [c32fe6722c] (rid 198799) by jan.nijtmans on 2022-03-07 10:13:40:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459645.92615994"
- closer changed to: "jan.nijtmans"
- icomment:
Just wondering, what character is \Uade19 ??? It's "" wherever I look ... Said that, let's demonstrate with another reasonable character 💣 In Tcl 8.6: <pre> $ tclsh8.6 % string length 💣 2 % string index 💣 0 ▒ % string index 💣 1 ▒ </pre> In Tcl 8.7: <pre> $ tclsh8.7 % string length 💣 2 % string index 💣 0 💣 % string index 💣 1 </pre> The fact that "string length" returns 2 comes from the internal UTF-16 representation for string in Tcl 8.x, not something that's trivial to change. You can change that compiling Tcl 8.7 with -DTCL_UTF_MAX=4. But that has effect on the C-API using Tcl_UniChar, therefore this is only done for Tcl 9.0. Since the UTF-8 encoding for 💣 is 0xF0 0x9F0 x92 0xA3, which cannot be split, the current 8.7 behavior is the best possible under the given restriction. So, this behavior is as designed. See also the "Caveat" section of [https://core.tcl-lang.org/tips/doc/trunk/tip/389.md|TIP #389], which explains this behavior. Sorry, but closing ....
- login: "jan.nijtmans"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
Ticket change [ef39a02941] (rid 198800) by jan.nijtmans on 2022-03-07 10:14:24:
- closedate changed to: "2459645.92666744"
- icomment:
Just wondering, what character is \Uade19 ??? It's "" wherever I look ... Said that, let's demonstrate with another reasonable character 💣 In Tcl 8.6: <pre> $ tclsh8.6 % string length 💣 2 % string index 💣 0 ▒ % string index 💣 1 ▒ </pre> In Tcl 8.7: <pre> $ tclsh8.7 % string length 💣 2 % string index 💣 0 💣 % string index 💣 1 </pre> The fact that "string length" returns 2 comes from the internal UTF-16 representation for string in Tcl 8.x, not something that's trivial to change. You can change that compiling Tcl 8.7 with -DTCL_UTF_MAX=4. But that has effect on the C-API using Tcl_UniChar, therefore this is only done for Tcl 9.0. Since the UTF-8 encoding for 💣 is 0xF0 0x9F0 x92 0xA3, which cannot be split, the current 8.7 behavior is the best possible under the given restriction. So, this behavior is as designed. See also the "Caveat" section of [https://core.tcl-lang.org/tips/doc/trunk/tip/389.md|TIP #389], which explains this behavior. Sorry, but closing ....
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [17b30f43a4] (rid 198818) by pooryorick on 2022-03-07 13:31:09:
- closedate changed to: "2459646.06330637"
- closer changed to: "pooryorick"
- icomment:
In my opinion, this is unacceptable behaviour, even for an "interim" release of Tcl, and no further releases of Tcl should feature it.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
Ticket change [f637b35211] (rid 198819) by dgp on 2022-03-07 14:47:20:
- closedate changed to: "2459646.11620507"
- closer changed to: "dgp"
- icomment:
Note this is new behavior in Tcl 8.6.10 and later.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [204e749262] (rid 198820) by jan.nijtmans on 2022-03-07 14:54:51:
- closedate changed to: "2459646.12143007"
- closer changed to: "jan.nijtmans"
- icomment:
> Note this is new behavior in Tcl 8.6.10 and later. Indeed, before Tcl 8.6.10, "string length 💣" gave the answer "4", which is even more surprising .....
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [633f84f451] (rid 198821) by dgp on 2022-03-07 14:59:08:
- closedate changed to: "2459646.12440735"
- closer changed to: "dgp"
- icomment:
In particular in late Tcl 8.6 patchlevels and in Tcl 8.7 pre-releases, [string length] is no longer counting characters, it is counting UTF-16 code units. This is at least controversial. That said, I think it's been TIP-approved (I'm hazy on the 8.6.* changes). It's not out of bounds to complain, and point out problems, possibly leading to a counter proposal, but "not a bug" is a fair assessment.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [3dae6863ea] (rid 198822) by jan.nijtmans on 2022-03-07 15:12:40:
- closedate changed to: "2459646.13379903"
- closer changed to: "jan.nijtmans"
- icomment:
The only 'real' solution is compiling Tcl 8.7 with UCS-2-support: <pre> ./configure CFLAGS="-DTCL_UTF_MAX=4" </pre> That's possible, it has some implications for extensions. It's up to you whether those implications are acceptable or not. Both TCL_UTF_MAX=3 and TCL_UTF_MAX=4 are supported for Tcl 8.7 (see [https://core.tcl-lang.org/tips/doc/trunk/tip/542.md|TIP #542]
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [ac9f99f443] (rid 198823) by dgp on 2022-03-07 15:15:02:
- closedate changed to: "2459646.13545057"
- closer changed to: "dgp"
- icomment:
The troubling disruptions are mostly in the inferences programmers have been able to make that have been invalidated by the change. As an example, whenever (string length [string index $s $i] == 0) && ($i >= 0) a programmer could reliably conclude [string length $s] < $i without making any additional tests. Any program built on inferences like that are at risk through this transition. Tcl 9 then reverses course and transitions back to: % string length 💣 1 % string index 💣 0 💣 % string index 💣 1 % I think this double transition back to where we started is fueling the stated plans of several people to skip Tcl 8.7 altogether.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [74598acdd5] (rid 198824) by dgp on 2022-03-07 15:33:41:
- closedate changed to: "2459646.14839932"
- icomment:
Another programming inference that might commonly be in use: [llength [split $s {}]] == [string length $s] We could use a list of such "Gotchas!" to call attention to in a migration guide to Tcl 8.7. These loops no longer reliably implement the same function in Tcl 8.7: foreach c [split $s {}] {process $c} for {set i 0} {$i < [string length $s]} {incr i} {process [string index $s $i]} Here again, the expectations of functional equivalence are restored in Tcl 9. - login: "dgp"
- mimetype: "text/plain"