[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:
Mark Shannon 2025-06-09 11:04:23 +01:00 committed by GitHub
parent 1497866198
commit a5274cd215
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 92 additions and 19 deletions

View file

@ -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) {