@@ -25,6 +25,7 @@ typedef struct {
25
25
PyTypeObject * permutations_type ;
26
26
PyTypeObject * starmap_type ;
27
27
PyTypeObject * takewhile_type ;
28
+ PyTypeObject * ziplongest_type ;
28
29
} itertools_state ;
29
30
30
31
static inline itertools_state *
@@ -4423,8 +4424,6 @@ typedef struct {
4423
4424
PyObject * fillvalue ;
4424
4425
} ziplongestobject ;
4425
4426
4426
- static PyTypeObject ziplongest_type ;
4427
-
4428
4427
static PyObject *
4429
4428
zip_longest_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
4430
4429
{
@@ -4496,16 +4495,19 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4496
4495
static void
4497
4496
zip_longest_dealloc (ziplongestobject * lz )
4498
4497
{
4498
+ PyTypeObject * tp = Py_TYPE (lz );
4499
4499
PyObject_GC_UnTrack (lz );
4500
4500
Py_XDECREF (lz -> ittuple );
4501
4501
Py_XDECREF (lz -> result );
4502
4502
Py_XDECREF (lz -> fillvalue );
4503
- Py_TYPE (lz )-> tp_free (lz );
4503
+ tp -> tp_free (lz );
4504
+ Py_DECREF (tp );
4504
4505
}
4505
4506
4506
4507
static int
4507
4508
zip_longest_traverse (ziplongestobject * lz , visitproc visit , void * arg )
4508
4509
{
4510
+ Py_VISIT (Py_TYPE (lz ));
4509
4511
Py_VISIT (lz -> ittuple );
4510
4512
Py_VISIT (lz -> result );
4511
4513
Py_VISIT (lz -> fillvalue );
@@ -4639,48 +4641,25 @@ are exhausted, the fillvalue is substituted in their place. The fillvalue\n\
4639
4641
defaults to None or can be specified by a keyword argument.\n\
4640
4642
" );
4641
4643
4642
- static PyTypeObject ziplongest_type = {
4643
- PyVarObject_HEAD_INIT (NULL , 0 )
4644
- "itertools.zip_longest" , /* tp_name */
4645
- sizeof (ziplongestobject ), /* tp_basicsize */
4646
- 0 , /* tp_itemsize */
4647
- /* methods */
4648
- (destructor )zip_longest_dealloc , /* tp_dealloc */
4649
- 0 , /* tp_vectorcall_offset */
4650
- 0 , /* tp_getattr */
4651
- 0 , /* tp_setattr */
4652
- 0 , /* tp_as_async */
4653
- 0 , /* tp_repr */
4654
- 0 , /* tp_as_number */
4655
- 0 , /* tp_as_sequence */
4656
- 0 , /* tp_as_mapping */
4657
- 0 , /* tp_hash */
4658
- 0 , /* tp_call */
4659
- 0 , /* tp_str */
4660
- PyObject_GenericGetAttr , /* tp_getattro */
4661
- 0 , /* tp_setattro */
4662
- 0 , /* tp_as_buffer */
4663
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
4664
- Py_TPFLAGS_BASETYPE , /* tp_flags */
4665
- zip_longest_doc , /* tp_doc */
4666
- (traverseproc )zip_longest_traverse , /* tp_traverse */
4667
- 0 , /* tp_clear */
4668
- 0 , /* tp_richcompare */
4669
- 0 , /* tp_weaklistoffset */
4670
- PyObject_SelfIter , /* tp_iter */
4671
- (iternextfunc )zip_longest_next , /* tp_iternext */
4672
- zip_longest_methods , /* tp_methods */
4673
- 0 , /* tp_members */
4674
- 0 , /* tp_getset */
4675
- 0 , /* tp_base */
4676
- 0 , /* tp_dict */
4677
- 0 , /* tp_descr_get */
4678
- 0 , /* tp_descr_set */
4679
- 0 , /* tp_dictoffset */
4680
- 0 , /* tp_init */
4681
- 0 , /* tp_alloc */
4682
- zip_longest_new , /* tp_new */
4683
- PyObject_GC_Del , /* tp_free */
4644
+ static PyType_Slot ziplongest_slots [] = {
4645
+ {Py_tp_dealloc , zip_longest_dealloc },
4646
+ {Py_tp_getattro , PyObject_GenericGetAttr },
4647
+ {Py_tp_doc , (void * )zip_longest_doc },
4648
+ {Py_tp_traverse , zip_longest_traverse },
4649
+ {Py_tp_iter , PyObject_SelfIter },
4650
+ {Py_tp_iternext , zip_longest_next },
4651
+ {Py_tp_methods , zip_longest_methods },
4652
+ {Py_tp_new , zip_longest_new },
4653
+ {Py_tp_free , PyObject_GC_Del },
4654
+ {0 , NULL },
4655
+ };
4656
+
4657
+ static PyType_Spec ziplongest_spec = {
4658
+ .name = "itertools.zip_longest" ,
4659
+ .basicsize = sizeof (ziplongestobject ),
4660
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
4661
+ Py_TPFLAGS_IMMUTABLETYPE ),
4662
+ .slots = ziplongest_slots ,
4684
4663
};
4685
4664
4686
4665
@@ -4735,6 +4714,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4735
4714
Py_VISIT (state -> permutations_type );
4736
4715
Py_VISIT (state -> starmap_type );
4737
4716
Py_VISIT (state -> takewhile_type );
4717
+ Py_VISIT (state -> ziplongest_type );
4738
4718
return 0 ;
4739
4719
}
4740
4720
@@ -4755,6 +4735,7 @@ itertoolsmodule_clear(PyObject *mod)
4755
4735
Py_CLEAR (state -> permutations_type );
4756
4736
Py_CLEAR (state -> starmap_type );
4757
4737
Py_CLEAR (state -> takewhile_type );
4738
+ Py_CLEAR (state -> ziplongest_type );
4758
4739
return 0 ;
4759
4740
}
4760
4741
@@ -4793,12 +4774,12 @@ itertoolsmodule_exec(PyObject *mod)
4793
4774
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4794
4775
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4795
4776
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4777
+ ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
4796
4778
4797
4779
PyTypeObject * typelist [] = {
4798
4780
& batched_type ,
4799
4781
& islice_type ,
4800
4782
& chain_type ,
4801
- & ziplongest_type ,
4802
4783
& product_type ,
4803
4784
& repeat_type ,
4804
4785
& tee_type ,
0 commit comments