Skip to content

Commit 786ad9f

Browse files
committed
gh-129069: use atomic _PyList_GetItemRef in stringlib_bytes_join
part of TSAN-0013 in gh-153852
1 parent cb9567a commit 786ad9f

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Objects/bytearrayobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
1010
#include "pycore_strhex.h" // _Py_strhex_with_sep()
1111
#include "pycore_long.h" // _PyLong_FromUnsignedChar()
12+
#include "pycore_list.h" // _PyList_GetItemRef
1213
#include "pycore_pyatomic_ft_wrappers.h"
1314
#include "bytesobject.h"
1415

Objects/stringlib/join.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
6060
*/
6161
for (i = 0, nbufs = 0; i < seqlen; i++) {
6262
Py_ssize_t itemlen;
63+
#ifdef Py_GIL_DISABLED
64+
if (PyList_Check(seq)) {
65+
item = _PyList_GetItemRef((PyListObject *)seq, i);
66+
}
67+
else {
68+
item = PyTuple_GET_ITEM(seq, i);
69+
}
70+
#else
6371
item = PySequence_Fast_GET_ITEM(seq, i);
72+
#endif
6473
if (PyBytes_CheckExact(item)) {
6574
/* Fast path. */
6675
buffers[i].obj = Py_NewRef(item);

0 commit comments

Comments
 (0)