8000 compiler_try_finally returns SUCCESS/ERROR · python/cpython@99a7257 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99a7257

Browse files
committed
compiler_try_finally returns SUCCESS/ERROR
1 parent fdf615f commit 99a7257

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Python/compile.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,45 +3512,46 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
35123512
NEW_JUMP_TARGET_LABEL(c, cleanup);
35133513

35143514
/* `try` block */
3515-
_ADDOP_JUMP(c, loc, SETUP_FINALLY, end);
3515+
ADDOP_JUMP(c, loc, SETUP_FINALLY, end);
35163516

35173517
USE_LABEL(c, body);
3518-
if (compiler_push_fblock(c, loc, FINALLY_TRY, body, end, s->v.Try.finalbody) < 0) {
3519-
return 0;
3520-
}
3518+
RETURN_IF_ERROR(
3519+
compiler_push_fblock(c, loc, FINALLY_TRY, body, end,
3520+
s->v.Try.finalbody));
3521+
35213522
if (s->v.Try.handlers && asdl_seq_LEN(s->v.Try.handlers)) {
3522-
if (!compiler_try_except(c, s))
3523-
return 0;
3523+
if (!compiler_try_except(c, s)) {
3524+
return ERROR;
3525+
}
35243526
}
35253527
else {
3526-
_VISIT_SEQ(c, stmt, s->v.Try.body);
3528+
VISIT_SEQ(c, stmt, s->v.Try.body);
35273529
}
3528-
_ADDOP(c, NO_LOCATION, POP_BLOCK);
3530+
ADDOP(c, NO_LOCATION, POP_BLOCK);
35293531
compiler_pop_fblock(c, FINALLY_TRY, body);
3530-
_VISIT_SEQ(c, stmt, s->v.Try.finalbody);
3532+
VISIT_SEQ(c, stmt, s->v.Try.finalbody);
35313533

3532-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
3534+
ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
35333535
/* `finally` block */
35343536

35353537
USE_LABEL(c, end);
35363538

35373539
loc = NO_LOCATION;
3538-
_ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup);
3539-
_ADDOP(c, loc, PUSH_EXC_INFO);
3540-
if (compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL) < 0) {
3541-
return 0;
3542-
}
3543-
_VISIT_SEQ(c, stmt, s->v.Try.finalbody);
3540+
ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup);
3541+
ADDOP(c, loc, PUSH_EXC_INFO);
3542+
RETURN_IF_ERROR(
3543+
compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL));
3544+
VISIT_SEQ(c, stmt, s->v.Try.finalbody);
35443545
loc = location_of_last_executing_statement(s->v.Try.finalbody);
35453546
compiler_pop_fblock(c, FINALLY_END, end);
35463547

3547-
_ADDOP_I(c, loc, RERAISE, 0);
3548+
ADDOP_I(c, loc, RERAISE, 0);
35483549

35493550
USE_LABEL(c, cleanup);
3550-
_POP_EXCEPT_AND_RERAISE(c, loc);
3551+
POP_EXCEPT_AND_RERAISE(c, loc);
35513552

35523553
USE_LABEL(c, exit);
3553-
return 1;
3554+
return SUCCESS;
35543555
}
35553556

35563557
static int
@@ -3973,7 +3974,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
39733974
static int
39743975
compiler_try(struct compiler *c, stmt_ty s) {
39753976
if (s->v.Try.finalbody && asdl_seq_LEN(s->v.Try.finalbody))
3976-
return compiler_try_finally(c, s);
3977+
return compiler_try_finally(c, s) == SUCCESS ? 1 : 0;
39773978
else
39783979
return compiler_try_except(c, s);
39793980
}

0 commit comments

Comments
 (0)
0