From 6d1ec2f7ff8332fcc2fb89cbd095a0b0b02178a1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 29 Oct 2018 19:45:41 +0100 Subject: [PATCH 1/2] bpo-35059: Convert _Py_Dealloc() to static inline function Convert _Py_Dealloc() macro into a static inline function. Moreover, it is now also defined as a static inline function if Py_TRACE_REFS is defined. --- Include/object.h | 21 +++++++++++++++------ Objects/object.c | 24 +++++++++--------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Include/object.h b/Include/object.h index f9c07f7d1398f9..e827b49562a58b 100644 --- a/Include/object.h +++ b/Include/object.h @@ -768,7 +768,6 @@ PyAPI_FUNC(int) _PyTraceMalloc_NewReference(PyObject *op); /* Py_TRACE_REFS is such major surgery that we call external routines. */ PyAPI_FUNC(void) _Py_NewReference(PyObject *); PyAPI_FUNC(void) _Py_ForgetReference(PyObject *); -PyAPI_FUNC(void) _Py_Dealloc(PyObject *); PyAPI_FUNC(void) _Py_PrintReferences(FILE *); PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *); PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force); @@ -790,15 +789,25 @@ static inline void _Py_ForgetReference(PyObject *op) { _Py_INC_TPFREES(op); } +#endif /* !Py_TRACE_REFS */ + -#ifdef Py_LIMITED_API PyAPI_FUNC(void) _Py_Dealloc(PyObject *); + +#ifndef Py_LIMITED_API +static inline void _Py_Dealloc_inline(PyObject *op) +{ + destructor dealloc = Py_TYPE(op)->tp_dealloc; +#ifdef Py_TRACE_REFS + _Py_ForgetReference(op); #else -#define _Py_Dealloc(op) ( \ - _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \ - (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op))) + _Py_INC_TPFREES(op); #endif -#endif /* !Py_TRACE_REFS */ + (*dealloc)(op); +} + +# define _Py_Dealloc(op) _Py_Dealloc_inline(op) +#endif /* !defined(Py_TRACE_REFS) && !defined(Py_LIMITED_API) */ static inline void _Py_INCREF(PyObject *op) diff --git a/Objects/object.c b/Objects/object.c index de9eb2cb4e2cda..b72ad019c796f2 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1964,14 +1964,6 @@ _Py_ForgetReference(PyObject *op) _Py_INC_TPFREES(op); } -void -_Py_Dealloc(PyObject *op) -{ - destructor dealloc = Py_TYPE(op)->tp_dealloc; - _Py_ForgetReference(op); - (*dealloc)(op); -} - /* Print all live objects. Because PyObject_Print is called, the * interpreter must be in a healthy state. */ @@ -2265,18 +2257,20 @@ _PyObject_AssertFailed(PyObject *obj, const char *msg, const char *expr, Py_FatalError("_PyObject_AssertFailed"); } -#ifndef Py_TRACE_REFS -/* For Py_LIMITED_API, we need an out-of-line version of _Py_Dealloc. - Define this here, so we can undefine the macro. */ + #undef _Py_Dealloc -void _Py_Dealloc(PyObject *); + void _Py_Dealloc(PyObject *op) { - _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA - (*Py_TYPE(op)->tp_dealloc)(op); -} + destructor dealloc = Py_TYPE(op)->tp_dealloc; +#ifdef Py_TRACE_REFS + _Py_ForgetReference(op); +#else + _Py_INC_TPFREES(op); #endif + (*dealloc)(op); +} #ifdef __cplusplus } From a20b426df39ecba082105ea9b1af09b2a6c56224 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 29 Oct 2018 20:08:48 +0100 Subject: [PATCH 2/2] Fix comment --- Include/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/object.h b/Include/object.h index e827b49562a58b..67840cca596ba5 100644 --- a/Include/object.h +++ b/Include/object.h @@ -807,7 +807,7 @@ static inline void _Py_Dealloc_inline(PyObject *op) } # define _Py_Dealloc(op) _Py_Dealloc_inline(op) -#endif /* !defined(Py_TRACE_REFS) && !defined(Py_LIMITED_API) */ +#endif /* !defined(Py_LIMITED_API) */ static inline void _Py_INCREF(PyObject *op)