Skip to content

gh-129068: allow concurrent iteration over range iterators #131921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
19 changes: 17 additions & 2 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,26 @@ Other objects

.. versionadded:: 3.3

``(items)`` (:class:`tuple`) [*matching-items*]
The object must be a Python sequence whose length is the number of format units
``(items)`` (sequence) [*matching-items*]
The object must be a Python sequence (except :class:`str`, :class:`bytes`
or :class:`bytearray`) whose length is the number of format units
in *items*. The C arguments must correspond to the individual format units in
*items*. Format units for sequences may be nested.

If *items* contains format units which store a :ref:`borrowed buffer
<c-arg-borrowed-buffer>` (``s``, ``s#``, ``z``, ``z#``, ``y``, or ``y#``)
or a :term:`borrowed reference` (``S``, ``Y``, ``U``, ``O``, or ``O!``),
the object must be a Python tuple.
The *converter* for the ``O&`` format unit in *items* must not store
a borrowed buffer or a borrowed reference.

.. versionchanged:: next
:class:`str` and :class:`bytearray` objects no longer accepted as a sequence.

.. deprecated:: next
Non-tuple sequences are deprecated if *items* contains format units
which store a borrowed buffer or a borrowed reference.

A few other characters have a meaning in a format string. These may not occur
inside nested parentheses. They are:

Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,13 @@ Deprecated
:c:macro:`!isfinite` available from :file:`math.h`
since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.)

* Non-tuple sequences are deprecated as argument for the ``(items)``
format unit in :c:func:`PyArg_ParseTuple` and other
:ref:`argument parsing <arg-parsing>` functions if *items* contains
format units which store a :ref:`borrowed buffer <c-arg-borrowed-buffer>`
or a :term:`borrowed reference`.
(Contributed by Serhiy Storchaka in :gh:`50333`.)

* The previously undocumented function :c:func:`PySequence_In` is :term:`soft deprecated`.
Use :c:func:`PySequence_Contains` instead.
(Contributed by Yuki Kobayashi in :gh:`127896`.)
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions Include/internal/pycore_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@ extern "C" {

typedef struct {
PyObject_HEAD
long start;
long step;
long len;
long end;
long step;
long stop;
} _PyRangeIterObject;

static inline long
_PyRangeIter_GetLengthAndStart(_PyRangeIterObject *r, long *value)
{
long len = FT_ATOMIC_LOAD_LONG_RELAXED(r->len);
*value = r->end - r->step * len;
return len;
}

static inline void
_PyRangeIter_SetLength(_PyRangeIterObject *r, long len)
{
FT_ATOMIC_STORE_LONG_RELAXED(r->len, len);
}

#ifdef __cplusplus
}
#endif
Expand Down
221 changes: 110 additions & 111 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading