diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-05-08 21:31:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 21:31:37 (GMT) |
commit | 7b9ca26812fabcd1202238c989f0f0a9e5b02e87 (patch) | |
tree | 6fdc1fa02b4ec5adb365b31d1112ae79b53f3748 /Objects | |
parent | 8f31af68d0767d4bc56022ab7cc30b1c7bd6a676 (diff) | |
download | cpython-7b9ca26812fabcd1202238c989f0f0a9e5b02e87.zip cpython-7b9ca26812fabcd1202238c989f0f0a9e5b02e87.tar.gz cpython-7b9ca26812fabcd1202238c989f0f0a9e5b02e87.tar.bz2 |
[3.13] gh-117657: Fix data races when writing / reading `ob_gc_bits` (GH-118292) (#118796)
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.
(cherry picked from commit cb6f75a32ca2649c6cc1cabb0301eb783efbd55b)
Co-authored-by: mpage <mpage@meta.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c index 8ad0389..a4c6999 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2431,6 +2431,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 @@ -2438,7 +2439,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 |