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