diff options
Diffstat (limited to 'Modules')
-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 cf419ad..e60ad5b 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -443,6 +443,7 @@ typedef struct { PyObject_HEAD PyObject *it; int numread; /* 0 <= numread <= LINKCELLS */ + int running; PyObject *nextlink; PyObject *(values[LINKCELLS]); } teedataobject; @@ -465,6 +466,7 @@ teedataobject_newinternal(PyObject *it) if (tdo == NULL) return NULL; + tdo->running = 0; tdo->numread = 0; tdo->nextlink = NULL; Py_INCREF(it); @@ -493,7 +495,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++; |