From 5fcd11dab96c251d9c4988b161b63be1aa53ed41 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Thu, 2 Jan 2025 13:34:37 -0700 Subject: [PATCH 1/2] gh-128426: Mention PySequence_Fast in free-threading C API HOWTO --- Doc/howto/free-threading-extensions.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/howto/free-threading-extensions.rst b/Doc/howto/free-threading-extensions.rst index c1ad42e7e55ee5..3ad274b083d2cf 100644 --- a/Doc/howto/free-threading-extensions.rst +++ b/Doc/howto/free-threading-extensions.rst @@ -99,7 +99,8 @@ Most of the C API is thread-safe, but there are some exceptions. * **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM` and :c:macro:`PyList_SET_ITEM` do not perform any error checking or locking. These macros are not thread-safe if the container object may be modified - concurrently. + concurrently. Similarly, using the object returned by + :c:func:`PySequence_Fast` concurrently is not thread-safe. * **Borrowed References**: C API functions that return :term:`borrowed references ` may not be thread-safe if the containing object is modified concurrently. See the section on From f5e706f8b61a6c2a00f01929f336dae3174e0bdc Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Thu, 2 Jan 2025 14:31:42 -0700 Subject: [PATCH 2/2] reword --- Doc/howto/free-threading-extensions.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/howto/free-threading-extensions.rst b/Doc/howto/free-threading-extensions.rst index 3ad274b083d2cf..95f214179bfb0e 100644 --- a/Doc/howto/free-threading-extensions.rst +++ b/Doc/howto/free-threading-extensions.rst @@ -96,11 +96,12 @@ Most of the C API is thread-safe, but there are some exceptions. * **Struct Fields**: Accessing fields in Python C API objects or structs directly is not thread-safe if the field may be concurrently modified. -* **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM` and - :c:macro:`PyList_SET_ITEM` do not perform any error checking or locking. +* **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM`, + :c:macro:`PyList_SET_ITEM`, and macros like + :c:macro:`PySequence_Fast_GET_SIZE` that use the object returned by + :c:func:`PySequence_Fast` do not perform any error checking or locking. These macros are not thread-safe if the container object may be modified - concurrently. Similarly, using the object returned by - :c:func:`PySequence_Fast` concurrently is not thread-safe. + concurrently. * **Borrowed References**: C API functions that return :term:`borrowed references ` may not be thread-safe if the containing object is modified concurrently. See the section on