|
2019-12-08
| ||
| 16:33 | Fix Valgrind problem reported as follow-up in [fc4393e9b0]. Since it happens only for TCL_UTF_MAX>3 ... check-in: 62c2c904c3 user: jan.nijtmans tags: core-8-6-branch | |
| 02:11 | • Ticket [fc4393e9b0] UnicodeToUtfProc bogus in [edce885a5c] status still Clo... artifact: 644c88bd27 user: chw | |
| 01:55 | • Ticket [fc4393e9b0]: 5 changes artifact: 5418945a30 user: chw | |
|
2019-12-07
| ||
| 22:03 | • Ticket [fc4393e9b0]: 5 changes artifact: 5aaf8dae8e user: jan.nijtmans | |
| 18:42 | • Ticket [fc4393e9b0]: 5 changes artifact: a4013b64df user: chw | |
| 17:38 | • Closed ticket [fc4393e9b0]. artifact: 00c0e4caa8 user: jan.nijtmans | |
| 15:44 | • New ticket [fc4393e9b0]. artifact: 8b436d0a90 user: chw | |
UnicodeToUtfProc bogus in [edce885a5c]
Check-in [edce885a5c] changes the data type which tclUtf.c function UnicodeToUtfProc() processes from Tcl_UniChar to unsigned short. For TCL_UTF_MAX=6 this is Plain Wrong(tm) effectively breaking this mode. Now I wonder why this change took place in the active 8.6 branch and wasn't first thoroughly tested in a development branch before being added to the 8.6 branch.
62c2c904c3Fix Valgrind problem reported as follow-up in [fc4393e9b0]. Since it happens only for TCL_UTF_MAX>3 it's not actully a 'bug' in 8.6, but it might be a corner-case not handled well in 8.7 check-in2019-12-08 16:33:18
There are test-cases in encoding.test, which test for the "unicode" encoding being 16-bit. On the TCL level, we cannot break compatibility, so the "unicode" encoding always needs to be equivalent to utf-16, we cannot change that, never! Agreed, "unicode" is a bad name for an encoding, that's why it's deprecated now.
If you want a UCS-4 encoding, then add one under a separate name and use that, that's the way to go forward. Or (since Androwish in TCL_UTF_MAX=6 mode is already binary incompatible with Tcl) simply don't take over this change in Androwish. But then you'll have to deal with this when makeing the transition to 8.7.
In Tcl 8.7, "unicode" is already equivalent to "utf-16". Check-in [edce885a5c] is basically a backport of part of the TIP #547 implementation, so it -actually - already in use for a long time in the core-8-branch.
Sorry I have no better news :-(
Sorry, too, for nerving more. I wonder why the opposite of UnicodeToUtfProc() (which BTW is in tclEncoding.c not in tclUtf.c) named UtfToUnicodeProc() takes appropriate steps to deal with 16 and 32 bit quantities depending on TCL_UTF_MAX and even automagically detects the byte order. Why make these functions asymmetric?
The main reason for this asymmetry is the function Tcl_UtfToUniChar(), which behaves differently for TCL_UTF_MAX=6: 4-byte UTF-8-sequences will be converted to Unicode in one step, while for TCL_UTF_MAX=3|4 upper/lower surrogates will be delivered. The encoding should result in exactly the same chars, so in case of TCL_UTF_MAX=6 we have to split them into surrogates ourselves.
All corner-cases have test-cases, even high-surrogates not followed by low-surrogates and low-surrogates not preceded by high-surrogates. But if you find a situation that's handled incorrectly, please let me know.
Most likely, I very was mislead in my guesstimations, but then
added I this (wrong) test case to encoding.test:
test encoding-16.3 {UnicodeToUtfProc} -constraints fullutf -body {
set val [encoding convertfrom unicode \
[testbytestring "\xdc\xdc\xd8\xd8\xee\xee"]]
list [format %x [scan $val %c]]
} -result [list dcdc]
and got for valgrind'ing TCL_UTF_MAX=4 and TCL_UTF_MAX=6 otherwise
not present indications of:
==31547== Conditional jump or move depends on uninitialised value(s)
==31547== at 0x2A1C44: Tcl_UniCharToUtf (tclUtf.c:161)
==31547== by 0x211512: UtfToUtfProc (tclEncoding.c:2384)
==31547== by 0x211110: UtfIntToUtfExtProc (tclEncoding.c:2199)
==31547== by 0x20FA04: Tcl_UtfToExternal (tclEncoding.c:1429)
==31547== by 0x24C289: Write (tclIO.c:4294)
==31547== by 0x24BFA8: Tcl_WriteObj (tclIO.c:4168)
==31547== by 0x255E3E: Tcl_PutsObjCmd (tclIOCmd.c:185)
==31547== by 0x14F97A: Dispatch (tclBasic.c:4456)
==31547== by 0x14FA00: TclNRRunCallbacks (tclBasic.c:4492)
==31547== by 0x14F2D6: Tcl_EvalObjv (tclBasic.c:4215)
==31547== by 0x151713: TclEvalEx (tclBasic.c:5361)
==31547== by 0x262AED: Tcl_FSEvalFileEx (tclIOUtil.c:1824)
...
and
==31547== Conditional jump or move depends on uninitialised value(s)
==31547== at 0x2A1C29: Tcl_UniCharToUtf (tclUtf.c:161)
==31547== by 0x211512: UtfToUtfProc (tclEncoding.c:2384)
==31547== by 0x211165: UtfExtToUtfIntProc (tclEncoding.c:2248)
==31547== by 0x20F724: Tcl_ExternalToUtf (tclEncoding.c:1257)
==31547== by 0x24DB5C: FilterInputBytes (tclIO.c:5306)
==31547== by 0x24C9AA: Tcl_GetsObj (tclIO.c:4576)
==31547== by 0x2561B6: Tcl_GetsObjCmd (tclIOCmd.c:327)
==31547== by 0x14F97A: Dispatch (tclBasic.c:4456)
==31547== by 0x14FA00: TclNRRunCallbacks (tclBasic.c:4492)
==31547== by 0x14F2D6: Tcl_EvalObjv (tclBasic.c:4215)
==31547== by 0x151713: TclEvalEx (tclBasic.c:5361)
==31547== by 0x262AED: Tcl_FSEvalFileEx (tclIOUtil.c:1824)
...
which could indicate a logic problem in the state machine of
detecting and handling surrogate pairs.
Sorry again, this was the (wrong) test case which triggered valgrind:
test encoding-16.3 {UnicodeToUtfProc} -constraints fullutf -body {
set val [encoding convertfrom unicode \
[testbytestring "\xdc\xdc\xd8\xd8\xee\xee"]]
[list "\udcdc\ud8d8\ueee" [format %x [scan $val %c]]]
} -result [list dcdc]