|
2006-08-28
| ||
| 20:09 | • Closed ticket [1546833fff]: wrong varname resolution in namespace upvar? p... artifact: 8ec06a5bda user: dgp | |
|
2006-08-27
| ||
| 11:36 | • Ticket [1546833fff]: 6 changes artifact: 8a2bd07474 user: dgp | |
| 10:49 | • Open ticket [1546833fff]. artifact: fe89d867f3 user: dgp | |
|
2006-08-26
| ||
| 19:54 | • Closed ticket [1546833fff]. artifact: 949c120e9f user: msofer | |
| 09:30 | • Ticket [1546833fff]: 4 changes artifact: 957e6b1a2b user: msofer | |
| 01:58 | • Ticket [1546833fff]: 4 changes artifact: 3e83312f01 user: msofer | |
|
2006-08-25
| ||
| 18:52 | • New ticket [1546833fff]. artifact: f1fe9fbd5b user: msofer | |
wrong varname resolution in [namespace upvar]?
Closed / Fixed1546833fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 20 years ago
Descriptionplain2006-08-25 18:52:11
Will Duquette reports by mail that varname resolution
of [namespace upvar] is failing to do the right thing
in the (non-fully) qualified case.
<quote>
Please consider the code:
namespace eval ::cat:: { }
namespace eval dog:: {
set dogInfo(a) "A"
set dogInfo(b) "B"
}
proc ::cat::TestProc {type} {
if {![info exists ${type}::dogInfo]} {
error "no such type: \"$type\""
}
upvar ${type}::dogInfo dogInfo1
parray dogInfo1
namespace upvar $type dogInfo dogInfo2
parray dogInfo2
}
::cat::TestProc dog
What happens when I run this is it prints the content
of dogInfo1, but then says there is no array dogInfo2;
[namespace upvar] is failing to alias dogInfo2 to
::dog::dogInfo.
Now, the behavior of [namespace upvar] doesn't surprise
me; since TestProc is in ::cat::, [namespace upvar] is
presumably trying to alias dogInfo2 to
::cat::dog::dogInfo. That makes sense to me.
[info exists] and [upvar], on the other hand, are
finding ::dog::dogInfo; this surprises me. Do lookups
of partially-qualified variable names fall back to ::
if the variable isn't found in the current namespace?
If so, [namespace upvar] should undoubtedly do the same
thing. I must say, I wasn't expecting them to do that,
though.
</quote>
msoferplain2006-08-26 01:58:52
Logged In: YES user_id=148712 According to the docs, "[namespace upvar $ns a b] has the same behaviour as [upvar 0 $ns::a b]. Event though Will's example does not test this directly, further tests show that this is failing to occur. The code is buggy, and the testsuite incomplete.
msoferplain2006-08-26 09:30:17
Logged In: YES user_id=148712 I now tend to think that [namespace upvar] is doing the right thing, and [upvar] is not. Note that upvar 0 b::x s b:y t may create vars that are linked to *different* namespaces; we certainly do not want to reproduce that in here. See also Bug #1274918
msoferplain2006-08-26 19:54:29
Logged In: YES
user_id=148712
[namespace upvar] is doing the right thing: the man page for
'namespace' clearly states that "Namespace names, on the
other hand, are always resolved by looking in only the
current namespace."
So this is actually a doc bug - the parallel to [upvar 0] is
imperfect. This is now fixed in HEAD.
There was an actual bug in the code (also fixed in HEAD),
illustrated by
% namespace eval a {
variable x 2
proc a {} {namespace upvar fake x w; set w}
a
}
2
This now properly returns an error, with message
namespace "fake" does not exist
(see test upvar-NS-1.9)
dgpplain2006-08-27 10:49:29
Logged In: YES user_id=80530 upvar-NS-1.3 segfaults.
dgpplain2006-08-27 11:36:24
Logged In: YES user_id=80530 The segfault appears to be in TclFormatObj() which is so far not used or tested anywhere else.
dgpplain2006-08-28 20:09:32
Logged In: YES user_id=80530 TclFormatObj issue is now bug 1547681
Log in (anonymous is fine) to add a comment.