mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
[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 cb6f75a32c
)
Co-authored-by: mpage <mpage@meta.com>
This commit is contained in:
parent
8f31af68d0
commit
7b9ca26812
4 changed files with 45 additions and 16 deletions
|
@ -168,7 +168,7 @@ static inline int
|
|||
_PyObject_HasDeferredRefcount(PyObject *op)
|
||||
{
|
||||
#ifdef Py_GIL_DISABLED
|
||||
return (op->ob_gc_bits & _PyGC_BITS_DEFERRED) != 0;
|
||||
return _PyObject_HAS_GC_BITS(op, _PyGC_BITS_DEFERRED);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -320,7 +320,7 @@ static inline void _PyObject_GC_TRACK(
|
|||
"object already tracked by the garbage collector",
|
||||
filename, lineno, __func__);
|
||||
#ifdef Py_GIL_DISABLED
|
||||
op->ob_gc_bits |= _PyGC_BITS_TRACKED;
|
||||
_PyObject_SET_GC_BITS(op, _PyGC_BITS_TRACKED);
|
||||
#else
|
||||
PyGC_Head *gc = _Py_AS_GC(op);
|
||||
_PyObject_ASSERT_FROM(op,
|
||||
|
@ -361,7 +361,7 @@ static inline void _PyObject_GC_UNTRACK(
|
|||
filename, lineno, __func__);
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
op->ob_gc_bits &= ~_PyGC_BITS_TRACKED;
|
||||
_PyObject_CLEAR_GC_BITS(op, _PyGC_BITS_TRACKED);
|
||||
#else
|
||||
PyGC_Head *gc = _Py_AS_GC(op);
|
||||
PyGC_Head *prev = _PyGCHead_PREV(gc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue