diff options
author | Raymond Hettinger <python@rcn.com> | 2003-08-29 23:09:58 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-08-29 23:09:58 (GMT) |
commit | a56f6b6600ea8906562cfaa31859b72a53a8c0d7 (patch) | |
tree | 5379c5da992031907cc63202247dd8fa185cb9df /Modules | |
parent | b738041c5db7a04b71ed4c3c8128dabc935ad60b (diff) | |
download | cpython-a56f6b6600ea8906562cfaa31859b72a53a8c0d7.zip cpython-a56f6b6600ea8906562cfaa31859b72a53a8c0d7.tar.gz cpython-a56f6b6600ea8906562cfaa31859b72a53a8c0d7.tar.bz2 |
SF bug #793826: using itertools.izip to mutate tuples
Avoid Armin Rigo's dastardly exercise in re-entrancy.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/itertoolsmodule.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 4a99fce..4dca054 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -1595,16 +1595,18 @@ izip_next(izipobject *lz) if (tuplesize == 0) return NULL; if (result->ob_refcnt == 1) { + Py_INCREF(result); for (i=0 ; i < tuplesize ; i++) { it = PyTuple_GET_ITEM(lz->ittuple, i); assert(PyIter_Check(it)); item = (*it->ob_type->tp_iternext)(it); - if (item == NULL) + if (item == NULL) { + Py_DECREF(result); return NULL; + } Py_DECREF(PyTuple_GET_ITEM(result, i)); PyTuple_SET_ITEM(result, i, item); } - Py_INCREF(result); } else { result = PyTuple_New(tuplesize); if (result == NULL) |