8000 bpo-40077: Convert itertools types to heap types by erlend-aasland · Pull Request #24065 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-40077: Convert itertools types to heap types #24065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
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 starmap type to heap type
  • Loading branch information
Erlend E. Aasland committed Jan 2, 2021
commit 676d4ef816ea5d9efe47fb40008e5dd4d6ffe1bd
4 changes: 2 additions & 2 deletions Modules/clinic/itertoolsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 27 additions & 47 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct {
PyTypeObject *cycle_type;
PyTypeObject *dropwhile_type;
PyTypeObject *takewhile_type;
PyTypeObject *starmap_type;
} itertoolsmodule_state;

static itertoolsmodule_state *
Expand Down Expand Up @@ -46,7 +47,7 @@ class itertools._tee "teeobject *" "&tee_type"
class itertools.cycle "cycleobject *" "clinic_find_state()->cycle_type"
class itertools.dropwhile "dropwhileobject *" "clinic_find_state()->dropwhile_type"
class itertools.takewhile "takewhileobject *" "clinic_find_state()->takewhile_type"
class itertools.starmap "starmapobject *" "&starmap_type"
class itertools.starmap "starmapobject *" "clinic_find_state()->starmap_type"
class itertools.chain "chainobject *" "&chain_type"
class itertools.combinations "combinationsobject *" "&combinations_type"
class itertools.combinations_with_replacement "cwr_object *" "&cwr_type"
Expand All @@ -57,11 +58,10 @@ class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
class itertools.count "countobject *" "&count_type"
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=355860e69ec3091a]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2378e41d4bd2ac8d]*/

static PyTypeObject teedataobject_type;
static PyTypeObject tee_type;
static PyTypeObject starmap_type;
static PyTypeObject combinations_type;
static PyTypeObject cwr_type;
static PyTypeObject permutations_type;
Expand Down Expand Up @@ -1805,10 +1805,12 @@ itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
static void
starmap_dealloc(starmapobject *lz)
{
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
tp->tp_free(lz);
Py_DECREF(tp);
}

static int
Expand Down Expand Up @@ -1854,48 +1856,24 @@ static PyMethodDef starmap_methods[] = {
{NULL, NULL} /* sentinel */
};

static PyTypeObject starmap_type = {
PyVarObject_HEAD_INIT(NULL, 0)
"itertools.starmap", /* tp_name */
sizeof(starmapobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)starmap_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 */
itertools_starmap__doc__, /* tp_doc */
(traverseproc)starmap_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)starmap_next, /* tp_iternext */
starmap_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 */
itertools_starmap, /* tp_new */
PyObject_GC_Del, /* tp_free */
static PyType_Slot starmap_slots[] = {
{Py_tp_dealloc, starmap_dealloc},
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_doc, (void *)itertools_starmap__doc__},
{Py_tp_traverse, starmap_traverse},
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, starmap_next},
{Py_tp_methods, starmap_methods},
{Py_tp_new, itertools_starmap},
{Py_tp_free, PyObject_GC_Del},
{0, NULL},
};

static PyType_Spec starmap_spec = {
.name = "itertools.starmap",
.basicsize = sizeof(starmapobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.slots = starmap_slots,
};


Expand Down Expand Up @@ -4757,6 +4735,7 @@ itertoolsmodule_traverse(PyObject *m, visitproc visit, void *arg)
Py_VISIT(state->cycle_type);
Py_VISIT(state->dropwhile_type);
Py_VISIT(state->takewhile_type);
Py_VISIT(state->starmap_type);
return 0;
}

Expand All @@ -4769,6 +4748,7 @@ itertoolsmodule_clear(PyObject *m)
Py_CLEAR(state->cycle_type);
Py_CLEAR(state->dropwhile_type);
Py_CLEAR(state->takewhile_type);
Py_CLEAR(state->starmap_type);
return 0;
}

Expand Down Expand Up @@ -4798,13 +4778,13 @@ itertoolsmodule_exec(PyObject *m)
ADD_TYPE(m, state->cycle_type, &cycle_spec);
ADD_TYPE(m, state->dropwhile_type, &dropwhile_spec);
ADD_TYPE(m, state->takewhile_type, &takewhile_spec);
ADD_TYPE(m, state->starmap_type, &starmap_spec);

PyTypeObject *typelist[] = {
&accumulate_type,
&combinations_type,
&cwr_type,
&islice_type,
&starmap_type,
&chain_type,
&compress_type,
&filterfalse_type,
Expand Down
0