Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 231af8abd61aeab69387d879e98c80e311114c97
Ticket: 218965ffffffffffffffffffffffffffffffffff
empty name array setting failure within namespace procedure
User & Date: nobody on 2000-10-26 01:08:41
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 3339 Bug
    Version: 8.2.1
    SubmitDate: '1999-11-05'
    LastModified: '1999-12-09'
    Severity: MED
    Status: Released
    Submitter: techsupp
    ChangedBy: hobbs
    RelatedBugIDs: 2551
    OS: Linux-Red Hat
    FixedDate: '1999-12-09'
    FixedInVersion: 8.3b1
    ClosedDate: '2000-10-25'
    
    
    Name:
    Jean-Luc Fontaine
    
    Comments:
    bug also present in 8.0 and 8.1 releases
    
    ReproducibleScript:
    namespace eval n {
            proc p {} {
                variable {}
                set (0) 0
                set (1) 1
                set n 2
                set ($n) 2
                set ($n,foo) 2
            }
            p
            parray {}
        }
    
    ObservedBehavior:
    ouput:
        (0)     = 0
        (2,foo) = 2
    
    DesiredBehavior:
    output:
        (0)     = 0
        (1)     = 1
        (2)     = 2
        (2,foo) = 2
    
    
    
    More info from Jean-Luc:
    
    I found what happened in tclCompile.c, TclFindCompiledLocal(): 
    
    ...
    for (i = 0;  i < localCt;  i++) {
      if (!TclIsVarTemporary(localPtr)) {
        char *localName = localPtr->name;
        if ((name[0] == localName[0])
          && (nameBytes == localPtr->nameLength)
          && (strncmp(name, localName, (unsigned) nameBytes) == 0)) {
            return i;
        }
      }
      localPtr = localPtr->nextPtr;
    }
    ...
    For the following Tcl source code: 
    namespace eval n {proc p {} {variable {}; set (a) 0; set (b) 1}}
    if we look at what happens at the following line: 
        if ((name[0] == localName[0])
    For (a), name is "(a) 0; set (b) 1" and we never get there, which is normal since the {} array is not yet allocated. For (b), name is "(b) 1" and since localName is "" (empty name array allocated at the (a) occurence), comparing the first characters ('(' and '\0') is wrong. The fix consists in removing the test on the first byte. 
    
    -----
    
    This is correct, that slight opt breaks the {} array name case,
    and is covered by the strncmp. 
    -- 12/09/1999 hobbs
    
    
    
  4. foundin changed to: "obsolete: 8.2.1"
  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: "07. Variables"
  10. title changed to:
    empty name array setting failure within namespace procedure
    
  11. type changed to: "Bug"