summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-08-16 10:03:05 (GMT)
committerGitHub <noreply@github.com>2023-08-16 10:03:05 (GMT)
commitaa9707dda9f8dcbe2ada8d8a7280f0f6a8229c59 (patch)
tree65b508c11793840d27e9f6b29c96496c740e75d5 /Include
parentbd2ef82a5010985abdeef2ca71bcbcc9a366993b (diff)
downloadcpython-aa9707dda9f8dcbe2ada8d8a7280f0f6a8229c59.zip
cpython-aa9707dda9f8dcbe2ada8d8a7280f0f6a8229c59.tar.gz
cpython-aa9707dda9f8dcbe2ada8d8a7280f0f6a8229c59.tar.bz2
[3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters (#107751)
* Unrevert "[3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters (gh-107567) (#107599)". This reverts commit 6e4eec760648a71e1cd8f8f551997b1823b4bb9f (gh-107648). * Initialize each interpreter's refchain properly. * Skip test_basic_multiple_interpreters_deleted_no_reset on tracerefs builds.
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_object.h5
-rw-r--r--Include/internal/pycore_object_state.h13
-rw-r--r--Include/internal/pycore_runtime_init.h11
3 files changed, 23 insertions, 6 deletions
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 0981d11..7a2f13a 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -152,6 +152,7 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
extern void _PyType_InitCache(PyInterpreterState *interp);
+extern void _PyObject_InitState(PyInterpreterState *interp);
/* Inline functions trading binary compatibility for speed:
_PyObject_Init() is the fast version of PyObject_Init(), and
@@ -271,8 +272,8 @@ extern void _PyDebug_PrintTotalRefs(void);
#ifdef Py_TRACE_REFS
extern void _Py_AddToAllObjects(PyObject *op, int force);
-extern void _Py_PrintReferences(FILE *);
-extern void _Py_PrintReferenceAddresses(FILE *);
+extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
+extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
#endif
diff --git a/Include/internal/pycore_object_state.h b/Include/internal/pycore_object_state.h
index 94005d7..65feb5a 100644
--- a/Include/internal/pycore_object_state.h
+++ b/Include/internal/pycore_object_state.h
@@ -11,17 +11,22 @@ extern "C" {
struct _py_object_runtime_state {
#ifdef Py_REF_DEBUG
Py_ssize_t interpreter_leaks;
-#else
- int _not_used;
#endif
+ int _not_used;
};
struct _py_object_state {
#ifdef Py_REF_DEBUG
Py_ssize_t reftotal;
-#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;
};
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index 4130188..7aace9f 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -101,6 +101,7 @@ extern PyTypeObject _PyExc_MemoryError;
{ .threshold = 10, }, \
}, \
}, \
+ .object_state = _py_object_state_INIT(INTERP), \
.dtoa = _dtoa_state_INIT(&(INTERP)), \
.dict_state = _dict_state_INIT, \
.func_state = { \
@@ -130,6 +131,16 @@ extern PyTypeObject _PyExc_MemoryError;
.context_ver = 1, \
}
+#ifdef Py_TRACE_REFS
+# define _py_object_state_INIT(INTERP) \
+ { \
+ .refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \
+ }
+#else
+# define _py_object_state_INIT(INTERP) \
+ { 0 }
+#endif
+
// global objects