Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
If the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs.
Example discovered by@chilaxan
defbug():ifbug.clear:return1else:bug.clear=Truelist(bug.iterator)return0bug.iterator=iter(bug,1)bug.clear=Falsenext(bug.iterator)
SystemError: Objects\object.c:722: bad argument to internal functionLikely cause
iterobject.calliter_iternext does not check whetherit->it_sentinel is NULL after the_PyObject_CallNoArgs call
https://github.com/python/cpython/blob/main/Objects/iterobject.c#L207-L237
static PyObject *calliter_iternext(calliterobject *it){ PyObject *result; if (it->it_callable == NULL) { return NULL; }+ result = _PyObject_CallNoArgs(it->it_callable); if (result != NULL) { int ok;+ ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ); if (ok == 0) { return result; /* Common case, fast path */ }(...)Your environment
Appears to affect 3.7-3.12