diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-09 09:38:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-09 09:38:05 (GMT) |
commit | 2fb6921ab296f933caf361a662e6471e143abefc (patch) | |
tree | 7d2241b4fd7d9f6809a5de02cbf8c0d6c1806832 /Modules/itertoolsmodule.c | |
parent | 0229b56d8c0cb65b8ad789e69dcd281fd92a6d96 (diff) | |
download | cpython-2fb6921ab296f933caf361a662e6471e143abefc.zip cpython-2fb6921ab296f933caf361a662e6471e143abefc.tar.gz cpython-2fb6921ab296f933caf361a662e6471e143abefc.tar.bz2 |
[2.7] bpo-34410: Fix a crash in the tee iterator when re-enter it. (GH-15625) (GH-15740)
RuntimeError is now raised in this case.
(cherry picked from commit 526a01467b3277f9fcf7f91e66c23321caa1245d)
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 04076fd..edd21be 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -314,6 +314,7 @@ typedef struct { PyObject_HEAD PyObject *it; int numread; + int running; PyObject *nextlink; PyObject *(values[LINKCELLS]); } teedataobject; @@ -336,6 +337,7 @@ teedataobject_new(PyObject *it) if (tdo == NULL) return NULL; + tdo->running = 0; tdo->numread = 0; tdo->nextlink = NULL; Py_INCREF(it); @@ -364,7 +366,14 @@ teedataobject_getitem(teedataobject *tdo, int i) else { /* this is the lead iterator, so fetch more data */ assert(i == tdo->numread); + if (tdo->running) { + PyErr_SetString(PyExc_RuntimeError, + "cannot re-enter the tee iterator"); + return NULL; + } + tdo->running = 1; value = PyIter_Next(tdo->it); + tdo->running = 0; if (value == NULL) return NULL; tdo->numread++; |