Taming test utf-2.11
Fresh ticket to sort out what we expect from test utf-2.11 with body:
string length [testbytestring "\xF4\x90\x80\x80"]
According to the normal rules of UTF-8, the test considers the proper
4 byte encoding of the codepoint U+10000 and the test is testing what
Tcl does with it. We should expect different version and different
configuration builds to give different results.
7db642d35aApply fix for [493dccc2de] and adjust tests. check-in2020-04-20 05:09:052282b5ecbf[493dccc2de] Revise sequence validity check to reject out of range decodes too. check-in2020-04-17 21:07:09610d63729c[493dccc2de] Coverage that Tcl_UtfPrev also checks the upper range validity. check-in2020-04-17 20:38:38
No, it translates to code point U+110000, which is too big.
Aha! Misread the lead byte and get the wrong answer.
\xF4\x90\x80\x80
^
would decode to U+110000 which is outside the Unicode range,
which is what the test is meant to check the handling of.
Important lesson, the set of codepoints that can be encoded in a 4-byte sequence is strictly greater than the set of codepoints acceptable in Unicode.
Thanks for your patience. This should be simple to fix with an adaptation of Overlong(). Stay tuned.
Fix committed to 8.5. Careful merge work still needed.
Since the fix is merged to 8.6, and never existed on 8.7 and 9.0, this ticket can be closed now. Don, agreed!
As for [b38c307e41], why not both (testsize command and format as fallback) for ucs2 constraint, Jan?
I mean:
Because if tested with compiled test-module, testsize is more "precise" or rather fewer error-prone then, otherwise the tests become "protected" by format expression (at least for 8.5/8.6).
[expr {[llength [info commands testsize]] ?
[testsize unichar] == 2 : [format %c 0x010000] eq "\uFFFD"
}]
@sebres, Well, "format %c" uses Tcl_UniCharToUtf() to convert the integer to a UTF-8 byte sequence. This function returns the UTF-8 sequence of \xFFFD for out-of range Unicode character values. It does this, even as far back as Tcl 8.4:
https://core.tcl-lang.org/tcl/artifact?udc=1&ln=183-211&name=b972e779b5e039b4
Looks like a perfect feature-test to me, works for any Tcl version in the past, should work for any Tcl version in the future. Your suggestion is harmless, but I don't see the added values. Sorry :-)
> 1. "format %c" uses Tcl_UniCharToUtf() to convert the integer to a UTF-8 byte sequence.Sure, but either 1 or 2 can change in some version (or derivation). But OK, I understand.
> 2. This function returns the UTF-8 sequence of \xFFFD for out-of range Unicode character values.
Nevertheless I would at least change it to something more clear and less conditional, like this:
[expr {[scan [format %c 0x010000] %c] != 0x010000}]
> Sure, but either 1 or 2 can change in some version (or derivation)
Well, Tcl 8.7 will use utf16 in stead of ucs2 for internal storage:
$ tclsh8.7 % format %c 0x010000 𐀀 % expr {[format %c 0x010000] eq "\uFFFD"} 0 % expr {[format %c 0x010000] eq "\U010000"} 1 %
This means that the "ucs2" 'feature' will be gone when Tcl 8.6 is gone. Long live Tcl 8.7!
Well, Tcl 8.7 will use utf16 in stead of ucs2 for internal storage:
$ tclsh8.7
% format %c 0x010000
𐀀
% expr {[format %c 0x010000] eq "\uFFFD"}
0
% expr {[format %c 0x010000] eq "\U010000"}
1
%
This means that the "ucs2" 'feature' will be gone when Tcl 8.6 is gone. Long live Tcl 8.7!
Ok, the constraint conversation is over here. Here's my comment copied over: The constraint "ucs2" is distinct from "compat85" and needs to be restored. "ucs2" might be a bad name for it. We can change that, but I need a way to directly determine whether (sizeof(Tcl_UniChar) == 2) and nothing else. The "compat85" constraint tests whether Tcl has no way to internally store codepoints > U+FFFF. That is not the same thing. In a default build of Tcl 8.7, the "compat85" constraint should be false, but the "ucs2" constraint should be true.
The purpose of the "ucs2" constraint is to permit skipping of tests in builds where the bug [1004065] is not fixed and not made irrelevant by other developments. My hope is that the use of this constraint will be temporary.
I like "ucs2" as a better name for what used to be "compat85". Keep that. I'll convert the other constraint to the name "twobyteunit" unless someone else beats me to it.