-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Move _Py_RefTotal to PyInterpreterState #102304
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItopic-subinterpreterstype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItopic-subinterpreterstype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Done
(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