Skip to content

Commit cb9567a

Browse files
committed
gh-129069: use atomic read in _Py_SIZE_impl()
part of TSAN-0013 in gh-153852
1 parent 206788a commit cb9567a

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

Include/cpython/listobject.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ typedef struct {
2929

3030
static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) {
3131
PyListObject *list = _PyList_CAST(op);
32-
#ifdef Py_GIL_DISABLED
33-
return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(list)->ob_size));
34-
#else
3532
return Py_SIZE(list);
36-
#endif
3733
}
3834
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
3935

Include/object.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ _Py_SIZE_impl(PyObject *ob)
240240
{
241241
assert(Py_TYPE(ob) != &PyLong_Type);
242242
assert(Py_TYPE(ob) != &PyBool_Type);
243-
return _PyVarObject_CAST(ob)->ob_size;
243+
#ifdef Py_GIL_DISABLED
244+
return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(ob)->ob_size));
245+
#else
246+
return _PyVarObject_CAST(ob)->ob_size;
247+
#endif
244248
}
245249

246250
static inline int

0 commit comments

Comments
 (0)