Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Include the legacy total in _Py_GetGlobalRefTotal().
  • Loading branch information
ericsnowcurrently committed Mar 9, 2023
commit 5ab4c4b8b63e7ce7631d5570b7e9cade44830130
1 change: 1 addition & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
/* These are useful as debugging aids when chasing down refleaks. */
PyAPI_FUNC(Py_ssize_t) _Py_GetGlobalRefTotal(void);
# define _Py_GetRefTotal() _Py_GetGlobalRefTotal()
PyAPI_FUNC(Py_ssize_t) _Py_GetLegacyRefTotal(void);
#endif


Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_object_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {

struct _py_object_runtime_state {
#ifdef Py_REF_DEBUG
Py_ssize_t last_legacy_reftotal;
Py_ssize_t reftotal;
#else
int _not_used;
Expand Down
19 changes: 18 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ _PyObject_CheckConsistency(PyObject *op, int check_content)
#ifdef Py_REF_DEBUG
/* We keep the legacy symbol around for backward compatibility. */
Py_ssize_t _Py_RefTotal;

static inline Py_ssize_t
get_legacy_reftotal(void)
{
return _Py_RefTotal;
}
#endif

#ifdef Py_REF_DEBUG
Expand Down Expand Up @@ -83,7 +89,10 @@ reftotal_add(Py_ssize_t n)
static inline Py_ssize_t
get_global_reftotal(void)
{
return REFTOTAL;
Py_ssize_t last = _PyRuntime.object_state.last_legacy_reftotal;
Py_ssize_t legacy = get_legacy_reftotal();
_PyRuntime.object_state.last_legacy_reftotal = legacy;
return REFTOTAL + legacy - last;
}

#undef REFTOTAL
Expand All @@ -93,6 +102,7 @@ _PyDebug_PrintTotalRefs(void) {
fprintf(stderr,
"[%zd refs, %zd blocks]\n",
get_global_reftotal(), _Py_GetAllocatedBlocks());
/* It may be helpful to also print the "legacy" reftotal separately. */
}
#endif /* Py_REF_DEBUG */

Expand Down Expand Up @@ -179,12 +189,19 @@ _Py_AddRefTotal(Py_ssize_t n)
reftotal_add(n);
}

/* This includes the legacy total. */
Py_ssize_t
_Py_GetGlobalRefTotal(void)
{
return get_global_reftotal();
}

Py_ssize_t
_Py_GetLegacyRefTotal(void)
{
return get_legacy_reftotal();
}

#endif /* Py_REF_DEBUG */

void
Expand Down