Skip to content

Commit 5805959

Browse files
vstinnerencukou
andauthored
Apply batched suggestions from code review
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 3a02f71 commit 5805959

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎Doc/c-api/list.rst‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ created list.
248248

249249
A list builder object.
250250

251-
The API is **not thread safe**. To share a builder with multiple threads, a
252-
critical section or a lock is needed.
251+
The API is **not thread safe**. To share a builder with multiple threads,
252+
external synchronization is needed.
253253

254254
The instance must be destroyed by :c:func:`PyListBuilder_Finish` on
255255
success, or :c:func:`PyListBuilder_Discard` on error.
@@ -293,8 +293,8 @@ created list.
293293

294294
.. c:function:: int PyListBuilder_AppendSteal(PyListBuilder *builder, PyObject *item)
295295

296-
Similar to :c:func:`PyListBuilder_Append`, but :term:`steals <steal>` the
297-
reference to *item*, instead of creating a new :term:`strong reference`.
296+
Same as :c:func:`PyListBuilder_Append`, except this function
297+
:term:`steals <steal>` the reference to *item*.
298298

299299
.. c:function:: int PyListBuilder_Extend(PyListBuilder *builder, PyObject *iterable)
300300

@@ -305,7 +305,9 @@ created list.
305305
On error, set an exception, leave the builder unchanged, and return ``-1``.
306306

307307
If consuming *iterable* raises an exception, the builder is restored to its
308-
previous state: discard added items.
308+
previous state, that is, items added by a failed call are discarded.
309+
However, note that *iterable* is not reverted: items consumed from an
310+
iterator are not added back.
309311

310312
.. c:function:: int PyListBuilder_ExtendArray(PyListBuilder *builder, PyObject *const *items, Py_ssize_t nitem)
311313

@@ -317,12 +319,15 @@ created list.
317319

318320
*nitem* must not be negative.
319321

320-
If resizing the builder fails (memory allocation failure), the builder is
321-
restored to its previous state: discard added items.
322+
On failure, the builder is restored to its previous state. That is, items
323+
added by a failed call are discarded from the builder.
322324

323325
.. c:function:: int PyListBuilder_ExtendArraySteal(PyListBuilder *builder, PyObject *const *items, Py_ssize_t nitem)
324326

325-
Similar to :c:func:`PyListBuilder_ExtendArray`, but :term:`steal` references
326-
instead of copying references.
327+
Same as :c:func:`PyListBuilder_ExtendArray`, but :term:`steal` references
328+
instead of copying them.
327329

328-
On error, all *items* references are also cleared.
330+
The caller must hold a strong reference to each item in *item*.
331+
Both on success and on error, these references are transferred to the builder;
332+
the caller must not use them after the call.
333+
(To clarify: on error, the references are "lost".)

‎Doc/whatsnew/3.16.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,8 +1609,8 @@ New features
16091609

16101610
* Add a new :ref:`PyListBuilder <pylistbuilder>` C API to create a :class:`list`
16111611
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:
1612+
API to create a :class:`list`, because it can avoid locking the
1613+
list as it's being built. Add functions:
16141614

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

0 commit comments

Comments
 (0)