Skip to content
Tcl Source Code History Of Ticket 633204ffffffffff
Login

History Of Ticket 633204ffffffffff

Artifacts Associated With Ticket 633204ffffffffff

  1. Ticket change [a668ba05d1] (rid 98595) by nobody on 2002-11-04 11:05:42:

    1. assignee initialized to: "msofer"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      
      In TCL 8.4.1: 
      
      % info patchlevel
      8.4.1
      % catch { return foo }
      2
      % proc foo {} { catch { return foo } }
      % foo
      0
      %
      
      ???  Putting the code inside a proc changes the return value?
      These should return the same thing.  In Tcl 8.3.3 
      
      % info patchlevel
      8.3.3
      % catch { return foo }
      2
      % proc foo {} { catch { return foo } }
      % foo
      2
      %
      
      Since the behaviour changes when the code is put inside a proc, 
      I *suspect* a bytecode compiler bug.
      
      Details: 
      
      Tcl 8.4.1
      $ uname -a
      SunOS xxxxxxxx 5.7 Generic_106541-10 sun4u sparc 
      SUNW,UltraSPARC-IIi-cEngine
      $ gcc --version
      2.95.2
      
      
    4. foundin initialized to: "obsolete: 8.4.1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "47. Bytecode Compiler"
    10. title initialized to: "catch { return foo } breaks inside proc "
    11. type initialized to: "Bug"
  2. Ticket change [22f191e388] (rid 130841) by msofer on 2002-11-05 07:19:16:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      Blast, bitten by bothersome bytecode bug! I do not
      immediately see how to fix this one :(
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  3. Ticket change [d8671ff718] (rid 107430) by dgp on 2002-12-05 06:46:01:

    1. assignee changed to: "dgp"
  4. Ticket change [e4766c0eb5] (rid 87953) by dgp on 2002-12-12 05:38:59:

    1. assignee changed to: "msofer"
    2. icomment:
      Logged In: YES 
      user_id=80530
      
      This must be a bug in the
      byte-compiling of [catch].
      
      Compare with:
      
      % proc foo {} {
      set catch catch
      $catch {return foo}
      }
      % foo
      2
      
      and
      
      % proc bar {} {
      set script {return foo}
      catch $script
      }
      % bar
      2
      
      Only the literal "catch {return foo}"
      is causing trouble, indicating some
      mistaken "optimization" in the
      bytecode.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  5. Ticket change [56d3049ca3] (rid 94389) by dgp on 2002-12-12 23:13:52:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      Is this bug found in line 343 of
      tclCompCmds.c ?  The
      comment on lines 329-333 says:
      
          /*
           * The "no errors" epilogue code: store the body's
      result into the
           * variable (if any), push "0" (TCL_OK) as the catch's
      "no error"
           * result, and jump around the "error case" code.
           */
      
      but the result of [catch] should not always be TCL_OK.
      It should be whatever the return code of the $script
      argument was.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  6. Ticket change [90cb1c2abc] (rid 120514) by dgp on 2002-12-12 23:20:18:

    1. assignee changed to: "andreas_kupries"
    2. icomment:
      Logged In: YES 
      user_id=80530
      
      seems this bug has been lurking
      in there for years, but only the
      recent bytecompilation of [return]
      has made it easy to expose?
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  7. Ticket change [0b8b16ac62] (rid 114012) by dgp on 2002-12-13 01:13:18:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      No, think I misread things.
      Real problem doesn't appear
      to be that simple after all.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  8. Ticket change [c91e53c21c] (rid 122227) by dgp on 2002-12-13 01:20:23:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      Note an apparent workaround is
      to defeat the compiling of
      [return] like so:
      
      proc foo {} {catch {return -code ok foo}}
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [204d49999d] (rid 91289) by dgp on 2002-12-17 00:47:05:

    1. assignee changed to: "msofer"
    2. icomment:
      Logged In: YES 
      user_id=80530
      
      The BC execution engine appears
      to be capable of doing the right thing:
      
      % proc myreturn {} {return -code return}
      % proc a {} {catch return}
      % proc b {} {catch myreturn}
      % a
      0
      % b
      2
      
      So what path through TEBC does
      [a] take, and how can TEBC be
      corrected so that [b] takes a similar
      path?
      
      At least this seems to confirm that
      TEBC is capable of returning TCL_RETURN,
      and if TEBC does return TCL_RETURN,
      then TclObjInterpProc() will do the right thing.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  10. Ticket change [06f3e85c1a] (rid 89301) by hobbs on 2002-12-17 01:36:46:

    1. icomment:
      Logged In: YES 
      user_id=72656
      
      In 'myreturn', the return is not byte-compiled, but a 
      regular "return" would be.
      
      
    2. login: "hobbs"
    3. mimetype: "text/plain"
    4. username: "hobbs"
  11. Ticket change [d662e17d9b] (rid 123794) by dgp on 2002-12-17 01:52:36:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      Yes, but both the body of [a]
      and the body of [b] are bytecompiled, right?
      
      So the problem is that
      bytecompiled [return] is
      not returning TCL_RETURN, when
      it should be, just like "bytecompiled"
      [myreturn] does.
      
      The example just shows that the TEBC
      and TclObjInterpProc framwork can
      handle a TCL_RETURN properly, so
      what's the obstacle to fixing BC'd [return]
      to return the correct return code?
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  12. Ticket change [7dae16dbfb] (rid 97283) by msofer on 2002-12-17 02:47:30:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      When compiling the body of 'a', the compiler encounters a
      bcc'ed command 'catch and proceeds to compile its arguments;
      as they are also bcc'ed ('return'), the whole thing gets
      compiled into the body of 'a'.
      
      When compiling 'b', the compiler encounters a non-bcc'ed
      command 'myreturn', and compiles an invocation for it.
      
      The effect at runtime is: the 'return' of 'a' executes in
      the same TEBC instance as the proc body, there is no
      C-return involved. OTOH, the return of 'b' comes from a
      child instance of TEBC, via a real C-return.
      
      The internal return in the first case cannot be handled in
      the same manner: as it essentially executes in the same
      process, the return value of an inlined 'retun -code $x'
      *has* to be $x for (almost) everything to work as it should
      - the exception being what we're talking about here :(
      
      I imagine things could conceivably be repaired, but at a
      high complexity cost in the compiler: the return-compiler
      could check if it is compiling within a catch-range or not,
      and compile-in the correct return code: TCL_OK if it is not
      caught, TCL_RETURN otherwise. New idea, I'll think about
      that ...
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  13. Ticket change [56021038bc] (rid 94249) by dgp on 2002-12-18 06:07:30:

    1. icomment:
      
      
      File Added - 37850: return.patch
      
      Logged In: YES 
      user_id=80530
      
      Attached is a patch that appears to
      be an effective fix.
      
      I don't fully know what I'm doing 
      in the BC engine, so it's very
      likely not the best fix, but it appears
      to fix the bug, and test suite results
      are unchanged.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  14. Ticket change [36e39f8df1] (rid 107179) by dgp on 2002-12-18 06:15:34:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      Improved patch; same basic approach.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  15. Add attachment "return.patch" [8c7039aad9] (rid 127746) by dgp on 2002-12-18 06:15:34.

  16. Ticket change [f80095dcaa] (rid 91466) by dgp on 2002-12-18 06:15:35:

    1. icomment:
      
      
      File Deleted - 37850: 
      
      
      
      File Added - 37851: return.patch
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  17. Ticket change [cbc24b2a1c] (rid 95580) by dgp on 2002-12-19 00:42:10:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      The patch defines a new opcode in
      the bytecode execution engine.
      In order to maintain compatibility
      with external bytecode brought in
      by tbcload, new opcodes can only
      be defined for a new minor release
      of Tcl, so this patch can't be applied
      until 8.5 development.
      
      So,
      1. Can't add an opcode.
      2. No existing opcode returns TCL_RETURN,
      Therefore,
      the only correct fix that can be applied in the
      8.4.x timeframe is to disable bytecompiling
      of [return].
      
      A workaround that would still be buggy, but
      would correct the reported example script,
      would be to add special detection of an
      enclosing [catch] in TclCompileReturnCmd()
      and return TCL_OUT_LINE_COMPILE in
      that case.
      
      The remaining bug after that workaround
      would be harder to demo.  TEBC and
      TclCompEvalObj() should evaluate general
      Tcl scripts.  The bug is that they are
      implicitly converting TCL_RETURN to TCL_OK,
      as if they were only good for evaluating proc
      bodies.  This bug might still be exposed by
      C code that calls Tcl_EvalObjEx().
      
      Better to get to 8.5 development and get
      the correct fix in the BC engine with the
      new opcode.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  18. Ticket change [5962e202ee] (rid 117974) by dgp on 2002-12-19 05:42:38:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      The bugs I feared in calls to
      Tcl_EvalObjEx() are probably 
      prevented by lines 2401-2403
      of tclCompCmds.s where
      the bytecompiling of [return]
      is disabled if an enclosing proc
      is not detected.
      
      This is similar in spirit to the proposed
      workaround for this bug that
      involves disabling bytecompiling
      when an enclosing [catch] is
      present.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  19. Add attachment "workaround.patch" [7de3691444] (rid 97304) by dgp on 2002-12-19 06:56:14.

  20. Ticket change [3a7c944d00] (rid 112571) by dgp on 2002-12-19 06:56:14:

    1. icomment:
      
      
      File Added - 37922: workaround.patch
      
      Logged In: YES 
      user_id=80530
      
      Here's a patch that implements
      the workaround suitable for 8.4.x
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  21. Ticket change [47191c24d1] (rid 99631) by dgp on 2003-01-08 07:37:04:

    1. assignee changed to: "dgp"
    2. closedate changed to: "2003-01-08T00:37:04"
    3. closer changed to: "dgp"
    4. icomment:
      Logged In: YES 
      user_id=80530
      
      workaround patch committed.
      
      
    5. login: "dgp"
    6. mimetype: "text/plain"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
    9. username: "dgp"
  22. Ticket change [0847d9fb01] (rid 89536) by dgp on 2003-01-10 04:11:13:

    1. closedate changed to: "2003-01-09T21:11:13"
    2. closer changed to: "dgp"
    3. icomment:
      
      
      File Added - 39299: correction.patch
      
      Logged In: YES 
      user_id=80530
      
      Ack!  workaround.patch had an "off-by-one" error.
      
      Here's a correction.patch to fix things.
      
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. username: "dgp"
  23. Add attachment "correction.patch" [bb0a4bafa8] (rid 129411) by dgp on 2003-01-10 04:11:13.

  24. Ticket change [7d32fe9cc4] (rid 97205) by dgp on 2003-01-10 04:17:29:

    1. closedate changed to: "2003-01-09T21:17:29"
    2. closer changed to: "dgp"
    3. icomment:
      Logged In: YES 
      user_id=80530
      
      correction patch committed to HEAD.
      
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. username: "dgp"