gh-117657: Fix TSAN list set failure (#118260)

* Fix TSAN list set failure

* Relaxed atomic is sufficient, add targetted test

* More list

* Remove atomic assign in list

* Fixup white space
This commit is contained in:
Dino Viehland 2024-05-02 13:03:05 -07:00 committed by GitHub
parent 8ed5466795
commit 1e67b9207c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 90 additions and 3 deletions

View file

@ -141,6 +141,9 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
target_bytes = allocated * sizeof(PyObject*);
}
memcpy(array->ob_item, self->ob_item, target_bytes);
}
if (new_allocated > (size_t)allocated) {
memset(array->ob_item + allocated, 0, sizeof(PyObject *) * (new_allocated - allocated));
}
_Py_atomic_store_ptr_release(&self->ob_item, &array->ob_item);
self->allocated = new_allocated;
@ -502,7 +505,7 @@ _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem)
Py_DECREF(newitem);
return -1;
}
PyList_SET_ITEM(self, len, newitem);
FT_ATOMIC_STORE_PTR_RELEASE(self->ob_item[len], newitem);
return 0;
}
@ -1181,7 +1184,7 @@ list_extend_fast(PyListObject *self, PyObject *iterable)
PyObject **dest = self->ob_item + m;
for (Py_ssize_t i = 0; i < n; i++) {
PyObject *o = src[i];
dest[i] = Py_NewRef(o);
FT_ATOMIC_STORE_PTR_RELEASE(dest[i], Py_NewRef(o));
}
return 0;
}
@ -1238,7 +1241,7 @@ list_extend_iter_lock_held(PyListObject *self, PyObject *iterable)
if (Py_SIZE(self) < self->allocated) {
Py_ssize_t len = Py_SIZE(self);
PyList_SET_ITEM(self, len, item); // steals item ref
FT_ATOMIC_STORE_PTR_RELEASE(self->ob_item[len], item); // steals item ref
Py_SET_SIZE(self, len + 1);
}
else {