diff options
Diffstat (limited to 'Include/object.h')
-rw-r--r-- | Include/object.h | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/Include/object.h b/Include/object.h index e1cc47a..175a208 100644 --- a/Include/object.h +++ b/Include/object.h @@ -379,25 +379,11 @@ decision that's up to the implementer of each new type so if you want, you can count such references to the type object.) */ -/* First define a pile of simple helper macros, one set per special - * build symbol. These either expand to the obvious things, or to - * nothing at all when the special mode isn't in effect. The main - * macros can later be defined just once then, yet expand to different - * things depending on which special build options are and aren't in effect. - * Trust me <wink>: while painful, this is 20x easier to understand than, - * e.g, defining _Py_NewReference five different times in a maze of nested - * #ifdefs (we used to do that -- it was impenetrable). - */ #ifdef Py_REF_DEBUG PyAPI_DATA(Py_ssize_t) _Py_RefTotal; PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno, PyObject *op); PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); -#define _Py_INC_REFTOTAL _Py_RefTotal++ -#define _Py_DEC_REFTOTAL _Py_RefTotal-- -#else -#define _Py_INC_REFTOTAL -#define _Py_DEC_REFTOTAL #endif /* Py_REF_DEBUG */ /* Update the Python traceback of an object. This function must be called @@ -406,33 +392,33 @@ PyAPI_FUNC(int) _PyTraceMalloc_NewReference(PyObject *op); #ifdef Py_TRACE_REFS /* 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_AddToAllObjects(PyObject *, int force); -#else -/* Without Py_TRACE_REFS, there's little enough to do that we expand code - inline. */ +#endif + + static inline void _Py_NewReference(PyObject *op) { if (_Py_tracemalloc_config.tracing) { _PyTraceMalloc_NewReference(op); } - _Py_INC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif Py_REFCNT(op) = 1; +#ifdef Py_TRACE_REFS + _Py_AddToAllObjects(op, 1); +#endif } -static inline void _Py_ForgetReference(PyObject *Py_UNUSED(op)) -{ - /* nothing to do */ -} -#endif /* !Py_TRACE_REFS */ - PyAPI_FUNC(void) _Py_Dealloc(PyObject *); static inline void _Py_INCREF(PyObject *op) { - _Py_INC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif op->ob_refcnt++; } @@ -444,7 +430,9 @@ static inline void _Py_DECREF( #endif PyObject *op) { - _Py_DEC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif if (--op->ob_refcnt != 0) { #ifdef Py_REF_DEBUG if (op->ob_refcnt < 0) { |