Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-05-10
09:57 • Closed ticket [1746143fff]: bug? Unset may not completely remove the variable</i... artifact: 1d60d195d4 user: msofer
2008-07-30
06:32 • Ticket [1746143fff]: 1 change artifact: 3cdd18cfeb user: msofer
2007-09-13
07:49 • Ticket [1746143fff]: 1 change artifact: dc14e7a01d user: msofer
2007-07-06
06:45 • Ticket [1746143fff]: 4 changes artifact: c76cb1c0a4 user: jenglish
06:31 • Ticket [1746143fff]: 4 changes artifact: 7fcc7a9381 user: jenglish
05:58 • Ticket [1746143fff]: 4 changes artifact: 325de769ed user: msofer
05:01 • Ticket [1746143fff]: 5 changes artifact: 0b099b28ed user: msofer
04:58 • Ticket [1746143fff]: 4 changes artifact: c7a918a5e3 user: jenglish
2007-07-02
23:18 • Ticket [1746143fff]: 5 changes artifact: 196d469c73 user: dgp
2007-07-01
19:17 • New ticket [1746143fff]. artifact: e03b9c7fdd user: msofer

bug? Unset may not completely remove the variable

Closed / Invalid1746143fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 18 years ago
Descriptionplain2007-07-01 19:17:56
Notice that traces set during unset traces survive the [unset] - which is IMO more than what the man page promises with "Traces are not disabled during unset traces, so if an unset trace command creates a new trace and accesses the variable, the trace will be invoked". Bug or not? Should the variable always be completely gone after [unset]?

Witness:

% trace add variable x unset {trace add variable ::x unset {puts foo;#} ;#}
% trace info variable x
{unset {trace add variable ::x unset {puts foo;#} ;#}}
% set x 1; unset x
% trace info variable x
{unset {puts foo;#}}

Interesting effect: unsetting a var in a namespace does not guarantee that later upvars go to the global namesake.

% set x 1
1
% namespace eval a {
set ::a::x 2
trace add variable x unset {trace add variable x unset {puts foo;#} ;#}
unset x
upvar 0 x y
set y 3
}
3
% set x
1
% set a::x
3
% unset a::y
foo
dgpplain2007-07-02 23:18:43
Logged In: YES 
user_id=80530
Originator: NO


I don't think you can know without
trying it and waiting to see who
complains.

What's the test suite think?
jenglishplain2007-07-06 04:58:16
Logged In: YES 
user_id=68433
Originator: NO

Tk relies on this behavior: whenever a widget has a linked -variable or -textvariable, it attaches a write+unset trace that reestablishes itself whenever it's called with TCL_TRACE_DESTROYED.

If traces added during an unset trace did not survive the [unset], it would break quite a lot of Tk and other megawidget packages that work the same way.
msoferplain2007-07-06 05:01:27
Logged In: YES 
user_id=148712
Originator: YES

Thanks! So this is a feature not a bug, it should be doc'ed and that's it.
msoferplain2007-07-06 05:58:18
Logged In: YES 
user_id=148712
Originator: YES

What does 'break' mean - error or segfault? Because namespace deletion does remove everything: if segfault, that is not good (TM)
jenglishplain2007-07-06 06:31:41
Logged In: YES 
user_id=68433
Originator: NO

"breaks" as in "the widget is in an inconsistent state", specifically that the widget value is no longer linked its -variable's value.

Don't know what happens when the -variable's namespace is deleted -- my best guess is that at worst it just leads to inconsistent behavior (of course that depends on how the widget in question manages linked -variables...)
jenglishplain2007-07-06 06:45:34
Logged In: YES 
user_id=68433
Originator: NO

Did a quick spot-check of a few widgets: the most common behavior is that the widget raises errors "Can't set {whatever}: parent namespace doesn't exist" at various times (generally whenever the widget value changes; sometimes more frequently, sometimes not at all) until such time as the parent namespace is recreated.  Then the variable will reappear, but without the write trace; so changes to the widget are reflected in the variable, but not vice versa.

No core dumps encountered so far (and, looking at the way linked variables are commonly implemented, I wouldn't expect any.)
msofer Ticket [1746143fff]: 1 change [History diff]2007-09-13 07:49:18
msofer Ticket [1746143fff]: 1 change [History diff]2008-07-30 06:32:22
msoferplain2009-05-10 09:57:16
allow_comments - 1
Log in (anonymous is fine) to add a comment.