Skip to content

Commit cfcef79

Browse files
authored
Revise freethreading-stable-abi.rst for clarity
Updated the documentation to clarify the use of the stable ABI and GIL management in Python extensions, including changes to member access and initialization methods.
1 parent a91024a commit cfcef79

File tree

1 file changed

+4
-44
lines changed

1 file changed

+4
-44
lines changed

Doc/howto/freethreading-stable-abi.rst

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ do one of the following:
3232
- on other systems, use the headers of free-threaded build of Python.
3333

3434
``PyObject`` and ``PyVarObject`` opaqueness
35-
=======================
35+
===========================================
3636

3737
Accessing any member of ``PyObject`` directly is now prohibited, like the non-GIL
3838
stable ABI. For instance, prefer ``Py_TYPE()`` and ``Py_SET_TYPE()`` over ``ob_type``,
@@ -48,7 +48,7 @@ Extension modules need to explicitly indicate that they support running with
4848
the GIL disabled; otherwise importing the extension will raise a warning and
4949
enable the GIL at runtime.
5050

51-
Multi-phase and single-phase initialization is supported to indicate that an extension module
51+
Multi-phase and single-phase initialization is supported to indicate that an extension module
5252
targeting the stable ABI supports running with the GIL disabled, though the former is preferred.
5353

5454
Multi-Phase Initialization
@@ -72,7 +72,7 @@ you should guard the slot with a :c:data:`Py_GIL_DISABLED` check.
7272
{0, NULL}
7373
};
7474

75-
Additionally, using :c:macro:`PyABIInfo_VAR and :c:data:`Py_mod_abi` is recommended so that an
75+
Additionally, using ``PyABIInfo_VAR`` and ``Py_mod_abi`` is recommended so that an
7676
extension module loaded for an incompatible interpreter will trigger an exception, rather than
7777
fail with a crash.
7878

@@ -119,25 +119,6 @@ Containers like :c:struct:`PyListObject`,
119119
in the free-threaded build. For example, the :c:func:`PyList_Append` will
120120
lock the list before appending an item.
121121

122-
.. _PyDict_Next:
123-
124-
``PyDict_Next``
125-
'''''''''''''''
126-
127-
A notable exception is :c:func:`PyDict_Next`, which does not lock the
128-
dictionary. You should use :c:macro:`Py_BEGIN_CRITICAL_SECTION` to protect
129-
the dictionary while iterating over it if the dictionary may be concurrently
130-
modified::
131-
132-
Py_BEGIN_CRITICAL_SECTION(dict);
133-
PyObject *key, *value;
134-
Py_ssize_t pos = 0;
135-
while (PyDict_Next(dict, &pos, &key, &value)) {
136-
...
137-
}
138-
Py_END_CRITICAL_SECTION();
139-
140-
141122
Borrowed References
142123
===================
143124

@@ -190,26 +171,6 @@ Some of these functions were added in Python 3.13. You can use the
190171
to provide implementations of these functions for older Python versions.
191172

192173

193-
.. _free-threaded-memory-allocation:
194-
195-
Memory Allocation APIs
196-
======================
197-
198-
Python's memory management C API provides functions in three different
199-
:ref:`allocation domains <allocator-domains>`: "raw", "mem", and "object".
200-
For thread-safety, the free-threaded build requires that only Python objects
201-
are allocated using the object domain, and that all Python objects are
202-
allocated using that domain. This differs from the prior Python versions,
203-
where this was only a best practice and not a hard requirement.
204-
205-
.. note::
206-
207-
Search for uses of :c:func:`PyObject_Malloc` in your
208-
extension and check that the allocated memory is used for Python objects.
209-
Use :c:func:`PyMem_Malloc` to allocate buffers instead of
210-
:c:func:`PyObject_Malloc`.
211-
212-
213174
Thread State and GIL APIs
214175
=========================
215176

@@ -405,8 +366,7 @@ If you use
405366
your extension, a future version of ``setuptools`` will allow ``py_limited_api=True``
406367
to be set to allow targeting limited API when building with the free-threaded build.
407368

408-
Other build tools will support this ABI as well:
409-
`<https://packaging.python.org/en/latest/guides/tool-recommendations/#build-backends-for-extension-modules>`
369+
`Other build tools will support this ABI as well <https://packaging.python.org/en/latest/guides/tool-recommendations/#build-backends-for-extension-modules>`_.
410370

411371
.. seealso::
412372

0 commit comments

Comments
 (0)