Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-07-25
17:18 • Ticket [0363f0146c] array search commands fail to recognize all names for variab... artifact: 09ee2ae5ad user: dgp
2016-07-22
23:27 • Ticket [0363f0146c]: 5 changes artifact: 8707c32219 user: mistachkin
2016-07-19
19:55 • Closed ticket [0363f0146c]. artifact: 79242fcac9 user: dgp
19:31
[0363f0146c] Fix [array startsearch] id handling to support var name variations check-in: 67c987ee93 user: dgp tags: trunk
17:17 • Ticket [0363f0146c] array search commands fail to recognize all names for variab... artifact: c999e4dca6 user: dgp
2016-04-07
23:22 • Ticket [0363f0146c]: 4 changes artifact: 5067c47848 user: anonymous
2016-04-04
20:12 • New ticket [0363f0146c]. artifact: 521a6ff7e1 user: dgp

array search commands fail to recognize all names for variable

Closed / Fixed0363f0146cb1f0fa152c7d853ea1788b851dacceCreated 11 years agoUpdated 10 years ago
Descriptionplain2016-04-04 20:12:54
Little used corner of Tcl apparently never made aware of namespaces,
or any other way distinct variable names can refer to the same variable.

% array anymore tcl_platform [array startsearch ::tcl_platform]
search identifier "s-1-::tcl_platform" isn't for variable "tcl_platform"
Referenced by1
  • 67c987ee93[0363f0146c] Fix [array startsearch] id handling to support var name variations check-in2016-07-19 19:31:28
anonymousplain2016-04-07 23:22:26
The suggested command returns that error, but this other command returns 1:
puts [array anymore ::tcl_platform [array startsearch ::tcl_platform]]
dgpplain2016-07-19 17:17:27
% array set foo {1 2 3 4 5 6}
% set as1 [array startsearch foo]
s-1-foo
% namespace eval n {
variable foo
array set foo {a b c d e f}
set ::as2 [array startsearch foo]
}
s-1-foo

At this point $::as1 and $::as2 hold
identical string values.  They are interchangeable
as identifiers of both searches, which implies
they are not unique identifiers of either search.
dgpplain2016-07-19 19:55:39
Fixed the original issue on trunk (8.7a).

Left the second issue alone and made no 
change to the 8.6 and lower branches out
of (too much?) concern for not disrupting things.
mistachkinplain2016-07-22 23:27:55
I don't understand why the variable name is part of the returned array search
identifier.  I'm guessing this is unspecified behavior?  Is this required for
script compatibility by anything that we know of?
dgpplain2016-07-25 17:18:34
The code was improperly using the varname embedded in the search
ID to compare the varname argument of the invoked command
and report that the wrong variable was used when they failed to
match.  As this bug report shows, that was done at best improperly
in any environment where the same variable can have many names.

Back when the array search command collection was invented, that
was at least a much rarer, if not impossible circumstance, with no
namespaces to bother us.

Clearly, it would be a sufficient interface revision to pass in the
search-ID only.  Then there could be no mismatch to worry about.
In that revision, we'd need only for the search ID to be unique among
the active searches in the interp. (To detect probable bugs, uniqueness
over interp lifetime would be even better.)

The one specific "user" that needs compatibility maintained is the
set of tests in set-old.test.  Could have changed them too, but I've
taken them as representative of other code out there not wanting
its applecart turned over -- especially not in a patch release.
Log in (anonymous is fine) to add a comment.