Skip to content

Commit 105d4e6

Browse files
authored
Merge branch 'main' into thread_name_fix
2 parents d5e9399 + 5ae8b97 commit 105d4e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1262
-602
lines changed

.github/CODEOWNERS

Lines changed: 532 additions & 291 deletions
Large diffs are not rendered by default.

Doc/c-api/dict.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ Dictionary Objects
301301
}
302302
Py_END_CRITICAL_SECTION();
303303
304+
.. note::
305+
306+
On the free-threaded build, this function can be used safely inside a
307+
critical section. However, the references returned for *pkey* and *pvalue*
308+
are :term:`borrowed <borrowed reference>` and are only valid while the
309+
critical section is held. If you need to use these objects outside the
310+
critical section or when the critical section can be suspended, create a
311+
:term:`strong reference <strong reference>` (for example, using
312+
:c:func:`Py_NewRef`).
304313
305314
.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)
306315

Doc/c-api/init.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,12 +2299,20 @@ per-object locks for :term:`free-threaded <free threading>` CPython. They are
22992299
intended to replace reliance on the :term:`global interpreter lock`, and are
23002300
no-ops in versions of Python with the global interpreter lock.
23012301
2302+
Critical sections are intended to be used for custom types implemented
2303+
in C-API extensions. They should generally not be used with built-in types like
2304+
:class:`list` and :class:`dict` because their public C-APIs
2305+
already use critical sections internally, with the notable
2306+
exception of :c:func:`PyDict_Next`, which requires critical section
2307+
to be acquired externally.
2308+
23022309
Critical sections avoid deadlocks by implicitly suspending active critical
2303-
sections and releasing the locks during calls to :c:func:`PyEval_SaveThread`.
2304-
When :c:func:`PyEval_RestoreThread` is called, the most recent critical section
2305-
is resumed, and its locks reacquired. This means the critical section API
2306-
provides weaker guarantees than traditional locks -- they are useful because
2307-
their behavior is similar to the :term:`GIL`.
2310+
sections, hence, they do not provide exclusive access such as provided by
2311+
traditional locks like :c:type:`PyMutex`. When a critical section is started,
2312+
the per-object lock for the object is acquired. If the code executed inside the
2313+
critical section calls C-API functions then it can suspend the critical section thereby
2314+
releasing the per-object lock, so other threads can acquire the per-object lock
2315+
for the same object.
23082316
23092317
Variants that accept :c:type:`PyMutex` pointers rather than Python objects are also
23102318
available. Use these variants to start a critical section in a situation where

Doc/c-api/typeobj.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,19 @@ and :c:data:`PyType_Type` effectively act as defaults.)
12861286
:c:member:`~PyTypeObject.tp_weaklistoffset` field is set in a superclass.
12871287

12881288

1289+
.. c:macro:: Py_TPFLAGS_PREHEADER
1290+
1291+
These bits indicate that the VM will manage some fields by storing them
1292+
before the object. Currently, this macro is equivalent to
1293+
:c:expr:`Py_TPFLAGS_MANAGED_DICT | Py_TPFLAGS_MANAGED_WEAKREF`.
1294+
1295+
This macro value relies on the implementation of the VM, so its value is not
1296+
stable and may change in a future version. Prefer using individual
1297+
flags instead.
1298+
1299+
.. versionadded:: 3.12
1300+
1301+
12891302
.. c:macro:: Py_TPFLAGS_ITEMS_AT_END
12901303
12911304
Only usable with variable-size types, i.e. ones with non-zero

Doc/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Glossary
107107
statements.
108108

109109
asynchronous generator iterator
110-
An object created by a :term:`asynchronous generator` function.
110+
An object created by an :term:`asynchronous generator` function.
111111

112112
This is an :term:`asynchronous iterator` which when called using the
113113
:meth:`~object.__anext__` method returns an awaitable object which will execute

0 commit comments

Comments
 (0)