Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a29f465408987fbde7740aca0b397a8b9c987b8e
Ticket: 2152286fffffffffffffffffffffffffffffffff
TCL_RETURN causes TclUpdateReturnInfo() to panic
User & Date: dgp on 2008-10-20 01:52:36
Changes

  1. icomment:
    
    The error here is in the evaluation
    of [cproc 1].  With a single argument
    the branch is taken that evaluates
    [tclproc].  If you examine the return
    code from that Tcl_Eval(), you will
    find that it is TCL_OK.  The command
    [tclproc] has run successfully.
    
    You then turn around and originate a
    TCL_RETURN return code, without
    dealing with the fact that an
    intervening Tcl_Eval() has taken
    the interp out of the reset state
    it had when it entered CProcCmd.
    
    There are a number of ways to
    fix the code, depending on just
    what it is this code is intended
    to do.  That is not clear at all
    from the example, which feels 
    contrived to demo the conditions
    for panic, more than directed
    toward any rational purpose.  That's
    fine; that's often true of bug
    demos, but leaves me without any
    context to choose what alternative
    might make sense.
    
    If you have a Tcl_ObjCmdProc that
    will return TCL_RETURN, you should
    either do that with the interp
    still in its original reset state,
    or do that after something you called
    also returned TCL_RETURN (the "pass
    along the exception" case), or take
    care to call Tcl_SetReturnOptions()
    to set the relevant options as needed
    for your command (the "I'm originating
    TCL_RETURN for my own purposes" case).
    
    It seems to me the panic is serving
    exactly the purpose intended, to call
    attention to C code that's not robust
    or safe so it can get corrected.
    
    Note that your workarounds are just
    tricky indirect ways to take my advice.
    Explicit returnLevel increment is just
    a sneaky "probe the internals" way to
    accomplish what a proper Tcl_SetReturnOptions()
    call would do.  The dummy proc call is just
    a very indirect way to call the
    Tcl_ResetResult() you need to get the
    interp back to an initial state where
    simple return of TCL_RETURN will cause
    no trouble.
    
    Hope that helps.  I'll keep this report
    pending in case you want to comment
    further or seek advice.
    
    
    
  2. login: "dgp"
  3. mimetype: "text/plain"
  4. username: "dgp"