Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 733ee1b91ddfbba979c7ca5fe2f1684dcbfaf37d09bb37591ab19098ea24ed14
Ticket: 554117eddec7220f1cda04c16cc45a77d6c175e0
Tcl_SaveInterpState/Tcl_RestoreInterpState are not usable to save interpreter state (error info/code)
User & Date: sebres on 2020-02-10 16:44:27
Changes

  1. comment changed to:
    Current implementation of <code>Tcl_SaveInterpState/Tcl_RestoreInterpState</code> does not consider (legacy) copy of interpreter state (errorInfo/errorCode variables), which can produce unexpected behavior overwriting both values like in following example:
    <code><pre style="padding-left:10pt">
    if {[catch {
       ... same code X producing error ...
    } msg]} {
       log INFO "unexpected error in block X: $msg"
       log DEBUG $::errorCode $::errorInfo
    }
    </pre></code>
    if routine log (can evaluate something in interp and even generate temporary errors) does "safe" handling to save interp state (uses Tcl_SaveInterpState/Tcl_RestoreInterpState), it can overwrite <code>::errorInfo</code> and <code>::errorCode</code> or rather does not restore both properly, if some <code>Tcl_ResetResult</code> (called internally) resets interim <code>iPtr->errorInfo</code> and <code>iPtr->errorCode</code> to NULL.
    
    This causes that system traces observing <code>::errorInfo</code> and <code>::errorCode</code> do nothing (because iPtr states are NULL) and both variables remain overwritten values.
    
    Although I know that <code>::errorInfo</code> and <code>::errorCode</code> are legacy either and one should rather use option dictionary (second parameter after msg variable in catch), but <code>Tcl_SaveInterpState/Tcl_RestoreInterpState</code> are pretty unusable together with any kind of evaluation (especially because <code>Tcl_ResetResult</code> is involved in-between internally, and it is almost always the case).
    
    The error is initially noticed in [https://github.com/sebres/tclclockmod/issues/19#issuecomment-582639778|GH/sebres/tclclockmod/issues/19#issuecomment-582639778].
    
    But now I have a branch [/timeline?r=bug-554117edde|bug-554117edde] with test cases [95db6756e8bd9f96] illustrating that.
    
  2. icomment:
    As one can see both 1.9.* test cases fails:
    <code><pre style="padding-left:10pt">
    ==== result-1.9.1 Tcl_SaveInterpState: "safe" eval without modifying states FAILED
    ...
    ---- Result was:
    <b style="color:red">{UNEXPERR INVISIBLE} {ERROR in safe block}</b>
    ---- Result should have been (exact matching):
    {EXPERR TEST-ERROR} {ERROR expected error}
    ==== result-1.9.1 FAILED
    
    
    ==== result-1.9.2 Tcl_SaveInterpState: nested save state does not modify error info/code FAILED
    ...
    ---- Result was:
    <b style="color:red">0 {UNEXPERR INVISIBLE} {ERROR in safe block}</b>
    ---- Result should have been (exact matching):
    0 {EXPERR TEST-ERROR} {ERROR expected error}
    ==== result-1.9.2 FAILED
    </pre></code>
    
  3. login: "sebres"
  4. mimetype: "text/x-fossil-wiki"