Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

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

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. 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 with test cases illustrating that.
    
  5. is_private changed to: "0"
  6. login: "sebres"
  7. priority changed to: "5 Medium"
  8. resolution changed to: "None"
  9. severity changed to: "Minor"
  10. status changed to: "Open"
  11. submitter changed to: "sebres"
  12. subsystem changed to: "45. Parsing and Eval"
  13. title changed to:
    Tcl_SaveInterpState/Tcl_RestoreInterpState are not usable to save interpreter state (error info/code)
    
  14. type changed to: "Bug"