Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ac81e20390d129175ae85393f27143f280bc4001
Ticket: 218497ffffffffffffffffffffffffffffffffff
Tcl_ObjSetVar2 erroneously clears interp->result when new va
User & Date: nobody on 2000-10-26 01:01:20
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 719 Bug
    Version: 8.0.3
    SubmitDate: '1998-10-13'
    LastModified: '1999-12-03'
    Severity: SER
    Status: Released
    Submitter: admin
    ChangedBy: hobbs
    OS: Solaris
    OSVersion: NA
    Machine: NA
    FixedDate: '1999-12-03'
    FixedInVersion: 8.2
    ClosedDate: '2000-10-25'
    
    
    Synopsis: Tcl_ObjSetVar2(..., TCL_LEAVE_ERR_MSG) clears interp->result
    when new variable is created
    
    ReproducibleScript:  /*
     * Demo program for bug in Tcl_ObjSetVar2() Tcl 8.0, 8.0p1, 8.0p2 and 8.0.3
     *
     * Really bug in TclLookupVar() on line 214 of tclVar.c where
     * Tcl_ResetResult() is called even though the variable creation
     * may yet succeed!
     */
    #include <stdio.h>
    #include <tcl.h>
    
    #define MAKE_OBJ(name, val)  Tcl_Obj *name = Tcl_NewStringObj(val, sizeof(val)-1)
    
    static int AppInit(Tcl_Interp *interp)
    {
        int ok;
        MAKE_OBJ(obj, "newVar");
        MAKE_OBJ(cmdObj, "list 1 + 2 + 3");
    
        if (Tcl_Init(interp) != TCL_OK)
            return TCL_ERROR;
    
        /*
         * Breaks the first time when variable needs to be created!
         */
        if (Tcl_EvalObj(interp, cmdObj) != TCL_OK)
            return TCL_ERROR;
    
        if (Tcl_ObjSetVar2(interp, obj, NULL, Tcl_GetObjResult(interp),
                           TCL_PARSE_PART1|TCL_LEAVE_ERR_MSG) == NULL)
            return TCL_ERROR;
    
        if (Tcl_VarEval(interp, "puts -nonewline {Value is empty: }\n",
                         "puts '$newVar'\n", (char *)0) != TCL_OK)
            return TCL_ERROR;
    
        /*
         * Works the second time when variable already exists!
         */
        if (Tcl_EvalObj(interp, cmdObj) != TCL_OK)
            return TCL_ERROR;
    
        if (Tcl_ObjSetVar2(interp, obj, NULL, Tcl_GetObjResult(interp),
                           TCL_PARSE_PART1|TCL_LEAVE_ERR_MSG) == NULL)
            return TCL_ERROR;
    
        if (Tcl_VarEval(interp, "puts -nonewline {Value is correct: }\n",
                         "puts '$newVar'\n", (char *)0) != TCL_OK)
            return TCL_ERROR;
    
        return Tcl_VarEval(interp, "exit 0", (char *)0);
    }
    
    int main(int argc, char *argv[])
    {
        Tcl_Main(argc, argv, AppInit);
        return 1;
    }
    
    ObservedBehavior: Creation of new variables with TCL_LEAVE_ERR_MSG
    clobbers interpreter result even when variable creation succeeds.  I
    do not believe this matches the desired semantics.
    
    DesiredBehavior: The interpreter result should be modified only on
    error.
    
    Patch: I do not have a patch that I am sure will work.  The bug is on
    line 214 of tclVar.c where Tcl_ResetResult(interp) is called before
    the variable creation is attempted.  I think this code could be moved
    lower or removed... but the implications for the functions called to
    create the variable are not clear to me.
    
    Comments: Cropped up while trying to fix "catch" to report a proper
    error message when unable to set result variables.  The current
    generic message is also a bug, trivial to fix if it were not for the
    SetVar2 problem.
    
    
    
    Tcl_ResetResult is not called at all in TclLookupVar as of 8.2. 
    -- 12/03/1999 hobbs
    
  4. foundin changed to: "obsolete: 8.0.3"
  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: "10. Objects"
  10. title changed to:
    Tcl_ObjSetVar2 erroneously clears interp->result when new va
    
  11. type changed to: "Bug"