@@ -26,6 +26,7 @@ typedef struct {
2626 PyTypeObject * permutations_type ;
2727 PyTypeObject * starmap_type ;
2828 PyTypeObject * takewhile_type ;
29+ PyTypeObject * ziplongest_type ;
2930} itertools_state ;
3031
3132static inline itertools_state *
@@ -4437,8 +4438,6 @@ typedef struct {
44374438 PyObject * fillvalue ;
44384439} ziplongestobject ;
44394440
4440- static PyTypeObject ziplongest_type ;
4441-
44424441static PyObject *
44434442zip_longest_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
44444443{
@@ -4510,16 +4509,19 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
45104509static void
45114510zip_longest_dealloc (ziplongestobject * lz )
45124511{
4512+ PyTypeObject * tp = Py_TYPE (lz );
45134513 PyObject_GC_UnTrack (lz );
45144514 Py_XDECREF (lz -> ittuple );
45154515 Py_XDECREF (lz -> result );
45164516 Py_XDECREF (lz -> fillvalue );
4517- Py_TYPE (lz )-> tp_free (lz );
4517+ tp -> tp_free (lz );
4518+ Py_DECREF (tp );
45184519}
45194520
45204521static int
45214522zip_longest_traverse (ziplongestobject * lz , visitproc visit , void * arg )
45224523{
4524+ Py_VISIT (Py_TYPE (lz ));
45234525 Py_VISIT (lz -> ittuple );
45244526 Py_VISIT (lz -> result );
45254527 Py_VISIT (lz -> fillvalue );
@@ -4653,48 +4655,25 @@ are exhausted, the fillvalue is substituted in their place. The fillvalue\n\
46534655defaults to None or can be specified by a keyword argument.\n\
46544656" );
46554657
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 ,
46984677};
46994678
47004679
@@ -4750,6 +4729,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
47504729 Py_VISIT (state -> permutations_type );
47514730 Py_VISIT (state -> starmap_type );
47524731 Py_VISIT (state -> takewhile_type );
4732+ Py_VISIT (state -> ziplongest_type );
47534733 return 0 ;
47544734}
47554735
@@ -4771,6 +4751,7 @@ itertoolsmodule_clear(PyObject *mod)
47714751 Py_CLEAR (state -> permutations_type );
47724752 Py_CLEAR (state -> starmap_type );
47734753 Py_CLEAR (state -> takewhile_type );
4754+ Py_CLEAR (state -> ziplongest_type );
47744755 return 0 ;
47754756}
47764757
@@ -4809,12 +4790,12 @@ itertoolsmodule_exec(PyObject *mod)
48094790 ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
48104791 ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
48114792 ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4793+ ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
48124794
48134795 PyTypeObject * typelist [] = {
48144796 & batched_type ,
48154797 & islice_type ,
48164798 & chain_type ,
4817- & ziplongest_type ,
48184799 & product_type ,
48194800 & repeat_type ,
48204801 & tee_type ,
0 commit comments