summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--generic/tclExecute.c22
-rw-r--r--tests/compile.test11
3 files changed, 29 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 48da8a5..ccb3db4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2002-04-15 Miguel Sofer <msofer@users.sourceforge.net>
+
+ * generic/tclExecute.c:
+ * tests/compile.test: made bytecodes check for a catch before
+ returning; the compiled [return] is otherwise non-catchable.
+ [Bug 542588] reported by Andreas Kupries.
+
2002-04-15 Don Porter <dgp@users.sourceforge.net>
* doc/tcltest.n:
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index d737299..fd369b2 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -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: tclExecute.c,v 1.51 2002/03/29 21:01:12 dgp Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.52 2002/04/15 17:32:18 msofer Exp $
*/
#include "tclInt.h"
@@ -1090,16 +1090,19 @@ TclExecuteByteCode(interp, codePtr)
#endif
switch (*pc) {
case INST_DONE:
+ if (stackTop <= initStackTop) {
+ goto abnormalReturn;
+ }
+
/*
- * Pop the topmost object from the stack, set the interpreter's
- * object result to point to it, and return.
+ * Set the interpreter's object result to point to the
+ * topmost object from the stack, and check for a possible
+ * [catch]. The stackTop's level and refCount will be handled
+ * by "processCatch" or "abnormalReturn".
*/
- valuePtr = POP_OBJECT();
+
+ valuePtr = stackPtr[stackTop];
Tcl_SetObjResult(interp, valuePtr);
- TclDecrRefCount(valuePtr);
- if (stackTop != initStackTop) {
- goto abnormalReturn;
- }
TRACE_WITH_OBJ(("=> return code=%d, result=", result),
iPtr->objResultPtr);
#ifdef TCL_COMPILE_DEBUG
@@ -1107,7 +1110,7 @@ TclExecuteByteCode(interp, codePtr)
fprintf(stdout, "\n");
}
#endif
- goto done;
+ goto checkForCatch;
case INST_PUSH1:
#ifdef TCL_COMPILE_DEBUG
@@ -4387,7 +4390,6 @@ TclExecuteByteCode(interp, codePtr)
* Free the catch stack array if malloc'ed storage was used.
*/
- done:
if (catchStackPtr != catchStackStorage) {
ckfree((char *) catchStackPtr);
}
diff --git a/tests/compile.test b/tests/compile.test
index 7086de5..aef9ac0 100644
--- a/tests/compile.test
+++ b/tests/compile.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: compile.test,v 1.18 2002/03/15 15:39:07 dkf Exp $
+# RCS: @(#) $Id: compile.test,v 1.19 2002/04/15 17:32:18 msofer Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
@@ -98,6 +98,15 @@ test compile-3.3 {TclCompileCatchCmd: overagressive compiling [bug 219184]} {
catch {catch-test error} ::foo
set ::foo
} {GOOD}
+test compile-3.4 {TclCompileCatchCmd: bcc'ed [return] is caught} {
+ proc foo {} {
+ set fail [catch {
+ return 1
+ }] ; # {}
+ return 2
+ }
+ foo
+} {2}
test compile-4.1 {TclCompileForCmd: command substituted test expression} {
set i 0