'gets' repeated after EOF doesn't work
Closed / Fixed5adc3506834c2aacc613cd0df7de6f07a728c0aaCreated 12 years agoUpdated 12 years ago
Descriptionplain2014-10-26 04:58:04
My program repeats attempts to read file after EOF condition appeared on it. The program looks for any new lines appended to that file. The program works with Tcl 8.5, but it doesn't see any new lines with Tcl 8.6. Here's the test: $ cat read-after-eof.tcl puts "Tcl patchlevel: [info patchlevel]" set h [open ./read-after-eof.txt] read $h set text [clock seconds] exec cat >>./read-after-eof.txt << $text puts "gets after EOF returns: '[gets $h]'" $ echo "" >read-after-eof.txt $ /opt/ActiveTcl-8.5/bin/tclsh read-after-eof.tcl Tcl patchlevel: 8.5.15 gets after EOF returns: '1414267142' $ echo "" >read-after-eof.txt $ /opt/ActiveTcl-8.6/bin/tclsh read-after-eof.tcl Tcl patchlevel: 8.6.2 gets after EOF returns: ''
Referenced by4
16bdf667aa[5adc350683] Stop Tcl forcing EOF condition on channels to be permanent. It may be fleeting, and all parts of Tcl channel ecosystem have to deal with that. New assertions and tests to keep us on track. check-in2014-11-06 16:34:03bd09a69e14[5adc350683] Stop Tcl forcing EOF condition on channels to be permanent. It may be fleeting, and all parts of Tcl channel ecosystem have to deal with that. New assertions and tests to keep us on track. check-in2014-11-06 16:24:0277bf4ea593[5adc350683] Reworked the management of the EOF states to re-enable the ability to read beyond EOF. Plenty of assert()s to keep thing from going off track again. check-in2014-11-03 20:39:2519b8cc5448Base test for [5adc350683]. check-in2014-10-29 14:54:11
dgpplain2014-10-26 19:00:16
You will find the same results in 8.5.16 and 8.6.17. A reworking of I/O leading up to 8.5.16 and 8.6.2 included as one of its premises that "EOF" means "end of any new bytes to be read from this channel". There a number of reasons for this, which I won't go into in detail right at the moment. (Better to be correct than to be quick.) While I ponder the use case in this ticket and whether and how it might prompt an effort to recover what it desires, I can at least offer a way to accomplish what is desired. Between the [exec cat....] and the final [puts ...] commands in the demo script above, insert this command: seek $h 0 current The resulting modified script should work as you wish in all new and old Tcl interps.
dgpplain2014-10-26 19:01:23
> You will find the same results in 8.5.16 and 8.6.17. That should refer to 8.5.16 and 8.5.17.
dgpplain2014-10-28 20:11:58
See bug-5adc350683 branch for work in progress restoring the capability, as well as addressing what the non-permanence of EOF on a read channel means for things like channel stacks and transformations.
dgpplain2014-10-29 20:34:09
The key routine here is GetInput(). Every caller of GetInput() has to (when otherwise warranted) make at least one call to GetInput() -- even if EOF is already set on the channel -- in order to enable the moving past EOF, and reading whatever new data may be available now. On the other hand, every caller of GetInput() must not make an additional call to GetInput() after a call to GetInput() has left EOF set in the channel. As soon as a call to GetInput() leaves EOF set in the channel, the caller must be on a path to return to its caller without calling GetInput() again. This must be achieved so that a fleeting EOF condition is not missed by the caller. There are 4 callers of GetInput(): TclGetsObjBinary(), FilterInputBytes(), DoReadChars(), and DoRead().
dgpplain2014-11-06 16:38:18
Fix committed for 8.5.18 and 8.6.3.
Log in (anonymous is fine) to add a comment.