summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-01-10 16:19:56 (GMT)
committerGuido van Rossum <guido@python.org>2007-01-10 16:19:56 (GMT)
commitb940e113bf90ff71b0ef57414ea2beea9d2a4bc0 (patch)
tree0b9ea19eba1e665dac95126c3140ac2bc36326ad /Python
parent893523e80a2003d4a630aafb84ba016e0070cbbd (diff)
downloadcpython-b940e113bf90ff71b0ef57414ea2beea9d2a4bc0.zip
cpython-b940e113bf90ff71b0ef57414ea2beea9d2a4bc0.tar.gz
cpython-b940e113bf90ff71b0ef57414ea2beea9d2a4bc0.tar.bz2
SF patch 1631942 by Collin Winter:
(a) "except E, V" -> "except E as V" (b) V is now limited to a simple name (local variable) (c) V is now deleted at the end of the except block
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c59
-rw-r--r--Python/graminit.c2
2 files changed, 57 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index d2374a9..481cc85 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1955,13 +1955,66 @@ compiler_try_except(struct compiler *c, stmt_ty s)
}
ADDOP(c, POP_TOP);
if (handler->name) {
+ basicblock *cleanup_end, *cleanup_body;
+ expr_context_ty orig_ctx;
+
+ assert(handler->name->kind == Name_kind);
+
+ cleanup_end = compiler_new_block(c);
+ cleanup_body = compiler_new_block(c);
+ if(!(cleanup_end || cleanup_body))
+ return 0;
+
VISIT(c, expr, handler->name);
+ ADDOP(c, POP_TOP);
+
+ /*
+ try:
+ # body
+ except type as name:
+ try:
+ # body
+ finally:
+ name = None
+ del name
+ */
+
+ /* second try: */
+ ADDOP_JREL(c, SETUP_FINALLY, cleanup_end);
+ compiler_use_next_block(c, cleanup_body);
+ if (!compiler_push_fblock(c, FINALLY_TRY, cleanup_body))
+ return 0;
+
+ /* second # body */
+ VISIT_SEQ(c, stmt, handler->body);
+ ADDOP(c, POP_BLOCK);
+ compiler_pop_fblock(c, FINALLY_TRY, cleanup_body);
+
+ /* finally: */
+ ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ compiler_use_next_block(c, cleanup_end);
+ if (!compiler_push_fblock(c, FINALLY_END, cleanup_end))
+ return 0;
+
+ /* name = None */
+ ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ orig_ctx = handler->name->v.Name.ctx;
+ handler->name->v.Name.ctx = Store;
+ VISIT(c, expr, handler->name);
+
+ /* del name */
+ handler->name->v.Name.ctx = Del;
+ VISIT(c, expr, handler->name);
+ handler->name->v.Name.ctx = orig_ctx;
+
+ ADDOP(c, END_FINALLY);
+ compiler_pop_fblock(c, FINALLY_END, cleanup_end);
}
else {
- ADDOP(c, POP_TOP);
+ ADDOP(c, POP_TOP);
+ ADDOP(c, POP_TOP);
+ VISIT_SEQ(c, stmt, handler->body);
}
- ADDOP(c, POP_TOP);
- VISIT_SEQ(c, stmt, handler->body);
ADDOP_JREL(c, JUMP_FORWARD, end);
compiler_use_next_block(c, except);
if (handler->type)
diff --git a/Python/graminit.c b/Python/graminit.c
index 93ee69a..3f02240 100644
--- a/Python/graminit.c
+++ b/Python/graminit.c
@@ -1049,7 +1049,7 @@ static arc arcs_46_1[2] = {
{0, 1},
};
static arc arcs_46_2[2] = {
- {28, 3},
+ {83, 3},
{0, 2},
};
static arc arcs_46_3[1] = {