11
11
*/
12
12
13
13
typedef struct {
14
+ PyTypeObject * accumulate_type ;
14
15
PyTypeObject * combinations_type ;
15
16
PyTypeObject * cwr_type ;
16
17
PyTypeObject * cycle_type ;
@@ -55,18 +56,17 @@ class itertools.chain "chainobject *" "&chain_type"
55
56
class itertools.combinations "combinationsobject *" "clinic_state()->combinations_type"
56
57
class itertools.combinations_with_replacement "cwr_object *" "clinic_state()->cwr_type"
57
58
class itertools.permutations "permutationsobject *" "clinic_state()->permutations_type"
58
- class itertools.accumulate "accumulateobject *" "& accumulate_type"
59
+ class itertools.accumulate "accumulateobject *" "clinic_state()-> accumulate_type"
59
60
class itertools.compress "compressobject *" "&compress_type"
60
61
class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
61
62
class itertools.count "countobject *" "&count_type"
62
63
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
63
64
[clinic start generated code]*/
64
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=1790ac655869a651 ]*/
65
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=e0155dd6d01d40dd ]*/
65
66
66
67
static PyTypeObject teedataobject_type ;
67
68
static PyTypeObject tee_type ;
68
69
static PyTypeObject batched_type ;
69
- static PyTypeObject accumulate_type ;
70
70
static PyTypeObject compress_type ;
71
71
static PyTypeObject filterfalse_type ;
72
72
static PyTypeObject count_type ;
@@ -3645,17 +3645,20 @@ itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable,
3645
3645
static void
3646
3646
accumulate_dealloc (accumulateobject * lz )
3647
3647
{
3648
+ PyTypeObject * tp = Py_TYPE (lz );
3648
3649
PyObject_GC_UnTrack (lz );
3649
3650
Py_XDECREF (lz -> binop );
3650
3651
Py_XDECREF (lz -> total );
3651
3652
Py_XDECREF (lz -> it );
3652
3653
Py_XDECREF (lz -> initial );
3653
- Py_TYPE (lz )-> tp_free (lz );
3654
+ tp -> tp_free (lz );
3655
+ Py_DECREF (tp );
3654
3656
}
3655
3657
3656
3658
static int
3657
3659
accumulate_traverse (accumulateobject * lz , visitproc visit , void * arg )
3658
3660
{
3661
+ Py_VISIT (Py_TYPE (lz ));
3659
3662
Py_VISIT (lz -> binop );
3660
3663
Py_VISIT (lz -> it );
3661
3664
Py_VISIT (lz -> total );
@@ -3749,48 +3752,25 @@ static PyMethodDef accumulate_methods[] = {
3749
3752
{NULL , NULL } /* sentinel */
3750
3753
};
3751
3754
3752
- static PyTypeObject accumulate_type = {
3753
- PyVarObject_HEAD_INIT (NULL , 0 )
3754
- "itertools.accumulate" , /* tp_name */
3755
- sizeof (accumulateobject ), /* tp_basicsize */
3756
- 0 , /* tp_itemsize */
3757
- /* methods */
3758
- (destructor )accumulate_dealloc , /* tp_dealloc */
3759
- 0 , /* tp_vectorcall_offset */
3760
- 0 , /* tp_getattr */
3761
- 0 , /* tp_setattr */
3762
- 0 , /* tp_as_async */
3763
- 0 , /* tp_repr */
3764
- 0 , /* tp_as_number */
3765
- 0 , /* tp_as_sequence */
3766
- 0 , /* tp_as_mapping */
3767
- 0 , /* tp_hash */
3768
- 0 , /* tp_call */
3769
- 0 , /* tp_str */
3770
- PyObject_GenericGetAttr , /* tp_getattro */
3771
- 0 , /* tp_setattro */
3772
- 0 , /* tp_as_buffer */
3773
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
3774
- Py_TPFLAGS_BASETYPE , /* tp_flags */
3775
- itertools_accumulate__doc__ , /* tp_doc */
3776
- (traverseproc )accumulate_traverse , /* tp_traverse */
3777
- 0 , /* tp_clear */
3778
- 0 , /* tp_richcompare */
3779
- 0 , /* tp_weaklistoffset */
3780
- PyObject_SelfIter , /* tp_iter */
3781
- (iternextfunc )accumulate_next , /* tp_iternext */
3782
- accumulate_methods , /* tp_methods */
3783
- 0 , /* tp_members */
3784
- 0 , /* tp_getset */
3785
- 0 , /* tp_base */
3786
- 0 , /* tp_dict */
3787
- 0 , /* tp_descr_get */
3788
- 0 , /* tp_descr_set */
3789
- 0 , /* tp_dictoffset */
3790
- 0 , /* tp_init */
3791
- 0 , /* tp_alloc */
3792
- itertools_accumulate , /* tp_new */
3793
- PyObject_GC_Del , /* tp_free */
3755
+ static PyType_Slot accumulate_slots [] = {
3756
+ {Py_tp_dealloc , accumulate_dealloc },
3757
+ {Py_tp_getattro , PyObject_GenericGetAttr },
3758
+ {Py_tp_doc , (void * )itertools_accumulate__doc__ },
3759
+ {Py_tp_traverse , accumulate_traverse },
3760
+ {Py_tp_iter , PyObject_SelfIter },
3761
+ {Py_tp_iternext , accumulate_next },
3762
+ {Py_tp_methods , accumulate_methods },
3763
+ {Py_tp_new , itertools_accumulate },
3764
+ {Py_tp_free , PyObject_GC_Del },
3765
+ {0 , NULL },
3766
+ };
3767
+
3768
+ static PyType_Spec accumulate_spec = {
3769
+ .name = "itertools.accumulate" ,
3770
+ .basicsize = sizeof (accumulateobject ),
3771
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
3772
+ Py_TPFLAGS_IMMUTABLETYPE ),
3773
+ .slots = accumulate_slots ,
3794
3774
};
3795
3775
3796
3776
@@ -4822,6 +4802,7 @@ static int
4822
4802
itertoolsmodule_traverse (PyObject * mod , visitproc visit , void * arg )
4823
4803
{
4824
4804
itertools_state * state = get_module_state (mod );
4805
+ Py_VISIT (state -> accumulate_type );
4825
4806
Py_VISIT (state -> combinations_type );
4826
4807
Py_VISIT (state -> cwr_type );
4827
4808
Py_VISIT (state -> cycle_type );
@@ -4838,6 +4819,7 @@ static int
4838
4819
itertoolsmodule_clear (PyObject * mod )
4839
4820
{
4840
4821
itertools_state * state = get_module_state (mod );
4822
+ Py_CLEAR (state -> accumulate_type );
4841
4823
Py_CLEAR (state -> combinations_type );
4842
4824
Py_CLEAR (state -> cwr_type );
4843
4825
Py_CLEAR (state -> cycle_type );
@@ -4871,6 +4853,7 @@ static int
4871
4853
itertoolsmodule_exec (PyObject * mod )
4872
4854
{
4873
4855
itertools_state * state = get_module_state (mod );
4856
+ ADD_TYPE (mod , state -> accumulate_type , & accumulate_spec );
4874
4857
ADD_TYPE (mod , state -> combinations_type , & combinations_spec );
4875
4858
ADD_TYPE (mod , state -> cwr_type , & cwr_spec );
4876
4859
ADD_TYPE (mod , state -> cycle_type , & cycle_spec );
@@ -4882,7 +4865,6 @@ itertoolsmodule_exec(PyObject *mod)
4882
4865
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4883
4866
4884
4867
PyTypeObject * typelist [] = {
4885
- & accumulate_type ,
4886
4868
& batched_type ,
4887
4869
& islice_type ,
4888
4870
& chain_type ,
0 commit comments