Menu

#4428 C version of [try] assumes return -level 0

obsolete: 8.6b1
closed-fixed
5
2009-09-28
2009-09-23
No

Try this on CVS head:
proc mumu {} { try { return -level 3 123} finally {} }
catch mumu rv ro
it gives 0 as result, -code 0 -level 0 as $ro
and on tcl 8.6b1 it gives (rightly)
2 as result, -code 0 -level 2 as $ro

The problem is caused by using TclProcessReturn in the C [try] implementation. TclProcessReturn expects -code and -level from the options to be the same as code and level passed as parameters. [try] implementation, on the other hand, passes constant 0 as level, and it may be wrong.

Proposed solution is to use Tcl_SetReturnOptions instead of TclProcessReturn in [try] implementation. I think it's the best of available alternatives, because it's symmetric to Tcl_GetReturnOptions call that is used to obtain these options in the first place.

Diff is attached.

Discussion

  • Anton Kovalenko

    Anton Kovalenko - 2009-09-23

    Use Tcl_SetReturnOptions instead of TclProcessReturn for [try] implementation

     
  • Donal K. Fellows

    I've no time to look at this at a time when I'm alert enough. Assigning to someone who might know what to do (and who knows return options well...)

     
  • Donal K. Fellows

    • assigned_to: dkf --> dgp
     
  • Don Porter

    Don Porter - 2009-09-24

    Good catch.

    The comments before TclProcessReturn (hey, I
    wrote them for once!) give the constraints:

    "Note that the code argument must agree
    with the -code entry in returnOpts and the
    level argument must agree with the -level
    entry in returnOpts,..."

    Replacing with calls to Tcl_SetReturnOptions()
    will enforce this constraint, so the submitted
    patch is a correct one. Before accepting, I'll
    examine if there's a more direct way instead.

     
  • Don Porter

    Don Porter - 2009-09-24

    Appears to be another (potential?) error
    here on line 4432:

    result = TCL_ERROR;

    Since this comes between the time
    result is captured as the return code
    of the body evaluation, and the time
    it is passed back to TclProcessReturn(),
    it's at least an opportunity for the same
    constraint to fail.

     
  • Don Porter

    Don Porter - 2009-09-24

    Since preservation of the level is not
    provided for, and preservation of result
    is questionable, and since in time we expect
    most [try] evaluations to become bytecompiled,
    doesn't seem worthwhile to make revisions
    to permit more efficient, yet correct, calls
    to TclProcessReturn(). Accepting the submitted
    patch...

     
  • Don Porter

    Don Porter - 2009-09-28

    committed tests demonstrating related,
    but different failures.

     
  • Don Porter

    Don Porter - 2009-09-28

    * tests/error.test (error-15.9.*): More coverage tests for [try].
    Test error-15.9.3.0.0 covers [Bug 2855247].

     
  • Don Porter

    Don Porter - 2009-09-28

    * generic/tclCmdMZ.c: Replaced TclProcessReturn() calls with
    * tests/error.test: Tcl_SetReturnOptions() calls as a simple fix
    for [Bug 2855247]. Thanks to Anton Kovalenko for the report and fix.
    Additional fixes for other failures demonstrated by new tests.

     
  • Don Porter

    Don Porter - 2009-09-28
    • status: open --> closed-fixed
     
MongoDB Logo MongoDB