mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
[3.13] gh-117657: Fix race involving immortalizing objects (GH-119927) (#120005)
The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.
This fixes a race condition involving the tracking of whether the
behavior is suppressed.
(cherry picked from commit 47fb4327b5
)
This commit is contained in:
parent
ca37034baa
commit
ae705319fc
9 changed files with 30 additions and 44 deletions
|
@ -110,7 +110,7 @@ should_intern_string(PyObject *o)
|
|||
// unless we've disabled immortalizing objects that use deferred reference
|
||||
// counting.
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (interp->gc.immortalize.enable_on_thread_created) {
|
||||
if (_Py_atomic_load_int(&interp->gc.immortalize) < 0) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -240,7 +240,7 @@ intern_constants(PyObject *tuple, int *modified)
|
|||
PyThreadState *tstate = PyThreadState_GET();
|
||||
if (!_Py_IsImmortal(v) && !PyCode_Check(v) &&
|
||||
!PyUnicode_CheckExact(v) &&
|
||||
tstate->interp->gc.immortalize.enable_on_thread_created)
|
||||
_Py_atomic_load_int(&tstate->interp->gc.immortalize) >= 0)
|
||||
{
|
||||
PyObject *interned = intern_one_constant(v);
|
||||
if (interned == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue