summaryrefslogtreecommitdiff
path: root/Include/internal/pycore_object.h
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-03-08 12:03:50 -0700
committerGitHub <noreply@github.com>2023-03-08 12:03:50 -0700
commitcbb0aa71d040022db61390380b8aebc7c04f3275 (patch)
tree9ff9e2f3141fbd5bdc2446144955722a7d63afa9 /Include/internal/pycore_object.h
parent11a2c6ce516b24b2435cb627742a6c4df92d411c (diff)
downloadcpython-git-cbb0aa71d040022db61390380b8aebc7c04f3275.tar.gz
gh-102304: Consolidate Direct Usage of _Py_RefTotal (gh-102514)
This simplifies further changes to _Py_RefTotal (e.g. make it atomic or move it to PyInterpreterState). https://github.com/python/cpython/issues/102304
Diffstat (limited to 'Include/internal/pycore_object.h')
-rw-r--r--Include/internal/pycore_object.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 8796dfe2f6..e15685f174 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -37,11 +37,23 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
#define _Py_FatalRefcountError(message) \
_Py_FatalRefcountErrorFunc(__func__, (message))
+
+#ifdef Py_REF_DEBUG
+/* The symbol is only exposed in the API for the sake of extensions
+ built against the pre-3.12 stable ABI. */
+PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
+
+extern void _Py_AddRefTotal(Py_ssize_t);
+extern void _Py_IncRefTotal(void);
+extern void _Py_DecRefTotal(void);
+# define _Py_DEC_REFTOTAL() _Py_RefTotal--
+#endif
+
// Increment reference count by n
static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
{
#ifdef Py_REF_DEBUG
- _Py_RefTotal += n;
+ _Py_AddRefTotal(n);
#endif
op->ob_refcnt += n;
}
@@ -52,7 +64,7 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
{
_Py_DECREF_STAT_INC();
#ifdef Py_REF_DEBUG
- _Py_RefTotal--;
+ _Py_DEC_REFTOTAL();
#endif
if (--op->ob_refcnt != 0) {
assert(op->ob_refcnt > 0);
@@ -70,7 +82,7 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
{
_Py_DECREF_STAT_INC();
#ifdef Py_REF_DEBUG
- _Py_RefTotal--;
+ _Py_DEC_REFTOTAL();
#endif
op->ob_refcnt--;
#ifdef Py_DEBUG
@@ -80,6 +92,11 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
#endif
}
+#ifdef Py_REF_DEBUG
+# undef _Py_DEC_REFTOTAL
+#endif
+
+
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);