@@ -26,6 +26,7 @@ typedef struct {
26
26
PyTypeObject * permutations_type ;
27
27
PyTypeObject * starmap_type ;
28
28
PyTypeObject * takewhile_type ;
29
+ PyTypeObject * ziplongest_type ;
29
30
} itertools_state ;
30
31
31
32
static inline itertools_state *
@@ -4437,8 +4438,6 @@ typedef struct {
4437
4438
PyObject * fillvalue ;
4438
4439
} ziplongestobject ;
4439
4440
4440
- static PyTypeObject ziplongest_type ;
4441
-
4442
4441
static PyObject *
4443
4442
zip_longest_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
4444
4443
{
@@ -4510,16 +4509,19 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4510
4509
static void
4511
4510
zip_longest_dealloc (ziplongestobject * lz )
4512
4511
{
4512
+ PyTypeObject * tp = Py_TYPE (lz );
4513
4513
PyObject_GC_UnTrack (lz );
4514
4514
Py_XDECREF (lz -> ittuple );
4515
4515
Py_XDECREF (lz -> result );
4516
4516
Py_XDECREF (lz -> fillvalue );
4517
- Py_TYPE (lz )-> tp_free (lz );
4517
+ tp -> tp_free (lz );
4518
+ Py_DECREF (tp );
4518
4519
}
4519
4520
4520
4521
static int
4521
4522
zip_longest_traverse (ziplongestobject * lz , visitproc visit , void * arg )
4522
4523
{
4524
+ Py_VISIT (Py_TYPE (lz ));
4523
4525
Py_VISIT (lz -> ittuple );
4524
4526
Py_VISIT (lz -> result );
4525
4527
Py_VISIT (lz -> fillvalue );
@@ -4653,48 +4655,25 @@ are exhausted, the fillvalue is substituted in their place. The fillvalue\n\
4653
4655
defaults to None or can be specified by a keyword argument.\n\
4654
4656
" );
4655
4657
4656
- static PyTypeObject ziplongest_type = {
4657
- PyVarObject_HEAD_INIT (NULL , 0 )
4658
- "itertools.zip_longest" , /* tp_name */
4659
- sizeof (ziplongestobject ), /* tp_basicsize */
4660
- 0 , /* tp_itemsize */
4661
- /* methods */
4662
- (destructor )zip_longest_dealloc , /* tp_dealloc */
4663
- 0 , /* tp_vectorcall_offset */
4664
- 0 , /* tp_getattr */
4665
- 0 , /* tp_setattr */
4666
- 0 , /* tp_as_async */
4667
- 0 , /* tp_repr */
4668
- 0 , /* tp_as_number */
4669
- 0 , /* tp_as_sequence */
4670
- 0 , /* tp_as_mapping */
4671
- 0 , /* tp_hash */
4672
- 0 , /* tp_call */
4673
- 0 , /* tp_str */
4674
- PyObject_GenericGetAttr , /* tp_getattro */
4675
- 0 , /* tp_setattro */
4676
- 0 , /* tp_as_buffer */
4677
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
4678
- Py_TPFLAGS_BASETYPE , /* tp_flags */
4679
- zip_longest_doc , /* tp_doc */
4680
- (traverseproc )zip_longest_traverse , /* tp_traverse */
4681
- 0 , /* tp_clear */
4682
- 0 , /* tp_richcompare */
4683
- 0 , /* tp_weaklistoffset */
4684
- PyObject_SelfIter , /* tp_iter */
4685
- (iternextfunc )zip_longest_next , /* tp_iternext */
4686
- zip_longest_methods , /* tp_methods */
4687
- 0 , /* tp_members */
4688
- 0 , /* tp_getset */
4689
- 0 , /* tp_base */
4690
- 0 , /* tp_dict */
4691
- 0 , /* tp_descr_get */
4692
- 0 , /* tp_descr_set */
4693
- 0 , /* tp_dictoffset */
4694
- 0 , /* tp_init */
4695
- 0 , /* tp_alloc */
4696
- zip_longest_new , /* tp_new */
4697
- PyObject_GC_Del , /* tp_free */
4658
+ static PyType_Slot ziplongest_slots [] = {
4659
+ {Py_tp_dealloc , zip_longest_dealloc },
4660
+ {Py_tp_getattro , PyObject_GenericGetAttr },
4661
+ {Py_tp_doc , (void * )zip_longest_doc },
4662
+ {Py_tp_traverse , zip_longest_traverse },
4663
+ {Py_tp_iter , PyObject_SelfIter },
4664
+ {Py_tp_iternext , zip_longest_next },
4665
+ {Py_tp_methods , zip_longest_methods },
4666
+ {Py_tp_new , zip_longest_new },
4667
+ {Py_tp_free , PyObject_GC_Del },
4668
+ {0 , NULL },
4669
+ };
4670
+
4671
+ static PyType_Spec ziplongest_spec = {
4672
+ .name = "itertools.zip_longest" ,
4673
+ .basicsize = sizeof (ziplongestobject ),
4674
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
4675
+ Py_TPFLAGS_IMMUTABLETYPE ),
4676
+ .slots = ziplongest_slots ,
4698
4677
};
4699
4678
4700
4679
@@ -4750,6 +4729,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4750
4729
Py_VISIT (state -> permutations_type );
4751
4730
Py_VISIT (state -> starmap_type );
4752
4731
Py_VISIT (state -> takewhile_type );
4732
+ Py_VISIT (state -> ziplongest_type );
4753
4733
return 0 ;
4754
4734
}
4755
4735
@@ -4771,6 +4751,7 @@ itertoolsmodule_clear(PyObject *mod)
4771
4751
Py_CLEAR (state -> permutations_type );
4772
4752
Py_CLEAR (state -> starmap_type );
4773
4753
Py_CLEAR (state -> takewhile_type );
4754
+ Py_CLEAR (state -> ziplongest_type );
4774
4755
return 0 ;
4775
4756
}
4776
4757
@@ -4809,12 +4790,12 @@ itertoolsmodule_exec(PyObject *mod)
4809
4790
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4810
4791
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4811
4792
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4793
+ ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
4812
4794
4813
4795
PyTypeObject * typelist [] = {
4814
4796
& batched_type ,
4815
4797
& islice_type ,
4816
4798
& chain_type ,
4817
- & ziplongest_type ,
4818
4799
& product_type ,
4819
4800
& repeat_type ,
4820
4801
& tee_type ,
0 commit comments