Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a race in ``list.__sizeof__()`` when a list is concurrently resized on a free-threaded build.
4 changes: 3 additions & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
py_list_resize(PyListObject *self, Py_ssize_t newsize)
{
size_t new_allocated, target_bytes;
Py_ssize_t allocated = self->allocated;

Check warning on line 140 in Objects/listobject.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

unused variable ‘allocated’ [-Wunused-variable]

Check warning on line 140 in Objects/listobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-26.04)

unused variable ‘allocated’ [-Wunused-variable]

Check warning on line 140 in Objects/listobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (installed) / build, install and test

unused variable ‘allocated’ [-Wunused-variable]

/* This over-allocates proportional to the list size, making room
* for additional growth. The over-allocation is mild, but is
Expand Down Expand Up @@ -3560,10 +3560,12 @@
{
size_t res = _PyObject_SIZE(Py_TYPE(self));
#ifdef Py_GIL_DISABLED
PyObject **ob_item = _Py_atomic_load_ptr(&self->ob_item);
Py_BEGIN_CRITICAL_SECTION(self);
PyObject **ob_item = self->ob_item;
if (ob_item != NULL) {
res += list_capacity(ob_item) * sizeof(PyObject *);
}
Py_END_CRITICAL_SECTION();
#else
res += (size_t)self->allocated * sizeof(PyObject *);
#endif
Expand Down
Loading