diff --git a/Include/cpython/listobject.h b/Include/cpython/listobject.h index 49f5e8d6d1a0d6c..8ade1b164681f9e 100644 --- a/Include/cpython/listobject.h +++ b/Include/cpython/listobject.h @@ -29,11 +29,7 @@ typedef struct { static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) { PyListObject *list = _PyList_CAST(op); -#ifdef Py_GIL_DISABLED - return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(list)->ob_size)); -#else return Py_SIZE(list); -#endif } #define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op)) diff --git a/Include/object.h b/Include/object.h index 20c2dab4401fef0..bace149881b7dbd 100644 --- a/Include/object.h +++ b/Include/object.h @@ -240,7 +240,11 @@ _Py_SIZE_impl(PyObject *ob) { assert(Py_TYPE(ob) != &PyLong_Type); assert(Py_TYPE(ob) != &PyBool_Type); - return _PyVarObject_CAST(ob)->ob_size; +#ifdef Py_GIL_DISABLED + return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(ob)->ob_size)); +#else + return _PyVarObject_CAST(ob)->ob_size; +#endif } static inline int diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 696ddad8efaae55..f6725f644d65247 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -9,6 +9,7 @@ #include "pycore_object.h" // _PyObject_GC_UNTRACK() #include "pycore_strhex.h" // _Py_strhex_with_sep() #include "pycore_long.h" // _PyLong_FromUnsignedChar() +#include "pycore_list.h" // _PyList_GetItemRef #include "pycore_pyatomic_ft_wrappers.h" #include "bytesobject.h" diff --git a/Objects/stringlib/join.h b/Objects/stringlib/join.h index fe460d41f6700f8..d5a0fd6694c5e8e 100644 --- a/Objects/stringlib/join.h +++ b/Objects/stringlib/join.h @@ -60,7 +60,16 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) */ for (i = 0, nbufs = 0; i < seqlen; i++) { Py_ssize_t itemlen; +#ifdef Py_GIL_DISABLED + if (PyList_Check(seq)) { + item = _PyList_GetItemRef((PyListObject *)seq, i); + } + else { + item = PyTuple_GET_ITEM(seq, i); + } +#else item = PySequence_Fast_GET_ITEM(seq, i); +#endif if (PyBytes_CheckExact(item)) { /* Fast path. */ buffers[i].obj = Py_NewRef(item);