gh-101892: Fix SystemError when a callable iterator call exhausts the iterator (#101896)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
This commit is contained in:
Raj 2023-03-04 19:51:29 +05:30 committed by GitHub
parent b022250e67
commit 705487c655
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View file

@ -219,7 +219,7 @@ calliter_iternext(calliterobject *it)
}
result = _PyObject_CallNoArgs(it->it_callable);
if (result != NULL) {
if (result != NULL && it->it_sentinel != NULL){
int ok;
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
@ -227,7 +227,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);
@ -238,6 +237,7 @@ calliter_iternext(calliterobject *it)
Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel);
}
Py_XDECREF(result);
return NULL;
}