Skip to content

Commit 3a02f71

Browse files
committed
Finish() always calls list_resize()
Replace also "On Free Threading" with "On the free-threaded build".
1 parent 4d48166 commit 3a02f71

4 files changed

Lines changed: 12 additions & 18 deletions

File tree

‎Doc/c-api/list.rst‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ PyListBuilder
237237
The :c:type:`PyListBuilder` API can be used to create a Python :class:`list`
238238
object.
239239
240-
On Free Threading, it's more efficient than the ``PyList`` C API to create a
241-
:class:`list`, because it can avoid the critical section on the created list.
240+
On the free-threaded build, it's more efficient than the ``PyList`` C API to
241+
create a :class:`list`, because it can avoid the critical section on the
242+
created list.
242243
243244
.. versionadded:: next
244245

‎Doc/whatsnew/3.16.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,9 +1608,9 @@ New features
16081608
(Contributed by Victor Stinner in :gh:`148233`.)
16091609

16101610
* Add a new :ref:`PyListBuilder <pylistbuilder>` C API to create a :class:`list`
1611-
object. On Free Threading, it's more efficient than the ``PyList`` C API to
1612-
create a :class:`list`, because it can avoid the critical section on the
1613-
created list. Add functions:
1611+
object. On the free-threaded build, it's more efficient than the ``PyList`` C
1612+
API to create a :class:`list`, because it can avoid the critical section on
1613+
the created list. Add functions:
16141614

16151615
* :c:func:`PyListBuilder_Create`
16161616
* :c:func:`PyListBuilder_Finish`

‎Misc/NEWS.d/next/C_API/2026-10-21-16-35-42.gh-issue-158660.KvixNp.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Add a new :ref:`PyListBuilder <pylistbuilder>` C API to create a :class:`list`
2-
object. On Free Threading, it's more efficient than the ``PyList`` C API to
3-
create a :class:`list`, because it can avoid the critical section on the
2+
object. On the free-threaded build, it's more efficient than the ``PyList`` C
3+
API to create a :class:`list`, because it can avoid the critical section on the
44
created list. Add functions:
55

66
* :c:func:`PyListBuilder_Create`

‎Objects/listobject.c‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4493,17 +4493,10 @@ PyListBuilder_Finish(PyListBuilder *builder)
44934493
// Shrink the list if the allocated size is greater than the double size.
44944494
// For example, if PyListBuilder_Create() argument overestimated the final
44954495
// size.
4496-
if (Py_SIZE(list) < (list->allocated >> 1)
4497-
&& list->allocated > LIST_SMALL_ALLOCATED)
4498-
{
4499-
if (list_resize(list, Py_SIZE(list)) < 0) {
4500-
// This case cannot happen: list_resize() never fails when
4501-
// shrinking
4502-
PyListBuilder_Discard(builder);
4503-
return NULL;
4504-
}
4505-
// Note: cannot test that list->allocated changed in debug mode, since
4506-
// it's left unchanged on memory allocation failure.
4496+
if (list_resize(list, Py_SIZE(list)) < 0) {
4497+
// This case cannot happen: list_resize() never fails when shrinking
4498+
PyListBuilder_Discard(builder);
4499+
return NULL;
45074500
}
45084501

45094502
#if _PyListBuilder_INIT_ITEMS

0 commit comments

Comments
 (0)