@@ -24,6 +24,7 @@ typedef struct {
24
24
PyTypeObject * pairwise_type ;
25
25
PyTypeObject * permutations_type ;
26
26
PyTypeObject * product_type ;
27
+ PyTypeObject * repeat_type ;
27
28
PyTypeObject * starmap_type ;
28
29
PyTypeObject * takewhile_type ;
29
30
PyTypeObject * ziplongest_type ;
@@ -4247,8 +4248,6 @@ typedef struct {
4247
4248
Py_ssize_t cnt ;
4248
4249
} repeatobject ;
4249
4250
4250
- static PyTypeObject repeat_type ;
4251
-
4252
4251
static PyObject *
4253
4252
repeat_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
4254
4253
{
@@ -4278,14 +4277,17 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4278
4277
static void
4279
4278
repeat_dealloc (repeatobject * ro )
4280
4279
{
4280
+ PyTypeObject * tp = Py_TYPE (ro );
4281
4281
PyObject_GC_UnTrack (ro );
4282
4282
Py_XDECREF (ro -> element );
4283
- Py_TYPE (ro )-> tp_free (ro );
4283
+ tp -> tp_free (ro );
4284
+ Py_DECREF (tp );
4284
4285
}
4285
4286
4286
4287
static int
4287
4288
repeat_traverse (repeatobject * ro , visitproc visit , void * arg )
4288
4289
{
4290
+ Py_VISIT (Py_TYPE (ro ));
4289
4291
Py_VISIT (ro -> element );
4290
4292
return 0 ;
4291
4293
}
@@ -4347,48 +4349,25 @@ PyDoc_STRVAR(repeat_doc,
4347
4349
for the specified number of times. If not specified, returns the object\n\
4348
4350
endlessly." );
4349
4351
4350
- static PyTypeObject repeat_type = {
4351
- PyVarObject_HEAD_INIT (NULL , 0 )
4352
- "itertools.repeat" , /* tp_name */
4353
- sizeof (repeatobject ), /* tp_basicsize */
4354
- 0 , /* tp_itemsize */
4355
- /* methods */
4356
- (destructor )repeat_dealloc , /* tp_dealloc */
4357
- 0 , /* tp_vectorcall_offset */
4358
- 0 , /* tp_getattr */
4359
- 0 , /* tp_setattr */
4360
- 0 , /* tp_as_async */
4361
- (reprfunc )repeat_repr , /* tp_repr */
4362
- 0 , /* tp_as_number */
4363
- 0 , /* tp_as_sequence */
4364
- 0 , /* tp_as_mapping */
4365
- 0 , /* tp_hash */
4366
- 0 , /* tp_call */
4367
- 0 , /* tp_str */
4368
- PyObject_GenericGetAttr , /* tp_getattro */
4369
- 0 , /* tp_setattro */
4370
- 0 , /* tp_as_buffer */
4371
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
4372
- Py_TPFLAGS_BASETYPE , /* tp_flags */
4373
- repeat_doc , /* tp_doc */
4374
- (traverseproc )repeat_traverse , /* tp_traverse */
4375
- 0 , /* tp_clear */
4376
- 0 , /* tp_richcompare */
4377
- 0 , /* tp_weaklistoffset */
4378
- PyObject_SelfIter , /* tp_iter */
4379
- (iternextfunc )repeat_next , /* tp_iternext */
4380
- repeat_methods , /* tp_methods */
4381
- 0 , /* tp_members */
4382
- 0 , /* tp_getset */
4383
- 0 , /* tp_base */
4384
- 0 , /* tp_dict */
4385
- 0 , /* tp_descr_get */
4386
- 0 , /* tp_descr_set */
4387
- 0 , /* tp_dictoffset */
4388
- 0 , /* tp_init */
4389
- 0 , /* tp_alloc */
4390
- repeat_new , /* tp_new */
4391
- PyObject_GC_Del , /* tp_free */
4352
+ static PyType_Slot repeat_slots [] = {
4353
+ {Py_tp_dealloc , repeat_dealloc },
4354
+ {Py_tp_repr , repeat_repr },
4355
+ {Py_tp_getattro , PyObject_GenericGetAttr },
4356
+ {Py_tp_doc , (void * )repeat_doc },
4357
+ {Py_tp_traverse , repeat_traverse },
4358
+ {Py_tp_iter , PyObject_SelfIter },
4359
+ {Py_tp_iternext , repeat_next },
4360
+ {Py_tp_methods , repeat_methods },
4361
+ {Py_tp_new , repeat_new },
4362
+ {Py_tp_free , PyObject_GC_Del },
4363
+ {0 , NULL },
4364
+ };
4365
+
4366
+ static PyType_Spec repeat_spec = {
4367
+ .name = "itertools.repeat" ,
4368
+ .basicsize = sizeof (repeatobject ),
4369
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE ,
4370
+ .slots = repeat_slots ,
4392
4371
};
4393
4372
4394
4373
@@ -4692,6 +4671,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4692
4671
Py_VISIT (state -> _grouper_type );
4693
4672
Py_VISIT (state -> permutations_type );
4694
4673
Py_VISIT (state -> product_type );
4674
+ Py_VISIT (state -> repeat_type );
4695
4675
Py_VISIT (state -> starmap_type );
4696
4676
Py_VISIT (state -> takewhile_type );
4697
4677
Py_VISIT (state -> ziplongest_type );
@@ -4714,6 +4694,7 @@ itertoolsmodule_clear(PyObject *mod)
4714
4694
Py_CLEAR (state -> _grouper_type );
4715
4695
Py_CLEAR (state -> permutations_type );
4716
4696
Py_CLEAR (state -> product_type );
4697
+ Py_CLEAR (state -> repeat_type );
4717
4698
Py_CLEAR (state -> starmap_type );
4718
4699
Py_CLEAR (state -> takewhile_type );
4719
4700
Py_CLEAR (state -> ziplongest_type );
@@ -4754,6 +4735,7 @@ itertoolsmodule_exec(PyObject *mod)
4754
4735
ADD_TYPE (mod , state -> pairwise_type , & pairwise_spec );
4755
4736
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4756
4737
ADD_TYPE (mod , state -> product_type , & product_spec );
4738
+ ADD_TYPE (mod , state -> repeat_type , & repeat_spec );
4757
4739
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4758
4740
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4759
4741
ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
@@ -4762,7 +4744,6 @@ itertoolsmodule_exec(PyObject *mod)
4762
4744
& batched_type ,
4763
4745
& islice_type ,
4764
4746
& chain_type ,
4765
- & repeat_type ,
4766
4747
& tee_type ,
4767
4748
& teedataobject_type
4768
4749
};
0 commit comments