Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
gh-129069: use atomic _PyList_GetItemRef in stringlib_bytes_join
part of TSAN-0013 in gh-153852
  • Loading branch information
xxyzz committed Jul 23, 2026
commit 786ad9f8418fc216aac1e52aeffeab0157005dff
1 change: 1 addition & 0 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions Objects/stringlib/join.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a new reference and leaks (below the refcount is additionally increased in :75 or :82).

test_bytes -R 3:3 fails on this.

}
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);
Expand Down
Loading