Skip to content
Tcl Source Code History Of Ticket 2407783fffffffffffffffffffffffffffffffff
Login

History Of Ticket 2407783fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 2407783fffffffffffffffffffffffffffffffff

  1. Ticket change [d229dd74bf] (rid 113481) by sbron on 2008-12-08 22:44:14:

    1. assignee initialized to: "hobbs"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      I noticed that 'seek 0' on a file handle makes the handle accessible in all interps. I can't find any evidence in the docs that this is the intended behavior.
      
      Example: The following script will dump 2 x four bytes from /dev/random:
      
      interp create foo
      interp create bar
      
      set f [open /dev/random rb]
      
      interp eval foo {
          proc bytes {fh} {
              binary scan [read $fh 4] H* hex
              puts $hex
              close $fh
          }
      }
      
      interp eval bar {
          proc bytes {fh} {
              binary scan [read $fh 4] H* hex
              puts $hex
              close $fh
          }
      }
      
      seek $f 0
      interp eval foo [list bytes $f]
      interp eval bar [list bytes $f]
      close $f
      
      Without the seek command it reports an error as expected:
      can not find channel named "file5"
          while executing
      "read $fh 4"
          (procedure "bytes" line 2)
          invoked from within
      "bytes file5"
          invoked from within
      "interp eval foo [list byte $f]"
      
      
      SuSE linux 11.0
      Kernel 2.6.25.18-0.2-pae
      Tcl 8.5.5
      
      
    4. foundin initialized to: "obsolete: 8.5.5"
    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: "sbron"
    10. subsystem initialized to: "20. [interp]"
    11. title initialized to:
      Seek causes IO channel to be shared between all interps
      
    12. type initialized to: "Bug"
  2. Ticket change [dc9e3883d7] (rid 114512) by dkf on 2008-12-09 18:47:32:

    1. assignee changed to: "andreas_kupries"
    2. icomment:
      Diagnosis: leakage of file handle through Tcl_Obj internal rep. Problem is not [seek] itself, but rather Tcl_GetChannelFromObj.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. priority changed to: "9 Immediate"
    6. subsystem changed to: "25. Channel System"
    7. username: "dkf"
  3. Ticket change [658b72b65c] (rid 102566) by andreas_kupries on 2008-12-10 03:47:33:

    1. icomment:
      Ok, coming to this I see the problem in 8.5, but not 8.6/Head. As I also saw a commit by dkf to tclIO.c I am assuming right now that the 'Refactoring tclIO.c' commit was (intended as) a fix for this. Meaning that I 'just' have to back port it. Is that correct, Donal ?
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  4. Ticket change [59fd343d06] (rid 118065) by hobbs on 2008-12-10 05:54:02:

    1. icomment:
      Donal's changes do not look like they intentionally changed any behavior.  I'm skeptical that TclGetChannelFromObj is the source of the issue as it layers over Tcl_GetChannel, which maintains a table in the assocData of a single interp, and uses Tcl_Objs, which should not be shared.  Am I missing something?
      
      
    2. login: "hobbs"
    3. mimetype: "text/plain"
    4. username: "hobbs"
  5. Ticket change [3e975247cd] (rid 121297) by andreas_kupries on 2008-12-10 05:55:11:

    1. icomment:
      Note 1: There is no Tcl_GetChannelFromObj(). Only a TclGetChannelFromObj(). I.e. internal, not public.
      Note 2: Trying to trace where the fix is in all the unrelated changes is ... not fun. There do not seem to be any changes to fix it.
      
      Tracing the TclGetChannelFromObj a bit it seems that in 8.6 something invalidates the intrep after the seek, before the 'puts' in interp foo is reached. So far no idea what.
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  6. Ticket change [025a9fea70] (rid 119631) by andreas_kupries on 2008-12-10 05:58:06:

    1. icomment:
      @jeffh: The intrep of tclChannelType is the statePtr (ChannelState) of a channel, without an association to an interp. This means a Tcl_Obj with vlaid intrep can carry a channel into an interp which actually doesn't know, and it will be properly used by direct access to its state, without looking it up anywhere.
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  7. Ticket change [47edeb6eb3] (rid 99794) by andreas_kupries on 2008-12-10 06:06:03:

    1. icomment:
      Ok, I was possibly not too clear.
      SetChannelFromAny (SCFA) uses Tcl_GetChannel.
      However if and only if the intrep is not already tclChannelType. 
      If the intrep is properly tclChannelType it pulls the ChannelState*
      directly out of the intrep, and now we have direct access to a channel
      which may not be known to the interpreter we are in, because the intrep
      was set in a different interpreter.
      So, even with a properly typed intrep we have to recheck that the channel
      we got is actually known in the current interp, and the same.
      
      Best would be to not only store channelstate*, but also interp* of the interp which set the intrep. The moment we are in a different interp we invalidate and recompute the intrep. sort of like cmd resolution intreps.
      
      
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  8. Ticket change [0bfc2c0ac2] (rid 114095) by andreas_kupries on 2008-12-10 06:27:30:

    1. icomment:
      
      
      File Added - 304737: channel-intrep.patch
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  9. Add attachment "channel-intrep.patch" [d5213a08f1] (rid 123564) by andreas_kupries on 2008-12-10 06:27:30.

  10. Ticket change [36774aacb1] (rid 107107) by andreas_kupries on 2008-12-10 06:27:58:

    1. icomment:
      Added patch containing my proposed fix.
      dkf, schelte, please review.
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  11. Ticket change [e0eb25d16f] (rid 87357) by dkf on 2008-12-10 06:28:49:

    1. icomment:
      sounds like a reasonable fix. You also probably need to check an epoch counter or something like that so that if the channel is deleted and reallocated, that can be handled too...
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  12. Ticket change [b4d1689327] (rid 125109) by andreas_kupries on 2008-12-10 06:48:35:

    1. icomment:
      I do not believe that an epoch is required.
      SCFA checks the flags of the preserved channelState for CHANNEL_CLOSED.
      If that is true it already invalidated and refetched the intrep.
      This should handle the close/reopen case.
      
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  13. Ticket change [584c3e731e] (rid 117774) by dkf on 2008-12-10 17:07:58:

    1. icomment:
      If interpreter boundaries are the only concern (the "preservation within an interp" issue is a great thing to have a test case on in any case) then the patch is good. Needs a test, but that can probably be adapted from the bug report.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  14. Ticket change [bdd28214dc] (rid 101972) by dgp on 2008-12-10 21:11:15:

    1. icomment:
      
      comments on the chat indicated the
      solution here involved having the
      intrep of a Tcl_Obj set a Tcl_Preserve
      on a struct, with a matching Tcl_Release
      when the intrep is shimmered away.
      
      That's fine as a stopgap, but if at
      all possible, the need to do that
      means the preserved struct really
      needs its own refCount field.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  15. Ticket change [80b04221cc] (rid 116912) by andreas_kupries on 2008-12-11 00:09:44:

    1. icomment:
      @dgp: A bit of clarification.
      
      The functions of tclChannelType do indeed Tcl_Preserve/Release ChannelState pointers. This is however not because of my fix. They did that even before I put my hands into this particular pie. As such it is an integral part of this TclObjTyp I was not really willing to change for my fix. What I did was to extend this scheme to the Interp pointer I added to the intrep. It might actually not be necessary, as the Interp pointer is only copied and compared, never de-referenced, contrary to the ChannelState.
      
      I should further note that ChannelState structures actually have a refCount. This however is used to count how many interpreters have the the channel Tcl_RegisterChannel()'ed in them, and a refCount > 0 prevents fully closing the channel. I do not believe that it is a good idea to use this refCount to count how many Tcl_Obj refer to this channel. As it means that a 'close $f' will never really close the channel, but only at some arbitrary time later when the last intrep goes away. Which actually may be never during the lifetime of an interp.
      
      I will see that I can get a test done for 8.5 and 8.6 in the next days, and then check if may Preseve/Release of the Interp* was overkill. Likely yes. If so I will remove that part of the patch.
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  16. Add attachment "tcl85.diff-wu" [2ca61dcd08] (rid 118941) by andreas_kupries on 2008-12-11 07:37:08.

  17. Ticket change [12b0d736a8] (rid 124086) by andreas_kupries on 2008-12-11 07:37:09:

    1. icomment:
      
      
      File Added - 304858: tcl85.diff-wu
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  18. Add attachment "tcl86.diff-wu" [35eb151d48] (rid 107024) by andreas_kupries on 2008-12-11 07:37:52.

  19. Ticket change [5ab3936fd7] (rid 118188) by andreas_kupries on 2008-12-11 07:37:52:

    1. icomment:
      
      
      File Added - 304859: tcl86.diff-wu
      
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  20. Ticket change [94b9aacbcf] (rid 106040) by sbron on 2008-12-11 15:44:12:

    1. icomment:
      I don't know enough of the internals of Tcl to be able to give a theoretical opinion about the patch. I have confirmed that it works in practice with the application where I found the issue.
      
      One additional remark: I found that this bug was not present in Tcl 8.5.2. It must have been introduced in Tcl 8.5.3 or 8.5.4.
      
      
      
    2. login: "sbron"
    3. mimetype: "text/plain"
    4. username: "sbron"
  21. Ticket change [aa31dee268] (rid 99284) by andreas_kupries on 2008-12-12 00:31:16:

    1. icomment:
      Applied patches to both 8.5 and head.
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  22. Ticket change [6b312ea02c] (rid 128276) by andreas_kupries on 2008-12-12 00:31:26:

    1. closedate changed to: "2008-12-11T17:31:26"
    2. closer changed to: "andreas_kupries"
    3. resolution changed to: "Fixed"
    4. status changed to: "Closed"