summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-10-22 12:21:06 (GMT)
committerGitHub <noreply@github.com>2022-10-22 12:21:06 (GMT)
commit5871e19942fdcf83653924ae9a849941669c1143 (patch)
tree11d66b70737f04a53a5adfaf9832562e5907e14d
parentf7f55a5b9e37d7172ec47030484865b8c585ff46 (diff)
downloadcpython-5871e19942fdcf83653924ae9a849941669c1143.zip
cpython-5871e19942fdcf83653924ae9a849941669c1143.tar.gz
cpython-5871e19942fdcf83653924ae9a849941669c1143.tar.bz2
GH-98363: Slicing isn't necessary. A size reduction will suffice. (GH-98538)
-rw-r--r--Modules/itertoolsmodule.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 578c2d9..381ec3b 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -167,23 +167,22 @@ batched_next(batchedobject *bo)
null_item:
if (PyErr_Occurred()) {
- if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
- PyErr_Clear();
- } else {
- /* input raised an exception other than StopIteration */
+ if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
+ /* Input raised an exception other than StopIteration */
Py_CLEAR(bo->it);
Py_DECREF(result);
return NULL;
}
+ PyErr_Clear();
}
if (i == 0) {
Py_CLEAR(bo->it);
Py_DECREF(result);
return NULL;
}
- PyObject *short_list = PyList_GetSlice(result, 0, i);
- Py_DECREF(result);
- return short_list;
+ /* Elements in result[i:] are still NULL */
+ Py_SET_SIZE(result, i);
+ return result;
}
static PyTypeObject batched_type = {