Junk at start of errorInfo when using [dict get] on arrays
Closed / Fixed2431847fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-12-15 21:57:07
The script:
proc oops {} {
dict set array(index) poisonous garbage!
catch {
dict get $array(index) nonexistent
}
puts $::errorInfo
}
oops
prints the following:
poisonous garbage!key "nonexistent" not known in dictionary
while executing
"dict get $array(index) nonexistent"
The dictionary value is somehow prepended to $errorInfo when [dict get] fails to find the key it's looking for.
This problem does not occur when running at top level (i.e. not inside a proc). It also does not occur when not using an array (e.g. remove "(index)" from the script). If [dict get] fails for another reason, such as "missing value to go with key", the dictionary value is not prepended (replace "nonexistent" with "poisonous garbage!" to test).
dkfplain2008-12-16 06:09:24
Caused by fix for issue 1522803, though why the interpreter result isn't clean at that point is odd. Possibly some other fault (related to INST_INVOKE_STK1?) too. Fixed on HEAD
dkfplain2008-12-16 06:30:01
Fixed on 8.5 branch as well. Leaving open and assigned to bytecode engine maintainer for the issue of why the result was not cleared earlier. (Maintainers' note: the [dict set array(index) poisonous garbage!] spills to INST_INVOKE_STK1.)
ferrieuxplain2008-12-16 07:27:06
Simplified repro: no [catch], no array element, no [dict set] !
proc foo {} {return yo}
proc oops3 {} {
foo
dict get {} nonex
}
oops3
=> yokey "nonex" not known in dictionary
I think there is a hole in the ResetResultReform. The [dict get] code does an AppendResult assuming an invariant.
So either fix that invariant or use ResetResult again...
ferrieuxplain2008-12-16 22:10:57
OK after a bit of cvs history diving, I have the impression that the ResetResult reform by miguel on [revision 1.239, Fri Jul 21 10:47:18 2006 UTC] of tclExecute.c did include one unwanted commenting out of Tcl_ResetResult(). Indeed that reform was a positive move turning a random scattering of ResetResults into a few well-selected ones. But I fear the "removal" part was made in a rather automatic way (miguel correct me if I'm wrong), and (quite forgivably) overlooked the special case id [dict get] which is still required because it is coupled with a Tcl_AppendResult preparing an error message. So I think this Tcl_ResetResult should have stayed here. However Donal, you fixed it by emulating it at a lower level: TclNewObj+Tcl_SetObjResult. Can you explain why ?
dkfplain2008-12-16 22:19:58
Expected a lower actual overhead that way.
ferrieuxplain2008-12-16 22:25:46
Ouch... Why only there ? Can you specify in what situations this optimization is valid ? In that case why not define a Tcl_FastResetResult ? (I'm a bit weary about peephole optimizations in arbitrary places, not driven by mesaurements, and decreasing readability...)
dgpplain2008-12-16 22:28:16
I think Alex is correct, and a full Tcl_ResetResult()
needs to be restored. See this demo script:
% proc demo {} {
return -level 0 -code ok -noisy stuff
dict get {} noex
}
% catch demo m o
1
% set o
-noisy stuff -code 1 -level 0 -errorcode NONE -errorinfo {key "noex" not known in dictionary
while executing
"dict get {} noex"
(procedure "demo" line 3)
invoked from within
"demo"} -errorline 1
See how the "-noisy stuff" is leaking
into the unrelated error in [dict get].
ferrieuxplain2008-12-16 22:51:47
Thanks Don. Committed.
dgpplain2008-12-16 23:12:57
So the commit doesn't change the leaky return options. I think that's another bug.
ferrieuxplain2008-12-16 23:15:53
Right. Expecting your submission any time soon :)
dgpplain2008-12-16 23:24:29
Sorry. Gotta take care testing with shared libraries. There *is* another bug with leaky options, but not any longer with the demo scripts here.
dgpplain2008-12-16 23:27:44
Don't forget to backport the fix for 8.5.6 too.
ferrieuxplain2008-12-17 05:25:15
Done :)
Log in (anonymous is fine) to add a comment.