diff options
-rw-r--r-- | generic/tclEnsemble.c | 43 | ||||
-rw-r--r-- | tests/compile.test | 11 |
2 files changed, 54 insertions, 0 deletions
diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 8f7d1a2..986a553 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -3082,6 +3082,11 @@ TclAttemptCompileProc( Tcl_Token *saveTokenPtr = parsePtr->tokenPtr; int savedStackDepth = envPtr->currStackDepth; unsigned savedCodeNext = envPtr->codeNext - envPtr->codeStart; + int savedAuxDataArrayNext = envPtr->auxDataArrayNext; + int savedExceptArrayNext = envPtr->exceptArrayNext; +#ifdef TCL_COMPILE_DEBUG + int savedExceptDepth = envPtr->exceptDepth; +#endif DefineLineInformation; if (cmdPtr->compileProc == NULL) { @@ -3130,7 +3135,45 @@ TclAttemptCompileProc( * we avoid compiling subcommands that recursively call TclCompileScript(). */ +#ifdef TCL_COMPILE_DEBUG + if (envPtr->exceptDepth != savedExceptDepth) { + Tcl_Panic("ExceptionRange Starts and Ends do not balance"); + } +#endif + if (result != TCL_OK) { + ExceptionAux *auxPtr = envPtr->exceptAuxArrayPtr; + + for (i = 0; i < savedExceptArrayNext; i++) { + while (auxPtr->numBreakTargets > 0 + && auxPtr->breakTargets[auxPtr->numBreakTargets - 1] + >= savedCodeNext) { + auxPtr->numBreakTargets--; + } + while (auxPtr->numContinueTargets > 0 + && auxPtr->continueTargets[auxPtr->numContinueTargets - 1] + >= savedCodeNext) { + auxPtr->numContinueTargets--; + } + auxPtr++; + } + envPtr->exceptArrayNext = savedExceptArrayNext; + + if (savedAuxDataArrayNext != envPtr->auxDataArrayNext) { + AuxData *auxDataPtr = envPtr->auxDataArrayPtr; + AuxData *auxDataEnd = auxDataPtr; + + auxDataPtr += savedAuxDataArrayNext; + auxDataEnd += envPtr->auxDataArrayNext; + + while (auxDataPtr < auxDataEnd) { + if (auxDataPtr->type->freeProc != NULL) { + auxDataPtr->type->freeProc(auxDataPtr->clientData); + } + auxDataPtr++; + } + envPtr->auxDataArrayNext = savedAuxDataArrayNext; + } envPtr->currStackDepth = savedStackDepth; envPtr->codeNext = envPtr->codeStart + savedCodeNext; #ifdef TCL_COMPILE_DEBUG diff --git a/tests/compile.test b/tests/compile.test index 46e678a..bb12050 100644 --- a/tests/compile.test +++ b/tests/compile.test @@ -224,6 +224,17 @@ test compile-5.2 {TclCompileForeachCmd: non-local variables} { foreach-test set ::foo } 3 +test compile-5.3 {TclCompileForeachCmd: [Bug b9b2079e6d]} -setup { + proc demo {} { + foreach x y { + if 1 break else + } + } +} -body { + demo +} -cleanup { + rename demo {} +} -returnCodes error -result {wrong # args: no script following "else" argument} test compile-6.1 {TclCompileSetCmd: global scalar names with ::s} -setup { catch {unset x} |