[3.13] 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 [email protected]
- Issue: gh-116510
Please don't merge until the TraceRefs regression is fixed: https://github.com/python/cpython/pull/124865#issuecomment-2404820325
I think this can be merged now with GH-125709 applied on top or squashed into it.
Thanks @miss-islington for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. 🐍🍒⛏🤖
Sorry, @miss-islington and @encukou, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 02cd3ce0f201df98939c65bcba8445bb0b70717b 3.12