13
13
14
14
typedef struct {
15
15
PyTypeObject * accumulate_type ;
16
+ PyTypeObject * batched_type ;
16
17
PyTypeObject * chain_type ;
17
18
PyTypeObject * combinations_type ;
18
19
PyTypeObject * compress_type ;
@@ -59,7 +60,7 @@ class itertools.groupby "groupbyobject *" "clinic_state()->groupby_type"
59
60
class itertools._grouper "_grouperobject *" "clinic_state()->_grouper_type"
60
61
class itertools.teedataobject "teedataobject *" "clinic_state()->teedataobject_type"
61
62
class itertools._tee "teeobject *" "clinic_state()->tee_type"
62
- class itertools.batched "batchedobject *" "& batched_type"
63
+ class itertools.batched "batchedobject *" "clinic_state()-> batched_type"
63
64
class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
64
65
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
65
66
class itertools.takewhile "takewhileobject *" "clinic_state()->takewhile_type"
@@ -76,8 +77,6 @@ class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
76
77
[clinic start generated code]*/
77
78
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=419423f2d82cf388]*/
78
79
79
- static PyTypeObject batched_type ;
80
-
81
80
#include "clinic/itertoolsmodule.c.h"
82
81
#undef clinic_state
83
82
@@ -154,17 +153,18 @@ batched_new_impl(PyTypeObject *type, PyObject *iterable, Py_ssize_t n)
154
153
static void
155
154
batched_dealloc (batchedobject * bo )
156
155
{
156
+ PyTypeObject * tp = Py_TYPE (bo );
157
157
PyObject_GC_UnTrack (bo );
158
158
Py_XDECREF (bo -> it );
159
- Py_TYPE (bo )-> tp_free (bo );
159
+ tp -> tp_free (bo );
160
+ Py_DECREF (tp );
160
161
}
161
162
162
163
static int
163
164
batched_traverse (batchedobject * bo , visitproc visit , void * arg )
164
165
{
165
- if (bo -> it != NULL ) {
166
- Py_VISIT (bo -> it );
167
- }
166
+ Py_VISIT (Py_TYPE (bo ));
167
+ Py_VISIT (bo -> it );
168
168
return 0 ;
169
169
}
170
170
@@ -214,48 +214,25 @@ batched_next(batchedobject *bo)
214
214
return result ;
215
215
}
216
216
217
- static PyTypeObject batched_type = {
218
- PyVarObject_HEAD_INIT (& PyType_Type , 0 )
219
- "itertools.batched" , /* tp_name */
220
- sizeof (batchedobject ), /* tp_basicsize */
221
- 0 , /* tp_itemsize */
222
- /* methods */
223
- (destructor )batched_dealloc , /* tp_dealloc */
224
- 0 , /* tp_vectorcall_offset */
225
- 0 , /* tp_getattr */
226
- 0 , /* tp_setattr */
227
- 0 , /* tp_as_async */
228
- 0 , /* tp_repr */
229
- 0 , /* tp_as_number */
230
- 0 , /* tp_as_sequence */
231
- 0 , /* tp_as_mapping */
232
- 0 , /* tp_hash */
233
- 0 , /* tp_call */
234
- 0 , /* tp_str */
235
- PyObject_GenericGetAttr , /* tp_getattro */
236
- 0 , /* tp_setattro */
237
- 0 , /* tp_as_buffer */
238
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
239
- Py_TPFLAGS_BASETYPE , /* tp_flags */
240
- batched_new__doc__ , /* tp_doc */
241
- (traverseproc )batched_traverse , /* tp_traverse */
242
- 0 , /* tp_clear */
243
- 0 , /* tp_richcompare */
244
- 0 , /* tp_weaklistoffset */
245
- PyObject_SelfIter , /* tp_iter */
246
- (iternextfunc )batched_next , /* tp_iternext */
247
- 0 , /* tp_methods */
248
- 0 , /* tp_members */
249
- 0 , /* tp_getset */
250
- 0 , /* tp_base */
251
- 0 , /* tp_dict */
252
- 0 , /* tp_descr_get */
253
- 0 , /* tp_descr_set */
254
- 0 , /* tp_dictoffset */
255
- 0 , /* tp_init */
256
- PyType_GenericAlloc , /* tp_alloc */
257
- batched_new , /* tp_new */
258
- PyObject_GC_Del , /* tp_free */
217
+ static PyType_Slot batched_slots [] = {
218
+ {Py_tp_dealloc , batched_dealloc },
219
+ {Py_tp_getattro , PyObject_GenericGetAttr },
220
+ {Py_tp_doc , (void * )batched_new__doc__ },
221
+ {Py_tp_traverse , batched_traverse },
222
+ {Py_tp_iter , PyObject_SelfIter },
223
+ {Py_tp_iternext , batched_next },
224
+ {Py_tp_alloc , PyType_GenericAlloc },
225
+ {Py_tp_new , batched_new },
226
+ {Py_tp_free , PyObject_GC_Del },
227
+ {0 , NULL },
228
+ };
229
+
230
+ static PyType_Spec batched_spec = {
231
+ .name = "itertools.batched" ,
232
+ .basicsize = sizeof (batchedobject ),
233
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
234
+ Py_TPFLAGS_IMMUTABLETYPE ),
235
+ .slots = batched_slots ,
259
236
};
260
237
261
238
@@ -4599,6 +4576,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4599
4576
{
4600
4577
itertools_state * state = get_module_state (mod );
4601
4578
Py_VISIT (state -> accumulate_type );
4579
+ Py_VISIT (state -> batched_type );
4602
4580
Py_VISIT (state -> chain_type );
4603
4581
Py_VISIT (state -> combinations_type );
4604
4582
Py_VISIT (state -> compress_type );
@@ -4626,6 +4604,7 @@ itertoolsmodule_clear(PyObject *mod)
4626
4604
{
4627
4605
itertools_state * state = get_module_state (mod );
4628
4606
Py_CLEAR (state -> accumulate_type );
4607
+ Py_CLEAR (state -> batched_type );
4629
4608
Py_CLEAR (state -> chain_type );
4630
4609
Py_CLEAR (state -> combinations_type );
4631
4610
Py_CLEAR (state -> compress_type );
@@ -4670,6 +4649,7 @@ itertoolsmodule_exec(PyObject *mod)
4670
4649
{
4671
4650
itertools_state * state = get_module_state (mod );
4672
4651
ADD_TYPE (mod , state -> accumulate_type , & accumulate_spec );
4652
+ ADD_TYPE (mod , state -> batched_type , & batched_spec );
4673
4653
ADD_TYPE (mod , state -> chain_type , & chain_spec );
4674
4654
ADD_TYPE (mod , state -> combinations_type , & combinations_spec );
4675
4655
ADD_TYPE (mod , state -> compress_type , & compress_spec );
@@ -4691,18 +4671,7 @@ itertoolsmodule_exec(PyObject *mod)
4691
4671
ADD_TYPE (mod , state -> teedataobject_type , & teedataobject_spec );
4692
4672
ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
4693
4673
4694
- PyTypeObject * typelist [] = {
4695
- & batched_type ,
4696
- };
4697
-
4698
4674
Py_SET_TYPE (state -> teedataobject_type , & PyType_Type );
4699
-
4700
- for (size_t i = 0 ; i < Py_ARRAY_LENGTH (typelist ); i ++ ) {
4701
- if (PyModule_AddType (mod , typelist [i ]) < 0 ) {
4702
- return -1 ;
4703
- }
4704
- }
4705
-
4706
4675
return 0 ;
4707
4676
}
4708
4677
0 commit comments