@@ -25,6 +25,7 @@ typedef struct {
25
25
PyTypeObject * pairwise_type ;
26
26
PyTypeObject * permutations_type ;
27
27
PyTypeObject * product_type ;
28
+ PyTypeObject * repeat_type ;
28
29
PyTypeObject * starmap_type ;
29
30
PyTypeObject * takewhile_type ;
30
31
PyTypeObject * ziplongest_type ;
@@ -4261,8 +4262,6 @@ typedef struct {
4261
4262
Py_ssize_t cnt ;
4262
4263
} repeatobject ;
4263
4264
4264
- static PyTypeObject repeat_type ;
4265
-
4266
4265
static PyObject *
4267
4266
repeat_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
4268
4267
{
@@ -4292,14 +4291,17 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4292
4291
static void
4293
4292
repeat_dealloc (repeatobject * ro )
4294
4293
{
4294
+ PyTypeObject * tp = Py_TYPE (ro );
4295
4295
PyObject_GC_UnTrack (ro );
4296
4296
Py_XDECREF (ro -> element );
4297
- Py_TYPE (ro )-> tp_free (ro );
4297
+ tp -> tp_free (ro );
4298
+ Py_DECREF (tp );
4298
4299
}
4299
4300
4300
4301
static int
4301
4302
repeat_traverse (repeatobject * ro , visitproc visit , void * arg )
4302
4303
{
4304
+ Py_VISIT (Py_TYPE (ro ));
4303
4305
Py_VISIT (ro -> element );
4304
4306
return 0 ;
4305
4307
}
@@ -4361,48 +4363,25 @@ PyDoc_STRVAR(repeat_doc,
4361
4363
for the specified number of times. If not specified, returns the object\n\
4362
4364
endlessly." );
4363
4365
4364
- static PyTypeObject repeat_type = {
4365
- PyVarObject_HEAD_INIT (NULL , 0 )
4366
- "itertools.repeat" , /* tp_name */
4367
- sizeof (repeatobject ), /* tp_basicsize */
4368
- 0 , /* tp_itemsize */
4369
- /* methods */
4370
- (destructor )repeat_dealloc , /* tp_dealloc */
4371
- 0 , /* tp_vectorcall_offset */
4372
- 0 , /* tp_getattr */
4373
- 0 , /* tp_setattr */
4374
- 0 , /* tp_as_async */
4375
- (reprfunc )repeat_repr , /* tp_repr */
4376
- 0 , /* tp_as_number */
4377
- 0 , /* tp_as_sequence */
4378
- 0 , /* tp_as_mapping */
4379
- 0 , /* tp_hash */
4380
- 0 , /* tp_call */
4381
- 0 , /* tp_str */
4382
- PyObject_GenericGetAttr , /* tp_getattro */
4383
- 0 , /* tp_setattro */
4384
- 0 , /* tp_as_buffer */
4385
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
4386
- Py_TPFLAGS_BASETYPE , /* tp_flags */
4387
- repeat_doc , /* tp_doc */
4388
- (traverseproc )repeat_traverse , /* tp_traverse */
4389
- 0 , /* tp_clear */
4390
- 0 , /* tp_richcompare */
4391
- 0 , /* tp_weaklistoffset */
4392
- PyObject_SelfIter , /* tp_iter */
4393
- (iternextfunc )repeat_next , /* tp_iternext */
4394
- repeat_methods , /* tp_methods */
4395
- 0 , /* tp_members */
4396
- 0 , /* tp_getset */
4397
- 0 , /* tp_base */
4398
- 0 , /* tp_dict */
4399
- 0 , /* tp_descr_get */
4400
- 0 , /* tp_descr_set */
4401
- 0 , /* tp_dictoffset */
4402
- 0 , /* tp_init */
4403
- 0 , /* tp_alloc */
4404
- repeat_new , /* tp_new */
4405
- PyObject_GC_Del , /* tp_free */
4366
+ static PyType_Slot repeat_slots [] = {
4367
+ {Py_tp_dealloc , repeat_dealloc },
4368
+ {Py_tp_repr , repeat_repr },
4369
+ {Py_tp_getattro , PyObject_GenericGetAttr },
4370
+ {Py_tp_doc , (void * )repeat_doc },
4371
+ {Py_tp_traverse , repeat_traverse },
4372
+ {Py_tp_iter , PyObject_SelfIter },
4373
+ {Py_tp_iternext , repeat_next },
4374
+ {Py_tp_methods , repeat_methods },
4375
+ {Py_tp_new , repeat_new },
4376
+ {Py_tp_free , PyObject_GC_Del },
4377
+ {0 , NULL },
4378
+ };
4379
+
4380
+ static PyType_Spec repeat_spec = {
4381
+ .name = "itertools.repeat" ,
4382
+ .basicsize = sizeof (repeatobject ),
4383
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE ,
4384
+ .slots = repeat_slots ,
4406
4385
};
4407
4386
4408
4387
@@ -4707,6 +4686,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4707
4686
Py_VISIT (state -> pairwise_type );
4708
4687
Py_VISIT (state -> permutations_type );
4709
4688
Py_VISIT (state -> product_type );
4689
+ Py_VISIT (state -> repeat_type );
4710
4690
Py_VISIT (state -> starmap_type );
4711
4691
Py_VISIT (state -> takewhile_type );
4712
4692
Py_VISIT (state -> ziplongest_type );
@@ -4730,6 +4710,7 @@ itertoolsmodule_clear(PyObject *mod)
4730
4710
Py_CLEAR (state -> pairwise_type );
4731
4711
Py_CLEAR (state -> permutations_type );
4732
4712
Py_CLEAR (state -> product_type );
4713
+ Py_CLEAR (state -> repeat_type );
4733
4714
Py_CLEAR (state -> starmap_type );
4734
4715
Py_CLEAR (state -> takewhile_type );
4735
4716
Py_CLEAR (state -> ziplongest_type );
@@ -4770,6 +4751,7 @@ itertoolsmodule_exec(PyObject *mod)
4770
4751
ADD_TYPE (mod , state -> pairwise_type , & pairwise_spec );
4771
4752
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4772
4753
ADD_TYPE (mod , state -> product_type , & product_spec );
4754
+ ADD_TYPE (mod , state -> repeat_type , & repeat_spec );
4773
4755
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4774
4756
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4775
4757
ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
@@ -4778,7 +4760,6 @@ itertoolsmodule_exec(PyObject *mod)
4778
4760
& batched_type ,
4779
4761
& islice_type ,
4780
4762
& chain_type ,
4781
- & repeat_type ,
4782
4763
& tee_type ,
4783
4764
& teedataobject_type
4784
4765
};
0 commit comments