diff options
author | Raj <51259329+workingpayload@users.noreply.github.com> | 2023-03-04 14:21:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 14:21:29 (GMT) |
commit | 705487c6557c3d8866622b4d32528bf7fc2e4204 (patch) | |
tree | b9f348ce98df6e03549d282dab6b0a49b93863d1 /Objects | |
parent | b022250e67449e0bc49a3c982fe9e6a2d6a7b71a (diff) | |
download | cpython-705487c6557c3d8866622b4d32528bf7fc2e4204.zip cpython-705487c6557c3d8866622b4d32528bf7fc2e4204.tar.gz cpython-705487c6557c3d8866622b4d32528bf7fc2e4204.tar.bz2 |
gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (#101896)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/iterobject.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 149b701..7cb17a6 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -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; } |