Skip to content
Tcl Source Code History Of Ticket 2176669fffffffff
Login

History Of Ticket 2176669fffffffff

Artifacts Associated With Ticket 2176669fffffffff

  1. Ticket change [3da5c21232] (rid 121122) by nobody on 2008-10-18 11:57:20:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. 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. 
      
      
      
    4. foundin initialized to: "obsolete: 8.4.19"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "nobody"
    10. subsystem initialized to: "25. Channel System"
    11. title initialized to: "Strange seek bug"
    12. type initialized to: "Bug"
  2. Ticket change [3a9a2edf25] (rid 112583) by ferrieux on 2008-10-20 04:54:44:

    1. 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 ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  3. Ticket change [870933b25d] (rid 131623) by nobody on 2008-10-21 05:37:28:

    1. 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...
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. username: "[email protected]"
  4. Ticket change [f6e640bf17] (rid 130394) by ferrieux on 2008-10-21 06:28:40:

    1. icomment:
      Oops I forgot both to login and to attach the file, sorry ;-)
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  5. Add attachment "seek.diff" [2eab755dba] (rid 92931) by ferrieux on 2008-10-21 06:28:49.

  6. Ticket change [a597bf5264] (rid 110402) by ferrieux on 2008-10-21 06:28:49:

    1. icomment:
      
      
      File Added - 298169: seek.diff
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  7. Ticket change [2f4c8fcdbe] (rid 93037) by ferrieux on 2009-11-18 06:20:51:

    1. priority changed to: "8"
  8. Ticket change [6d36ced4a7] (rid 128653) by andreas_kupries on 2009-11-21 02:03:20:

    1. 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.
      
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  9. Add attachment "maketestfile.tcl" [1d72017407] (rid 90807) by andreas_kupries on 2009-11-21 02:47:12.

  10. Ticket change [93badca408] (rid 105862) by andreas_kupries on 2009-11-21 02:47:12:

    1. icomment:
      
      
      File Added - 351873: maketestfile.tcl
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  11. Ticket change [a48409b271] (rid 110219) by andreas_kupries on 2009-11-21 02:48:01:

    1. icomment:
      
      
      File Added - 351874: wr.tcl
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  12. Add attachment "wr.tcl" [40f7a998d5] (rid 116101) by andreas_kupries on 2009-11-21 02:48:01.

  13. Ticket change [849a44bfb1] (rid 117579) by andreas_kupries on 2009-11-21 02:49:35:

    1. 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.
      
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  14. Ticket change [43f1acc919] (rid 116638) by andreas_kupries on 2009-11-21 04:35:18:

    1. icomment:
      I believe this is a limitation which we should just document somewhere (seek ?), with example.
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  15. Ticket change [1c40741780] (rid 90568) by ferrieux on 2009-11-22 06:04:02:

    1. 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 ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  16. Ticket change [e882593c70] (rid 104655) by ferrieux on 2009-11-22 17:51:02:

    1. 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.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  17. Ticket change [1735af0af7] (rid 122450) by andreas_kupries on 2009-12-10 06:05:33:

    1. icomment:
      This artifact has been marked as a duplicate of artifact 2901998 with reason:
      Same thing internally, buffered output was not flushed before read
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. status changed to: "Closed"
    5. username: "andreas_kupries"
  18. Ticket change [cba7a36cfa] (rid 95555) by andreas_kupries on 2009-12-10 06:05:51:

    1. resolution changed to: "Duplicate"