| Ticket UUID: | 218871 | ||
| Title: | FIX for auto_mkindex/auto_load bugs on funny procedure names | ||
| Type: | Bug | Created on: | 2000-10-26 01:07:00 |
| Submitter: | nobody | Assigned to: | dgp |
| Subsystem: | 38. Init - Library - Autoload | Severity: | |
| Priority: | 2 | Last modified: | 2026-10-21 10:03:39 |
| Status: | Closed | Closed by: | dgp |
| Resolution: | Fixed | Closed on: | 2001-04-05 19:06:07 |
| Version: | obsolete: 8.4.4 | ||
| Description: | ||||
OriginalBugID: 2480 Bug
Version: 8.2b1
SubmitDate: '1999-08-02'
LastModified: '2000-01-28'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: ericm
RelatedBugIDs: 2611
OS: All
FixedDate: '2000-01-28'
FixedInVersion: 8.3
ClosedDate: '2000-10-25'
Name:
Krzysztof Kozminski
CVS:
RCS: @(#) $Id: auto.tcl,v 1.2 1999/04/16 00:46:56 stanton Exp $ and RCS: @(#) $Id: init.tcl,v 1.31 1999/06/25 23:29:53 welch Exp $
Comments:
The
return [expr {[info commands $name] != ""}]
line in proc auto_load should be also fixed to query the appropriate
namespace for the origin of the command, but I did not have any old
auto_mkindex versions to generate non-canonical auto_index entries to
test this part.
Also, where is test "autoMkindex-3.3" ? I just might take you up on the
gold star offer :-)
ReproducibleScript:
Prepare a file /tmp/test.tcl with the following contents:
proc {ugly* $procname [error GOTCHA!]} {some args} {
puts "$some $args"
}
proc {ugly*\*\\* \$\\$\\\$procname [\[\\[error GOTCHA!]]]} {some args} {
puts "$some $args"
}
Invoke protclsh82 and convince yourself that the procedure names are
quite legitimate and work just fine:
protclsh82
% source /tmp/test.tcl
% {ugly* $procname [error GOTCHA!]} this will be echoed
this will be echoed
% {ugly*\*\\* \$\\$\\\$procname [\[\\[error GOTCHA!]]]} this will be echoed
this will be echoed
Make the index:
% auto_mkindex /tmp /tmp/test.tcl
Invoke protclsh again, and add /tmp to auto_path, then try to execute
the above perfectly legitimate commands:
protclsh82
% lappend auto_path /tmp;\
{ugly* $procname [error GOTCHA!]} this will be echoed
error while autoloading "ugly* $procname [error GOTCHA!]": GOTCHA!
ObservedBehavior:
With a bit of tinkering, assorted other effects are possible: complaints
about undefined variables, mismatched brackets, and just plain return to
Unix shell if a procedure name is {[exit]}.
DesiredBehavior:
None of the above.
Patch:
*** old/auto.tcl Thu Jul 29 15:46:09 1999
--- ./auto.tcl Thu Jul 29 16:34:54 1999
***************
*** 463,472 ****
}
if {[namespace qualifiers $name] == ""} {
! return [namespace tail $name]
} elseif {![string match ::* $name]} {
! return "::$name"
}
return $name
}
--- 463,477 ----
}
if {[namespace qualifiers $name] == ""} {
! set name [namespace tail $name]
} elseif {![string match ::* $name]} {
! set name "::$name"
}
+
+ # Since auto_mkindex_parser::mkindex has escaped all $ characters, we
+ # should restore the correct procedure names:
+ regsub -all -- {\\\$} $name {$} name
+
return $name
}
***************
*** 311,318 ****
--- 311,324 ----
foreach name $nameList {
if {[info exists auto_index($name)]} {
uplevel #0 $auto_index($name)
+ # Command names may contain weird characters (e.g. []) that may
+ # prevent a successful match, so use a trick and if 'info command'
+ # fails, query the current namespace for the origin of the command.
+ #
if {[info commands $name] != ""} {
return 1
+ } elseif {[namespace which -command $name] != ""} {
+ return 1
}
}
}
***************
*** 353,359 ****
set error [catch {
set id [gets $f]
if {$id == "# Tcl autoload index file, version 2.0"} {
! eval [read $f]
} elseif {$id == \
"# Tcl autoload index file: each line identifies a Tcl"} {
while {[gets $f line] >= 0} {
--- 359,367 ----
set error [catch {
set id [gets $f]
if {$id == "# Tcl autoload index file, version 2.0"} {
! # eval [read $f] fails in various interesting ways, but
! # sourcing the file directly seems to work just fine.
! source [file join $dir tclIndex]
} elseif {$id == \
"# Tcl autoload index file: each line identifies a Tcl"} {
while {[gets $f line] >= 0} {
PatchFiles:
auto.tcl and init.tcl
I am unable to reproduce this bug in 8.3b2 (although I could in 8.2.1). There have been several changes to the auto.tcl and init.tcl files in that time, as well as many changes to the core itself, so I'm not certain when specifically this bug was fixed.
However, investigating this bug did expose a new bug in the auto loader, relating to the use of * and [] in the proc name. Because of the matching technique used to determine if the command had been successfully loaded, those characters were being interpreted as glob-style specifiers, which was causing the auto loader to think that the command had not been loaded when it actually had been. I fixed this bug for 8.3.
- eric
-- 01/28/2000 ericm
On further consideration, it seems that I misspoke. The error does exist, albeit in a slightly altered form. If you have code such as:
proc {\\$foobar} {} {}
You will see this problem. Realistically, however, people are not going to make procedure names like this, and the auto indexing procedures were not designed to handle this sort of case. If you need to index a file with procedure names like that, perhaps you could use auto_mkindex_old, which uses a less sophisticated but in some cases (like this one) more robust algorithm.
- eric
-- 01/28/2000 ericm
| ||||
| User Comments: | ||||
dgp added on 2003-09-23 11:22:29:
Logged In: YES user_id=80530 Re-opened. ericm's [info commands] -> [namespace which -command] fix was a good one, but he should have applied it throughout, not in only one place. Now that I found this report, it seems the bug should also remain open until the [auto_mkindex] issue is resolved. dgp added on 2003-09-23 11:51:25:
Logged In: YES user_id=80530 committed the expanded fix for 8.4.5+ keeping open at low priority as a reminder to examine the [auto_mkindex] issue. serhiy.storchaka added on 2026-10-21 10:03:39:
The [info commands] problem was fixed by [56990efadd] (8.3.0) and [dbc5f2a73f]/[2ce276bdca] (8.4.5). The auto_mkindex part kept open here works too: the reported procedure names are indexed and autoloaded correctly from 8.4.2 through 9.1. Closing. | ||||
