Skip to content

Commit fad8dbf

Browse files
committed
Merge remote-tracking branch 'upstream/main' into gi_frame-type2
2 parents 99b8dbd + 65a12c5 commit fad8dbf

File tree

131 files changed

+5040
-2768
lines changed

Some content is hidden

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

131 files changed

+5040
-2768
lines changed

.readthedocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ build:
2626
exit 183;
2727
fi
2828
29+
- asdf plugin add uv
30+
- asdf install uv latest
31+
- asdf global uv latest
2932
- make -C Doc venv html
3033
- mkdir _readthedocs
3134
- mv Doc/build/html _readthedocs/html

Doc/Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ htmlview: html
152152

153153
.PHONY: ensure-sphinx-autobuild
154154
ensure-sphinx-autobuild: venv
155-
$(VENVDIR)/bin/sphinx-autobuild --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install sphinx-autobuild
155+
$(call ensure_package,sphinx-autobuild)
156156

157157
.PHONY: htmllive
158158
htmllive: SPHINXBUILD = $(VENVDIR)/bin/sphinx-autobuild
@@ -174,10 +174,15 @@ venv:
174174
echo "To recreate it, remove it first with \`make clean-venv'."; \
175175
else \
176176
echo "Creating venv in $(VENVDIR)"; \
177-
$(PYTHON) -m venv $(VENVDIR); \
178-
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
179-
$(VENVDIR)/bin/python3 -m pip install -r $(REQUIREMENTS); \
180-
echo "The venv has been created in the $(VENVDIR) directory"; \
177+
if uv --version > /dev/null; then \
178+
uv venv $(VENVDIR); \
179+
VIRTUAL_ENV=$(VENVDIR) uv pip install -r $(REQUIREMENTS); \
180+
else \
181+
$(PYTHON) -m venv $(VENVDIR); \
182+
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
183+
$(VENVDIR)/bin/python3 -m pip install -r $(REQUIREMENTS); \
184+
echo "The venv has been created in the $(VENVDIR) directory"; \
185+
fi; \
181186
fi
182187

183188
.PHONY: dist
@@ -235,9 +240,17 @@ dist:
235240
rm -r dist/python-$(DISTVERSION)-docs-texinfo
236241
rm dist/python-$(DISTVERSION)-docs-texinfo.tar
237242

