@@ -15,6 +15,7 @@ typedef struct {
15
15
PyTypeObject * dropwhile_type ;
16
16
PyTypeObject * groupby_type ;
17
17
PyTypeObject * _grouper_type ;
18
+ PyTypeObject * takewhile_type ;
18
19
} itertools_state ;
19
20
20
21
static inline itertools_state *
@@ -44,7 +45,7 @@ class itertools._tee "teeobject *" "&tee_type"
44
45
class itertools.batched "batchedobject *" "&batched_type"
45
46
class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
46
47
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
47
- class itertools.takewhile "takewhileobject *" "& takewhile_type"
48
+ class itertools.takewhile "takewhileobject *" "clinic_state()-> takewhile_type"
48
49
class itertools.starmap "starmapobject *" "&starmap_type"
49
50
class itertools.chain "chainobject *" "&chain_type"
50
51
class itertools.combinations "combinationsobject *" "&combinations_type"
@@ -56,12 +57,11 @@ class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
56
57
class itertools.count "countobject *" "&count_type"
57
58
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
58
59
[clinic start generated code]*/
59
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ef6f5c44c6837d9e ]*/
60
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3015dff7a88cfc00 ]*/
60
61
61
62
static PyTypeObject teedataobject_type ;
62
63
static PyTypeObject tee_type ;
63
64
static PyTypeObject batched_type ;
64
- static PyTypeObject takewhile_type ;
65
65
static PyTypeObject starmap_type ;
66
66
static PyTypeObject combinations_type ;
67
67
static PyTypeObject cwr_type ;
@@ -1583,10 +1583,12 @@ itertools_takewhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq)
1583
1583
static void
1584
1584
takewhile_dealloc (takewhileobject * lz )
1585
1585
{
1586
+ PyTypeObject * tp = Py_TYPE (lz );
1586
1587
PyObject_GC_UnTrack (lz );
1587
1588
Py_XDECREF (lz -> func );
1588
1589
Py_XDECREF (lz -> it );
1589
- Py_TYPE (lz )-> tp_free (lz );
1590
+ tp -> tp_free (lz );
1591
+ Py_DECREF (tp );
1590
1592
}
1591
1593
1592
1594
static int
@@ -1651,48 +1653,25 @@ static PyMethodDef takewhile_reduce_methods[] = {
1651
1653
{NULL , NULL } /* sentinel */
1652
1654
};
1653
1655
1654
- static PyTypeObject takewhile_type = {
1655
- PyVarObject_HEAD_INIT (NULL , 0 )
1656
- "itertools.takewhile" , /* tp_name */
1657
- sizeof (takewhileobject ), /* tp_basicsize */
1658
- 0 , /* tp_itemsize */
1659
- /* methods */
1660
- (destructor )takewhile_dealloc , /* tp_dealloc */
1661
- 0 , /* tp_vectorcall_offset */
1662
- 0 , /* tp_getattr */
1663
- 0 , /* tp_setattr */
1664
- 0 , /* tp_as_async */
1665
- 0 , /* tp_repr */
1666
- 0 , /* tp_as_number */
1667
- 0 , /* tp_as_sequence */
1668
- 0 , /* tp_as_mapping */
1669
- 0 , /* tp_hash */
1670
- 0 , /* tp_call */
1671
- 0 , /* tp_str */
1672
- PyObject_GenericGetAttr , /* tp_getattro */
1673
- 0 , /* tp_setattro */
1674
- 0 , /* tp_as_buffer */
1675
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1676
- Py_TPFLAGS_BASETYPE , /* tp_flags */
1677
- itertools_takewhile__doc__ , /* tp_doc */
1678
- (traverseproc )takewhile_traverse , /* tp_traverse */
1679
- 0 , /* tp_clear */
1680
- 0 , /* tp_richcompare */
1681
- 0 , /* tp_weaklistoffset */
1682
- PyObject_SelfIter , /* tp_iter */
1683
- (iternextfunc )takewhile_next , /* tp_iternext */
1684
- takewhile_reduce_methods , /* tp_methods */
1685
- 0 , /* tp_members */
1686
- 0 , /* tp_getset */
1687
- 0 , /* tp_base */
1688
- 0 , /* tp_dict */
1689
- 0 , /* tp_descr_get */
1690
- 0 , /* tp_descr_set */
1691
- 0 , /* tp_dictoffset */
1692
- 0 , /* tp_init */
1693
- 0 , /* tp_alloc */
1694
- itertools_takewhile , /* tp_new */
1695
- PyObject_GC_Del , /* tp_free */
1656
+ static PyType_Slot takewhile_slots [] = {
1657
+ {Py_tp_dealloc , takewhile_dealloc },
1658
+ {Py_tp_getattro , PyObject_GenericGetAttr },
1659
+ {Py_tp_doc , (void * )itertools_takewhile__doc__ },
1660
+ {Py_tp_traverse , takewhile_traverse },
1661
+ {Py_tp_iter , PyObject_SelfIter },
1662
+ {Py_tp_iternext , takewhile_next },
1663
+ {Py_tp_methods , takewhile_reduce_methods },
1664
+ {Py_tp_new , itertools_takewhile },
1665
+ {Py_tp_free , PyObject_GC_Del },
1666
+ {0 , NULL },
1667
+ };
1668
+
1669
+ static PyType_Spec takewhile_spec = {
1670
+ .name = "itertools.takewhile" ,
1671
+ .basicsize = sizeof (takewhileobject ),
1672
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
1673
+ Py_TPFLAGS_IMMUTABLETYPE ),
1674
+ .slots = takewhile_slots ,
1696
1675
};
1697
1676
1698
1677
@@ -4926,6 +4905,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4926
4905
Py_VISIT (state -> dropwhile_type );
4927
4906
Py_VISIT (state -> groupby_type );
4928
4907
Py_VISIT (state -> _grouper_type );
4908
+ Py_VISIT (state -> takewhile_type );
4929
4909
return 0 ;
4930
4910
}
4931
4911
@@ -4937,6 +4917,7 @@ itertoolsmodule_clear(PyObject *mod)
4937
4917
Py_CLEAR (state -> dropwhile_type );
4938
4918
Py_CLEAR (state -> groupby_type );
4939
4919
Py_CLEAR (state -> _grouper_type );
4920
+ Py_CLEAR (state -> takewhile_type );
4940
4921
return 0 ;
4941
4922
}
4942
4923
@@ -4965,13 +4946,13 @@ itertoolsmodule_exec(PyObject *mod)
4965
4946
ADD_TYPE (mod , state -> dropwhile_type , & dropwhile_spec );
4966
4947
ADD_TYPE (mod , state -> groupby_type , & groupby_spec );
4967
4948
ADD_TYPE (mod , state -> _grouper_type , & _grouper_spec );
4949
+ ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4968
4950
4969
4951
PyTypeObject * typelist [] = {
4970
4952
& accumulate_type ,
4971
4953
& batched_type ,
4972
4954
& combinations_type ,
4973
4955
& cwr_type ,
4974
- & takewhile_type ,
4975
4956
& islice_type ,
4976
4957
& starmap_type ,
4977
4958
& chain_type ,
0 commit comments