Skip to content

Commit

Permalink
Fix a case of lf not being flushed in certain cases when the crlf seq…
Browse files Browse the repository at this point in the history
…uence gets split across two buffers on channels in crlf mode with line buffering [https://core.tcl-lang.org/tcllib/tktview?name=c9d8a52fe]
  • Loading branch information
max committed Aug 4, 2022
1 parent 4036ad6 commit 00abbc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions generic/tclIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -4435,8 +4435,8 @@ Write(
}
ReleaseChannelBuffer(bufPtr);
}
if ((flushed < total) && (GotFlag(statePtr, CHANNEL_UNBUFFERED) ||
(needNlFlush && GotFlag(statePtr, CHANNEL_LINEBUFFERED)))) {
if (((flushed < total) && GotFlag(statePtr, CHANNEL_UNBUFFERED)) ||
(needNlFlush && GotFlag(statePtr, CHANNEL_LINEBUFFERED))) {
if (FlushChannel(NULL, chanPtr, 0) != 0) {
return -1;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/io.test
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ test io-3.8 {WriteChars: reset sawLF after each buffer} {
close $f
lappend x [contents $path(test1)]
} [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"]
test io-3.9 {Write: flush line-buffered channels when crlf is split over two buffers} -body {
# https://core.tcl-lang.org/tcllib/tktedit?name=c9d8a52fe
set f [open $path(test1) w]
fconfigure $f -buffering line -translation crlf -buffersize 8
puts $f "1234567"
string map {"\r" "<cr>" "\n" "<lf>"} [contents $path(test1)]
} -cleanup {
close $f
} -result "1234567<cr><lf>"

test io-4.1 {TranslateOutputEOL: lf} {
# search for \n
Expand Down

0 comments on commit 00abbc6

Please sign in to comment.