Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: aa62eea50e6a2f196c3f6383fbdbdc6bf4c08f02
Ticket: 218871ffffffffffffffffffffffffffffffffff
FIX for auto_mkindex/auto_load bugs on funny procedure names
User & Date: nobody on 2000-10-26 01:07:00
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
    
    
  4. foundin changed to: "obsolete: 8.2b1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "56. LibTomMath"
  10. title changed to:
    FIX for auto_mkindex/auto_load bugs on funny procedure names
    
  11. type changed to: "Bug"