Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert ziplongest type to heap type
  • Loading branch information
Erlend E. Aasland committed Jan 2, 2021
commit ea4ac6460f2e3fb63424718676937a9184d5deed
71 changes: 25 additions & 46 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct {
PyTypeObject *filterfalse_type;
PyTypeObject *count_type;
PyTypeObject *pairwise_type;
PyTypeObject *ziplongest_type;
} itertoolsmodule_state;

static itertoolsmodule_state *
Expand Down Expand Up @@ -4251,8 +4252,6 @@ typedef struct {
PyObject *fillvalue;
} ziplongestobject;

static PyTypeObject ziplongest_type;

static PyObject *
zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Expand Down Expand Up @@ -4326,11 +4325,13 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
zip_longest_dealloc(ziplongestobject *lz)
{
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->ittuple);
Py_XDECREF(lz->result);
Py_XDECREF(lz->fillvalue);
Py_TYPE(lz)->tp_free(lz);
tp->tp_free(lz);
Py_DECREF(tp);
}

static int
Expand Down Expand Up @@ -4473,48 +4474,24 @@ are exhausted, the fillvalue is substituted in their place. The fillvalue\n\
defaults to None or can be specified by a keyword argument.\n\
");

static PyTypeObject ziplongest_type = {
PyVarObject_HEAD_INIT(NULL, 0)
"itertools.zip_longest", /* tp_name */
sizeof(ziplongestobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)zip_longest_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
zip_longest_doc, /* tp_doc */
(traverseproc)zip_longest_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)zip_longest_next, /* tp_iternext */
zip_longest_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
zip_longest_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
static PyType_Slot ziplongest_slots[] = {
{Py_tp_dealloc, zip_longest_dealloc},
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_doc, (void *)zip_longest_doc},
{Py_tp_traverse, zip_longest_traverse},
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, zip_longest_next},
{Py_tp_methods, zip_longest_methods},
{Py_tp_new, zip_longest_new},
{Py_tp_free, PyObject_GC_Del},
{0, NULL},
};

static PyType_Spec ziplongest_spec = {
.name = "itertools.zip_longest",
.basicsize = sizeof(ziplongestobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.slots = ziplongest_slots,
};


Expand Down Expand Up @@ -4569,6 +4546,7 @@ itertoolsmodule_traverse(PyObject *m, visitproc visit, void *arg)
Py_VISIT(state->filterfalse_type);
Py_VISIT(state->count_type);
Py_VISIT(state->pairwise_type);
Py_VISIT(state->ziplongest_type);
return 0;
}

Expand All @@ -4590,6 +4568,7 @@ itertoolsmodule_clear(PyObject *m)
Py_CLEAR(state->filterfalse_type);
Py_CLEAR(state->count_type);
Py_CLEAR(state->pairwise_type);
Py_CLEAR(state->ziplongest_type);
return 0;
}

Expand Down Expand Up @@ -4628,11 +4607,11 @@ itertoolsmodule_exec(PyObject *m)
ADD_TYPE(m, state->filterfalse_type, &filterfalse_spec);
ADD_TYPE(m, state->count_type, &count_spec);
ADD_TYPE(m, state->pairwise_type, &pairwise_spec);
ADD_TYPE(m, state->ziplongest_type, &ziplongest_spec);

PyTypeObject *typelist[] = {
&islice_type,
&chain_type,
&ziplongest_type,
&product_type,
&repeat_type,
&tee_type,
Expand Down