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 /Objects/dictobject.c | |
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 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 87f88ab..ae6b50f 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -311,7 +311,9 @@ static void free_keys_object(PyDictKeysObject *keys); static inline void dictkeys_incref(PyDictKeysObject *dk) { - _Py_INC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif dk->dk_refcnt++; } @@ -319,7 +321,9 @@ static inline void dictkeys_decref(PyDictKeysObject *dk) { assert(dk->dk_refcnt > 0); - _Py_DEC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif if (--dk->dk_refcnt == 0) { free_keys_object(dk); } @@ -563,7 +567,9 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) return NULL; } } - _Py_INC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif dk->dk_refcnt = 1; dk->dk_size = size; dk->dk_usable = usable; @@ -687,10 +693,12 @@ clone_combined_dict(PyDictObject *orig) } /* Since we copied the keys table we now have an extra reference - in the system. Manually call _Py_INC_REFTOTAL to signal that + in the system. Manually call increment _Py_RefTotal to signal that we have it now; calling dictkeys_incref would be an error as keys->dk_refcnt is already set to 1 (after memcpy). */ - _Py_INC_REFTOTAL; +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif return (PyObject *)new; } @@ -1249,13 +1257,15 @@ dictresize(PyDictObject *mp, Py_ssize_t minsize) assert(oldkeys->dk_lookup != lookdict_split); assert(oldkeys->dk_refcnt == 1); +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif if (oldkeys->dk_size == PyDict_MINSIZE && - numfreekeys < PyDict_MAXFREELIST) { - _Py_DEC_REFTOTAL; + numfreekeys < PyDict_MAXFREELIST) + { keys_free_list[numfreekeys++] = oldkeys; } else { - _Py_DEC_REFTOTAL; PyObject_FREE(oldkeys); } } |