summaryrefslogtreecommitdiffstats
path: root/Objects/iterobject.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-03-04 14:46:17 (GMT)
committerGitHub <noreply@github.com>2023-03-04 14:46:17 (GMT)
commit06a3bb8c9416a53018ea23414d6018764a9e2845 (patch)
tree3b95a3faac050cd441fc3b70ea30671dabd40dee /Objects/iterobject.c
parent00791f23b78cc61d732ef4a6386c9ce255113c3e (diff)
downloadcpython-06a3bb8c9416a53018ea23414d6018764a9e2845.zip
cpython-06a3bb8c9416a53018ea23414d6018764a9e2845.tar.gz
cpython-06a3bb8c9416a53018ea23414d6018764a9e2845.tar.bz2
gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (GH-101896)
(cherry picked from commit 705487c6557c3d8866622b4d32528bf7fc2e4204) Co-authored-by: Raj <51259329+workingpayload@users.noreply.github.com> Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Diffstat (limited to 'Objects/iterobject.c')
-rw-r--r--Objects/iterobject.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index ae09d2c..822f9e2 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -222,7 +222,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);
@@ -230,7 +230,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);
@@ -241,6 +240,7 @@ calliter_iternext(calliterobject *it)
Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel);
}
+ Py_XDECREF(result);
return NULL;
}