mirror of
https://github.com/python/cpython.git
synced 2025-08-25 11:15:02 +00:00
[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 f2cb399470
, AKA gh-124865)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
parent
b49e902b81
commit
49da170709
10 changed files with 124 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue