11
11
*/
12
12
13
13
typedef struct {
14
+ PyTypeObject * cycle_type ;
14
15
PyTypeObject * groupby_type ;
15
16
PyTypeObject * _grouper_type ;
16
17
} itertools_state ;
@@ -40,7 +41,7 @@ class itertools._grouper "_grouperobject *" "clinic_state()->_grouper_type"
40
41
class itertools.teedataobject "teedataobject *" "&teedataobject_type"
41
42
class itertools._tee "teeobject *" "&tee_type"
42
43
class itertools.batched "batchedobject *" "&batched_type"
43
- class itertools.cycle "cycleobject *" "& cycle_type"
44
+ class itertools.cycle "cycleobject *" "clinic_state()-> cycle_type"
44
45
class itertools.dropwhile "dropwhileobject *" "&dropwhile_type"
45
46
class itertools.takewhile "takewhileobject *" "&takewhile_type"
46
47
class itertools.starmap "starmapobject *" "&starmap_type"
@@ -54,12 +55,11 @@ class itertools.filterfalse "filterfalseobject *" "&filterfalse_type"
54
55
class itertools.count "countobject *" "&count_type"
55
56
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
56
57
[clinic start generated code]*/
57
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=424108522584b55b ]*/
58
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b73cdca8e1fddfb5 ]*/
58
59
59
60
static PyTypeObject teedataobject_type ;
60
61
static PyTypeObject tee_type ;
61
62
static PyTypeObject batched_type ;
62
- static PyTypeObject cycle_type ;
63
63
static PyTypeObject dropwhile_type ;
64
64
static PyTypeObject takewhile_type ;
65
65
static PyTypeObject starmap_type ;
@@ -1273,15 +1273,18 @@ itertools_cycle_impl(PyTypeObject *type, PyObject *iterable)
1273
1273
static void
1274
1274
cycle_dealloc (cycleobject * lz )
1275
1275
{
1276
+ PyTypeObject * tp = Py_TYPE (lz );
1276
1277
PyObject_GC_UnTrack (lz );
1277
1278
Py_XDECREF (lz -> it );
1278
1279
Py_XDECREF (lz -> saved );
1279
- Py_TYPE (lz )-> tp_free (lz );
1280
+ tp -> tp_free (lz );
1281
+ Py_DECREF (tp );
1280
1282
}
1281
1283
1282
1284
static int
1283
1285
cycle_traverse (cycleobject * lz , visitproc visit , void * arg )
1284
1286
{
1287
+ Py_VISIT (Py_TYPE (lz ));
1285
1288
Py_VISIT (lz -> it );
1286
1289
Py_VISIT (lz -> saved );
1287
1290
return 0 ;
@@ -1368,48 +1371,25 @@ static PyMethodDef cycle_methods[] = {
1368
1371
{NULL , NULL } /* sentinel */
1369
1372
};
1370
1373
1371
- static PyTypeObject cycle_type = {
1372
- PyVarObject_HEAD_INIT (NULL , 0 )
1373
- "itertools.cycle" , /* tp_name */
1374
- sizeof (cycleobject ), /* tp_basicsize */
1375
- 0 , /* tp_itemsize */
1376
- /* methods */
1377
- (destructor )cycle_dealloc , /* tp_dealloc */
1378
- 0 , /* tp_vectorcall_offset */
1379
- 0 , /* tp_getattr */
1380
- 0 , /* tp_setattr */
1381
- 0 , /* tp_as_async */
1382
- 0 , /* tp_repr */
1383
- 0 , /* tp_as_number */
1384
- 0 , /* tp_as_sequence */
1385
- 0 , /* tp_as_mapping */
1386
- 0 , /* tp_hash */
1387
- 0 , /* tp_call */
1388
- 0 , /* tp_str */
1389
- PyObject_GenericGetAttr , /* tp_getattro */
1390
- 0 , /* tp_setattro */
1391
- 0 , /* tp_as_buffer */
1392
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1393
- Py_TPFLAGS_BASETYPE , /* tp_flags */
1394
- itertools_cycle__doc__ , /* tp_doc */
1395
- (traverseproc )cycle_traverse , /* tp_traverse */
1396
- 0 , /* tp_clear */
1397
- 0 , /* tp_richcompare */
1398
- 0 , /* tp_weaklistoffset */
1399
- PyObject_SelfIter , /* tp_iter */
1400
- (iternextfunc )cycle_next , /* tp_iternext */
1401
- cycle_methods , /* tp_methods */
1402
- 0 , /* tp_members */
1403
- 0 , /* tp_getset */
1404
- 0 , /* tp_base */
1405
- 0 , /* tp_dict */
1406
- 0 , /* tp_descr_get */
1407
- 0 , /* tp_descr_set */
1408
- 0 , /* tp_dictoffset */
1409
- 0 , /* tp_init */
1410
- 0 , /* tp_alloc */
1411
- itertools_cycle , /* tp_new */
1412
- PyObject_GC_Del , /* tp_free */
1374
+ static PyType_Slot cycle_slots [] = {
1375
+ {Py_tp_dealloc , cycle_dealloc },
1376
+ {Py_tp_getattro , PyObject_GenericGetAttr },
1377
+ {Py_tp_doc , (void * )itertools_cycle__doc__ },
1378
+ {Py_tp_traverse , cycle_traverse },
1379
+ {Py_tp_iter , PyObject_SelfIter },
1380
+ {Py_tp_iternext , cycle_next },
1381
+ {Py_tp_methods , cycle_methods },
1382
+ {Py_tp_new , itertools_cycle },
1383
+ {Py_tp_free , PyObject_GC_Del },
1384
+ {0 , NULL },
1385
+ };
1386
+
1387
+ static PyType_Spec cycle_spec = {
1388
+ .name = "itertools.cycle" ,
1389
+ .basicsize = sizeof (cycleobject ),
1390
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
1391
+ Py_TPFLAGS_IMMUTABLETYPE ),
1392
+ .slots = cycle_slots ,
1413
1393
};
1414
1394
1415
1395
@@ -4962,6 +4942,7 @@ static int
4962
4942
itertoolsmodule_traverse (PyObject * mod , visitproc visit , void * arg )
4963
4943
{
4964
4944
itertools_state * state = get_module_state (mod );
4945
+ Py_VISIT (state -> cycle_type );
4965
4946
Py_VISIT (state -> groupby_type );
4966
4947
Py_VISIT (state -> _grouper_type );
4967
4948
return 0 ;
@@ -4971,6 +4952,7 @@ static int
4971
4952
itertoolsmodule_clear (PyObject * mod )
4972
4953
{
4973
4954
itertools_state * state = get_module_state (mod );
4955
+ Py_CLEAR (state -> cycle_type );
4974
4956
Py_CLEAR (state -> groupby_type );
4975
4957
Py_CLEAR (state -> _grouper_type );
4976
4958
return 0 ;
@@ -4997,6 +4979,7 @@ static int
4997
4979
itertoolsmodule_exec (PyObject * mod )
4998
4980
{
4999
4981
itertools_state * state = get_module_state (mod );
4982
+ ADD_TYPE (mod , state -> cycle_type , & cycle_spec );
5000
4983
ADD_TYPE (mod , state -> groupby_type , & groupby_spec );
5001
4984
ADD_TYPE (mod , state -> _grouper_type , & _grouper_spec );
5002
4985
@@ -5005,7 +4988,6 @@ itertoolsmodule_exec(PyObject *mod)
5005
4988
& batched_type ,
5006
4989
& combinations_type ,
5007
4990
& cwr_type ,
5008
- & cycle_type ,
5009
4991
& dropwhile_type ,
5010
4992
& takewhile_type ,
5011
4993
& islice_type ,
0 commit comments