FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-102304: Move _Py_RefTotal to _PyRuntimeState by ericsnowcurrently · Pull Request #102543 · python/cpython · GitHub

Repository navigation

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Factor out sync_legacy_reftotal().
  • Loading branch information
ericsnowcurrently committed Mar 17, 2023
commit 0abec9c7cecc0d52e8d318fdaddca24466eb1811
29 changes: 21 additions & 8 deletions Objects/object.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
extern "C" {
#endif

#define OBJSTATE(runtime) \
(runtime)->object_state

/* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr);

Expand Down Expand Up @@ -57,16 +60,25 @@ _PyObject_CheckConsistency(PyObject *op, int check_content)
/* We keep the legacy symbol around for backward compatibility. */
Py_ssize_t _Py_RefTotal;

static inline void
sync_legacy_reftotal(_PyRuntimeState *runtime)
{
Py_ssize_t last = OBJSTATE(runtime).last_legacy_reftotal;
OBJSTATE(runtime).last_legacy_reftotal = _Py_RefTotal;
OBJSTATE(runtime).reftotal += _Py_RefTotal - last;
}

static inline Py_ssize_t
get_legacy_reftotal(void)
get_legacy_reftotal(_PyRuntimeState *runtime)
{
sync_legacy_reftotal(runtime);
return _Py_RefTotal;
}
#endif

#ifdef Py_REF_DEBUG

# define REFTOTAL ((runtime)->object_state.reftotal)
# define REFTOTAL (OBJSTATE(runtime).reftotal)

static inline void
reftotal_increment(_PyRuntimeState *runtime)
Expand All @@ -86,6 +98,8 @@ reftotal_add(_PyRuntimeState *runtime, Py_ssize_t n)
REFTOTAL += n;
}

static inline Py_ssize_t get_global_reftotal(_PyRuntimeState *);

/* We preserve the number of refs leaked during runtime finalization,
so they can be reported if the runtime is initialized again. */
// XXX We don't lose any information by dropping this,
Expand All @@ -95,17 +109,16 @@ static Py_ssize_t last_final_reftotal = 0;
void
_Py_ClearRefTotal(_PyRuntimeState *runtime)
{
last_final_reftotal += REFTOTAL;
last_final_reftotal += get_global_reftotal(runtime);
REFTOTAL = 0;
_Py_RefTotal = 0;
}

static inline Py_ssize_t
get_global_reftotal(_PyRuntimeState *runtime)
{
Py_ssize_t last = _PyRuntime.object_state.last_legacy_reftotal;
Py_ssize_t legacy = get_legacy_reftotal();
_PyRuntime.object_state.last_legacy_reftotal = legacy;
REFTOTAL += legacy - last;
/* For an update from _Py_RefTotal first. */
sync_legacy_reftotal(runtime);
return REFTOTAL + last_final_reftotal;
}

Expand Down Expand Up @@ -215,7 +228,7 @@ _Py_GetGlobalRefTotal(void)
Py_ssize_t
_Py_GetLegacyRefTotal(void)
{
return get_legacy_reftotal();
return get_legacy_reftotal(&_PyRuntime);
}

#endif /* Py_REF_DEBUG */
Expand Down

Back | FazBrowse Home | New Git URL