@@ -721,25 +721,34 @@ static struct PyMethodDef multibytecodec_methods[] = {
721721 {NULL , NULL },
722722};
723723
724+ static int
725+ multibytecodec_traverse (PyObject * self , visitproc visit , void * arg )
726+ {
727+ Py_VISIT (Py_TYPE (self ));
728+ return 0 ;
729+ }
730+
724731static void
725732multibytecodec_dealloc (MultibyteCodecObject * self )
726733{
734+ PyObject_GC_UnTrack (self );
727735 PyTypeObject * tp = Py_TYPE (self );
728- PyObject_Free (self );
736+ tp -> tp_free (self );
729737 Py_DECREF (tp );
730738}
731739
732740static PyType_Slot multibytecodec_slots [] = {
733741 {Py_tp_dealloc , multibytecodec_dealloc },
734742 {Py_tp_getattro , PyObject_GenericGetAttr },
735743 {Py_tp_methods , multibytecodec_methods },
744+ {Py_tp_traverse , multibytecodec_traverse },
736745 {0 , NULL },
737746};
738747
739748static PyType_Spec multibytecodec_spec = {
740749 .name = MODULE_NAME ".MultibyteCodec" ,
741750 .basicsize = sizeof (MultibyteCodecObject ),
742- .flags = Py_TPFLAGS_DEFAULT ,
751+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
743752 .slots = multibytecodec_slots ,
744753};
745754
@@ -1944,11 +1953,12 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
19441953 return NULL ;
19451954
19461955 _multibytecodec_state * state = _multibytecodec_get_state (module );
1947- self = PyObject_New (MultibyteCodecObject , state -> multibytecodec_type );
1956+ self = PyObject_GC_New (MultibyteCodecObject , state -> multibytecodec_type );
19481957 if (self == NULL )
19491958 return NULL ;
19501959 self -> codec = codec ;
19511960
1961+ PyObject_GC_Track (self );
19521962 return (PyObject * )self ;
19531963}
19541964
0 commit comments