Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 39983:f5d7de5031aa legacy-trunk
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.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Wed, 04 Oct 2006 02:24:52 +0000 |
| parents | 17f1df1553c9 |
| children | 3608605a74d5 |
line wrap: on
line diff
--- a/Python/compile.c Wed Oct 04 02:06:36 2006 +0000 +++ b/Python/compile.c Wed Oct 04 02:24:52 2006 +0000 @@ -187,6 +187,8 @@ 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 @@ 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 @@ 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. */
