Artifacts Associated With Ticket 0306a5563c65ab14
Ticket change [ffb54d09ec] (rid 213632) by pointsman on 2023-04-22 17:53:43:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- comment initialized to:
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}] ""] close $fd the tail of the created file looks like: a a a a a a a aa a which also seems wrong. - foundin initialized to: "Tcl 9"
- is_private initialized to: "0"
- login: "pointsman"
- priority initialized to: "5 Medium"
- private_contact initialized to: "4ca203a8e925aecdd9419645f936bccf18cd6ea7"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "pointsman"
- subsystem initialized to: "18. Commands M-Z"
- title initialized to: "Writing large lists to file create wrong results"
- type initialized to: "Bug"
Ticket change [884a74c8d7] (rid 213633) by pointsman on 2023-04-22 17:54:09:
- comment changed to:
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. - login: "pointsman"
- mimetype: "text/plain"
- comment changed to:
Ticket change [c35111efcd] (rid 213646) by apnadkarni on 2023-04-23 02:35:40:
- icomment:
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.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [c4ac86310a] (rid 213647) by apnadkarni on 2023-04-23 02:36:36:
- icomment:
Changed ticket title as I think it is not related to lists.
- login: "apnadkarni"
- mimetype: "text/plain"
- title changed to: "Writing large strings to file create wrong results"
- icomment:
Ticket change [e1ac8520fc] (rid 213731) by pointsman on 2023-04-23 23:57:41:
- icomment:
[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" - login: "pointsman"
- mimetype: "text/x-fossil-plain"
- icomment:
Ticket change [b6acc08d1a] (rid 214369) by pointsman on 2023-05-02 22:06:54:
- closedate changed to: "2460067.42146787"
- closer changed to: "pointsman"
- icomment:
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]
- login: "pointsman"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"