Artifacts Associated With Ticket 554117edde
Ticket change [5d6b49a2f1] (rid 179106) by sebres on 2020-02-10 16:35:07:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized 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. - is_private initialized to: "0"
- login: "sebres"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "sebres"
- subsystem initialized to: "45. Parsing and Eval"
- title initialized to:
Tcl_SaveInterpState/Tcl_RestoreInterpState are not usable to save interpreter state (error info/code)
- type initialized to: "Bug"
Ticket change [733ee1b91d] (rid 179112) by sebres on 2020-02-10 16:44:27:
- 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. - 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> - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- comment changed to:
Ticket change [4427912eac] (rid 179120) by sebres on 2020-02-10 16:52:21:
- icomment:
Fixed in [9cace6cc78], tests passed.<br/> I guess it should be cherry-picked to 8.5 as well.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Pending"
- icomment:
Ticket change [943348dc93] (rid 218022) by jan.nijtmans on 2023-09-12 13:40:37:
- icomment:
I'm seeing 3 failing test-cases: <pre> init.test ==== init-0.1 no error on initialization phase (init.tcl) FAILED ==== Contents of test case: child eval { list [set v [info exists ::errorInfo]] [if {$v} {set ::errorInfo}] [set v [info exists ::errorCode]] [if {$v} {set ::errorCode}] } ---- Result was: 0 {} 1 {} ---- Result should have been (exact matching): 0 {} 0 {} ==== init-0.1 FAILED ioCmd.test ==== iocmd-21.8 chan create, initialize failed, bad result, not a list FAILED ==== Contents of test case: proc foo {args} {return "\{"} catch {chan create {r w} foo} msg rename foo {} set ::errorInfo ---- Result was: wrong # args: should be "::foo" while executing "::foo initialize rc3 {read write}" (chan handler subcommand "initialize") invoked from within "chan create {r w} ::foo" invoked from within "chan create {r w} foo" ---- Result should have been (glob matching): chan handler "foo initialize" returned non-list: * ==== iocmd-21.8 FAILED ioTrans.test ==== iortrans-2.7 chan push, initialize failed, bad result, not a list FAILED ==== Contents of test case: proc foo {args} {return "\{"} catch {chan push [tempchan] foo} return $::errorInfo ---- Result was: wrong # args: should be "::foo" while executing "::foo initialize rt2 {read write}" (chan handler subcommand "initialize") invoked from within "chan push [tempchan] ::foo" ("uplevel" body line 3) invoked from within "uplevel 1 $script" invoked from within "chan push [tempchan] foo" ---- Result should have been (glob matching): chan handler "foo initialize" returned non-list: * ==== iortrans-2.7 FAILED </pre> - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment: