diff options
author | Victor Stinner <vstinner@python.org> | 2020-02-03 16:55:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-03 16:55:04 (GMT) |
commit | 49932fec62c616ec88da52642339d83ae719e924 (patch) | |
tree | b489d2b97cf56c0b51a15f27ecf4064c5084d9d8 /Include | |
parent | 24e5ad4689de9adc8e4a7d8c08fe400dcea668e6 (diff) | |
download | cpython-49932fec62c616ec88da52642339d83ae719e924.zip cpython-49932fec62c616ec88da52642339d83ae719e924.tar.gz cpython-49932fec62c616ec88da52642339d83ae719e924.tar.bz2 |
bpo-39542: Simplify _Py_NewReference() (GH-18332)
* Remove _Py_INC_REFTOTAL and _Py_DEC_REFTOTAL macros: modify
directly _Py_RefTotal.
* _Py_ForgetReference() is no longer defined if the Py_TRACE_REFS
macro is not defined.
* Remove _Py_NewReference() implementation from object.c:
unify the two implementations in object.h inline function.
* Fix Py_TRACE_REFS build: _Py_INC_TPALLOCS() macro has been removed.
Diffstat (limited to 'Include')
-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) { |