Attachment "bcCatch.patch" to
ticket [542142ffff]
added by
msofer
2002-04-11 03:12:32.
Index: generic/tclExecute.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
retrieving revision 1.51
diff -u -r1.51 tclExecute.c
--- generic/tclExecute.c 29 Mar 2002 21:01:12 -0000 1.51
+++ generic/tclExecute.c 10 Apr 2002 20:06:19 -0000
@@ -1090,16 +1090,19 @@
#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 @@
fprintf(stdout, "\n");
}
#endif
- goto done;
+ goto checkForCatch;
case INST_PUSH1:
#ifdef TCL_COMPILE_DEBUG
@@ -4387,7 +4390,6 @@
* Free the catch stack array if malloc'ed storage was used.
*/
- done:
if (catchStackPtr != catchStackStorage) {
ckfree((char *) catchStackPtr);
}
Index: tests/compile.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/compile.test,v
retrieving revision 1.18
diff -u -r1.18 compile.test
--- tests/compile.test 15 Mar 2002 15:39:07 -0000 1.18
+++ tests/compile.test 10 Apr 2002 20:06:20 -0000
@@ -98,6 +98,15 @@
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