summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2006-10-04 02:24:52 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2006-10-04 02:24:52 (GMT)
commit82271f13e7eab69b909d538556e4781e971f7584 (patch)
tree1e6933364df5194411899d9b6535a525667d1948 /Python
parent1e3c3b15df64a8ca083f63af7884ce60bf4e9c16 (diff)
downloadcpython-82271f13e7eab69b909d538556e4781e971f7584.zip
cpython-82271f13e7eab69b909d538556e4781e971f7584.tar.gz
cpython-82271f13e7eab69b909d538556e4781e971f7584.tar.bz2
Fix for SF bug 1569998: break permitted inside try.
The compiler was checking that there was something on the fblock stack, but not that there was a loop on the stack. Fixed that and added a test for the specific syntax error. Bug fix candidate.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index a03de0d..374cf1c 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -187,6 +187,8 @@ static int compiler_push_fblock(struct compiler *, enum fblocktype,
basicblock *);
static void compiler_pop_fblock(struct compiler *, enum fblocktype,
basicblock *);
+/* Returns true if there is a loop on the fblock stack. */
+static int compiler_in_loop(struct compiler *);
static int inplace_binop(struct compiler *, operator_ty);
static int expr_constant(expr_ty e);
@@ -2157,7 +2159,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
case Pass_kind:
break;
case Break_kind:
- if (!c->u->u_nfblocks)
+ if (!compiler_in_loop(c))
return compiler_error(c, "'break' outside loop");
ADDOP(c, BREAK_LOOP);
break;
@@ -3147,6 +3149,16 @@ compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b)
assert(u->u_fblock[u->u_nfblocks].fb_block == b);
}
+static int
+compiler_in_loop(struct compiler *c) {
+ int i;
+ struct compiler_unit *u = c->u;
+ for (i = 0; i < u->u_nfblocks; ++i) {
+ if (u->u_fblock[i].fb_type == LOOP)
+ return 1;
+ }
+ return 0;
+}
/* Raises a SyntaxError and returns 0.
If something goes wrong, a different exception may be raised.
*/