summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-11-01 20:45:16 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-11-01 20:45:16 (GMT)
commitfa7dadd339ab1d69f846fd4f7a4bf0d5882fc7c3 (patch)
treef6e9081807f8055f5f923369e3d854cfb87a3b0c /Modules
parent38f5d8fcc24f0ec04b8171cbde62d50238b69fa8 (diff)
downloadcpython-fa7dadd339ab1d69f846fd4f7a4bf0d5882fc7c3.zip
cpython-fa7dadd339ab1d69f846fd4f7a4bf0d5882fc7c3.tar.gz
cpython-fa7dadd339ab1d69f846fd4f7a4bf0d5882fc7c3.tar.bz2
Fix exception handling in itertools.izip_longest().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 64e3606..f12d874 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3865,71 +3865,73 @@ izip_longest_traverse(iziplongestobject *lz, visitproc visit, void *arg)
static PyObject *
izip_longest_next(iziplongestobject *lz)
{
- Py_ssize_t i;
- Py_ssize_t tuplesize = lz->tuplesize;
- PyObject *result = lz->result;
- PyObject *it;
- PyObject *item;
- PyObject *olditem;
-
- if (tuplesize == 0)
- return NULL;
+ Py_ssize_t i;
+ Py_ssize_t tuplesize = lz->tuplesize;
+ PyObject *result = lz->result;
+ PyObject *it;
+ PyObject *item;
+ PyObject *olditem;
+
+ if (tuplesize == 0)
+ return NULL;
if (lz->numactive == 0)
return NULL;
- if (Py_REFCNT(result) == 1) {
- Py_INCREF(result);
- for (i=0 ; i < tuplesize ; i++) {
- it = PyTuple_GET_ITEM(lz->ittuple, i);
+ if (Py_REFCNT(result) == 1) {
+ Py_INCREF(result);
+ for (i=0 ; i < tuplesize ; i++) {
+ it = PyTuple_GET_ITEM(lz->ittuple, i);
if (it == NULL) {
Py_INCREF(lz->fillvalue);
item = lz->fillvalue;
} else {
- item = (*Py_TYPE(it)->tp_iternext)(it);
+ item = PyIter_Next(it);
if (item == NULL) {
- lz->numactive -= 1;
- if (lz->numactive == 0) {
+ lz->numactive -= 1;
+ if (lz->numactive == 0 || PyErr_Occurred()) {
+ lz->numactive = 0;
Py_DECREF(result);
return NULL;
} else {
Py_INCREF(lz->fillvalue);
- item = lz->fillvalue;
+ item = lz->fillvalue;
PyTuple_SET_ITEM(lz->ittuple, i, NULL);
Py_DECREF(it);
}
}
}
- olditem = PyTuple_GET_ITEM(result, i);
- PyTuple_SET_ITEM(result, i, item);
- Py_DECREF(olditem);
- }
- } else {
- result = PyTuple_New(tuplesize);
- if (result == NULL)
- return NULL;
- for (i=0 ; i < tuplesize ; i++) {
- it = PyTuple_GET_ITEM(lz->ittuple, i);
+ olditem = PyTuple_GET_ITEM(result, i);
+ PyTuple_SET_ITEM(result, i, item);
+ Py_DECREF(olditem);
+ }
+ } else {
+ result = PyTuple_New(tuplesize);
+ if (result == NULL)
+ return NULL;
+ for (i=0 ; i < tuplesize ; i++) {
+ it = PyTuple_GET_ITEM(lz->ittuple, i);
if (it == NULL) {
Py_INCREF(lz->fillvalue);
item = lz->fillvalue;
} else {
- item = (*Py_TYPE(it)->tp_iternext)(it);
+ item = PyIter_Next(it);
if (item == NULL) {
- lz->numactive -= 1;
- if (lz->numactive == 0) {
+ lz->numactive -= 1;
+ if (lz->numactive == 0 || PyErr_Occurred()) {
+ lz->numactive = 0;
Py_DECREF(result);
return NULL;
} else {
Py_INCREF(lz->fillvalue);
- item = lz->fillvalue;
+ item = lz->fillvalue;
PyTuple_SET_ITEM(lz->ittuple, i, NULL);
Py_DECREF(it);
}
}
}
- PyTuple_SET_ITEM(result, i, item);
- }
- }
- return result;
+ PyTuple_SET_ITEM(result, i, item);
+ }
+ }
+ return result;
}
PyDoc_STRVAR(izip_longest_doc,