summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-05-08 20:03:39 (GMT)
committerGitHub <noreply@github.com>2024-05-08 20:03:39 (GMT)
commitcb6f75a32ca2649c6cc1cabb0301eb783efbd55b (patch)
treec579943eb25f2bdd8ca51363bc8b7de433f08b7a /Objects/object.c
parent8d84120b4175daaf4ae6038621f3005cdb65acda (diff)
downloadcpython-cb6f75a32ca2649c6cc1cabb0301eb783efbd55b.zip
cpython-cb6f75a32ca2649c6cc1cabb0301eb783efbd55b.tar.gz
cpython-cb6f75a32ca2649c6cc1cabb0301eb783efbd55b.tar.bz2
gh-117657: Fix data races when writing / reading `ob_gc_bits` (#118292)
Use relaxed atomics when reading / writing to the field. There are still a few places in the GC where we do not use atomics. Those should be safe as the world is stopped.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 29183dc..d4fe14c 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2427,6 +2427,7 @@ _PyObject_SetDeferredRefcount(PyObject *op)
assert(PyType_IS_GC(Py_TYPE(op)));
assert(_Py_IsOwnedByCurrentThread(op));
assert(op->ob_ref_shared == 0);
+ _PyObject_SET_GC_BITS(op, _PyGC_BITS_DEFERRED);
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->gc.immortalize.enabled) {
// gh-117696: immortalize objects instead of using deferred reference
@@ -2434,7 +2435,6 @@ _PyObject_SetDeferredRefcount(PyObject *op)
_Py_SetImmortal(op);
return;
}
- op->ob_gc_bits |= _PyGC_BITS_DEFERRED;
op->ob_ref_local += 1;
op->ob_ref_shared = _Py_REF_QUEUED;
#endif