diff options
author | Sam Gross <colesbury@gmail.com> | 2024-06-03 22:21:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-03 22:21:32 (GMT) |
commit | ae705319fcde864b504987dc8e579e3eef68e1e5 (patch) | |
tree | 022166446a352d99b784b44a86f163bec179e94d /Objects | |
parent | ca37034baa2909722df58c02dfd13e1d667252ce (diff) | |
download | cpython-ae705319fcde864b504987dc8e579e3eef68e1e5.zip cpython-ae705319fcde864b504987dc8e579e3eef68e1e5.tar.gz cpython-ae705319fcde864b504987dc8e579e3eef68e1e5.tar.bz2 |
[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 47fb4327b5c405da6df066dcaa01b7c1aefab313)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/codeobject.c | 4 | ||||
-rw-r--r-- | Objects/object.c | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 3d804f7..23fc8a7 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -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) { diff --git a/Objects/object.c b/Objects/object.c index a4c6999..ce3df37 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2433,7 +2433,7 @@ _PyObject_SetDeferredRefcount(PyObject *op) assert(op->ob_ref_shared == 0); _PyObject_SET_GC_BITS(op, _PyGC_BITS_DEFERRED); PyInterpreterState *interp = _PyInterpreterState_GET(); - if (interp->gc.immortalize.enabled) { + if (_Py_atomic_load_int_relaxed(&interp->gc.immortalize) == 1) { // gh-117696: immortalize objects instead of using deferred reference // counting for now. _Py_SetImmortal(op); |