@@ -721,25 +721,34 @@ static struct PyMethodDef multibytecodec_methods[] = {
721
721
{NULL , NULL },
722
722
};
723
723
724
+ static int
725
+ multibytecodec_traverse (PyObject * self , visitproc visit , void * arg )
726
+ {
727
+ Py_VISIT (Py_TYPE (self ));
728
+ return 0 ;
729
+ }
730
+
724
731
static void
725
732
multibytecodec_dealloc (MultibyteCodecObject * self )
726
733
{
734
+ PyObject_GC_UnTrack (self );
727
735
PyTypeObject * tp = Py_TYPE (self );
728
- PyObject_Free (self );
736
+ tp -> tp_free (self );
729
737
Py_DECREF (tp );
730
738
}
731
739
732
740
static PyType_Slot multibytecodec_slots [] = {
733
741
{Py_tp_dealloc , multibytecodec_dealloc },
734
742
{Py_tp_getattro , PyObject_GenericGetAttr },
735
743
{Py_tp_methods , multibytecodec_methods },
744
+ {Py_tp_traverse , multibytecodec_traverse },
736
745
{0 , NULL },
737
746
};
738
747
739
748
static PyType_Spec multibytecodec_spec = {
740
749
.name = MODULE_NAME ".MultibyteCodec" ,
741
750
.basicsize = sizeof (MultibyteCodecObject ),
742
- .flags = Py_TPFLAGS_DEFAULT ,
751
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
743
752
.slots = multibytecodec_slots ,
744
753
};
745
754
@@ -1944,11 +1953,12 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
1944
1953
return NULL ;
1945
1954
1946
1955
_multibytecodec_state * state = _multibytecodec_get_state (module );
1947
- self = PyObject_New (MultibyteCodecObject , state -> multibytecodec_type );
1956
+ self = PyObject_GC_New (MultibyteCodecObject , state -> multibytecodec_type );
1948
1957
if (self == NULL )
1949
1958
return NULL ;
1950
1959
self -> codec = codec ;
1951
1960
1961
+ PyObject_GC_Track (self );
1952
1962
return (PyObject * )self ;
1953
1963
}
1954
1964
0 commit comments