Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-04-13
20:36 • Closed ticket [2662380fff]: Bug in append plus 7 other changes artifact: 6824a85e14 user: msofer
20:36 • Ticket [2662380fff]: 4 changes artifact: 85a9c04ab3 user: msofer
2011-04-12
18:39 • Ticket [2662380fff]: 4 changes artifact: 97b0155ab3 user: msofer
09:30 • Ticket [2662380fff]: 6 changes artifact: 287d207fb1 user: msofer
2009-04-08
21:42 • Ticket [2662380fff]: 5 changes artifact: 31ead71b26 user: dgp
20:32 • Ticket [2662380fff]: 4 changes artifact: eb7a2609f1 user: dgp
03:12 • Ticket [2662380fff]: 1 change artifact: 98aff6c411 user: dkf
02:25 • Ticket [2662380fff]: 4 changes artifact: 004f36d349 user: dgp
2009-04-05
00:34 • Ticket [2662380fff]: 1 change artifact: aaf7ebd722 user: dkf
00:34 • Ticket [2662380fff]: 5 changes artifact: 061cdc6b41 user: dkf
2009-03-05
00:04 • Ticket [2662380fff]: 1 change artifact: 3a298c87b7 user: dkf
00:02 • Ticket [2662380fff]: 4 changes artifact: 401cb374e2 user: a3a3el
00:02 • Add attachment tclVar-trunk.diff to ticket [2662380fffffffff|2662380fff... artifact: 8c4e129dff user: a3a3el
00:02 • Ticket [2662380fff] Bug in append status still Open with 4 other changes artifact: 1665e93b58 user: a3a3el
00:02 • Add attachment tclVar-8.5.diff to ticket [2662380fff] artifact: 5206d80f34 user: a3a3el
00:01 • Ticket [2662380fff] Bug in append status still Open with 4 other changes artifact: fac61244ca user: a3a3el
00:01 • Add attachment tclVar-8.4.diff to ticket [2662380fff] artifact: 6758ac82ef user: a3a3el
2009-03-04
17:01 • New ticket [2662380fff] Bug in append. artifact: cd50c22409 user: a3a3el

Bug in append

Closed / Fixed2662380fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 16 years ago
Descriptionplain2009-03-04 17:01:47
The following can crash 8.4, 8.5 and 8.6:

  array set a [list]

  trace variable a w unset_key

  proc unset_key { var key op } {

    puts stderr "$var, $key, $op"

    global a

    if { [info exists a($key)] } {
      puts stderr "Unsetting a($key)."
      unset a($key)
    } else {
      puts stderr "Cannot unset a($key)."
    }

  }

  append a(test) one two

Since 8.4, Tcl_AppendObjCmd has stopped calling Tcl_ObjSetVar2, and calls
TclPtrSetVar instead.  However, although TclPtrSetVar returns iPtr->emptyObj if
the variable has been unset by a trace, Tcl_AppendObjCmd is still checking for
NULL, and so attempts to append the next argument.  I've attached patches for
the 8.4 and 8.5 branches, and the trunk.

Az.
a3a3elplain2009-03-05 00:01:47
File Added - 316175: tclVar-8.4.diff
a3a3elplain2009-03-05 00:02:08
File Added - 316176: tclVar-8.5.diff

File Added: tclVar-8.5.diff
a3a3elplain2009-03-05 00:02:24
File Added - 316178: tclVar-trunk.diff

File Added: tclVar-trunk.diff
dkf Ticket [2662380fff]: 1 change [History diff]2009-03-05 00:04:36
dkfplain2009-04-05 00:34:36
data_type - 110894
dkf Ticket [2662380fff]: 1 change [History diff]2009-04-05 00:34:52
dgpplain2009-04-08 02:25:39
I see no crash.

On 8.4 I see:

a, test, w
Unsetting a(test).
a, test, w
Cannot unset a(test).

On Tcl 8.5 and HEAD I see an uncaught errors,
but not always the same one (!).  Either :

a, test, w
Unsetting a(test).
can't set "a(test)": upvar refers to element in deleted array
    while executing
"append a(test) one two"
    (file "/home/dgp/2662380.tcl" line 20)

or this:

a, test, w
Unsetting a(test).
can't set "a(test)": upvar refers to variable in deleted namespace
    while executing
"append a(test) one two"
    (file "/home/dgp/2662380.tcl" line 20)
dkf Ticket [2662380fff]: 1 change [History diff]2009-04-08 03:12:25
dgpplain2009-04-08 20:32:48
Relevant tests:
append-7.1
appendComp-7.1
namespace-8.6
trace-16.8,9,10,13,14
dgpplain2009-04-08 21:42:01
I modified the test script so that the "Unsetting"
messages reports the value of the variable about
to be unset.  Then testing on Tcl releases 7.6p2
and 8.3.5, I see they agree on this output:

a, test, w
Unsetting a(test) = one.
a, test, w
Unsetting a(test) = two.

Without thinking too deeply about it, 
I admit, that output also makes sense
to me.  [append] can operate on
a name of a non-existent variable,
creating the variable by making the
appending write to it.  Write traces
come after the writing, so at that point
the variable exists, and the trace can
unset it.  We end up back where we
started with no existing variable.
Multiple arguments to append
just means we repeat the cycle.

Appears this report is exposing some
flaws in some of the varName resolution
caching machinery that's come in releases
8.4 and later.

Fixing that right may take some time
and thought (*), and since it appears the
claims of "crashes" are incorrect, I'll
leave this one to come back to.

The submitted patches may well be the
right answer, I'm not sure yet, but the
flaws exposed are broader and deeper,
so I'd prefer to be more certain about a
more complete fix.

(*) or at least some input from msofer. :)
msoferplain2011-04-12 09:30:37
Crashes HEAD but not core-8-5-branch as of today. Valgrind however still dislikes it in 8.5
msoferplain2011-04-12 18:39:41
The "gross change in write traces" covers 2 cases:

* trace undefined the var: in that case, TclPtrSetVar should just clear the var and return NULL

* trace converted the var to an array: so what do we do now? What should append/set/etc return? In 8.4:

% trace add variable x write foo
% proc foo {name args} {upvar 1 $name x; unset x; set x(1) 1}
% append x 2
% set x
can't read "x": variable is array
% parray x
x(1) = 1
msoferplain2011-04-13 20:36:26
fixed in all 3 branches
msoferplain2011-04-13 20:36:28
allow_comments - 1
Log in (anonymous is fine) to add a comment.

Attachments: