summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-10-08 07:12:23 +0000
committerGeorg Brandl <georg@python.org>2006-10-08 07:12:23 +0000
commita5fe3ef8d835d8dffe42b58398d101eb42b897af (patch)
tree943f16877663a74e8c2dd623460ebeb6ee9d9fc4 /Python
parent74284b9606b4c2743ef82119b41eb3a74dd5b2d2 (diff)
downloadcpython-git-a5fe3ef8d835d8dffe42b58398d101eb42b897af.tar.gz
Fix #1569998: no break inside try statement (outside loop) allowed.
(backport from rev. 52129)
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 76c462829d..038bc2f4fe 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);
@@ -2764,7 +2766,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;
@@ -3754,6 +3756,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.
*/