@@ -564,7 +564,8 @@ static PyTypeObject LogAdapterType = {
564
564
.tp_dealloc = (destructor )LogAdapter_dealloc ,
565
565
.tp_flags = Py_TPFLAGS_DEFAULT ,
566
566
.tp_methods = LogAdapter_methods ,
567
- .tp_init = (initproc )LogAdapter_init
567
+ .tp_init = (initproc )LogAdapter_init ,
568
+ .tp_new = PyType_GenericNew ,
568
569
};
569
570
570
571
@@ -718,10 +719,24 @@ static int IoAdapter_init(IoAdapter *self, PyObject *args, PyObject *kwds)
718
719
return 0 ;
719
720
}
720
721
722
+ // visit all members which may conceivably participate in reference cycles
723
+ static int IoAdapter_traverse (IoAdapter * self , visitproc visit , void * arg )
724
+ {
725
+ Py_VISIT (self -> handler );
726
+ return 0 ;
727
+ }
728
+
729
+ static int IoAdapter_clear (IoAdapter * self )
730
+ {
731
+ Py_CLEAR (self -> handler );
732
+ return 0 ;
733
+ }
734
+
721
735
static void IoAdapter_dealloc (IoAdapter * self )
722
736
{
723
737
qdr_core_unsubscribe (self -> sub );
724
- Py_DECREF (self -> handler );
738
+ PyObject_GC_UnTrack (self );
739
+ IoAdapter_clear (self );
725
740
Py_TYPE (self )-> tp_free ((PyObject * )self );
726
741
}
727
742
@@ -814,10 +829,13 @@ static PyTypeObject IoAdapterType = {
814
829
.tp_name = DISPATCH_MODULE ".IoAdapter" ,
815
830
.tp_doc = "Dispatch IO Adapter" ,
816
831
.tp_basicsize = sizeof (IoAdapter ),
832
+ .tp_traverse = (traverseproc )IoAdapter_traverse ,
833
+ .tp_clear = (inquiry )IoAdapter_clear ,
817
834
.tp_dealloc = (destructor )IoAdapter_dealloc ,
818
- .tp_flags = Py_TPFLAGS_DEFAULT ,
835
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
819
836
.tp_methods = IoAdapter_methods ,
820
837
.tp_init = (initproc )IoAdapter_init ,
838
+ .tp_new = PyType_GenericNew ,
821
839
};
822
840
823
841
@@ -833,8 +851,6 @@ static void qd_register_constant(PyObject *module, const char *name, uint32_t va
833
851
834
852
static void qd_python_setup (void )
835
853
{
836
- LogAdapterType .tp_new = PyType_GenericNew ;
837
- IoAdapterType .tp_new = PyType_GenericNew ;
838
854
if ((PyType_Ready (& LogAdapterType ) < 0 ) || (PyType_Ready (& IoAdapterType ) < 0 )) {
839
855
qd_error_py ();
840
856
qd_log (log_source , QD_LOG_CRITICAL , "Unable to initialize Adapters" );
0 commit comments