@@ -21,6 +21,7 @@ typedef struct {
21
21
PyTypeObject * filterfalse_type ;
22
22
PyTypeObject * groupby_type ;
23
23
PyTypeObject * _grouper_type ;
24
+ PyTypeObject * pairwise_type ;
24
25
PyTypeObject * permutations_type ;
25
26
PyTypeObject * starmap_type ;
26
27
PyTypeObject * takewhile_type ;
@@ -63,14 +64,13 @@ class itertools.accumulate "accumulateobject *" "clinic_state()->accumulate_type
63
64
class itertools.compress "compressobject *" "clinic_state()->compress_type"
64
65
class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_type"
65
66
class itertools.count "countobject *" "clinic_state()->count_type"
66
- class itertools.pairwise "pairwiseobject *" "& pairwise_type"
67
+ class itertools.pairwise "pairwiseobject *" "clinic_state()-> pairwise_type"
67
68
[clinic start generated code]*/
68
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=338b4d26465f3eb1 ]*/
69
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7 ]*/
69
70
70
71
static PyTypeObject teedataobject_type ;
71
72
static PyTypeObject tee_type ;
72
73
static PyTypeObject batched_type ;
73
- static PyTypeObject pairwise_type ;
74
74
75
75
#include "clinic/itertoolsmodule.c.h"
76
76
#undef clinic_state
@@ -296,15 +296,18 @@ pairwise_new_impl(PyTypeObject *type, PyObject *iterable)
296
296
static void
297
297
pairwise_dealloc (pairwiseobject * po )
298
298
{
299
+ PyTypeObject * tp = Py_TYPE (po );
299
300
PyObject_GC_UnTrack (po );
300
301
Py_XDECREF (po -> it );
301
302
Py_XDECREF (po -> old );
302
- Py_TYPE (po )-> tp_free (po );
303
+ tp -> tp_free (po );
304
+ Py_DECREF (tp );
303
305
}
304
306
305
307
static int
306
308
pairwise_traverse (pairwiseobject * po , visitproc visit , void * arg )
307
309
{
310
+ Py_VISIT (Py_TYPE (po ));
308
311
Py_VISIT (po -> it );
309
312
Py_VISIT (po -> old );
310
313
return 0 ;
@@ -339,48 +342,25 @@ pairwise_next(pairwiseobject *po)
339
342
return result ;
340
343
}
341
344
342
- static PyTypeObject pairwise_type = {
343
- PyVarObject_HEAD_INIT (& PyType_Type , 0 )
344
- "itertools.pairwise" , /* tp_name */
345
- sizeof (pairwiseobject ), /* tp_basicsize */
346
- 0 , /* tp_itemsize */
347
- /* methods */
348
- (destructor )pairwise_dealloc , /* tp_dealloc */
349
- 0 , /* tp_vectorcall_offset */
350
- 0 , /* tp_getattr */
351
- 0 , /* tp_setattr */
352
- 0 , /* tp_as_async */
353
- 0 , /* tp_repr */
354
- 0 , /* tp_as_number */
355
- 0 , /* tp_as_sequence */
356
- 0 , /* tp_as_mapping */
357
- 0 , /* tp_hash */
358
- 0 , /* tp_call */
359
- 0 , /* tp_str */
360
- PyObject_GenericGetAttr , /* tp_getattro */
361
- 0 , /* tp_setattro */
362
- 0 , /* tp_as_buffer */
363
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
364
- Py_TPFLAGS_BASETYPE , /* tp_flags */
365
- pairwise_new__doc__ , /* tp_doc */
366
- (traverseproc )pairwise_traverse , /* tp_traverse */
367
- 0 , /* tp_clear */
368
- 0 , /* tp_richcompare */
369
- 0 , /* tp_weaklistoffset */
370
- PyObject_SelfIter , /* tp_iter */
371
- (iternextfunc )pairwise_next , /* tp_iternext */
372
- 0 , /* tp_methods */
373
- 0 , /* tp_members */
374
- 0 , /* tp_getset */
375
- 0 , /* tp_base */
376
- 0 , /* tp_dict */
377
- 0 , /* tp_descr_get */
378
- 0 , /* tp_descr_set */
379
- 0 , /* tp_dictoffset */
380
- 0 , /* tp_init */
381
- PyType_GenericAlloc , /* tp_alloc */
382
- pairwise_new , /* tp_new */
383
- PyObject_GC_Del , /* tp_free */
345
+ static PyType_Slot pairwise_slots [] = {
346
+ {Py_tp_dealloc , pairwise_dealloc },
347
+ {Py_tp_getattro , PyObject_GenericGetAttr },
348
+ {Py_tp_doc , (void * )pairwise_new__doc__ },
349
+ {Py_tp_traverse , pairwise_traverse },
350
+ {Py_tp_iter , PyObject_SelfIter },
351
+ {Py_tp_iternext , pairwise_next },
352
+ {Py_tp_alloc , PyType_GenericAlloc },
353
+ {Py_tp_new , pairwise_new },
354
+ {Py_tp_free , PyObject_GC_Del },
355
+ {0 , NULL },
356
+ };
357
+
358
+ static PyType_Spec pairwise_spec = {
359
+ .name = "itertools.pairwise" ,
360
+ .basicsize = sizeof (pairwiseobject ),
361
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
362
+ Py_TPFLAGS_IMMUTABLETYPE ),
363
+ .slots = pairwise_slots ,
384
364
};
385
365
386
366
@@ -4753,6 +4733,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4753
4733
Py_VISIT (state -> filterfalse_type );
4754
4734
Py_VISIT (state -> groupby_type );
4755
4735
Py_VISIT (state -> _grouper_type );
4736
+ Py_VISIT (state -> pairwise_type );
4756
4737
Py_VISIT (state -> permutations_type );
4757
4738
Py_VISIT (state -> starmap_type );
4758
4739
Py_VISIT (state -> takewhile_type );
@@ -4773,6 +4754,7 @@ itertoolsmodule_clear(PyObject *mod)
4773
4754
Py_CLEAR (state -> filterfalse_type );
4774
4755
Py_CLEAR (state -> groupby_type );
4775
4756
Py_CLEAR (state -> _grouper_type );
4757
+ Py_CLEAR (state -> pairwise_type );
4776
4758
Py_CLEAR (state -> permutations_type );
4777
4759
Py_CLEAR (state -> starmap_type );
4778
4760
Py_CLEAR (state -> takewhile_type );
@@ -4810,6 +4792,7 @@ itertoolsmodule_exec(PyObject *mod)
4810
4792
ADD_TYPE (mod , state -> filterfalse_type , & filterfalse_spec );
4811
4793
ADD_TYPE (mod , state -> groupby_type , & groupby_spec );
4812
4794
ADD_TYPE (mod , state -> _grouper_type , & _grouper_spec );
4795
+ ADD_TYPE (mod , state -> pairwise_type , & pairwise_spec );
4813
4796
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4814
4797
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4815
4798
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
@@ -4819,7 +4802,6 @@ itertoolsmodule_exec(PyObject *mod)
4819
4802
& islice_type ,
4820
4803
& chain_type ,
4821
4804
& ziplongest_type ,
4822
- & pairwise_type ,
4823
4805
& product_type ,
4824
4806
& repeat_type ,
4825
4807
& tee_type ,
0 commit comments