Subject: 3613854 - Fixup stack maintenance /code generation for [array set x $oddList].

From: dgp <[email-masked]>
Date: Fri, 24 May 2013 18:37:19 +0000

Postscript - I see that this commit created a memory leak.
Will commit a fix within a few days.
---
 generic/tclCompCmds.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index 10faff7..5a5cd88 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -263,11 +263,6 @@ TclCompileArraySetCmd(
     }
 
     varTokenPtr = TokenAfter(parsePtr->tokenPtr);
-    PushVarNameWord(interp, varTokenPtr, envPtr, TCL_NO_ELEMENT,
-	    &localIndex, &simpleVarName, &isScalar, 1);
-    if (!isScalar) {
-	return TCL_ERROR;
-    }
     dataTokenPtr = TokenAfter(varTokenPtr);
     literalObj = Tcl_NewObj();
     isDataLiteral = TclWordKnownAtCompileTime(dataTokenPtr, literalObj);
@@ -276,6 +271,23 @@ TclCompileArraySetCmd(
     isDataEven = (isDataValid && (len & 1) == 0);
 
     /*
+     * Special case: literal odd-length argument is always an error.
+     */
+
+    if (isDataValid && !isDataEven) {
+	PushStringLiteral(envPtr, "list must have an even number of elements");
+	PushStringLiteral(envPtr, "-errorCode {TCL ARGUMENT FORMAT}");
+	TclEmitInstInt4(INST_RETURN_IMM, 1,			envPtr);
+	TclEmitInt4(		0,				envPtr);
+	goto done;
+    }
+
+    PushVarNameWord(interp, varTokenPtr, envPtr, TCL_NO_ELEMENT,
+	    &localIndex, &simpleVarName, &isScalar, 1);
+    if (!isScalar) {
+	return TCL_ERROR;
+    }
+    /*
      * Special case: literal empty value argument is just an "ensure array"
      * operation.
      */
@@ -300,21 +312,6 @@ TclCompileArraySetCmd(
     }
 
     /*
-     * Special case: literal odd-length argument is always an error.
-     */
-
-    if (isDataValid && !isDataEven) {
-	savedStackDepth = envPtr->currStackDepth;
-	PushStringLiteral(envPtr, "list must have an even number of elements");
-	PushStringLiteral(envPtr, "-errorCode {TCL ARGUMENT FORMAT}");
-	TclEmitInstInt4(INST_RETURN_IMM, 1,			envPtr);
-	TclEmitInt4(		0,				envPtr);
-	envPtr->currStackDepth = savedStackDepth;
-	PushStringLiteral(envPtr, "");
-	goto done;
-    }
-
-    /*
      * Prepare for the internal foreach.
      */
 
-- 
cgit v0.12