Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2006-10-02
04:48 • Ticket [959052ffff] variable name resolution and unset vars status still Ope... artifact: dbeda0f952 user: msofer
2005-01-07
17:26 • Ticket [959052ffff]: 1 change artifact: b677afa76a user: dkf
2004-11-18
00:52 • Ticket [959052ffff]: 1 change artifact: 5ab6fdbeb3 user: hobbs
2004-08-23
08:51 • Open ticket [959052ffff]. artifact: bd54c5f13b user: msofer
2004-05-26
02:53 • Closed ticket [959052ffff]. artifact: a24b1a5e9d user: msofer
2004-05-24
08:37 • Ticket [959052ffff]: 4 changes artifact: 0399a95e6e user: msofer
05:48 • Ticket [959052ffff]: 4 changes artifact: b4cb71f3a3 user: msofer
05:48 • Ticket [959052ffff]: 6 changes artifact: bf008191f1 user: msofer
05:48 • Add attachment 959052.patch to ticket [959052ffff] artifact: 92b2bba1c6 user: msofer
2004-05-23
20:10 • New ticket [959052ffff] variable name resolution and unset vars. artifact: 012202d056 user: msofer

variable name resolution and unset vars

Open959052ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 20 years ago
Descriptionplain2004-05-23 20:10:04
Name resolution for variablesin namespaces sometimes
finds variables that "do not exist" according to [info
vars].

  % namespace eval a upvar x q
  % info vars x
  % namespace eval b set x 1
  1
  % set x
  1
 
  % trace add variable x write {;#}
  % info vars x
  % namespace eval a set x 1
  1
  % set x
  1

  % namespace eval a {trace add variable x write {;#}}
  % set x 0
  0
  % info vars a::x
  % namespace eval a set x 1
  1
  % set x
  0
  % info vars a::x
  ::a::x

The variables which are found contrary to [info vars]
satisfy:
 - they have an entry in their namespace's hash table
 - they are unset, ie (varPtr->flags & VAR_UNDEFINED)
 - they are not namespace variables, ie 
       !(varPtr->flags & VAR_NAMESPACE_VAR)
msoferplain2004-05-24 05:48:50
Logged In: YES 
user_id=148712

Attaching a patch, already committed to HEAD. Please review
for itcl compat. Are there any other known users of
Tcl_FindNamespaceVar that may rely on the weird lookup
semantics?

Second Q: should this be backported to 8.4? 8.3?
msoferplain2004-05-24 05:48:51
File Added - 88161: 959052.patch
msoferplain2004-05-24 08:37:54
Logged In: YES 
user_id=148712

Note that the final judge of which variable should be set is 
[namespace which -variable], according to namespace.n 
This is not changed by the patch. 

The patch insures that 
   set name [namespace which -variable x]
   info vars $name
always returns $name. Previously:

  % trace add variable x write {;#}
  % namespace eval a {
          set name [namespace which -variable x]
      }
  ::x
  %  info vars ::x
msoferplain2004-05-26 02:53:45
Logged In: YES 
user_id=148712

As many (?) scripts and apps (at least, AlphaTk: see bug
#959786) rely on the details of the definition of
"existence" for variable name resolution, they break with
any change in these details.

Any action on this bug will have to wait. The patch was
reverted from HEAD, and should not be applied in the 8.4
line either.
msofer Open ticket [959052ffff]. [History diff]2004-08-23 08:51:12
hobbs Ticket [959052ffff]: 1 change [History diff]2004-11-18 00:52:31
dkf Ticket [959052ffff]: 1 change [History diff]2005-01-07 17:26:57
msoferplain2006-10-02 04:48:53
Logged In: YES 
user_id=148712

Another surprise:
% namespace eval a set x
can't read "x": no such variable
% set x 1
1
% namespace eval a set x
1
% upvar 0 ::a::x y
% namespace eval a set x
can't read "x": no such variable
%
Log in (anonymous is fine) to add a comment.

Attachments: