diff options
author | Miguel Sofer <miguel.sofer@gmail.com> | 2001-08-10 13:10:13 (GMT) |
---|---|---|
committer | Miguel Sofer <miguel.sofer@gmail.com> | 2001-08-10 13:10:13 (GMT) |
commit | e3e4bcea9c4105e94029baa9f8c5ddad79fdc692 (patch) | |
tree | c9e4138fcbb2e69dcb5e9e7dcf03f049e2cca084 | |
parent | a824d7b8087eb9e6024ad460b982386fe419faea (diff) | |
download | tcl-e3e4bcea9c4105e94029baa9f8c5ddad79fdc692.zip tcl-e3e4bcea9c4105e94029baa9f8c5ddad79fdc692.tar.gz tcl-e3e4bcea9c4105e94029baa9f8c5ddad79fdc692.tar.bz2 |
insure that [array] traces work for undefined vars [bug: 449094]
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | generic/tclVar.c | 22 | ||||
-rw-r--r-- | tests/trace.test | 7 |
3 files changed, 26 insertions, 9 deletions
@@ -1,3 +1,9 @@ +2001-08-10 Miguel Sofer <msofer@users.sourceforge.net> + + * generic/tclVar.c: + * tests/trace.test: Insure that [array] traces work correctly for + undefined variables [Bug: 449094] + 2001-08-09 Mo DeJong <mdejong@redhat.com> * unix/Makefile.in: Delete the unused getcwd.o diff --git a/generic/tclVar.c b/generic/tclVar.c index ba76f00..c342522 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclVar.c,v 1.35 2001/07/04 00:55:08 hobbs Exp $ + * RCS: @(#) $Id: tclVar.c,v 1.36 2001/08/10 13:10:13 msofer Exp $ */ #include "tclInt.h" @@ -3061,19 +3061,13 @@ Tcl_ArrayObjCmd(dummy, interp, objc, objv) } /* - * Locate the array variable (and it better be an array). + * Locate the array variable */ varName = TclGetString(objv[2]); varPtr = TclLookupVar(interp, varName, (char *) NULL, /*flags*/ 0, /*msg*/ 0, /*createPart1*/ 0, /*createPart2*/ 0, &arrayPtr); - notArray = 0; - if ((varPtr == NULL) || !TclIsVarArray(varPtr) - || TclIsVarUndefined(varPtr)) { - notArray = 1; - } - /* * Special array trace used to keep the env array in sync for * array names, array get, etc. @@ -3091,6 +3085,18 @@ Tcl_ArrayObjCmd(dummy, interp, objc, objv) } /* + * Verify that it is indeed an array variable. This test comes after + * the traces - the variable may actually become an array as an effect + * of said traces. + */ + + notArray = 0; + if ((varPtr == NULL) || !TclIsVarArray(varPtr) + || TclIsVarUndefined(varPtr)) { + notArray = 1; + } + + /* * We have to wait to get the resultPtr until here because * CallTraces can affect the result. */ diff --git a/tests/trace.test b/tests/trace.test index 66ec08f..102850a 100644 --- a/tests/trace.test +++ b/tests/trace.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: trace.test,v 1.9 2000/08/25 20:39:32 ericm Exp $ +# RCS: @(#) $Id: trace.test,v 1.10 2001/08/10 13:10:13 msofer Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -336,6 +336,11 @@ test trace-5.7 {array traces fire for undefined variables} { array set x {a 1} set ::info } {x {} array} +test trace-5.8 {array traces fire for undefined variables} { + catch {unset x} + trace add variable x array {set x(foo) 1 ;#} + set res "names: [array names x]" +} {names: foo} # Trace multiple trace types at once. |