PyObject *ittuple; /* tuple of iterators */
PyObject *result;
PyObject *fillvalue;
- PyObject *filler; /* repeat(fillvalue) */
} iziplongestobject;
static PyTypeObject iziplongest_type;
PyObject *ittuple; /* tuple of iterators */
PyObject *result;
PyObject *fillvalue = Py_None;
- PyObject *filler;
Py_ssize_t tuplesize = PySequence_Length(args);
if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_Size(kwds) > 0) {
PyTuple_SET_ITEM(ittuple, i, it);
}
- filler = PyObject_CallFunctionObjArgs((PyObject *)(&repeat_type), fillvalue, NULL);
- if (filler == NULL) {
- Py_DECREF(ittuple);
- return NULL;
- }
-
/* create a result holder */
result = PyTuple_New(tuplesize);
if (result == NULL) {
Py_DECREF(ittuple);
- Py_DECREF(filler);
return NULL;
}
for (i=0 ; i < tuplesize ; i++) {
lz = (iziplongestobject *)type->tp_alloc(type, 0);
if (lz == NULL) {
Py_DECREF(ittuple);
- Py_DECREF(filler);
Py_DECREF(result);
return NULL;
}
lz->result = result;
Py_INCREF(fillvalue);
lz->fillvalue = fillvalue;
- Py_INCREF(filler);
- lz->filler = filler; /* XXX */
return (PyObject *)lz;
}
Py_XDECREF(lz->ittuple);
Py_XDECREF(lz->result);
Py_XDECREF(lz->fillvalue);
- Py_XDECREF(lz->filler);
lz->ob_type->tp_free(lz);
}
Py_VISIT(lz->ittuple);
Py_VISIT(lz->result);
Py_VISIT(lz->fillvalue);
- Py_VISIT(lz->filler);
return 0;
}
if (tuplesize == 0)
return NULL;
+ if (lz->numactive == 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 (lz->numactive <= 1) {
- Py_DECREF(result);
- return NULL;
- } else {
- Py_INCREF(lz->filler);
- PyTuple_SET_ITEM(lz->ittuple, i, lz->filler);
- Py_INCREF(lz->fillvalue);
- item = lz->fillvalue;
- Py_DECREF(it);
- lz->numactive -= 1;
- }
- }
+ if (it == NULL) {
+ Py_INCREF(lz->fillvalue);
+ item = lz->fillvalue;
+ } else {
+ assert(PyIter_Check(it));
+ item = (*it->ob_type->tp_iternext)(it);
+ if (item == NULL) {
+ lz->numactive -= 1;
+ if (lz->numactive == 0) {
+ Py_DECREF(result);
+ return NULL;
+ } else {
+ Py_INCREF(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);
return NULL;
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 (lz->numactive <= 1) {
- Py_DECREF(result);
- return NULL;
- } else {
- Py_INCREF(lz->filler);
- PyTuple_SET_ITEM(lz->ittuple, i, lz->filler);
- Py_INCREF(lz->fillvalue);
- item = lz->fillvalue;
- Py_DECREF(it);
- lz->numactive -= 1;
- }
- }
+ if (it == NULL) {
+ Py_INCREF(lz->fillvalue);
+ item = lz->fillvalue;
+ } else {
+ assert(PyIter_Check(it));
+ item = (*it->ob_type->tp_iternext)(it);
+ if (item == NULL) {
+ lz->numactive -= 1;
+ if (lz->numactive == 0) {
+ Py_DECREF(result);
+ return NULL;
+ } else {
+ Py_INCREF(lz->fillvalue);
+ item = lz->fillvalue;
+ PyTuple_SET_ITEM(lz->ittuple, i, NULL);
+ Py_DECREF(it);
+ }
+ }
+ }
PyTuple_SET_ITEM(result, i, item);
}
}