Skip to content

Commit 54c43a4

Browse files
pythongh-101277: Add dropwhile type to module state
1 parent 98636d2 commit 54c43a4

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
@@ -12,6 +12,7 @@
1212

1313
typedef struct {
1414
PyTypeObject *cycle_type;
15+
PyTypeObject *dropwhile_type;
1516
PyTypeObject *groupby_type;
1617
PyTypeObject *_grouper_type;
1718
} itertools_state;
@@ -42,7 +43,7 @@ class itertools.teedataobject "teedataobject *" "&teedataobject_type"
4243
class itertools._tee "teeobject *" "&tee_type"
4344
class itertools.batched "batchedobject *" "&batched_type"
4445
class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
45-
class itertools.dropwhile "dropwhileobject *" "&dropwhile_type"
46+
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
4647
class itertools.takewhile "takewhileobject *" "&takewhile_type"
4748
class itertools.starmap "starmapobject *" "&starmap_type"
4849
class itertools.chain "chainobject *" "&chain_type"
@@ -55,12 +56,11 @@ class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
5556
class itertools.count "countobject *" "&count_type"
5657
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
5758
[clinic start generated code]*/
58-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b73cdca8e1fddfb5]*/
59+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ef6f5c44c6837d9e]*/
5960

6061
static PyTypeObject teedataobject_type;
6162
static PyTypeObject tee_type;
6263
static PyTypeObject batched_type;
63-
static PyTypeObject dropwhile_type;
6464
static PyTypeObject takewhile_type;
6565
static PyTypeObject starmap_type;
6666
static PyTypeObject combinations_type;
@@ -1441,15 +1441,18 @@ itertools_dropwhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
14411441
static void
14421442
dropwhile_dealloc(dropwhileobject *lz)
14431443
{
1444+
PyTypeObject *tp = Py_TYPE(lz);
14441445
PyObject_GC_UnTrack(lz);
14451446
Py_XDECREF(lz->func);
14461447
Py_XDECREF(lz->it);
1447-
Py_TYPE(lz)->tp_free(lz);
1448+
tp->tp_free(lz);
1449+
Py_DECREF(tp);
14481450
}
14491451

14501452
static int
14511453
dropwhile_traverse(dropwhileobject *lz, visitproc visit, void *arg)
14521454
{
1455+
Py_VISIT(Py_TYPE(lz));
14531456
Py_VISIT(lz->it);
14541457
Py_VISIT(lz->func);
14551458
return 0;
@@ -1512,48 +1515,25 @@ static PyMethodDef dropwhile_methods[] = {
15121515
{NULL, NULL} /* sentinel */
15131516
};
15141517

1515-
static PyTypeObject dropwhile_type = {
1516-
PyVarObject_HEAD_INIT(NULL, 0)
1517-
"itertools.dropwhile", /* tp_name */
1518-
sizeof(dropwhileobject), /* tp_basicsize */
1519-
0, /* tp_itemsize */
1520-
/* methods */
1521-
(destructor)dropwhile_dealloc, /* tp_dealloc */
1522-
0, /* tp_vectorcall_offset */
1523-
0, /* tp_getattr */
1524-
0, /* tp_setattr */
1525-
0, /* tp_as_async */
1526-
0, /* tp_repr */
1527-
0, /* tp_as_number */
1528-
0, /* tp_as_sequence */
1529-
0, /* tp_as_mapping */
1530-
0, /* tp_hash */
1531-
0, /* tp_call */
1532-
0, /* tp_str */
1533-
PyObject_GenericGetAttr, /* tp_getattro */
1534-
0, /* tp_setattro */
1535-
0, /* tp_as_buffer */
1536-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1537-
Py_TPFLAGS_BASETYPE, /* tp_flags */
1538-
itertools_dropwhile__doc__, /* tp_doc */
1539-
(traverseproc)dropwhile_traverse, /* tp_traverse */
1540-
0, /* tp_clear */
1541-
0, /* tp_richcompare */
1542-
0, /* tp_weaklistoffset */
1543-
PyObject_SelfIter, /* tp_iter */
1544-
(iternextfunc)dropwhile_next, /* tp_iternext */
1545-
dropwhile_methods, /* tp_methods */
1546-
0, /* tp_members */
1547-
0, /* tp_getset */
1548-
0, /* tp_base */
1549-
0, /* tp_dict */
1550-
0, /* tp_descr_get */
1551-
0, /* tp_descr_set */
1552-
0, /* tp_dictoffset */
1553-
0, /* tp_init */
1554-
0, /* tp_alloc */
1555-
itertools_dropwhile, /* tp_new */
1556-
PyObject_GC_Del, /* tp_free */
1518+
static PyType_Slot dropwhile_slots[] = {
1519+
{Py_tp_dealloc, dropwhile_dealloc},
1520+
{Py_tp_getattro, PyObject_GenericGetAttr},
1521+
{Py_tp_doc, (void *)itertools_dropwhile__doc__},
1522+
{Py_tp_traverse, dropwhile_traverse},
1523+
{Py_tp_iter, PyObject_SelfIter},
1524+
{Py_tp_iternext, dropwhile_next},
1525+
{Py_tp_methods, dropwhile_methods},
1526+
{Py_tp_new, itertools_dropwhile},
1527+
{Py_tp_free, PyObject_GC_Del},
1528+
{0, NULL},
1529+
};
1530+
1531+
static PyType_Spec dropwhile_spec = {
1532+
.name = "itertools.dropwhile",
1533+
.basicsize = sizeof(dropwhileobject),
1534+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
1535+
Py_TPFLAGS_IMMUTABLETYPE),
1536+
.slots = dropwhile_slots,
15571537
};
15581538

15591539

@@ -4943,6 +4923,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
49434923
{
49444924
itertools_state *state = get_module_state(mod);
49454925
Py_VISIT(state->cycle_type);
4926+
Py_VISIT(state->dropwhile_type);
49464927
Py_VISIT(state->groupby_type);
49474928
Py_VISIT(state->_grouper_type);
49484929
return 0;
@@ -4953,6 +4934,7 @@ itertoolsmodule_clear(PyObject *mod)
49534934
{
49544935
itertools_state *state = get_module_state(mod);
49554936
Py_CLEAR(state->cycle_type);
4937+
Py_CLEAR(state->dropwhile_type);
49564938
Py_CLEAR(state->groupby_type);
49574939
Py_CLEAR(state->_grouper_type);
49584940
return 0;
@@ -4980,6 +4962,7 @@ itertoolsmodule_exec(PyObject *mod)
49804962
{
49814963
itertools_state *state = get_module_state(mod);
49824964
ADD_TYPE(mod, state->cycle_type, &cycle_spec);
4965+
ADD_TYPE(mod, state->dropwhile_type, &dropwhile_spec);
49834966
ADD_TYPE(mod, state->groupby_type, &groupby_spec);
49844967
ADD_TYPE(mod, state->_grouper_type, &_grouper_spec);
49854968

@@ -4988,7 +4971,6 @@ itertoolsmodule_exec(PyObject *mod)
49884971
&batched_type,
49894972
&combinations_type,
49904973
&cwr_type,
4991-
&dropwhile_type,
49924974
&takewhile_type,
49934975
&islice_type,
49944976
&starmap_type,

0 commit comments

Comments
 (0)