Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2020-05-12
13:56 • Ticket [81242a48c8] Documentation for Tcl_UtfAtIndex() is incorrect status s... artifact: 9f08cfd775 user: jan.nijtmans
2018-01-12
10:05 • Closed ticket [11ae2be95d]: tip-389 branch: string range errors with code points... artifact: b4e87ec708 user: jan.nijtmans
10:03
Fix [11ae2be95d]: tip-389 branch: string range errors with code points greater than U+FFFF check-in: de13f558fb user: jan.nijtmans tags: tip-389
2018-01-11
15:44
Fix behavior of Tcl_GetRange() and "string range" regarding surrogates, when Tcl is compiled with -D... check-in: 27a52735df user: jan.nijtmans tags: core-8-6-branch
15:28 • Ticket [11ae2be95d] tip-389 branch: string range errors with code points greater... artifact: 7afa1860bb user: jan.nijtmans
14:53 • Ticket [11ae2be95d]: 3 changes artifact: 0aabe07e26 user: sebres
14:11
Add test-cases for bug [11ae2be95dac9417], and make a start fixing it. Almost works. check-in: 6758341b2f user: jan.nijtmans tags: tip-389
2018-01-10
15:54 • Ticket [11ae2be95d] tip-389 branch: string range errors with code points greater... artifact: de4882c638 user: dgp
15:45 • Ticket [11ae2be95d]: 3 changes artifact: b66ce02af5 user: jan.nijtmans
15:24 • Ticket [11ae2be95d]: 3 changes artifact: 3d2e55ac65 user: dgp
15:18 • Ticket [11ae2be95d]: 3 changes artifact: 4346da0f77 user: sebres
15:04 • Ticket [11ae2be95d]: 3 changes artifact: 927bf31db6 user: dgp
15:03 • Open ticket [11ae2be95d]. artifact: 397da76cb2 user: dgp
2014-12-12
15:10 • Closed ticket [11ae2be95d]. artifact: 82653b05b8 user: jan.nijtmans
15:10 • Ticket [11ae2be95d]: 5 changes artifact: ebdac6e309 user: jan.nijtmans
2014-12-11
21:38 • New ticket [11ae2be95d]. artifact: 7197819b58 user: anonymous

tip-389 branch: string range errors with code points greater than U+FFFF

Closed / Fixed11ae2be95dac941790db43dcfb265f8586072cd8Created 12 years agoUpdated 9 years ago
Descriptionplain2014-12-11 21:38:40
% string range a\U10000b 0 0
a
% string range a\U10000b 1 1
Segmentation fault
% string range a\U10000b 2 2
Segmentation fault
Referenced by1
  • de13f558fbFix [11ae2be95d]: tip-389 branch: string range errors with code points greater than U+FFFF check-in2018-01-12 10:03:58
jan.nijtmanswiki2014-12-12 15:10:19

Dup of [3408718]

jan.nijtmans Closed ticket [11ae2be95d]. [History diff]2014-12-12 15:10:43
dgpplain2018-01-10 15:03:16
Re-opening.

The segfaults are indeed gone but now on the tip-389 branch:

% string range a\U10000b 0 0
a
% string range a\U10000b 1 1
% string range a\U10000b 2 2
st

Especially for the last command, I'd expect the result "b"

I'm far from confident the middle command is doing the right thing too.
dgp Ticket [11ae2be95d]: 3 changes [History diff]2018-01-10 15:04:09
sebresplain2018-01-10 15:18:44
> @dgp Especially for the last command, I'd expect the result "b"

Just to be sure: is it a valid escape-sequence at all? 
I mean, do you not need 32-bit hex value there?

For example doing this in python will cause following error:

>>> 'a\U10000b'
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 1-8: truncated \UXXXXXXXX escape
dgpplain2018-01-10 15:24:55
To remove the abiguity about where \UHHHHHHHHH parsing ends....

% string index a\U10ffff! 2
pßÿ¿
% string index a-! 2
!
jan.nijtmansplain2018-01-10 15:45:28
I'll have a loot at "string range"  and "string index". In the current implementation, a character > \U0ffff occupies 2 locations in the string (= actually 'character array'). So we must implement a precaution that we can never point in the middle of a upper/lower surrogate pair. That's what goes wrong here.

The best thing to do is - I think - to round up any index that points in the middle of a surrogate pair. So, what I would expect:

% string range a\U10000b 0 0
a
% string range a\U10000b 1 1
\U10000 (however that would be displayed ...)
% string range a\U10000b 2 2

% string range a\U10000b 3 3
b

Indeed, there's still something to be done here.

Thanks!
dgpplain2018-01-10 15:54:11
Aarrggh. used the wrong number of 0's in an earlier comment.

lets try again....

% string range a\U100000b 0 0
a
% string range a\U100000b 1 1
% string range a\U100000b 2 2
st
% string range a\U100000b 3 3
b

Ok, that's a somewhat different kettle of fish.
I thought we were getting just wrong answers.

Instead it's a more subtle issue of the "two surrogates"
instead of "one Unicode codepoint" leaking through the
abstraction.  This isn't ideal, but might be the tradeoff
that's in place.

Sorry about the botched demo.
sebreswiki2018-01-11 14:53:33

Hi Jan,

really printf in StringIndexCmd?.. :)

Do we need always use `int` instead of `Tcl_UniChar` now by call of Tcl_GetUniChar?... (if/after TIP get merged).

jan.nijtmansplain2018-01-11 15:28:39
> really printf in StringIndexCmd?.. :)

Work in progress ... will be fixed.

> Do we need always use `int` instead of `Tcl_UniChar` now by call of Tcl_GetUniChar?... (if/after TIP get merged).

Yes, at least if you want to make use of characters >U+FFFF. If you decide to keep using Tcl_UniChar, that's OK too, but then characters in other Unicode planes will be mapped to characters in the BMP. Since Tcl <= 8.6 cannot handle characters >U+FFFF anyway, I consider that an improvement ;-)
jan.nijtmanswiki2018-01-12 10:05:45

Fixed in: [de13f558fb5352c9]. Closing.

Log in (anonymous is fine) to add a comment.