diff options
author | Oleg Iarygin <oleg@arhadthedev.net> | 2023-03-04 15:26:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 15:26:12 (GMT) |
commit | fe36778968a0fdddada282fbd7e28e8ccd0debe0 (patch) | |
tree | d48878c8dbb6b7848afdee365cadd8a1b01c2a34 /Objects/iterobject.c | |
parent | 6c2e052ee07f10a6336bb4de1cef71dbe7d30ee6 (diff) | |
download | cpython-fe36778968a0fdddada282fbd7e28e8ccd0debe0.zip cpython-fe36778968a0fdddada282fbd7e28e8ccd0debe0.tar.gz cpython-fe36778968a0fdddada282fbd7e28e8ccd0debe0.tar.bz2 |
[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 705487c6557c3d8866622b4d32528bf7fc2e4204)
Co-authored-by: Raj <51259329+workingpayload@users.noreply.github.com>
Diffstat (limited to 'Objects/iterobject.c')
-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 980c04b..ffea129 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -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; } |