mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Remove filler struct item and fix leak.
This commit is contained in:
parent
d36862cf78
commit
1b6ca54c44
1 changed files with 40 additions and 44 deletions
|
|
@ -2483,7 +2483,6 @@ typedef struct {
|
||||||
PyObject *ittuple; /* tuple of iterators */
|
PyObject *ittuple; /* tuple of iterators */
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
PyObject *fillvalue;
|
PyObject *fillvalue;
|
||||||
PyObject *filler; /* repeat(fillvalue) */
|
|
||||||
} iziplongestobject;
|
} iziplongestobject;
|
||||||
|
|
||||||
static PyTypeObject iziplongest_type;
|
static PyTypeObject iziplongest_type;
|
||||||
|
|
@ -2496,7 +2495,6 @@ izip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
PyObject *ittuple; /* tuple of iterators */
|
PyObject *ittuple; /* tuple of iterators */
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
PyObject *fillvalue = Py_None;
|
PyObject *fillvalue = Py_None;
|
||||||
PyObject *filler;
|
|
||||||
Py_ssize_t tuplesize = PySequence_Length(args);
|
Py_ssize_t tuplesize = PySequence_Length(args);
|
||||||
|
|
||||||
if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_Size(kwds) > 0) {
|
if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_Size(kwds) > 0) {
|
||||||
|
|
@ -2529,17 +2527,10 @@ izip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
PyTuple_SET_ITEM(ittuple, i, it);
|
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 */
|
/* create a result holder */
|
||||||
result = PyTuple_New(tuplesize);
|
result = PyTuple_New(tuplesize);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
Py_DECREF(ittuple);
|
Py_DECREF(ittuple);
|
||||||
Py_DECREF(filler);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i=0 ; i < tuplesize ; i++) {
|
for (i=0 ; i < tuplesize ; i++) {
|
||||||
|
|
@ -2551,7 +2542,6 @@ izip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
lz = (iziplongestobject *)type->tp_alloc(type, 0);
|
lz = (iziplongestobject *)type->tp_alloc(type, 0);
|
||||||
if (lz == NULL) {
|
if (lz == NULL) {
|
||||||
Py_DECREF(ittuple);
|
Py_DECREF(ittuple);
|
||||||
Py_DECREF(filler);
|
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -2561,8 +2551,6 @@ izip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
lz->result = result;
|
lz->result = result;
|
||||||
Py_INCREF(fillvalue);
|
Py_INCREF(fillvalue);
|
||||||
lz->fillvalue = fillvalue;
|
lz->fillvalue = fillvalue;
|
||||||
Py_INCREF(filler);
|
|
||||||
lz->filler = filler; /* XXX */
|
|
||||||
return (PyObject *)lz;
|
return (PyObject *)lz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2573,7 +2561,6 @@ izip_longest_dealloc(iziplongestobject *lz)
|
||||||
Py_XDECREF(lz->ittuple);
|
Py_XDECREF(lz->ittuple);
|
||||||
Py_XDECREF(lz->result);
|
Py_XDECREF(lz->result);
|
||||||
Py_XDECREF(lz->fillvalue);
|
Py_XDECREF(lz->fillvalue);
|
||||||
Py_XDECREF(lz->filler);
|
|
||||||
lz->ob_type->tp_free(lz);
|
lz->ob_type->tp_free(lz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2583,7 +2570,6 @@ izip_longest_traverse(iziplongestobject *lz, visitproc visit, void *arg)
|
||||||
Py_VISIT(lz->ittuple);
|
Py_VISIT(lz->ittuple);
|
||||||
Py_VISIT(lz->result);
|
Py_VISIT(lz->result);
|
||||||
Py_VISIT(lz->fillvalue);
|
Py_VISIT(lz->fillvalue);
|
||||||
Py_VISIT(lz->filler);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2599,23 +2585,29 @@ izip_longest_next(iziplongestobject *lz)
|
||||||
|
|
||||||
if (tuplesize == 0)
|
if (tuplesize == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (lz->numactive == 0)
|
||||||
|
return NULL;
|
||||||
if (result->ob_refcnt == 1) {
|
if (result->ob_refcnt == 1) {
|
||||||
Py_INCREF(result);
|
Py_INCREF(result);
|
||||||
for (i=0 ; i < tuplesize ; i++) {
|
for (i=0 ; i < tuplesize ; i++) {
|
||||||
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
||||||
|
if (it == NULL) {
|
||||||
|
Py_INCREF(lz->fillvalue);
|
||||||
|
item = lz->fillvalue;
|
||||||
|
} else {
|
||||||
assert(PyIter_Check(it));
|
assert(PyIter_Check(it));
|
||||||
item = (*it->ob_type->tp_iternext)(it);
|
item = (*it->ob_type->tp_iternext)(it);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
if (lz->numactive <= 1) {
|
lz->numactive -= 1;
|
||||||
|
if (lz->numactive == 0) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
Py_INCREF(lz->filler);
|
|
||||||
PyTuple_SET_ITEM(lz->ittuple, i, lz->filler);
|
|
||||||
Py_INCREF(lz->fillvalue);
|
Py_INCREF(lz->fillvalue);
|
||||||
item = lz->fillvalue;
|
item = lz->fillvalue;
|
||||||
|
PyTuple_SET_ITEM(lz->ittuple, i, NULL);
|
||||||
Py_DECREF(it);
|
Py_DECREF(it);
|
||||||
lz->numactive -= 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
olditem = PyTuple_GET_ITEM(result, i);
|
olditem = PyTuple_GET_ITEM(result, i);
|
||||||
|
|
@ -2628,19 +2620,23 @@ izip_longest_next(iziplongestobject *lz)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (i=0 ; i < tuplesize ; i++) {
|
for (i=0 ; i < tuplesize ; i++) {
|
||||||
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
||||||
|
if (it == NULL) {
|
||||||
|
Py_INCREF(lz->fillvalue);
|
||||||
|
item = lz->fillvalue;
|
||||||
|
} else {
|
||||||
assert(PyIter_Check(it));
|
assert(PyIter_Check(it));
|
||||||
item = (*it->ob_type->tp_iternext)(it);
|
item = (*it->ob_type->tp_iternext)(it);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
if (lz->numactive <= 1) {
|
lz->numactive -= 1;
|
||||||
|
if (lz->numactive == 0) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
Py_INCREF(lz->filler);
|
|
||||||
PyTuple_SET_ITEM(lz->ittuple, i, lz->filler);
|
|
||||||
Py_INCREF(lz->fillvalue);
|
Py_INCREF(lz->fillvalue);
|
||||||
item = lz->fillvalue;
|
item = lz->fillvalue;
|
||||||
|
PyTuple_SET_ITEM(lz->ittuple, i, NULL);
|
||||||
Py_DECREF(it);
|
Py_DECREF(it);
|
||||||
lz->numactive -= 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(result, i, item);
|
PyTuple_SET_ITEM(result, i, item);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue