Artifacts Associated With Ticket 2176669fffffffffffffffffffffffffffffffff
Ticket change [3da5c21232] (rid 121122) by nobody on 2008-10-18 11:57:20:
- assignee initialized to: "andreas_kupries"
- cmimetype initialized to: "text/plain"
- comment initialized to:
I've got strange seek behavior executing this simple script (Windows XP, tcl 8.4.19/8.5.2/8.6a1): --- exp.tcl --- set fd [open hash.db r+] seek $fd 100 puts [tell $fd] puts -nonewline $fd 0 puts [tell $fd] read $fd 2 seek $fd 0 puts [tell $fd] --- Result is: 100 101 error during seek on "filea3bf40": bad address in system call argument while executing "seek $fd 0" (file "exp.tcl" line 8) ------------ It seems that it originates from here: ----- tclIO.c ----- ... In Tcl_Seek: /* * Compute how much input and output is buffered. If both input and output * is buffered, cannot compute the current position. */ inputBuffered = Tcl_InputBuffered(chan); outputBuffered = Tcl_OutputBuffered(chan); if ((inputBuffered != 0) && (outputBuffered != 0)) { Tcl_SetErrno(EFAULT); return Tcl_LongAsWide(-1); } -------- So, [flush]-ing channel before seeking helps. I didn't find this documented anywhere. Moreover, as Alexandre Ferrieux said, [seek] is documented to flush the output side. - foundin initialized to: "obsolete: 8.4.19"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "25. Channel System"
- title initialized to: "Strange seek bug"
- type initialized to: "Bug"
Ticket change [3a9a2edf25] (rid 112583) by ferrieux on 2008-10-20 04:54:44:
- icomment:
Looking at the code in Tcl_Seek, there's something I don't understand: a few lines below the above test against simultaneous input and output data buffered, there is: DiscardInputQueued(statePtr, 0); whose effect is to guaranteed nothing's left in the input buffer chain. So, why not do it first, and avoid the error ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [870933b25d] (rid 131623) by nobody on 2008-10-21 05:37:28:
- icomment:
The attached patch fixes that strange behavior *and* passes the test suite. The idea is that the check was useless because of the DiscardInputQueued(). The important part which I kept is the if (mode == SEEK_CUR) { offset -= inputBuffered; } What is unclear to me though, is the reason for this check... - login: "[email protected]"
- mimetype: "text/plain"
- username: "[email protected]"
- icomment:
Ticket change [f6e640bf17] (rid 130394) by ferrieux on 2008-10-21 06:28:40:
- icomment:
Oops I forgot both to login and to attach the file, sorry ;-)
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Add attachment "seek.diff" [2eab755dba] (rid 92931) by ferrieux on 2008-10-21 06:28:49.
Ticket change [a597bf5264] (rid 110402) by ferrieux on 2008-10-21 06:28:49:
- icomment:
File Added - 298169: seek.diff
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [2f4c8fcdbe] (rid 93037) by ferrieux on 2009-11-18 06:20:51:
- priority changed to: "8"
Ticket change [6d36ced4a7] (rid 128653) by andreas_kupries on 2009-11-21 02:03:20:
- icomment:
Notes ... Regarding "[seek] is documented to flush the output side. " Yes. That happens too. It happens quite a bit after the check which fails here.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Add attachment "maketestfile.tcl" [1d72017407] (rid 90807) by andreas_kupries on 2009-11-21 02:47:12.
Ticket change [93badca408] (rid 105862) by andreas_kupries on 2009-11-21 02:47:12:
- icomment:
File Added - 351873: maketestfile.tcl
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [a48409b271] (rid 110219) by andreas_kupries on 2009-11-21 02:48:01:
- icomment:
File Added - 351874: wr.tcl
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Add attachment "wr.tcl" [40f7a998d5] (rid 116101) by andreas_kupries on 2009-11-21 02:48:01.
Ticket change [849a44bfb1] (rid 117579) by andreas_kupries on 2009-11-21 02:49:35:
- icomment:
I have attached 2 scripts, one generating the test input file for the other. The other, wr.tcl, should explain why having both input and output buffered is a bad thing regarding seek and tell, i.e. why they are reported as error. See the comments in the script.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [43f1acc919] (rid 116638) by andreas_kupries on 2009-11-21 04:35:18:
- icomment:
I believe this is a limitation which we should just document somewhere (seek ?), with example.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [1c40741780] (rid 90568) by ferrieux on 2009-11-22 06:04:02:
- icomment:
Looking in detail at your example, I'm a bit surprised by yet another effect of this internal I/O conflict: after the 1-byte [puts], if we ask [tell] (which your example doesn't do), we get 1 of course. But then, at script level, how do we explain the fact that the subsequent [read] starts from the beginning of the file ? In other words, if we forget about the underlying OS file position and concentrate on the only Tcl-visible thing which is what [tell/seek] manipulate, it seems only logical to assume it is *both* a read and write pointer (otherwise we'd need extra API to separate them). Then after writing one byte we're at position 1, and the subsequent [read 2] should read from that position, and hence return the 2nd and 3rd byte of the file ("0a" here). Of course the implication of such a semantics is that a read might incur a flush (otherwise costly overlap computations are needed). So what ? Apart from the POTENTIAL INCOMPATIBILITY, what's wrong with such a simplified "Tcl r/w file pointer" concept ? - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [e882593c70] (rid 104655) by ferrieux on 2009-11-22 17:51:02:
- icomment:
Previous comment now promoted to a bug by itself: 2901998. The reason is that it is simpler and more spectacular. Note that the fix I propose (assuming the potential incompatibility is validated as benign) would solve both.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [1735af0af7] (rid 122450) by andreas_kupries on 2009-12-10 06:05:33:
- icomment:
This artifact has been marked as a duplicate of artifact 2901998 with reason: Same thing internally, buffered output was not flushed before read
- login: "andreas_kupries"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "andreas_kupries"
- icomment:
Ticket change [cba7a36cfa] (rid 95555) by andreas_kupries on 2009-12-10 06:05:51:
- resolution changed to: "Duplicate"