mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
[3.14] GH-135171: Fix generator expressions one last time (hopefully) (GH-135225)
* Add NULL check to FOR_ITER * Move GET_ITER back to genexpr creation
This commit is contained in:
parent
1497866198
commit
a5274cd215
8 changed files with 92 additions and 19 deletions
|
@ -4411,7 +4411,7 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
|
|||
|
||||
comprehension_ty gen = (comprehension_ty)asdl_seq_GET(generators,
|
||||
gen_index);
|
||||
|
||||
int is_outer_genexpr = gen_index == 0 && type == COMP_GENEXP;
|
||||
if (!iter_on_stack) {
|
||||
if (gen_index == 0) {
|
||||
assert(METADATA(c)->u_argcount == 1);
|
||||
|
@ -4442,14 +4442,15 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
|
|||
}
|
||||
if (IS_JUMP_TARGET_LABEL(start)) {
|
||||
VISIT(c, expr, gen->iter);
|
||||
ADDOP(c, LOC(gen->iter), GET_ITER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_JUMP_TARGET_LABEL(start)) {
|
||||
depth++;
|
||||
ADDOP(c, LOC(gen->iter), GET_ITER);
|
||||
if (!is_outer_genexpr) {
|
||||
ADDOP(c, LOC(gen->iter), GET_ITER);
|
||||
}
|
||||
USE_LABEL(c, start);
|
||||
ADDOP_JUMP(c, LOC(gen->iter), FOR_ITER, anchor);
|
||||
}
|
||||
|
@ -4775,6 +4776,7 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
|
|||
location loc = LOC(e);
|
||||
|
||||
outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
|
||||
int is_sync_genexpr = type == COMP_GENEXP && !outermost->is_async;
|
||||
if (is_inlined) {
|
||||
VISIT(c, expr, outermost->iter);
|
||||
if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
|
||||
|
@ -4851,6 +4853,9 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
|
|||
Py_CLEAR(co);
|
||||
|
||||
VISIT(c, expr, outermost->iter);
|
||||
if (is_sync_genexpr) {
|
||||
ADDOP(c, loc, GET_ITER);
|
||||
}
|
||||
ADDOP_I(c, loc, CALL, 0);
|
||||
|
||||
if (is_async_comprehension && type != COMP_GENEXP) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue