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