14
14
15
15
typedef struct {
16
16
PyTypeObject * accumulate_type ;
17
+ PyTypeObject * batched_type ;
17
18
PyTypeObject * chain_type ;
18
19
PyTypeObject * combinations_type ;
19
20
PyTypeObject * compress_type ;
@@ -69,7 +70,7 @@ class itertools.groupby "groupbyobject *" "clinic_state()->groupby_type"
69
70
class itertools._grouper "_grouperobject *" "clinic_state()->_grouper_type"
70
71
class itertools.teedataobject "teedataobject *" "clinic_state()->teedataobject_type"
71
72
class itertools._tee "teeobject *" "clinic_state()->tee_type"
72
- class itertools.batched "batchedobject *" "& batched_type"
73
+ class itertools.batched "batchedobject *" "clinic_state()-> batched_type"
73
74
class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
74
75
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
75
76
class itertools.takewhile "takewhileobject *" "clinic_state()->takewhile_type"
@@ -84,9 +85,7 @@ class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_t
84
85
class itertools.count "countobject *" "clinic_state()->count_type"
85
86
class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
86
87
[clinic start generated code]*/
87
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=419423f2d82cf388]*/
88
-
89
- static PyTypeObject batched_type ;
88
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=aa48fe4de9d4080f]*/
90
89
91
90
#define clinic_state_by_cls () (get_module_state_by_cls(base_tp))
92
91
#include "clinic/itertoolsmodule.c.h"
@@ -166,17 +165,18 @@ batched_new_impl(PyTypeObject *type, PyObject *iterable, Py_ssize_t n)
166
165
static void
167
166
batched_dealloc (batchedobject * bo )
168
167
{
168
+ PyTypeObject * tp = Py_TYPE (bo );
169
169
PyObject_GC_UnTrack (bo );
170
170
Py_XDECREF (bo -> it );
171
- Py_TYPE (bo )-> tp_free (bo );
171
+ tp -> tp_free (bo );
172
+ Py_DECREF (tp );
172
173
}
173
174
174
175
static int
175
176
batched_traverse (batchedobject * bo , visitproc visit , void * arg )
176
177
{
177
- if (bo -> it != NULL ) {
178
- Py_VISIT (bo -> it );
179
- }
178
+ Py_VISIT (Py_TYPE (bo ));
179
+ Py_VISIT (bo -> it );
180
180
return 0 ;
181
181
}
182
182
@@ -226,48 +226,25 @@ batched_next(batchedobject *bo)
226
226
return result ;
227
227
}
228
228
229
- static PyTypeObject batched_type = {
230
- PyVarObject_HEAD_INIT (& PyType_Type , 0 )
231
- "itertools.batched" , /* tp_name */
232
- sizeof (batchedobject ), /* tp_basicsize */
233
- 0 , /* tp_itemsize */
234
- /* methods */
235
- (destructor )batched_dealloc , /* tp_dealloc */
236
- 0 , /* tp_vectorcall_offset */
237
- 0 , /* tp_getattr */
238
- 0 , /* tp_setattr */
239
- 0 , /* tp_as_async */
240
- 0 , /* tp_repr */
241
- 0 , /* tp_as_number */
242
- 0 , /* tp_as_sequence */
243
- 0 , /* tp_as_mapping */
244
- 0 , /* tp_hash */
245
- 0 , /* tp_call */
246
- 0 , /* tp_str */
247
- PyObject_GenericGetAttr , /* tp_getattro */
248
- 0 , /* tp_setattro */
249
- 0 , /* tp_as_buffer */
250
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
251
- Py_TPFLAGS_BASETYPE , /* tp_flags */
252
- batched_new__doc__ , /* tp_doc */
253
- (traverseproc )batched_traverse , /* tp_traverse */
254
- 0 , /* tp_clear */
255
- 0 , /* tp_richcompare */
256
- 0 , /* tp_weaklistoffset */
257
- PyObject_SelfIter , /* tp_iter */
258
- (iternextfunc )batched_next , /* tp_iternext */
259
- 0 , /* tp_methods */
260
- 0 , /* tp_members */
261
- 0 , /* tp_getset */
262
- 0 , /* tp_base */
263
- 0 , /* tp_dict */
264
- 0 , /* tp_descr_get */
265
- 0 , /* tp_descr_set */
266
- 0 , /* tp_dictoffset */
267
- 0 , /* tp_init */
268
- PyType_GenericAlloc , /* tp_alloc */
269
- batched_new , /* tp_new */
270
- PyObject_GC_Del , /* tp_free */
229
+ static PyType_Slot batched_slots [] = {
230
+ {Py_tp_dealloc , batched_dealloc },
231
+ {Py_tp_getattro , PyObject_GenericGetAttr },
232
+ {Py_tp_doc , (void * )batched_new__doc__ },
233
+ {Py_tp_traverse , batched_traverse },
234
+ {Py_tp_iter , PyObject_SelfIter },
235
+ {Py_tp_iternext , batched_next },
236
+ {Py_tp_alloc , PyType_GenericAlloc },
237
+ {Py_tp_new , batched_new },
238
+ {Py_tp_free , PyObject_GC_Del },
239
+ {0 , NULL },
240
+ };
241
+
242
+ static PyType_Spec batched_spec = {
243
+ .name = "itertools.batched" ,
244
+ .basicsize = sizeof (batchedobject ),
245
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
246
+ Py_TPFLAGS_IMMUTABLETYPE ),
247
+ .slots = batched_slots ,
271
248
};
272
249
273
250
@@ -4612,6 +4589,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4612
4589
{
4613
4590
itertools_state * state = get_module_state (mod );
4614
4591
Py_VISIT (state -> accumulate_type );
4592
+ Py_VISIT (state -> batched_type );
4615
4593
Py_VISIT (state -> chain_type );
4616
4594
Py_VISIT (state -> combinations_type );
4617
4595
Py_VISIT (state -> compress_type );
@@ -4639,6 +4617,7 @@ itertoolsmodule_clear(PyObject *mod)
4639
4617
{
4640
4618
itertools_state * state = get_module_state (mod );
4641
4619
Py_CLEAR (state -> accumulate_type );
4620
+ Py_CLEAR (state -> batched_type );
4642
4621
Py_CLEAR (state -> chain_type );
4643
4622
Py_CLEAR (state -> combinations_type );
4644
4623
Py_CLEAR (state -> compress_type );
@@ -4683,6 +4662,7 @@ itertoolsmodule_exec(PyObject *mod)
4683
4662
{
4684
4663
itertools_state * state = get_module_state (mod );
4685
4664
ADD_TYPE (mod , state -> accumulate_type , & accumulate_spec );
4665
+ ADD_TYPE (mod , state -> batched_type , & batched_spec );
4686
4666
ADD_TYPE (mod , state -> chain_type , & chain_spec );
4687
4667
ADD_TYPE (mod , state -> combinations_type , & combinations_spec );
4688
4668
ADD_TYPE (mod , state -> compress_type , & compress_spec );
@@ -4704,18 +4684,7 @@ itertoolsmodule_exec(PyObject *mod)
4704
4684
ADD_TYPE (mod , state -> teedataobject_type , & teedataobject_spec );
4705
4685
ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
4706
4686
4707
- PyTypeObject * typelist [] = {
4708
- & batched_type ,
4709
- };
4710
-
4711
4687
Py_SET_TYPE (state -> teedataobject_type , & PyType_Type );
4712
-
4713
- for (size_t i = 0 ; i < Py_ARRAY_LENGTH (typelist ); i ++ ) {
4714
- if (PyModule_AddType (mod , typelist [i ]) < 0 ) {
4715
- return -1 ;
4716
- }
4717
- }
4718
-
4719
4688
return 0 ;
4720
4689
}
4721
4690
0 commit comments