From b4a422ed36e7c285f443647777c091e0ccd78443 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 2 Nov 2026 16:26:54 +0100 Subject: [PATCH] Fix a compiler warning in py_list_resize() Fix a compiler warning when Python is built with the GIL (default) and without C assertions (in release mode). Fix the warning: Objects/listobject.c: In function 'py_list_resize': Objects/listobject.c:140:16: warning: unused variable 'allocated' [-Wunused-variable] 140 | Py_ssize_t allocated = self->allocated; --- Objects/listobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 063830c68688990..6de6b864df45559 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -137,7 +137,6 @@ static int py_list_resize(PyListObject *self, Py_ssize_t newsize) { size_t new_allocated, target_bytes; - Py_ssize_t allocated = self->allocated; /* This over-allocates proportional to the list size, making room * for additional growth. The over-allocation is mild, but is @@ -159,11 +158,12 @@ py_list_resize(PyListObject *self, Py_ssize_t newsize) if (newsize == 0) new_allocated = 0; - assert(newsize > allocated || new_allocated < (size_t)allocated); + assert(newsize > self->allocated || new_allocated < (size_t)self->allocated); ensure_shared_on_resize(self); #ifdef Py_GIL_DISABLED + Py_ssize_t allocated = self->allocated; _PyListArray *array = list_allocate_array(new_allocated); if (array == NULL) { PyErr_NoMemory();