Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 08d22588bd555280a108bd0e3ca85823dae0739a
Ticket: 1499394fffffffffffffffffffffffffffffffff
TIP 285: Script Cancellation with Tcl_CancelEval
User & Date: mistachkin on 2006-06-12 15:45:01
Changes

  1. icomment:
    Logged In: YES 
    user_id=113501
    
    
    The v4 patch is basically code complete.  However, I'm still
    working on the documentation and test cases for [cancel].
    
    Quite a lot of fine tuning has been done to both the new
    code and the comments.  The Tcl_CancelEval function now
    accepts a new flag TCL_CANCEL_UNWIND that allows the
    evaluation stack for the target interpreter to be completely
    unwound in the event of the pathological test cases like:
    
    while {1} { catch { while {1} {incr x} } }
    
    Here are some other test cases that work correctly with the
    v4 patch:
    
    # Tcl_CancelEval after delay test
    # returns TCL_ERROR "eval cancelled" or "eval unwound" 
    # based on flags passed to Tcl_CancelEval
    after 30000
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval vwait test
    # returns TCL_ERROR "eval cancelled" or "eval unwound" 
    # based on flags passed to Tcl_CancelEval
    vwait forever
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval very tight loop test
    # returns TCL_ERROR "eval cancelled" or "eval unwound" 
    # based on flags passed to Tcl_CancelEval
    while {1} {}
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval tight loop with body test
    # returns TCL_ERROR "eval cancelled" or "eval unwound" 
    # based on flags passed to Tcl_CancelEval
    while {1} {incr x}
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval with TCL_CANCEL_UNWIND test.
    # This can only be cancelled if the TCL_CANCEL_UNWIND
    # flag is used with Tcl_CancelEval.  It will return 
    # TCL_ERROR "eval unwound" in that case.
    while {1} { catch { while {1} {incr x} } }
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval with TCL_CANCEL_UNWIND slightly more 
    # pathological unwind test
    # returns TCL_ERROR "eval unwound" 
    while {1} {
      catch { 
        while {1} {
          catch { 
            while {1} {incr x}
          } 
        } 
      } 
    }
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval slave interp test
    # returns TCL_ERROR "eval cancelled" or "eval unwound" 
    # based on flags passed to Tcl_CancelEval
    interp create foo; foo eval { while {1} {incr x} }
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval [subst] test
    # returns TCL_ERROR "eval cancelled" or "eval unwound" 
    # based on flags passed to Tcl_CancelEval
    subst {[while {1} {incr x}]}
    
    ----------------------------------------------------------
    
    # Tcl_CancelEval with TCL_CANCEL_UNWIND pathological slave 
    # interp test
    # returns TCL_ERROR "eval unwound"
    interp create foo; foo eval {
      while {1} {
        catch { 
          while {1} { 
            catch { 
              while {1} {incr x}
            }
          }
        } 
      } 
    }
    
    ----------------------------------------------------------
    
    # basic [cancel] test
    # returns TCL_ERROR "eval cancelled"
    cancel
    
    ----------------------------------------------------------
    
    # basic [cancel] test with "--"
    # returns TCL_ERROR "eval cancelled"
    cancel --
    
    ----------------------------------------------------------
    
    # basic [cancel -unwind] test
    # returns TCL_ERROR "eval unwound"
    cancel -unwind --
    
    ----------------------------------------------------------
    
    # [cancel] test
    # returns TCL_ERROR "eval cancelled"
    catch {unset foo i}
    while {1} {
      incr i; lappend foo $i
      # pretend this is some complex 
      # logic or Tk button command.
      if {$i > 3} then {cancel} 
    }
    
    ----------------------------------------------------------
    
    # [cancel -unwind] test
    # returns TCL_ERROR "eval unwound"
    catch {unset foo i}
    while {1} { 
      catch { 
        while {1} { 
          incr i; lappend foo $i
          # pretend this is some complex 
          # logic or Tk button command.
          if {$i > 3} then {cancel -unwind} 
        }
      } 
    }
    
    ----------------------------------------------------------
    
    # recursion test
    # returns TCL_ERROR "eval cancelled"
    proc foo { i } {
      if {$i > 10} then { 
        cancel 
      } else {
        return [foo [expr {$i + 1}]] 
      }
    }; foo 0
    
    
    
  2. login: "mistachkin"
  3. mimetype: "text/plain"
  4. username: "mistachkin"