243+
define ensure_package
244+
if uv --version > /dev/null; then \
245+
$(VENVDIR)/bin/python3 -m $(1) --version > /dev/null || VIRTUAL_ENV=$(VENVDIR) uv pip install $(1); \
246+
else \
247+
$(VENVDIR)/bin/python3 -m $(1) --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install $(1); \
248+
fi
249+
endef
250+
238251
.PHONY: check
239252
check: venv
240-
$(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit
253+
$(call ensure_package,pre_commit)
241254
$(VENVDIR)/bin/python3 -m pre_commit run --all-files
242255

243256
.PHONY: serve

Doc/c-api/init.rst

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,16 @@ Initializing and finalizing the interpreter
396396
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
397397
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
398398
allocated by the Python interpreter. This is a no-op when called for a second
399-
time (without calling :c:func:`Py_Initialize` again first). Normally the
400-
return value is ``0``. If there were errors during finalization
401-
(flushing buffered data), ``-1`` is returned.
399+
time (without calling :c:func:`Py_Initialize` again first).
400+
401+
Since this is the reverse of :c:func:`Py_Initialize`, it should be called
402+
in the same thread with the same interpreter active. That means
403+
the main thread and the main interpreter.
404+
This should never be called while :c:func:`Py_RunMain` is running.
405+
406+
Normally the return value is ``0``.
407+
If there were errors during finalization (flushing buffered data),
408+
``-1`` is returned.
402409
403410
This function is provided for a number of reasons. An embedding application
404411
might want to restart Python without having to restart the application itself.
@@ -2195,3 +2202,107 @@ The C-API provides a basic mutual exclusion lock.
21952202
issue a fatal error.
21962203
21972204
.. versionadded:: 3.13
2205+
2206+
.. _python-critical-section-api:
2207+
2208+
Python Critical Section API
2209+
---------------------------
2210+
2211+
The critical section API provides a deadlock avoidance layer on top of
2212+
per-object locks for :term:`free-threaded <free threading>` CPython. They are
2213+
intended to replace reliance on the :term:`global interpreter lock`, and are
2214+
no-ops in versions of Python with the global interpreter lock.
2215+
2216+
Critical sections avoid deadlocks by implicitly suspending active critical
2217+
sections and releasing the locks during calls to :c:func:`PyEval_SaveThread`.
2218+
When :c:func:`PyEval_RestoreThread` is called, the most recent critical section
2219+
is resumed, and its locks reacquired. This means the critical section API
2220+
provides weaker guarantees than traditional locks -- they are useful because
2221+
their behavior is similar to the :term:`GIL`.
2222+
2223+
The functions and structs used by the macros are exposed for cases
2224+
where C macros are not available. They should only be used as in the
2225+
given macro expansions. Note that the sizes and contents of the structures may
2226+
change in future Python versions.
2227+
2228+
.. note::
2229+
2230+
Operations that need to lock two objects at once must use
2231+
:c:macro:`Py_BEGIN_CRITICAL_SECTION2`. You *cannot* use nested critical
2232+
sections to lock more than one object at once, because the inner critical
2233+
section may suspend the outer critical sections. This API does not provide
2234+
a way to lock more than two objects at once.
2235+
2236+
Example usage::
2237+
2238+
static PyObject *
2239+
set_field(MyObject *self, PyObject *value)
2240+
{
2241+
Py_BEGIN_CRITICAL_SECTION(self);
2242+
Py_SETREF(self->field, Py_XNewRef(value));
2243+
Py_END_CRITICAL_SECTION();
2244+
Py_RETURN_NONE;
2245+
}
2246+
2247+
In the above example, :c:macro:`Py_SETREF` calls :c:macro:`Py_DECREF`, which
2248+
can call arbitrary code through an object's deallocation function. The critical
2249+
section API avoids potentital deadlocks due to reentrancy and lock ordering
2250+
by allowing the runtime to temporarily suspend the critical section if the
2251+
code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
2252+
2253+
.. c:macro:: Py_BEGIN_CRITICAL_SECTION(op)
2254+
2255+
Acquires the per-object lock for the object *op* and begins a
2256+
critical section.
2257+
2258+
In the free-threaded build, this macro expands to::
2259+
2260+
{
2261+
PyCriticalSection _py_cs;
2262+
PyCriticalSection_Begin(&_py_cs, (PyObject*)(op))
2263+
2264+
In the default build, this macro expands to ``{``.
2265+
2266+
.. versionadded:: 3.13
2267+
2268+
.. c:macro:: Py_END_CRITICAL_SECTION()
2269+
2270+
Ends the critical section and releases the per-object lock.
2271+
2272+
In the free-threaded build, this macro expands to::
2273+
2274+
PyCriticalSection_End(&_py_cs);
2275+
}
2276+
2277+
In the default build, this macro expands to ``}``.
2278+
2279+
.. versionadded:: 3.13
2280+
2281+
.. c:macro:: Py_BEGIN_CRITICAL_SECTION2(a, b)
2282+
2283+
Acquires the per-objects locks for the objects *a* and *b* and begins a
2284+
critical section. The locks are acquired in a consistent order (lowest
2285+
address first) to avoid lock ordering deadlocks.
2286+
2287+
In the free-threaded build, this macro expands to::
2288+
2289+
{
2290+
PyCriticalSection2 _py_cs2;
2291+
PyCriticalSection_Begin2(&_py_cs2, (PyObject*)(a), (PyObject*)(b))
2292+
2293+
In the default build, this macro expands to ``{``.
2294+
2295+
.. versionadded:: 3.13
2296+
2297+
.. c:macro:: Py_END_CRITICAL_SECTION2()
2298+
2299+
Ends the critical section and releases the per-object locks.
2300+
2301+
In the free-threaded build, this macro expands to::
2302+
2303+
PyCriticalSection_End2(&_py_cs2);
2304+
}
2305+
2306+
In the default build, this macro expands to ``}``.
2307+
2308+
.. versionadded:: 3.13

Doc/c-api/unicode.rst

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,9 +1551,17 @@ object.
15511551
On success, return ``0``.
15521552
On error, set an exception, leave the writer unchanged, and return ``-1``.
15531553
1554-
To use a different error handler than ``strict``,
1555-
:c:func:`PyUnicode_DecodeUTF8` can be used with
1556-
:c:func:`PyUnicodeWriter_WriteStr`.
1554+
See also :c:func:`PyUnicodeWriter_DecodeUTF8Stateful`.
1555+
1556+
.. c:function:: int PyUnicodeWriter_WriteWideChar(PyUnicodeWriter *writer, const wchar_t *str, Py_ssize_t size)
1557+
1558+
Writer the wide string *str* into *writer*.
1559+
1560+
*size* is a number of wide characters. If *size* is equal to ``-1``, call
1561+
``wcslen(str)`` to get the string length.
1562+
1563+
On success, return ``0``.
1564+
On error, set an exception, leave the writer unchanged, and return ``-1``.
15571565
15581566
.. c:function:: int PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
15591567
@@ -1586,3 +1594,24 @@ object.
15861594
15871595
On success, return ``0``.
15881596
On error, set an exception, leave the writer unchanged, and return ``-1``.
1597+
1598+
.. c:function:: int PyUnicodeWriter_DecodeUTF8Stateful(PyUnicodeWriter *writer, const char *string, Py_ssize_t length, const char *errors, Py_ssize_t *consumed)
1599+
1600+
Decode the string *str* from UTF-8 with *errors* error handler and write the
1601+
output into *writer*.
1602+
1603+
*size* is the string length in bytes. If *size* is equal to ``-1``, call
1604+
``strlen(str)`` to get the string length.
1605+
1606+
*errors* is an error handler name, such as ``"replace"``. If *errors* is
1607+
``NULL``, use the strict error handler.
1608+
1609+
If *consumed* is not ``NULL``, set *\*consumed* to the number of decoded
1610+
bytes on success.
1611+
If *consumed* is ``NULL``, treat trailing incomplete UTF-8 byte sequences
1612+
as an error.
1613+
1614+
On success, return ``0``.
1615+
On error, set an exception, leave the writer unchanged, and return ``-1``.
1616+
1617+
See also :c:func:`PyUnicodeWriter_WriteUTF8`.

Doc/library/asyncio-eventloop.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,14 @@ DNS
11551155

11561156
Asynchronous version of :meth:`socket.getnameinfo`.
11571157

1158+
.. note::
1159+
Both *getaddrinfo* and *getnameinfo* internally utilize their synchronous
1160+
versions through the loop's default thread pool executor.
1161+
When this executor is saturated, these methods may experience delays,
1162+
which higher-level networking libraries may report as increased timeouts.
1163+
To mitigate this, consider using a custom executor for other user tasks,
1164+
or setting a default executor with a larger number of workers.
1165+
11581166
.. versionchanged:: 3.7
11591167
Both *getaddrinfo* and *getnameinfo* methods were always documented
11601168
to return a coroutine, but prior to Python 3.7 they were, in fact,

Doc/library/asyncio-platforms.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ Subprocess Support on Windows
7777
On Windows, the default event loop :class:`ProactorEventLoop` supports
7878
subprocesses, whereas :class:`SelectorEventLoop` does not.
7979

80-
The :meth:`policy.set_child_watcher()
81-
<AbstractEventLoopPolicy.set_child_watcher>` function is also
82-
not supported, as :class:`ProactorEventLoop` has a different mechanism
83-
to watch child processes.
84-
8580

8681
macOS
8782
=====

0 commit comments

Comments
 (0)