Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2023-05-03
15:18
Removed the bug specific test constraint from the tests related to [0306a5563c] because the bug is ... check-in: 1c4a696c6b user: pointsman tags: trunk, main
2023-05-02
22:11
Fix for [0306a5563c]. check-in: eb76c36249 user: pointsman tags: trunk, main
22:06 • Closed ticket [0306a5563c]: Writing large strings to file create wrong results</... artifact: b6acc08d1a user: pointsman
21:50
Fix for [0306a5563c]. closed check-in: 36eb6e3921 user: pointsman tags: bug-0306a5563
2023-04-24
09:41
Fixes the examples given in [0306a5563c]. Still more to do for a full fix. check-in: 8b3c80eeba user: pointsman tags: bug-0306a5563
2023-04-23
23:57 • Ticket [0306a5563c] Writing large strings to file create wrong results statu... artifact: e1ac8520fc user: pointsman
18:25
That fixes the examples given in [0306a5563c]. Needs more consideration before claim success. closed check-in: 67231d38a8 user: pointsman tags: pyk-whatever, bug-0306a5563c
18:14
That fixes the examples given in [0306a5563c]. Needs more consideration before claim success. closed check-in: 1cf1f44a14 user: pointsman tags: bug-0306a5563c
02:36 • Ticket [0306a5563c] Writing large strings to file create wrong results statu... artifact: c4ac86310a user: apnadkarni
02:35 • Ticket [0306a5563c]: 3 changes artifact: c35111efcd user: apnadkarni
2023-04-22
17:54 • Ticket [0306a5563c]: 3 changes artifact: 884a74c8d7 user: pointsman
17:53 • New ticket [0306a5563c]. artifact: ffb54d09ec user: pointsman

Writing large strings to file create wrong results

Closed / Fixed0306a5563c65ab14410c426f59f00d714bf276fcCreated 4 years agoUpdated 4 years ago
Descriptionplain2023-04-22 17:53:43
Run this script:

package require Tcl 9
set fd [open out.txt w+]
puts $fd [lrepeat [expr {int(pow(2,31)) + 1}] ""]
close $fd

The tail of the created file (here the output of tail -c 20) look like:

 {} {} {} {} {{} {}

Note here:   ^

If I run the variant from above

package require Tcl 9
set fd [open out.txt w+]
puts $fd [lrepeat [expr {int(pow(2,31)) + 1}] a]
close $fd

the tail of the created file looks like:

 a a a a a a a aa a

which also seems wrong.
Referenced by6
pointsman Ticket [0306a5563c]: 3 changes [History diff]2023-04-22 17:54:09
apnadkarnimarkdown2023-04-23 02:35:40

The issue could be in string generation from a list or in the puts / channel system. The following seems to indicate the latter.

% set s [testbigdata string 0x80000004]; string length $s
2147483652
% set fd [open x.txt w]
file2a4826a5a68
% puts $fd $s
% close $fd
% string range $s end-20 end
123456789012345678901

Tailing the file,

apnadkarni@IO:/mnt/d/src/tcltk/trunk/tcl/win$ tail -c 40 x.txt
45678901234567890123456789012345601234

Notice the 6 followed by 0 at the end. That's right around the INT_MAX offset into the string.

apnadkarniplain2023-04-23 02:36:36
Changed ticket title as I think it is not related to lists.
pointsmanplain2023-04-23 23:57:41
[Sorry again. While not completely wrong at the previous place it belongs to here.]

The fix for[3d01d51bc4] with commit [186e4d9317] didn't really fix the problem.

Look at 
[https://core.tcl-lang.org/tcl/artifact?udc=1&ln=4262-4278&name=ce11265346dd36a3]

In that loop the scr pointer will not be incrementend. Which means that after every INT_MAX bytes written it starts over from the start of the string instead of continuing. This explains the output of the examples given so far.

An obvious fix is

https://core.tcl-lang.org/tcl/artifact?udc=1&ln=4276&name=abf0f8ddf7519a1f

with which all the so far given examples run as expected.

But this raises the question what WriteChars(chanPtr, src, chunkSize) does if the chunkSize ends in the middle of a multibyte char?

Some answers to that question doesn't look promissing (need a Tcl 9 tcltest to run this example script):

set s [testbigdata string 0x7FFFFFFE]
# The character to append in the next line is EM DASH, 
# code point 0x2014 (decimal 8212, UTF-8 #xE2 #x80 #x94, 
append s —
set fd [open out.txt w+]
puts $fd $s
close $fd

If I run this (on debian) I get:

error writing "file6": invalid or incomplete multibyte or wide character
    while executing
"puts $fd $s"
pointsmanplain2023-05-02 22:06:54
Turns out instead of breaking up the data in Tcl_WriteObj() into MAX_INT chunks it's much easier the make the called function Write() to work correctly on larger strings.

Processing in chunks has a problem with chunks that ends inbetween a multi-byte character. To work around that seemd unnecessary convoluted.

So I basically restored Tcl_WriteObj() to before the [3d01d51bc4] triggered changes and made Write() Tcl_Size ready.

Fixed with [36eb6e392]
Log in (anonymous is fine) to add a comment.