[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

@ -3155,7 +3155,14 @@ dummy_func(
replaced op(_FOR_ITER, (iter -- iter, next)) {
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
iternextfunc func = Py_TYPE(iter_o)->tp_iternext;
if (func == NULL) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.100s' object is not an iterator",
Py_TYPE(iter_o)->tp_name);
ERROR_NO_POP();
}
PyObject *next_o = func(iter_o);
if (next_o == NULL) {
if (_PyErr_Occurred(tstate)) {
int matches = _PyErr_ExceptionMatches(tstate, PyExc_StopIteration);
@ -3179,7 +3186,14 @@ dummy_func(
op(_FOR_ITER_TIER_TWO, (iter -- iter, next)) {
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
iternextfunc func = Py_TYPE(iter_o)->tp_iternext;
if (func == NULL) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.100s' object is not an iterator",
Py_TYPE(iter_o)->tp_name);
ERROR_NO_POP();
}
PyObject *next_o = func(iter_o);
if (next_o == NULL) {
if (_PyErr_Occurred(tstate)) {
int matches = _PyErr_ExceptionMatches(tstate, PyExc_StopIteration);
@ -3202,7 +3216,14 @@ dummy_func(
inst(INSTRUMENTED_FOR_ITER, (unused/1, iter -- iter, next)) {
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
iternextfunc func = Py_TYPE(iter_o)->tp_iternext;
if (func == NULL) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.100s' object is not an iterator",
Py_TYPE(iter_o)->tp_name);
ERROR_NO_POP();
}
PyObject *next_o = func(iter_o);
if (next_o != NULL) {
next = PyStackRef_FromPyObjectSteal(next_o);
INSTRUMENTED_JUMP(this_instr, next_instr, PY_MONITORING_EVENT_BRANCH_LEFT);