Skip to content

Commit aca9ef5

Browse files
gh-101277: Add starmap type to module state
1 parent 2ede7ad commit aca9ef5

File tree

2 files changed

+32
-50
lines changed

2 files changed

+32
-50
lines changed

Modules/clinic/itertoolsmodule.c.h

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/itertoolsmodule.c

+29-47
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct {
1515
PyTypeObject *dropwhile_type;
1616
PyTypeObject *groupby_type;
1717
PyTypeObject *_grouper_type;
18+
PyTypeObject *starmap_type;
1819
PyTypeObject *takewhile_type;
1920
} itertools_state;
2021

@@ -46,7 +47,7 @@ class itertools.batched "batchedobject *" "&batched_type"
4647
class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
4748
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
4849
class itertools.takewhile "takewhileobject *" "clinic_state()->takewhile_type"
49-
class itertools.starmap "starmapobject *" "&starmap_type"
50+
class itertools.starmap "starmapobject *" "clinic_state()->starmap_type"
5051
class itertools.chain "chainobject *" "&chain_type"
5152
class itertools.combinations "combinationsobject *" "&combinations_type"
5253
class itertools.combinations_with_replacement "cwr_object *" "&cwr_type"
@@ -57,12 +58,11 @@ class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
5758
class itertools.count "countobject *" "&count_type"
5859
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
5960
[clinic start generated code]*/
60-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3015dff7a88cfc00]*/
61+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3b9f0718b7d49b01]*/
6162

6263
static PyTypeObject teedataobject_type;
6364
static PyTypeObject tee_type;
6465
static PyTypeObject batched_type;
65-
static PyTypeObject starmap_type;
6666
static PyTypeObject combinations_type;
6767
static PyTypeObject cwr_type;
6868
static PyTypeObject permutations_type;
@@ -1978,15 +1978,18 @@ itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
19781978
static void
19791979
starmap_dealloc(starmapobject *lz)
19801980
{
1981+
PyTypeObject *tp = Py_TYPE(lz);
19811982
PyObject_GC_UnTrack(lz);
19821983
Py_XDECREF(lz->func);
19831984
Py_XDECREF(lz->it);
1984-
Py_TYPE(lz)->tp_free(lz);
1985+
tp->tp_free(lz);
1986+
Py_DECREF(tp);
19851987
}
19861988

19871989
static int
19881990
starmap_traverse(starmapobject *lz, visitproc visit, void *arg)
19891991
{
1992+
Py_VISIT(Py_TYPE(lz));
19901993
Py_VISIT(lz->it);
19911994
Py_VISIT(lz->func);
19921995
return 0;
@@ -2027,48 +2030,25 @@ static PyMethodDef starmap_methods[] = {
20272030
{NULL, NULL} /* sentinel */
20282031
};
20292032

2030-
static PyTypeObject starmap_type = {
2031-
PyVarObject_HEAD_INIT(NULL, 0)
2032-
"itertools.starmap", /* tp_name */
2033-
sizeof(starmapobject), /* tp_basicsize */
2034-
0, /* tp_itemsize */
2035-
/* methods */
2036-
(destructor)starmap_dealloc, /* tp_dealloc */
2037-
0, /* tp_vectorcall_offset */
2038-
0, /* tp_getattr */
2039-
0, /* tp_setattr */
2040-
0, /* tp_as_async */
2041-
0, /* tp_repr */
2042-
0, /* tp_as_number */
2043-
0, /* tp_as_sequence */
2044-
0, /* tp_as_mapping */
2045-
0, /* tp_hash */
2046-
0, /* tp_call */
2047-
0, /* tp_str */
2048-
PyObject_GenericGetAttr, /* tp_getattro */
2049-
0, /* tp_setattro */
2050-
0, /* tp_as_buffer */
2051-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2052-
Py_TPFLAGS_BASETYPE, /* tp_flags */
2053-
itertools_starmap__doc__, /* tp_doc */
2054-
(traverseproc)starmap_traverse, /* tp_traverse */
2055-
0, /* tp_clear */
2056-
0, /* tp_richcompare */
2057-
0, /* tp_weaklistoffset */
2058-
PyObject_SelfIter, /* tp_iter */
2059-
(iternextfunc)starmap_next, /* tp_iternext */
2060-
starmap_methods, /* tp_methods */
2061-
0, /* tp_members */
2062-
0, /* tp_getset */
2063-
0, /* tp_base */
2064-
0, /* tp_dict */
2065-
0, /* tp_descr_get */
2066-
0, /* tp_descr_set */
2067-
0, /* tp_dictoffset */
2068-
0, /* tp_init */
2069-
0, /* tp_alloc */
2070-
itertools_starmap, /* tp_new */
2071-
PyObject_GC_Del, /* tp_free */
2033+
static PyType_Slot starmap_slots[] = {
2034+
{Py_tp_dealloc, starmap_dealloc},
2035+
{Py_tp_getattro, PyObject_GenericGetAttr},
2036+
{Py_tp_doc, (void *)itertools_starmap__doc__},
2037+
{Py_tp_traverse, starmap_traverse},
2038+
{Py_tp_iter, PyObject_SelfIter},
2039+
{Py_tp_iternext, starmap_next},
2040+
{Py_tp_methods, starmap_methods},
2041+
{Py_tp_new, itertools_starmap},
2042+
{Py_tp_free, PyObject_GC_Del},
2043+
{0, NULL},
2044+
};
2045+
2046+
static PyType_Spec starmap_spec = {
2047+
.name = "itertools.starmap",
2048+
.basicsize = sizeof(starmapobject),
2049+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
2050+
Py_TPFLAGS_IMMUTABLETYPE),
2051+
.slots = starmap_slots,
20722052
};
20732053

20742054

@@ -4905,6 +4885,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
49054885
Py_VISIT(state->dropwhile_type);
49064886
Py_VISIT(state->groupby_type);
49074887
Py_VISIT(state->_grouper_type);
4888+
Py_VISIT(state->starmap_type);
49084889
Py_VISIT(state->takewhile_type);
49094890
return 0;
49104891
}
@@ -4917,6 +4898,7 @@ itertoolsmodule_clear(PyObject *mod)
49174898
Py_CLEAR(state->dropwhile_type);
49184899
Py_CLEAR(state->groupby_type);
49194900
Py_CLEAR(state->_grouper_type);
4901+
Py_CLEAR(state->starmap_type);
49204902
Py_CLEAR(state->takewhile_type);
49214903
return 0;
49224904
}
@@ -4946,6 +4928,7 @@ itertoolsmodule_exec(PyObject *mod)
49464928
ADD_TYPE(mod, state->dropwhile_type, &dropwhile_spec);
49474929
ADD_TYPE(mod, state->groupby_type, &groupby_spec);
49484930
ADD_TYPE(mod, state->_grouper_type, &_grouper_spec);
4931+
ADD_TYPE(mod, state->starmap_type, &starmap_spec);
49494932
ADD_TYPE(mod, state->takewhile_type, &takewhile_spec);
49504933

49514934
PyTypeObject *typelist[] = {
@@ -4954,7 +4937,6 @@ itertoolsmodule_exec(PyObject *mod)
49544937
&combinations_type,
49554938
&cwr_type,
49564939
&islice_type,
4957-
&starmap_type,
49584940
&chain_type,
49594941
&compress_type,
49604942
&filterfalse_type,

0 commit comments

Comments
 (0)