gh-126366: Fix crash if __iter__ raises an exception during yield from (#126369)

This commit is contained in:
Peter Bierma 2024-11-05 04:56:36 -05:00 committed by GitHub
parent 407c0366d9
commit 1371295e67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 6 deletions

View file

@ -2811,11 +2811,12 @@ dummy_func(
}
else {
/* `iterable` is not a generator. */
iter = PyStackRef_FromPyObjectSteal(PyObject_GetIter(iterable_o));
PyObject *iter_o = PyObject_GetIter(iterable_o);
DEAD(iterable);
if (PyStackRef_IsNull(iter)) {
if (iter_o == NULL) {
ERROR_NO_POP();
}
iter = PyStackRef_FromPyObjectSteal(iter_o);
DECREF_INPUTS();
}
}

View file

@ -3437,11 +3437,12 @@
else {
/* `iterable` is not a generator. */
_PyFrame_SetStackPointer(frame, stack_pointer);
iter = PyStackRef_FromPyObjectSteal(PyObject_GetIter(iterable_o));
PyObject *iter_o = PyObject_GetIter(iterable_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (PyStackRef_IsNull(iter)) {
if (iter_o == NULL) {
JUMP_TO_ERROR();
}
iter = PyStackRef_FromPyObjectSteal(iter_o);
PyStackRef_CLOSE(iterable);
}
}

View file

@ -4304,11 +4304,12 @@
else {
/* `iterable` is not a generator. */
_PyFrame_SetStackPointer(frame, stack_pointer);
iter = PyStackRef_FromPyObjectSteal(PyObject_GetIter(iterable_o));
PyObject *iter_o = PyObject_GetIter(iterable_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (PyStackRef_IsNull(iter)) {
if (iter_o == NULL) {
goto error;
}
iter = PyStackRef_FromPyObjectSteal(iter_o);
PyStackRef_CLOSE(iterable);
}
}