8000 gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters by ericsnowcurrently · Pull Request #107567 · python/cpython · GitHub
[go: up one dir, main page]

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
Next Next commit
Move refchain to _PyRuntimeState.
  • Loading branch information
ericsnowcurrently committed Aug 2, 2023
commit 11d48cddbd2501cb918be4aa31bd7889518f4b1d
10 changes: 8 additions & 2 deletions Include/internal/pycore_object_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ extern "C" {
struct _py_object_runtime_state {
#ifdef Py_REF_DEBUG
Py_ssize_t interpreter_leaks;
#else
int _not_used;
#endif
#ifdef Py_TRACE_REFS
/* Head of circular doubly-linked list of all objects. These are linked
* together via the _ob_prev and _ob_next members of a PyObject, which
* exist only in a Py_TRACE_REFS build.
*/
PyObject refchain;
#endif
int _not_used;
};

struct _py_object_state {
Expand Down
11 changes: 11 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern PyTypeObject _PyExc_MemoryError;
}, \
.faulthandler = _faulthandler_runtime_state_INIT, \
.tracemalloc = _tracemalloc_runtime_state_INIT, \
.object_state = _py_object_runtime_state_INIT(runtime), \
.float_state = { \
.float_format = _py_float_format_unknown, \
.double_format = _py_float_format_unknown, \
Expand Down Expand Up @@ -186,6 +187,16 @@ extern PyTypeObject _PyExc_MemoryError;
.context_ver = 1, \
}

#ifdef Py_TRACE_REFS
# define _py_object_runtime_state_INIT(runtime) \
{ \
.refchain = {&runtime.object_state.refchain, &runtime.object_state.refchain}, \
}
#else
# define _py_object_runtime_state_INIT(runtime) \
{ 0 }
#endif


// global objects

Expand Down
7 changes: 2 additions & 5 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,8 @@ _PyDebug_PrintTotalRefs(void) {
Do not call them otherwise, they do not initialize the object! */

#ifdef Py_TRACE_REFS
/* Head of circular doubly-linked list of all objects. These are linked
* together via the _ob_prev and _ob_next members of a PyObject, which
* exist only in a Py_TRACE_REFS build.
*/
static PyObject refchain = {&refchain, &refchain};

# define refchain _PyRuntime.object_state.refchain

/* Insert op at the front of the list of all objects. If force is true,
* op is added even if _ob_prev and _ob_next are non-NULL already. If
Expand Down
0