Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-116510: Fix a Crash Due to Shared Immortal Interned Strings#124865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2491,6 +2491,42 @@ _Py_ResurrectReference(PyObject *op) | ||
#ifdef Py_TRACE_REFS | ||
/* Make sure the ref is associated with the right interpreter. | ||
* This only needs special attention for heap-allocated objects | ||
* that have been immortalized, and only when the object might | ||
* outlive the interpreter where it was created. That means the | ||
* object was necessarily created using a global allocator | ||
* (i.e. from the main interpreter). Thus in that specific case | ||
* we move the object over to the main interpreter's refchain. | ||
* | ||
* This was added for the sake of the immortal interned strings, | ||
* where legacy subinterpreters share the main interpreter's | ||
* interned dict (and allocator), and therefore the strings can | ||
* outlive the subinterpreter. | ||
* | ||
* It may make sense to fold this into _Py_SetImmortalUntracked(), | ||
* but that requires further investigation. In the meantime, it is | ||
* up to the caller to know if this is needed. There should be | ||
* very few cases. | ||
*/ | ||
void | ||
_Py_NormalizeImmortalReference(PyObject *op) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Having some comment here would be helpful. Otherwise this function looks quite mysterious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. done! | ||
{ | ||
assert(_Py_IsImmortal(op)); | ||
PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
if (!_PyRefchain_IsTraced(interp, op)) { | ||
return; | ||
} | ||
PyInterpreterState *main_interp = _PyInterpreterState_Main(); | ||
if (interp != main_interp | ||
&& interp->feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC) | ||
{ | ||
assert(!_PyRefchain_IsTraced(main_interp, op)); | ||
_PyRefchain_Remove(interp, op); | ||
_PyRefchain_Trace(main_interp, op); | ||
} | ||
} | ||
void | ||
_Py_ForgetReference(PyObject *op) | ||
{ | ||
Uh oh!
There was an error while loading.Please reload this page.