mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.10] gh-101892: Fix SystemError when a callable iterator call exhausts the iterator (GH-101896) (#102422)
gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (#101896)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
(cherry picked from commit 705487c655)
Co-authored-by: Raj <51259329+workingpayload@users.noreply.github.com>
This commit is contained in:
parent
6c2e052ee0
commit
fe36778968
3 changed files with 30 additions and 2 deletions
|
|
@ -223,7 +223,7 @@ calliter_iternext(calliterobject *it)
|
|||
}
|
||||
|
||||
result = _PyObject_CallNoArg(it->it_callable);
|
||||
if (result != NULL) {
|
||||
if (result != NULL && it->it_sentinel != NULL){
|
||||
int ok;
|
||||
|
||||
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
|
||||
|
|
@ -231,7 +231,6 @@ calliter_iternext(calliterobject *it)
|
|||
return result; /* Common case, fast path */
|
||||
}
|
||||
|
||||
Py_DECREF(result);
|
||||
if (ok > 0) {
|
||||
Py_CLEAR(it->it_callable);
|
||||
Py_CLEAR(it->it_sentinel);
|
||||
|
|
@ -242,6 +241,7 @@ calliter_iternext(calliterobject *it)
|
|||
Py_CLEAR(it->it_callable);
|
||||
Py_CLEAR(it->it_sentinel);
|
||||
}
|
||||
Py_XDECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue