summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-11-12 12:45:12 (GMT)
committerGitHub <noreply@github.com>2024-11-12 12:45:12 (GMT)
commit02cd3ce0f201df98939c65bcba8445bb0b70717b (patch)
treeb9c41e26f84bc71aa464253d010ebdfaf27ac87a /Python
parent4f1440fd89c58c46094422423972496b5d870316 (diff)
downloadcpython-02cd3ce0f201df98939c65bcba8445bb0b70717b.zip
cpython-02cd3ce0f201df98939c65bcba8445bb0b70717b.tar.gz
cpython-02cd3ce0f201df98939c65bcba8445bb0b70717b.tar.bz2
[3.13] gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-124865) (gh-125709) (GH-125204)
* gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-124865) Fix a crash caused by immortal interned strings being shared between sub-interpreters that use basic single-phase init. In that case, the string can be used by an interpreter that outlives the interpreter that created and interned it. For interpreters that share obmalloc state, also share the interned dict with the main interpreter. This is an un-revert of gh-124646 that then addresses the Py_TRACE_REFS failures identified by gh-124785. (cherry picked from commit f2cb39947093feda3ff85b8dc820922cc5e5f954) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com> * [3.13] gh-125286: Share the Main Refchain With Legacy Interpreters (gh-125709) They used to be shared, before 3.12. Returning to sharing them resolves a failure on Py_TRACE_REFS builds. --------- Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c14
-rw-r--r--Python/pystate.c6
2 files changed, 16 insertions, 4 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 1701a1c..0cd4fb4 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -670,6 +670,13 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}
+ // This could be done in init_interpreter() (in pystate.c) if it
+ // didn't depend on interp->feature_flags being set already.
+ status = _PyObject_InitState(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
// initialize the interp->obmalloc state. This must be done after
// the settings are loaded (so that feature_flags are set) but before
// any calls are made to obmalloc functions.
@@ -2290,6 +2297,13 @@ new_interpreter(PyThreadState **tstate_p,
goto error;
}
+ // This could be done in init_interpreter() (in pystate.c) if it
+ // didn't depend on interp->feature_flags being set already.
+ status = _PyObject_InitState(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
// initialize the interp->obmalloc state. This must be done after
// the settings are loaded (so that feature_flags are set) but before
// any calls are made to obmalloc functions.
diff --git a/Python/pystate.c b/Python/pystate.c
index 66fd392..ad3fdce 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -632,10 +632,8 @@ init_interpreter(PyInterpreterState *interp,
assert(next != NULL || (interp == runtime->interpreters.main));
interp->next = next;
- PyStatus status = _PyObject_InitState(interp);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
+ // We would call _PyObject_InitState() at this point
+ // if interp->feature_flags were alredy set.
_PyEval_InitState(interp);
_PyGC_InitState(&interp->gc);