@@ -22,6 +22,7 @@ typedef struct {
22
22
PyTypeObject * filterfalse_type ;
23
23
PyTypeObject * groupby_type ;
24
24
PyTypeObject * _grouper_type ;
25
+ PyTypeObject * pairwise_type ;
25
26
PyTypeObject * permutations_type ;
26
27
PyTypeObject * starmap_type ;
27
28
PyTypeObject * takewhile_type ;
@@ -73,14 +74,13 @@ class itertools.accumulate "accumulateobject *" "clinic_state()->accumulate_type
73
74
class itertools.compress "compressobject *" "clinic_state()->compress_type"
74
75
class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_type"
75
76
class itertools.count "countobject *" "clinic_state()->count_type"
76
- class itertools.pairwise "pairwiseobject *" "& pairwise_type"
77
+ class itertools.pairwise "pairwiseobject *" "clinic_state()-> pairwise_type"
77
78
[clinic start generated code]*/
78
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=338b4d26465f3eb1 ]*/
79
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7 ]*/
79
80
80
81
static PyTypeObject teedataobject_type ;
81
82
static PyTypeObject tee_type ;
82
83
static PyTypeObject batched_type ;
83
- static PyTypeObject pairwise_type ;
84
84
85
85
#define clinic_state_by_cls () (get_module_state_by_cls(base_tp))
86
86
#include "clinic/itertoolsmodule.c.h"
@@ -308,15 +308,18 @@ pairwise_new_impl(PyTypeObject *type, PyObject *iterable)
308
308
static void
309
309
pairwise_dealloc (pairwiseobject * po )
310
310
{
311
+ PyTypeObject * tp = Py_TYPE (po );
311
312
PyObject_GC_UnTrack (po );
312
313
Py_XDECREF (po -> it );
313
314
Py_XDECREF (po -> old );
314
- Py_TYPE (po )-> tp_free (po );
315
+ tp -> tp_free (po );
316
+ Py_DECREF (tp );
315
317
}
316
318
317
319
static int
318
320
pairwise_traverse (pairwiseobject * po , visitproc visit , void * arg )
319
321
{
322
+ Py_VISIT (Py_TYPE (po ));
320
323
Py_VISIT (po -> it );
321
324
Py_VISIT (po -> old );
322
325
return 0 ;
@@ -351,48 +354,25 @@ pairwise_next(pairwiseobject *po)
351
354
return result ;
352
355
}
353
356
354
- static PyTypeObject pairwise_type = {
355
- PyVarObject_HEAD_INIT (& PyType_Type , 0 )
356
- "itertools.pairwise" , /* tp_name */
357
- sizeof (pairwiseobject ), /* tp_basicsize */
358
- 0 , /* tp_itemsize */
359
- /* methods */
360
- (destructor )pairwise_dealloc , /* tp_dealloc */
361
- 0 , /* tp_vectorcall_offset */
362
- 0 , /* tp_getattr */
363
- 0 , /* tp_setattr */
364
- 0 , /* tp_as_async */
365
- 0 , /* tp_repr */
366
- 0 , /* tp_as_number */
367
- 0 , /* tp_as_sequence */
368
- 0 , /* tp_as_mapping */
369
- 0 , /* tp_hash */
370
- 0 , /* tp_call */
371
- 0 , /* tp_str */
372
- PyObject_GenericGetAttr , /* tp_getattro */
373
- 0 , /* tp_setattro */
374
- 0 , /* tp_as_buffer */
375
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
376
- Py_TPFLAGS_BASETYPE , /* tp_flags */
377
- pairwise_new__doc__ , /* tp_doc */
378
- (traverseproc )pairwise_traverse , /* tp_traverse */
379
- 0 , /* tp_clear */
380
- 0 , /* tp_richcompare */
381
- 0 , /* tp_weaklistoffset */
382
- PyObject_SelfIter , /* tp_iter */
383
- (iternextfunc )pairwise_next , /* tp_iternext */
384
- 0 , /* tp_methods */
385
- 0 , /* tp_members */
386
- 0 , /* tp_getset */
387
- 0 , /* tp_base */
388
- 0 , /* tp_dict */
389
- 0 , /* tp_descr_get */
390
- 0 , /* tp_descr_set */
391
- 0 , /* tp_dictoffset */
392
- 0 , /* tp_init */
393
- PyType_GenericAlloc , /* tp_alloc */
394
- pairwise_new , /* tp_new */
395
- PyObject_GC_Del , /* tp_free */
357
+ static PyType_Slot pairwise_slots [] = {
358
+ {Py_tp_dealloc , pairwise_dealloc },
359
+ {Py_tp_getattro , PyObject_GenericGetAttr },
360
+ {Py_tp_doc , (void * )pairwise_new__doc__ },
361
+ {Py_tp_traverse , pairwise_traverse },
362
+ {Py_tp_iter , PyObject_SelfIter },
<
6D40
tr class="diff-line-row">
363
+ {Py_tp_iternext , pairwise_next },
364
+ {Py_tp_alloc , PyType_GenericAlloc },
365
+ {Py_tp_new , pairwise_new },
366
+ {Py_tp_free , PyObject_GC_Del },
367
+ {0 , NULL },
368
+ };
369
+
370
+ static PyType_Spec pairwise_spec = {
371
+ .name = "itertools.pairwise" ,
372
+ .basicsize = sizeof (pairwiseobject ),
373
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
374
+ Py_TPFLAGS_IMMUTABLETYPE ),
375
+ .slots = pairwise_slots ,
396
376
};
397
377
398
378
@@ -4766,6 +4746,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4766
4746
Py_VISIT (state -> filterfalse_type );
4767
4747
Py_VISIT (state -> groupby_type );
4768
4748
Py_VISIT (state -> _grouper_type );
4749
+ Py_VISIT (state -> pairwise_type );
4769
4750
Py_VISIT (state -> permutations_type );
4770
4751
Py_VISIT (state -> starmap_type );
4771
4752
Py_VISIT (state -> takewhile_type );
@@ -4786,6 +4767,7 @@ itertoolsmodule_clear(PyObject *mod)
4786
4767
Py_CLEAR (state -> filterfalse_type );
4787
4768
Py_CLEAR (state -> groupby_type );
4788
4769
Py_CLEAR (state -> _grouper_type );
4770
+ Py_CLEAR (state -> pairwise_type );
4789
4771
Py_CLEAR (state -> permutations_type );
4790
4772
Py_CLEAR (state -> starmap_type );
4791
4773
Py_CLEAR (state -> takewhile_type );
@@ -4823,6 +4805,7 @@ itertoolsmodule_exec(PyObject *mod)
4823
4805
ADD_TYPE (mod , state -> filterfalse_type , & filterfalse_spec );
4824
4806
ADD_TYPE (mod , state -> groupby_type , & groupby_spec );
4825
4807
ADD_TYPE (mod , state -> _grouper_type , & _grouper_spec );
4808
+ ADD_TYPE (mod , state -> pairwise_type , & pairwise_spec );
4826
4809
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4827
4810
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4828
4811
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
@@ -4832,7 +4815,6 @@ itertoolsmodule_exec(PyObject *mod)
4832
4815
& islice_type ,
4833
4816
& chain_type ,
4834
4817
& ziplongest_type ,
4835
- & pairwise_type ,
4836
4818
& product_type ,
4837
4819
& repeat_type ,
4838
4820
& tee_type ,
0 commit comments