summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-03-20 16:03:04 (GMT)
committerGitHub <noreply@github.com>2023-03-20 16:03:04 (GMT)
commitad77d16a6252c2e616bf41b981a6d919c1122b4d (patch)
tree17a73242035ac8da8c0096effe17d665cdfe843b /Python
parent96e05b62e827a6dee6c658fea9b4976dfd8d30e3 (diff)
downloadcpython-ad77d16a6252c2e616bf41b981a6d919c1122b4d.zip
cpython-ad77d16a6252c2e616bf41b981a6d919c1122b4d.tar.gz
cpython-ad77d16a6252c2e616bf41b981a6d919c1122b4d.tar.bz2
gh-102304: Move _Py_RefTotal to _PyRuntimeState (gh-102543)
The essentially eliminates the global variable, with the associated benefits. This is also a precursor to isolating this bit of state to PyInterpreterState. Folks that currently read _Py_RefTotal directly would have to start using _Py_GetGlobalRefTotal() instead. https://github.com/python/cpython/issues/102304
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c1
-rw-r--r--Python/pystate.c3
-rw-r--r--Python/sysmodule.c2
3 files changed, 5 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 317d696..731f340 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1930,6 +1930,7 @@ Py_FinalizeEx(void)
if (show_ref_count) {
_PyDebug_PrintTotalRefs();
}
+ _Py_FinalizeRefTotal(runtime);
#endif
#ifdef Py_TRACE_REFS
diff --git a/Python/pystate.c b/Python/pystate.c
index 3a2966c..4d42135 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -482,6 +482,9 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
void
_PyRuntimeState_Fini(_PyRuntimeState *runtime)
{
+ /* The reftotal is cleared by _Py_FinalizeRefTotal(). */
+ assert(runtime->object_state.reftotal == 0);
+
if (gilstate_tss_initialized(runtime)) {
gilstate_tss_fini(runtime);
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 126b7d4..2076173 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1854,7 +1854,7 @@ static Py_ssize_t
sys_gettotalrefcount_impl(PyObject *module)
/*[clinic end generated code: output=4103886cf17c25bc input=53b744faa5d2e4f6]*/
{
- return _Py_GetRefTotal();
+ return _Py_GetGlobalRefTotal();
}
#endif /* Py_REF_DEBUG */