Skip to content

Commit d082634

Browse files
[3.7] bpo-33041: Add missed error checks when compile "async for" (GH-6053) (GH-6060)
and remove redundant code. (cherry picked from commit 67ee077) Co-authored-by: Serhiy Storchaka <[email protected]> (cherry picked from commit 9e94c0d) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 017e9fd commit d082634

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

‎Python/compile.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ compiler_async_for(struct compiler *c, stmt_ty s)
21892189
_Py_IDENTIFIER(StopAsyncIteration);
21902190

21912191
basicblock *try, *except, *end, *after_try, *try_cleanup,
2192-
*after_loop, *after_loop_else;
2192+
*after_loop_else;
21932193

21942194
PyObject *stop_aiter_error = _PyUnicode_FromId(&PyId_StopAsyncIteration);
21952195
if (stop_aiter_error == NULL) {
@@ -2201,14 +2201,14 @@ compiler_async_for(struct compiler *c, stmt_ty s)
22012201
end = compiler_new_block(c);
22022202
after_try = compiler_new_block(c);
22032203
try_cleanup = compiler_new_block(c);
2204-
after_loop = compiler_new_block(c);
22052204
after_loop_else = compiler_new_block(c);
22062205

22072206
if (try == NULL || except == NULL || end == NULL
2208-
|| after_try == NULL || try_cleanup == NULL)
2207+
|| after_try == NULL || try_cleanup == NULL
2208+
|| after_loop_else == NULL)
22092209
return 0;
22102210

2211-
ADDOP_JREL(c, SETUP_LOOP, after_loop);
2211+
ADDOP_JREL(c, SETUP_LOOP, end);
22122212
if (!compiler_push_fblock(c, LOOP, try))
22132213
return 0;
22142214

@@ -2257,9 +2257,6 @@ compiler_async_for(struct compiler *c, stmt_ty s)
22572257
ADDOP(c, POP_BLOCK); /* for SETUP_LOOP */
22582258
compiler_pop_fblock(c, LOOP, try);
22592259

2260-
compiler_use_next_block(c, after_loop);
2261-
ADDOP_JABS(c, JUMP_ABSOLUTE, end);
2262-
22632260
compiler_use_next_block(c, after_loop_else);
22642261
VISIT_SEQ(c, stmt, s->v.For.orelse);
22652262

@@ -3753,7 +3750,7 @@ compiler_async_comprehension_generator(struct compiler *c,
37533750
_Py_IDENTIFIER(StopAsyncIteration);
37543751

37553752
comprehension_ty gen;
3756-
basicblock *anchor, *skip, *if_cleanup, *try,
3753+
basicblock *anchor, *if_cleanup, *try,
37573754
*after_try, *except, *try_cleanup;
37583755
Py_ssize_t i, n;
37593756

@@ -3766,13 +3763,12 @@ compiler_async_comprehension_generator(struct compiler *c,
37663763
after_try = compiler_new_block(c);
37673764
try_cleanup = compiler_new_block(c);
37683765
except = compiler_new_block(c);
3769-
skip = compiler_new_block(c);
37703766
if_cleanup = compiler_new_block(c);
37713767
anchor = compiler_new_block(c);
37723768

3773-
if (skip == NULL || if_cleanup == NULL || anchor == NULL ||
3769+
if (if_cleanup == NULL || anchor == NULL ||
37743770
try == NULL || after_try == NULL ||
3775-
except == NULL || after_try == NULL) {
3771+
except == NULL || try_cleanup == NULL) {
37763772
return 0;
37773773
}
37783774

@@ -3866,8 +3862,6 @@ compiler_async_comprehension_generator(struct compiler *c,
38663862
default:
38673863
return 0;
38683864
}
3869-
3870-
compiler_use_next_block(c, skip);
38713865
}
38723866
compiler_use_next_block(c, if_cleanup);
38733867
ADDOP_JABS(c, JUMP_ABSOLUTE, try);

0 commit comments

Comments
 (0)