Subject: 3614102 - Reset stack housekeeping when compileProc fails.

From: dgp <[email-masked]>
Date: Wed, 29 May 2013 17:20:29 +0000

---
 generic/tclCompile.c | 8 ++++++--
 tests/compile.test   | 6 ++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/generic/tclCompile.c b/generic/tclCompile.c
index dd179ea..039a694 100644
--- a/generic/tclCompile.c
+++ b/generic/tclCompile.c
@@ -2069,9 +2069,7 @@ TclCompileScript(
 			unsigned savedCodeNext =
 				envPtr->codeNext - envPtr->codeStart;
 			int update = 0;
-#ifdef TCL_COMPILE_DEBUG
 			int startStackDepth = envPtr->currStackDepth;
-#endif
 
 			/*
 			 * Mark the start of the command; the proper bytecode
@@ -2164,6 +2162,12 @@ TclCompileScript(
 
 			envPtr->numCommands = savedNumCmds;
 			envPtr->codeNext = envPtr->codeStart + savedCodeNext;
+
+			/*
+			 * And the stack depth too!!  [Bug 3614102].
+			 */
+
+			envPtr->currStackDepth = startStackDepth;
 		    }
 
 		    /*
diff --git a/tests/compile.test b/tests/compile.test
index 4d91940..51db0a2 100644
--- a/tests/compile.test
+++ b/tests/compile.test
@@ -707,6 +707,12 @@ test compile-18.19 {disassembler - basics} -setup {
 } -cleanup {
     foo destroy
 } -match glob -result *
+
+test compile-19.0 {Bug 3614102: reset stack housekeeping} -body {
+    # This will panic in a --enable-symbols=compile build, unless bug is fixed.
+    apply {{} {list [if 1]}}
+} -returnCodes error -match glob -result *
+
 # TODO sometime - check that bytecode from tbcload is *not* disassembled.
 
 # cleanup
-- 
cgit v0.12