From 1ab24ec46bdc6447719c997fcd98b072588e57cd Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 10 Dec 2024 21:23:17 +0000 Subject: [PATCH] Experiment: reftracer --- Objects/object.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Objects/object.c b/Objects/object.c index 74f47fa4239032..11b8d31f35c19b 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2953,6 +2953,14 @@ _PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg, Py_FatalError("_PyObject_AssertFailed"); } +Py_NO_INLINE +static void +reftracer_destroy(PyObject *op) +{ + _PyReftracerTrack(op, PyRefTracer_DESTROY); + Py_DECREF(op); +} + void _Py_Dealloc(PyObject *op) @@ -2972,8 +2980,12 @@ _Py_Dealloc(PyObject *op) #ifdef Py_TRACE_REFS _Py_ForgetReference(op); #endif - _PyReftracerTrack(op, PyRefTracer_DESTROY); - (*dealloc)(op); + if (_PyRuntime.ref_tracer.tracer_func) { + reftracer_destroy(op); + } + else { + (*dealloc)(op); + } #ifdef Py_DEBUG // gh-89373: The tp_dealloc function must leave the current exception