summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-12-03 17:26:25 (GMT)
committerGitHub <noreply@github.com>2024-12-03 17:26:25 (GMT)
commit49da170709dd47c49bfc1e5d4b5d46122a049a3b (patch)
treeffe9d0289f8a1098ec779d9c97371ab0e38771bd /Python
parentb49e902b81a0ead84e2002f94a2a2b2ae9b09ada (diff)
downloadcpython-49da170709dd47c49bfc1e5d4b5d46122a049a3b.zip
cpython-49da170709dd47c49bfc1e5d4b5d46122a049a3b.tar.gz
cpython-49da170709dd47c49bfc1e5d4b5d46122a049a3b.tar.bz2
[3.12] gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-125205)
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 (i.e. backporting gh-125709 too). (cherry picked from commit f2cb39947093feda3ff85b8dc820922cc5e5f954, AKA gh-124865) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c8
-rw-r--r--Python/pystate.c4
2 files changed, 11 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 6d580c6..e9c1a0d 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -650,6 +650,10 @@ 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.
+ _PyObject_InitState(interp);
+
PyThreadState *tstate = _PyThreadState_New(interp);
if (tstate == NULL) {
return _PyStatus_ERR("can't make first thread");
@@ -2103,6 +2107,10 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
goto error;
}
+ // This could be done in init_interpreter() (in pystate.c) if it
+ // didn't depend on interp->feature_flags being set already.
+ _PyObject_InitState(interp);
+
status = init_interp_create_gil(tstate, config->gil);
if (_PyStatus_EXCEPTION(status)) {
goto error;
diff --git a/Python/pystate.c b/Python/pystate.c
index f0e0d41..6aed9ac 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -686,7 +686,9 @@ init_interpreter(PyInterpreterState *interp,
_obmalloc_pools_INIT(interp->obmalloc.pools);
memcpy(&interp->obmalloc.pools.used, temp, sizeof(temp));
}
- _PyObject_InitState(interp);
+
+ // We would call _PyObject_InitState() at this point
+ // if interp->feature_flags were alredy set.
_PyEval_InitState(interp, pending_lock);
_PyGC_InitState(&interp->gc);