Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2006-07-21
22:00 • Ticket [1522803fff] wrong backtrace on arithmetic error status still Closed ... artifact: e16ccec0b2 user: dgp
17:48 • Closed ticket [1522803fff]. artifact: d7e9abfec3 user: msofer
00:17 • Ticket [1522803fff]: 5 changes artifact: dc9afb5ad3 user: dgp
00:17 • Add attachment 1522803.patch to ticket [1522803fff] artifact: 83914dffd2 user: dgp
2006-07-18
10:16 • Ticket [1522803fff] wrong backtrace on arithmetic error status still Open wi... artifact: 482d45bd05 user: dgp
10:08 • Ticket [1522803fff]: 4 changes artifact: fe43b39925 user: dgp
02:54 • Ticket [1522803fff]: 4 changes artifact: 6bde94256d user: dgp
00:41 • Ticket [1522803fff]: 4 changes artifact: c3f38ea060 user: kennykb
00:07 • Ticket [1522803fff]: 4 changes artifact: d6d59eb735 user: dgp
2006-07-14
21:35 • New ticket [1522803fff]. artifact: d5d4f81a37 user: kennykb

wrong backtrace on arithmetic error

Closed / Fixed1522803fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 20 years ago
Descriptionplain2006-07-14 21:35:09
On an arithmetic error, such as division by zero,
the backtrace in ::errorInfo shows the last previous
error, rather than the current error.

Behold:

% catch {unset foo(bar)}; set c 0; expr {1/$c}
divide by zero
% set errorInfo
can't unset "foo(bar)": no such variable
    while executing
"unset foo(bar)"
    invoked from within
"expr {1/$c}"

I'm looking at this briefly, but don't expect
to solve it quickly, and hope that one of the
other developers that understands the bytecode
engine might have a keener insight.
dgpplain2006-07-18 00:07:37
Logged In: YES 
user_id=80530


can someone confirm this
problem only shows up in
an interactive interp?
kennykbplain2006-07-18 00:41:20
Logged In: YES 
user_id=99768

I confirm that it fails only in an interactive interpreter.
dgpplain2006-07-18 02:54:27
Logged In: YES 
user_id=80530


To demo in a non-interactive
shell, use the script:

  set c 0
  if 1 {
    catch {set foo}
    expr {1/$c}
  }

The interactive / non-interactive
is just a proxy for compiled /
direct evaluation, and its
bytecompilation one must force
to demo the bug.
dgpplain2006-07-18 10:08:57
Logged In: YES 
user_id=80530


Between revisions 1.153 and
1.154 of tclExecute.c, there
were several conversions like:

-    Tcl_ResetResult(interp);
-    Tcl_AppendToObj(Tcl_GetObjResult(interp), "divide by
zero", -1);
+    Tcl_SetObjResult(interp, Tcl_NewStringObj("divide by
zero", -1));

The loss of the Tcl_ResetResult()
call means the loss of a clearing
of the ERR_ALREADY_LOGGED flag,
leading to the observed bug.

This may just be the exposing trigger
with the real cause the E_A_L reform
that happened earlier.  still examining...
dgpplain2006-07-18 10:16:36
Logged In: YES 
user_id=80530


Making that same conversion
on core-8-4-branch leads to
the same bug, even though no
ERR_ALREADY_LOGGED reform
was done on that branch.

The real cause is the loss
of several Tcl_ResetResult()
calls in the bytecode execution
engine that had real useful 
flag clearing effects in addition
to initializing an empty result
to append to.

Simple fix is to put them all back.
Better fix might be to find where
one call might go to get the function
done where it's needed.
dgpplain2006-07-21 00:17:35
File Added - 185569: 1522803.patch

Logged In: YES 
user_id=80530


Please test/review this
patch.
msoferplain2006-07-21 17:48:44
Logged In: YES 
user_id=148712

Worth recording dgp's explanation in the chat: "the entire
patch is general reform. Do the reset operation in the one
right place, not here, there, and everywhere."

Looks good to me; gets the same 196 failures as unpatched :)
Committed.
dgpplain2006-07-21 22:00:35
Logged In: YES 
user_id=80530


The commit brought in some
unrelated changes to
tclInt.h and tclObj.c.

I took those back out.
Log in (anonymous is fine) to add a comment.

Attachments: