Skip to content
Tcl Source Code History Of Ticket 218001ffffffffffffffffffffffffffffffffff
Login

History Of Ticket 218001ffffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 218001ffffffffffffffffffffffffffffffffff

  1. Ticket change [ee117a5bd8] (rid 104019) by nobody on 2000-10-26 00:51:51:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 684 Bug
      Version: 8.0.3
      SubmitDate: '1998-10-01'
      LastModified: '1999-08-06'
      Severity: MED
      Status: Closed
      Submitter: stanton
      ChangedBy: hobbs
      OS: All
      OSVersion: NA
      Machine: NA
      FixedDate: '2000-10-25'
      FixedInVersion: NA
      ClosedDate: '1999-08-06'
      
      
      Date: Wed, 23 Sep 1998 06:04:38 -0700 (PDT)
      To: [email protected]
      Subject: Tcl 'C' compiled parameters "argv" are passed by reference, not by value!
      From: [email protected]
      Content-type: text
      
      Bug report from:  [email protected]
      
      bugrfe:  Bug
      Product:  tcl8.0.3
      Version:  1.0
      priority:  2
      app:  in-house extension
      interp:  Tclsh
      interpv:  8.0.3
      os:  Solaris
      OSVers:  5.5.1
      Synopsis:  Tcl 'C' compiled parameters "argv" are passed by reference, not by value!  
      Detail:  A Tcl 'C' routine (Tcl_CreateCommand generated) which alters the "argv" parameter internally within the 'C' routine, has the altered parameter passed back to the Tcl variable.  In addition, all Tcl variables tagged to the initial variable also get altered (all have a common referenct point to data storage).
      
      The following is the "C" code in question :
      ================================
      
      #include <stdlib.h>
      #include <ctype.h>
      #include <string.h>
      #include <unistd.h>
      #include "tcl.h"
      
      int 
      TestCmd ( ClientData  clientData
              , Tcl_Interp *interp
              , int         argc
              , char       *argv[]
              )
      {
        int i;  
        printf( "\nargv[1] @ %d .... argv[2] @ %d\n\n", argv[1], argv[2]);
        Tcl_AppendResult( interp
                        , "Before : argv[1] = >>"
                        , argv[1]
                        ,"<< ... argv[2] = >>"
                        , argv[2]
                        ,"<<\n"
                        , (char *)NULL 
                        );
        for (i=0; i<strlen(argv[1]); i++)
          argv[1][i] = toupper(argv[1][i]);                
        for (i=0; i<strlen(argv[2]); i++)
          argv[2][i] = tolower(argv[2][i]);      
        Tcl_AppendResult( interp
                        , "After :  argv[1] = >>"
                        , argv[1]
                        ,"<< ... argv[2] = >>"
                        , argv[2]
                        ,"<<\n"
                        , (char *)NULL 
                        );
        return (0);
      }
      
      int 
      Test_Init (Tcl_Interp *interp)  
      { 
        Tcl_CreateCommand( interp
                         , "test"
                         , TestCmd
                         , (ClientData *) NULL
                         , (Tcl_CmdDeleteProc *) NULL
                         );  
        return (0);
      }
      
      Now considet the following script :
      ==========================
      set T1  "aaaaa"
      set T11 $T1
      set T2  "BBBBB"
      set T22 $T2
      puts "Variable Values prior to running the test"
      puts "T1 = $T1 .... T11 = $T11"
      puts "T2 = $T2 .... T22 = $T22"
      puts " "
      puts "Running the test on Variables T1 as argv\[1\] and T2 as argv\[2\]"
      puts [test $T1 $T2]
      puts "Variable Values post to running the test"
      puts "T1 = $T1 .... T11 = $T11"
      puts "T2 = $T2 .... T22 = $T22"
      puts " "
      
      Expected Result :
      ==============
      
      Variable Values prior to running the test
      T1 = aaaaa .... T11 = aaaaa
      T2 = BBBBB .... T22 = BBBBB
      
      Running the test on Variables T1 as argv[1] and T2 as argv[2]
      
      argv[1] @ 580472 .... argv[2] @ 580456
      
      Before : argv[1] = >>aaaaa<< ... argv[2] = >>BBBBB<<
      After :  argv[1] = >>AAAAA<< ... argv[2] = >>bbbbb<<
      
      Variable Values post to running the test
      T1 = aaaaa .... T11 = aaaaa
      T2 = BBBBB .... T22 = BBBBB
      
      Result Obtained :
      ==============
      
      Variable Values prior to running the test
      T1 = aaaaa .... T11 = aaaaa
      T2 = BBBBB .... T22 = BBBBB
      
      Running the test on Variables T1 as argv[1] and T2 as argv[2]
      
      argv[1] @ 580280 .... argv[2] @ 622680
      
      Before : argv[1] = >>aaaaa<< ... argv[2] = >>BBBBB<<
      After :  argv[1] = >>AAAAA<< ... argv[2] = >>bbbbb<<
      
      Variable Values post to running the test
      T1 = AAAAA .... T11 = AAAAA
      T2 = bbbbb .... T22 = bbbbb
      
      In addition if we should run the following:
      ===============================
      
      set T1  "aaaaa"
      set T11 $T1
      
      puts "Variable Values prior to running the test"
      puts "T1 = $T1 .... T11 = $T11"
      puts " "
      
      puts "Running the test on Variables T1 as argv\[1\] and T11 as argv\[2\]"
      puts [test $T1 $T11]
      
      puts "Variable Values post to running the test"
      puts "T1 = $T1 .... T11 = $T11"
      puts " "
      
      we find the following (both argv[1] and argv[2] have same reference):
      ========================================================
      Variable Values prior to running the test
      T1 = aaaaa .... T11 = aaaaa
      
      Running the test on Variables T1 as argv[1] and T11 as argv[2]
      
      argv[1] @ 580280 .... argv[2] @ 580280
      
      Before : argv[1] = >>aaaaa<< ... argv[2] = >>aaaaa<<
      After :  argv[1] = >>aaaaa<< ... argv[2] = >>aaaaa<<
      
      Variable Values post to running the test
      T1 = aaaaa .... T11 = aaaaa
      
      I have the "C" code and test scripts available if needed.
      
      
      
      The problem is that the argv array is constructed from references to shared strings instead of being copies as they were in 7.6.  This was done to improve the performance of string commands in 8.0, but is not backwards compatible for commands that expected to be able to modify the strings in place.  A workaround is to copy the strings in the commands that need to modify the strings.  It is not clear whether we should consider this a feature change rather than a bug.
      
      The above should be considered a feature, or the expected result,
      and not a bug.  The incoming argv should be considered shared, and
      not modified in place. 
      -- 08/06/1999 hobbs
      
      
      
    4. foundin initialized to: "obsolete: 8.0.3"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "10. Objects"
    10. title initialized to:
      arguments to string commands are passed by reference
      
    11. type initialized to: "Bug"
  2. Ticket change [7a4951d238] (rid 90291) by welch on 2000-10-26 08:12:11:

    1. closedate changed to: "2000-10-26T01:12:11"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"