|
2000-10-26
| ||
| 08:23 | • Closed ticket [218497ffff]: Tcl_ObjSetVar2 erroneously clears interp->result ... artifact: a7e3aa6a22 user: welch | |
| 01:01 | • New ticket [218497ffff]. artifact: ac81e20390 user: nobody | |
Tcl_ObjSetVar2 erroneously clears interp->result when new va
Closed / Fixed218497ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:01:20
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
welch Closed ticket [218497ffff].
[History diff]2000-10-26 08:23:18
Log in (anonymous is fine) to add a comment.