(See gh-100227.)
_Py_RefTotal holds the current global total number of refcounts. It only exists if Py_REF_DEBUG is defined (implied by Py_DEBUG). It is exposed by sys.gettotalrefcount() and set by Py_INCREF(), Py_DECREF(), etc. and _Py_NewReference().
Modications to _Py_RefTotal are currently protected by the GIL so it should be moved to PyInterpreterState. For various aspects of compatibility, it makes sense to keep the _Py_RefTotal symbol around (and correct) and keep returning the global total from sys.gettotalrefcount().
Also, _Py_RefTotal is used by stable ABI extensions only where Py_REF_DEBUG is defined (unlikely) and only where built against 3.9 or earlier. Just in case, though, we must still keep the global variable around, so any solution here must respect that.
Linked PRs
(See gh-100227.)
_Py_RefTotalholds the current global total number of refcounts. It only exists ifPy_REF_DEBUGis defined (implied byPy_DEBUG). It is exposed bysys.gettotalrefcount()and set byPy_INCREF(),Py_DECREF(), etc. and_Py_NewReference().Modications to
_Py_RefTotalare currently protected by the GIL so it should be moved toPyInterpreterState. For various aspects of compatibility, it makes sense to keep the_Py_RefTotalsymbol around (and correct) and keep returning the global total fromsys.gettotalrefcount().Also,
_Py_RefTotalis used by stable ABI extensions only wherePy_REF_DEBUGis defined (unlikely) and only where built against 3.9 or earlier. Just in case, though, we must still keep the global variable around, so any solution here must respect that.Linked PRs