|
2019-09-07
| ||
| 16:25 | • Ticket [775ee88560] upvar (used with wrong level) causes a segfault status s... artifact: f160d73a20 user: jan.nijtmans | |
|
2019-09-06
| ||
| 21:06 | • Closed ticket [775ee88560]. artifact: 2e1be56375 user: sebres | |
| 20:37 | simple and binary compatible fix for [775ee88560]: use correct relative level (1) in case of top-1, ... check-in: b229e78d78 user: sebres tags: core-8-branch | |
| 17:52 | • Ticket [775ee88560] upvar (used with wrong level) causes a segfault status s... artifact: bcf2364fd0 user: sebres | |
| 17:36 | cherry-pick [af744d56e0ffcc65] fixed segfault of [775ee88560] in 8.7 check-in: e42893986d user: sebres tags: core-8-branch | |
| 17:23 | cherry-pick [b87d2183ca]: test cases covering bug [775ee88560]: segfault in upvar at wrong level, wr... check-in: 29918c736d user: sebres tags: core-8-5-branch | |
| 17:04 | • Ticket [775ee88560] upvar (used with wrong level) causes a segfault status s... artifact: 0f80fe6b1a user: dgp | |
| 16:56 | • Ticket [775ee88560]: 3 changes artifact: d0675e22cd user: sebres | |
| 16:52 | extend TclObjGetFrame with flags, currently supports 1 only - signaling that a supplied level-argume... closed check-in: 3a85616c61 user: sebres tags: bug-775ee88560 | |
| 16:36 | • Ticket [775ee88560] upvar (used with wrong level) causes a segfault status s... artifact: 07218cebd6 user: dgp | |
| 16:25 | • Ticket [775ee88560]: 3 changes artifact: b40b841d05 user: sebres | |
| 15:03 | • Ticket [775ee88560]: 3 changes artifact: c78e45ca1f user: sebres | |
| 14:46 | • Ticket [775ee88560]: 3 changes artifact: 7ff58dd463 user: dgp | |
| 14:38 | • Ticket [775ee88560]: 3 changes artifact: fbad580a7d user: dgp | |
| 14:04 | test cases covering bug [775ee88560]: segfault in upvar at wrong level, wrong message of uplevel check-in: b87d2183ca user: sebres tags: bug-775ee88560 | |
| 13:35 | • Ticket [775ee88560] upvar (used with wrong level) causes a segfault status s... artifact: 77944b6141 user: sebres | |
| 13:33 | • New ticket [775ee88560]. artifact: c2eb33fdc6 user: sebres | |
upvar (used with wrong level) causes a segfault
upvar error error; lappend error BOOM
Initially found (mistakenly) trying to check an idea in trace:
trace add variable r read {upvar error error; lappend error BOOM}
set r
or here (test executed in top-level, so it is bad level too):
proc test {} {uplevel {upvar error error; lappend error BOOM}}
test
Also following error is a bit unexpected:
% uplevel {lappend error BOOM}; # expecting bad level "1"
bad level "lappend error BOOM"
Tcl 8.6 seems to be not affected by both.
b229e78d78simple and binary compatible fix for [775ee88560]: use correct relative level (1) in case of top-1, "bad level" message points "below global level" (no regressions anymore, all tests pass) check-in2019-09-06 20:37:21e42893986dcherry-pick [af744d56e0ffcc65] fixed segfault of [775ee88560] in 8.7 check-in2019-09-06 17:36:0629918c736dcherry-pick [b87d2183ca]: test cases covering bug [775ee88560]: segfault in upvar at wrong level, wrong message of uplevel check-in2019-09-06 17:23:053a85616c61extend TclObjGetFrame with flags, currently supports 1 only - signaling that a supplied level-argument (objPtr) is optional (e. g. in case of [uplevel $something]) to proper distinguish the level/body (in order to handle syntax error, TIP 515), see bug [775ee88560] check-in2019-09-06 16:52:34b87d2183catest cases covering bug [775ee88560]: segfault in upvar at wrong level, wrong message of uplevel check-in2019-09-06 14:04:40
Looks like a bug in the TIP 515 implementation.
Fix committed to bug branch. Pls review and merge.
Crossed... exactly my fix for upvar, Don (just without space before semicolon :)
I'd like to fix uplevel too - new test-cases (uplevel-4.0.*) still failing.
I've also a solution for that, but then it would conflict with uplevel-4.4 now:
==== uplevel-4.4 error: not enough args FAILED ==== Contents of test case:I'd expect that ?level? is optional where command is don't, so I'd really read it an intention to execute "1" here. Or am I wrong?apply {{} { uplevel 1 }}---- Result was: invalid command name "1" ---- Result should have been (exact matching): wrong # args: should be "uplevel ?level? command ?arg ...?" ==== uplevel-4.4 FAILED
BTW, several upvar tests failing if executed directly (source upvar.test), should we provide some constrain for direct execution (similar singleproc) or should we fix it using some relative level.
Furthermore I think TIP 515 has also some conceptual errors:
It intends to write syntax error in case of:
% apply {{} { uplevel 1 }}
wrong # args: should be "uplevel ?level? command ?arg ...?"
But would "fail" with bad level if given (or relative calculated as current - 1) levels are really wrong:
% uplevel 1
bad level "1"
% uplevel -1
bad level "-1"
% uplevel {lappend error BOOM}
bad level "lappend error BOOM"
Just noone from that is level at all.
I don't think it is possible to provide simple fix at all using current handling of TclObjGetFrame, either the return code (-1) should be rewritten to "negative is error", where -1 mean supplied level is wrong, -2 relative level is wrong (or supplied argument is not a level), and/or TclObjGetFrame should consider arguments count additionally (to bypass several cases of confusion level/body).
I'd prefer totally without a TIP 515 as with implementation like this.
Again, note the syntax of uplevel:
uplevel ?level? command ?arg ...?It is pretty clear that the
command (in opposite to level) is not optional, so in my opinion better to catch invalid command "1" instead of usage, as bad level "body" like now.
Can we please fix the clear problem with the clear fix first, and open the other proposed improvements as a separate ticket?
Too late Don :) In [3a85616c61] I pushed "proper" implementation for that.
But we should anyway cherry-pick the test cases (>= 8.5) to cover all this corner cases across all versions.
Then also your (our;) fix for "upvar" could be cherry-picked in 8.7.
The history and dependencies on this syntax are a mess. At least once before the conclusion was "Won't Fix". https://core.tcl-lang.org/tcl/tktview/1017884 I'm willing to take another look at the issue, but it is not a matter where the right thing to do is obviously clear to every viewer. It is a mistake to entangle a clearly correct segfault fix with a longstanding controversial topic.
Test cases are cherry-picked everywhere since 8.5, bad level fixed in 8.5 (same as in 8.6), 8.7 got your fix (for segfault) applied. In 8.5 and 8.6 all tests should pass. In 8.7 (and trunk if merged) the tests "uplevel-4.0.*" would fail, so they have to get a KnownBug constraint or my branch can be merged (just the internal TclObjGetFrame will be not compatible to 8.6 due to new parameter), or it could be rewriten using new function TclObjGetFrameEx (with new parameter flags), or even something else. I'm done here. You (=TCT) can decide about what would be correct here.
I found another solution for second part (invalid level used in "bad level" message, if relative level out of frames) as in branch "bug-775ee88560", which is simplier, also TIP#515-conform as well as binary compatible.
Fixed now, so I'll close this.
BTW. I fixed another wrong case across all branches (so TclGetFrame and Tcl_UpVar2 are more consistent to TclObjGetFrame now, as regards the error message).
If frameName (actual level) does not contain a real level (#0 or 1) historically TclGetFrame and Tcl_UpVar2 use current level - 1, so to put supplied name in case of bad level (error at top - 1) was wrong but also not consistent with TclObjGetFrame.
The fix affects only the error message (and test "upvar-9.1").
Although I don't think it is good at all to accept wrong level, but Tcl_UpVar2 works so very very long time.
Just I don't think scenarios covered with "upvar-9.1.1", "upvar-9.3" etc as well as following are good at all:
apply {{} {testupvar "this is a bad level" a {} x local; puts OK}}
In my opinion reasonable would be to allow Tcl_UpVar2 only "#0", "1", NULL (and may be "") as argument frameName, and bad level in other case, but at the moment (as one can see above and in mentioned test cases) it allows any bad value if called from level > 0, and fails only if called at top-level (so all values were invalid).
I'm thinking: Can't we think of a better error-message than:
bad level "1"
???
I agree that "bad level xyz" is confusing, but 'bad level "1"' is just as confusing because the command causing this error-message doesn't contain "1" anywhere.
> I'm done here.
> You (=TCT) can decide about what would be correct here.
Looks like you're not done yet ;-) Although this ticket is fixed now (the segfault is gone, thanks!), there still is room for better error-messages. I don't think changing the error-messages is against TIP #515: This TIP only changes the interpretation on what syntax is valid and what not, changing the error-message in case of invalid syntax is always a good thing to consider. As long as the only thing changing is the error-message, that can be discussed here without a TIP