mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix exception handling in itertools.izip_longest().
This commit is contained in:
parent
cafc22f0b8
commit
fc438518a0
3 changed files with 79 additions and 34 deletions
|
@ -3344,71 +3344,73 @@ zip_longest_traverse(ziplongestobject *lz, visitproc visit, void *arg)
|
|||
static PyObject *
|
||||
zip_longest_next(ziplongestobject *lz)
|
||||
{
|
||||
Py_ssize_t i;
|
||||
Py_ssize_t tuplesize = lz->tuplesize;
|
||||
PyObject *result = lz->result;
|
||||
PyObject *it;
|
||||
PyObject *item;
|
||||
PyObject *olditem;
|
||||
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 (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(zip_longest_doc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue