Tcl Source Code

View Ticket
Login
Ticket UUID: 0363f0146cb1f0fa152c7d853ea1788b851dacce
Title: array search commands fail to recognize all names for variable
Type: Bug Version: all
Submitter: dgp Created on: 2016-04-04 20:12:54
Subsystem: 07. Variables Assigned To: dgp
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2016-07-25 17:18:34
Resolution: Fixed Closed By: dgp
    Closed on: 2016-07-25 17:18:34
Description:
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"
User Comments: dgp added on 2016-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.

mistachkin added on 2016-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?

dgp added on 2016-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.

dgp added on 2016-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.

anonymous added on 2016-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]]