@@ -25,6 +25,7 @@ typedef struct {
2525 PyTypeObject * permutations_type ;
2626 PyTypeObject * starmap_type ;
2727 PyTypeObject * takewhile_type ;
28+ PyTypeObject * ziplongest_type ;
2829} itertools_state ;
2930
3031static inline itertools_state *
@@ -4424,8 +4425,6 @@ typedef struct {
44244425 PyObject * fillvalue ;
44254426} ziplongestobject ;
44264427
4427- static PyTypeObject ziplongest_type ;
4428-
44294428static PyObject *
44304429zip_longest_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
44314430{
@@ -4497,16 +4496,19 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
44974496static void
44984497zip_longest_dealloc (ziplongestobject * lz )
44994498{
4499+ PyTypeObject * tp = Py_TYPE (lz );
45004500 PyObject_GC_UnTrack (lz );
45014501 Py_XDECREF (lz -> ittuple );
45024502 Py_XDECREF (lz -> result );
45034503 Py_XDECREF (lz -> fillvalue );
4504- Py_TYPE (lz )-> tp_free (lz );
4504+ tp -> tp_free (lz );
4505+ Py_DECREF (tp );
45054506}
45064507
45074508static int
45084509zip_longest_traverse (ziplongestobject * lz , visitproc visit , void * arg )
45094510{
4511+ Py_VISIT (Py_TYPE (lz ));
45104512 Py_VISIT (lz -> ittuple );
45114513 Py_VISIT (lz -> result );
45124514 Py_VISIT (lz -> fillvalue );
@@ -4640,48 +4642,25 @@ are exhausted, the fillvalue is substituted in their place. The fillvalue\n\
46404642defaults to None or can be specified by a keyword argument.\n\
46414643" );
46424644
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 ,
46854664};
46864665
46874666
@@ -4737,6 +4716,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
47374716 Py_VISIT (state -> permutations_type );
47384717 Py_VISIT (state -> starmap_type );
47394718 Py_VISIT (state -> takewhile_type );
4719+ Py_VISIT (state -> ziplongest_type );
47404720 return 0 ;
47414721}
47424722
@@ -4758,6 +4738,7 @@ itertoolsmodule_clear(PyObject *mod)
47584738 Py_CLEAR (state -> permutations_type );
47594739 Py_CLEAR (state -> starmap_type );
47604740 Py_CLEAR (state -> takewhile_type );
4741+ Py_CLEAR (state -> ziplongest_type );
47614742 return 0 ;
47624743}
47634744
@@ -4796,12 +4777,12 @@ itertoolsmodule_exec(PyObject *mod)
47964777 ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
47974778 ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
47984779 ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4780+ ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
47994781
48004782 PyTypeObject * typelist [] = {
48014783 & batched_type ,
48024784 & islice_type ,
48034785 & chain_type ,
4804- & ziplongest_type ,
48054786 & product_type ,
48064787 & repeat_type ,
48074788 & tee_type ,
0 commit comments