bpo-35059: Convert _Py_Dealloc() to static inline function (GH-10223)

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.
This commit is contained in:
Victor Stinner 2018-10-30 14:48:26 +01:00 committed by GitHub
parent e1b29950bf
commit 3c09dca4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 24 deletions

View File

@ -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,17 +789,27 @@ static inline void _Py_ForgetReference(PyObject *op)
{
_Py_INC_TPFREES(op);
}
#ifdef Py_LIMITED_API
PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
#else
#define _Py_Dealloc(op) ( \
_Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
(*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
#endif
#endif /* !Py_TRACE_REFS */
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
_Py_INC_TPFREES(op);
#endif
(*dealloc)(op);
}
# define _Py_Dealloc(op) _Py_Dealloc_inline(op)
#endif /* !defined(Py_LIMITED_API) */
static inline void _Py_INCREF(PyObject *op)
{
_Py_INC_REFTOTAL;

View File

@ -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
}