Skip to content

Commit d34adeb

Browse files
committed
Merge branch 'main' into pythongh-115999-thread-local-bytecode
2 parents 8b97771 + b1d6f8a commit d34adeb

File tree

155 files changed

+25228
-22007
lines changed

Some content is hidden

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

155 files changed

+25228
-22007
lines changed

.gitattributes

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Lib/test/cjkencodings/* noeol
2727
Lib/test/tokenizedata/coding20731.py noeol
2828
Lib/test/decimaltestdata/*.decTest noeol
2929
Lib/test/test_email/data/*.txt noeol
30-
Lib/test/test_importlib/resources/data01/* noeol
31-
Lib/test/test_importlib/resources/namespacedata01/* noeol
3230
Lib/test/xmltestdata/* noeol
3331

3432
# Shell scripts should have LF even on Windows because of Cygwin

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.3.4
3+
rev: v0.4.10
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/
@@ -20,15 +20,15 @@ repos:
2020
files: ^Doc/
2121

2222
- repo: https://github.com/psf/black-pre-commit-mirror
23-
rev: 24.4.2
23+
rev: 24.8.0
2424
hooks:
2525
- id: black
2626
name: Run Black on Tools/jit/
2727
files: ^Tools/jit/
2828
language_version: python3.12
2929

3030
- repo: https://github.com/pre-commit/pre-commit-hooks
31-
rev: v4.5.0
31+
rev: v4.6.0
3232
hooks:
3333
- id: check-case-conflict
3434
- id: check-merge-conflict
@@ -42,7 +42,7 @@ repos:
4242
types_or: [c, inc, python, rst]
4343

4444
- repo: https://github.com/sphinx-contrib/sphinx-lint
45-
rev: v0.9.1
45+
rev: v1.0.0
4646
hooks:
4747
- id: sphinx-lint
4848
args: [--enable=default-role]

Android/README.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ approachable user experience:
1212

1313
## Prerequisites
1414

15-
Export the `ANDROID_HOME` environment variable to point at your Android SDK. If
16-
you don't already have the SDK, here's how to install it:
15+
First, make sure you have all the usual tools and libraries needed to build
16+
Python for your development machine.
17+
18+
Second, you'll need an Android SDK. If you already have the SDK installed,
19+
export the `ANDROID_HOME` environment variable to point at its location.
20+
Otherwise, here's how to install it:
1721

1822
* Download the "Command line tools" from <https://developer.android.com/studio>.
1923
* Create a directory `android-sdk/cmdline-tools`, and unzip the command line
@@ -37,11 +41,6 @@ development tools, which currently means Linux or macOS. This involves doing a
3741
cross-build where you use a "build" Python (for your development machine) to
3842
help produce a "host" Python for Android.
3943

40-
First, make sure you have all the usual tools and libraries needed to build
41-
Python for your development machine. The only Android tool you need to install
42-
is the command line tools package above: the build script will download the
43-
rest.
44-
4544
The easiest way to do a build is to use the `android.py` script. You can either
4645
have it perform the entire build process from start to finish in one step, or
4746
you can do it in discrete steps that mirror running `configure` and `make` for
@@ -80,12 +79,15 @@ call. For example, if you want a pydebug build that also caches the results from
8079

8180
## Testing
8281

83-
The tests can be run on Linux, macOS, or Windows, although on Windows you'll
84-
have to build the `cross-build/HOST` subdirectory on one of the other platforms
85-
and copy it over.
82+
The test suite can be run on Linux, macOS, or Windows:
83+
84+
* On Linux, the emulator needs access to the KVM virtualization interface, and
85+
a DISPLAY environment variable pointing at an X server.
86+
* On Windows, you won't be able to do the build on the same machine, so you'll
87+
have to copy the `cross-build/HOST` directory from somewhere else.
8688

87-
The test suite can usually be run on a device with 2 GB of RAM, though for some
88-
configurations or test orders you may need to increase this. As of Android
89+
The test suite can usually be run on a device with 2 GB of RAM, but this is
90+
borderline, so you may need to increase it to 4 GB. As of Android
8991
Studio Koala, 2 GB is the default for all emulators, although the user interface
9092
may indicate otherwise. The effective setting is `hw.ramSize` in
9193
~/.android/avd/*.avd/hardware-qemu.ini, whereas Android Studio displays the

Android/android.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ def setup_testbed():
259259
f"{temp_dir}/{outer_jar}", "gradle-wrapper.jar"])
260260

261261

262-
# run_testbed will build the app automatically, but it hides the Gradle output
263-
# by default, so it's useful to have this as a separate command for the buildbot.
262+
# run_testbed will build the app automatically, but it's useful to have this as
263+
# a separate command to allow running the app outside of this script.
264264
def build_testbed(context):
265265
setup_sdk()
266266
setup_testbed()
@@ -376,6 +376,8 @@ async def find_pid(serial):
376376
shown_error = False
377377
while True:
378378
try:
379+
# `pidof` requires API level 24 or higher. The level 23 emulator
380+
# includes it, but it doesn't work (it returns all processes).
379381
pid = (await async_check_output(
380382
adb, "-s", serial, "shell", "pidof", "-s", APP_ID
381383
)).strip()
@@ -407,6 +409,7 @@ async def logcat_task(context, initial_devices):
407409
serial = await wait_for(find_device(context, initial_devices), startup_timeout)
408410
pid = await wait_for(find_pid(serial), startup_timeout)
409411

412+
# `--pid` requires API level 24 or higher.
410413
args = [adb, "-s", serial, "logcat", "--pid", pid, "--format", "tag"]
411414
hidden_output = []
412415
async with async_process(
@@ -421,11 +424,15 @@ async def logcat_task(context, initial_devices):
421424
# such messages, but other components might.
422425
level, message = None, line
423426

427+
# Exclude high-volume messages which are rarely useful.
428+
if context.verbose < 2 and "from python test_syslog" in message:
429+
continue
430+
424431
# Put high-level messages on stderr so they're highlighted in the
425432
# buildbot logs. This will include Python's own stderr.
426433
stream = (
427434
sys.stderr
428-
if level in ["E", "F"] # ERROR and FATAL (aka ASSERT)
435+
if level in ["W", "E", "F"] # WARNING, ERROR, FATAL (aka ASSERT)
429436
else sys.stdout
430437
)
431438

@@ -573,8 +580,9 @@ def parse_args():
573580
test = subcommands.add_parser(
574581
"test", help="Run the test suite")
575582
test.add_argument(
576-
"-v", "--verbose", action="store_true",
577-
help="Show Gradle output, and non-Python logcat messages")
583+
"-v", "--verbose", action="count", default=0,
584+
help="Show Gradle output, and non-Python logcat messages. "
585+
"Use twice to include high-volume messages which are rarely useful.")
578586
device_group = test.add_mutually_exclusive_group(required=True)
579587
device_group.add_argument(
580588
"--connected", metavar="SERIAL", help="Run on a connected device. "
@@ -591,6 +599,13 @@ def parse_args():
591599

592600
def main():
593601
install_signal_handler()
602+
603+
# Under the buildbot, stdout is not a TTY, but we must still flush after
604+
# every line to make sure our output appears in the correct order relative
605+
# to the output of our subprocesses.
606+
for stream in [sys.stdout, sys.stderr]:
607+
stream.reconfigure(line_buffering=True)
608+
594609
context = parse_args()
595610
dispatch = {"configure-build": configure_build_python,
596611
"make-build": make_build_python,

Android/testbed/app/src/main/python/main.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@
55
import sys
66

77
# Some tests use SIGUSR1, but that's blocked by default in an Android app in
8-
# order to make it available to `sigwait` in the "Signal Catcher" thread. That
9-
# thread's functionality is only relevant to the JVM ("forcing GC (no HPROF) and
10-
# profile save"), so disabling it should not weaken the tests.
8+
# order to make it available to `sigwait` in the Signal Catcher thread.
9+
# (https://cs.android.com/android/platform/superproject/+/android14-qpr3-release:art/runtime/signal_catcher.cc).
10+
# That thread's functionality is only useful for debugging the JVM, so disabling
11+
# it should not weaken the tests.
12+
#
13+
# There's no safe way of stopping the thread completely (#123982), but simply
14+
# unblocking SIGUSR1 is enough to fix most tests.
15+
#
16+
# However, in tests that generate multiple different signals in quick
17+
# succession, it's possible for SIGUSR1 to arrive while the main thread is busy
18+
# running the C-level handler for a different signal. In that case, the SIGUSR1
19+
# may be sent to the Signal Catcher thread instead, which will generate a log
20+
# message containing the text "reacting to signal".
21+
#
22+
# Such tests may need to be changed in one of the following ways:
23+
# * Use a signal other than SIGUSR1 (e.g. test_stress_delivery_simultaneous in
24+
# test_signal.py).
25+
# * Send the signal to a specific thread rather than the whole process (e.g.
26+
# test_signals in test_threadsignals.py.
1127
signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGUSR1])
1228

1329
sys.argv[1:] = shlex.split(os.environ["PYTHON_ARGS"])

Doc/Makefile

-10
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,6 @@ dist:
222222
cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
223223
@echo "Build finished and archived!"
224224

225-
# archive the letter latex
226-
@echo "Building LaTeX (US paper)..."
227-
rm -rf build/latex
228-
$(MAKE) latex PAPER=letter
229-
-sed -i 's/: all-$$(FMT)/:/' build/latex/Makefile
230-
(cd build/latex; $(MAKE) clean && $(MAKE) --jobs=$$((`nproc`+1)) --output-sync LATEXMKOPTS='-quiet' all-pdf && $(MAKE) FMT=pdf zip bz2)
231-
cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip
232-
cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2
233-
@echo "Build finished and archived!"
234-
235225
# copy the epub build
236226
@echo "Building EPUB..."
237227
rm -rf build/epub

Doc/c-api/memory.rst

+22-12
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,38 @@ All allocating functions belong to one of three different "domains" (see also
102102
strategies and are optimized for different purposes. The specific details on
103103
how every domain allocates memory or what internal functions each domain calls
104104
is considered an implementation detail, but for debugging purposes a simplified
105-
table can be found at :ref:`here <default-memory-allocators>`. There is no hard
106-
requirement to use the memory returned by the allocation functions belonging to
107-
a given domain for only the purposes hinted by that domain (although this is the
108-
recommended practice). For example, one could use the memory returned by
109-
:c:func:`PyMem_RawMalloc` for allocating Python objects or the memory returned
110-
by :c:func:`PyObject_Malloc` for allocating memory for buffers.
105+
table can be found at :ref:`here <default-memory-allocators>`.
106+
The APIs used to allocate and free a block of memory must be from the same domain.
107+
For example, :c:func:`PyMem_Free` must be used to free memory allocated using :c:func:`PyMem_Malloc`.
111108

112109
The three allocation domains are:
113110

114111
* Raw domain: intended for allocating memory for general-purpose memory
115112
buffers where the allocation *must* go to the system allocator or where the
116113
allocator can operate without the :term:`GIL`. The memory is requested directly
117-
to the system.
114+
from the system. See :ref:`Raw Memory Interface <raw-memoryinterface>`.
118115

119116
* "Mem" domain: intended for allocating memory for Python buffers and
120117
general-purpose memory buffers where the allocation must be performed with
121118
the :term:`GIL` held. The memory is taken from the Python private heap.
119+
See :ref:`Memory Interface <memoryinterface>`.
122120

123-
* Object domain: intended for allocating memory belonging to Python objects. The
124-
memory is taken from the Python private heap.
121+
* Object domain: intended for allocating memory for Python objects. The
122+
memory is taken from the Python private heap. See :ref:`Object allocators <objectinterface>`.
125123

126-
When freeing memory previously allocated by the allocating functions belonging to a
127-
given domain,the matching specific deallocating functions must be used. For example,
128-
:c:func:`PyMem_Free` must be used to free memory allocated using :c:func:`PyMem_Malloc`.
124+
.. note::
125+
126+
The :term:`free-threaded <free threading>` build requires that only Python objects are allocated using the "object" domain
127+
and that all Python objects are allocated using that domain. This differs from the prior Python versions,
128+
where this was only a best practice and not a hard requirement.
129+
130+
For example, buffers (non-Python objects) should be allocated using :c:func:`PyMem_Malloc`,
131+
:c:func:`PyMem_RawMalloc`, or :c:func:`malloc`, but not :c:func:`PyObject_Malloc`.
132+
133+
See :ref:`Memory Allocation APIs <free-threaded-memory-allocation>`.
134+
135+
136+
.. _raw-memoryinterface:
129137

130138
Raw Memory Interface
131139
====================
@@ -299,6 +307,8 @@ versions and is therefore deprecated in extension modules.
299307
* ``PyMem_DEL(ptr)``
300308
301309
310+
.. _objectinterface:
311+
302312
Object allocators
303313
=================
304314

Doc/c-api/type.rst

+27-13
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,12 @@ The following functions and structs are used to create
345345
The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*.
346346
which may result in incomplete initialization.
347347
Creating classes whose metaclass overrides
348-
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
349-
will be no longer allowed.
348+
:c:member:`~PyTypeObject.tp_new` is deprecated.
349+
350+
.. versionchanged:: 3.14
351+
352+
Creating classes whose metaclass overrides
353+
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
350354
351355
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
352356
@@ -362,8 +366,12 @@ The following functions and structs are used to create
362366
The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*.
363367
which may result in incomplete initialization.
364368
Creating classes whose metaclass overrides
365-
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
366-
will be no longer allowed.
369+
:c:member:`~PyTypeObject.tp_new` is deprecated.
370+
371+
.. versionchanged:: 3.14
372+
373+
Creating classes whose metaclass overrides
374+
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
367375
368376
.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
369377
@@ -378,8 +386,12 @@ The following functions and structs are used to create
378386
The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*.
379387
which may result in incomplete initialization.
380388
Creating classes whose metaclass overrides
381-
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
382-
will be no longer allowed.
389+
:c:member:`~PyTypeObject.tp_new` is deprecated.
390+
391+
.. versionchanged:: 3.14
392+
393+
Creating classes whose metaclass overrides
394+
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
383395
384396
.. raw:: html
385397
@@ -492,14 +504,10 @@ The following functions and structs are used to create
492504
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
493505
for details.
494506
495-
The following fields cannot be set at all when creating a heap type:
507+
The following internal fields cannot be set at all when creating a heap
508+
type:
496509
497-
* :c:member:`~PyTypeObject.tp_vectorcall`
498-
(use :c:member:`~PyTypeObject.tp_new` and/or
499-
:c:member:`~PyTypeObject.tp_init`)
500-
501-
* Internal fields:
502-
:c:member:`~PyTypeObject.tp_dict`,
510+
* :c:member:`~PyTypeObject.tp_dict`,
503511
:c:member:`~PyTypeObject.tp_mro`,
504512
:c:member:`~PyTypeObject.tp_cache`,
505513
:c:member:`~PyTypeObject.tp_subclasses`, and
@@ -519,6 +527,12 @@ The following functions and structs are used to create
519527
:c:member:`~PyBufferProcs.bf_releasebuffer` are now available
520528
under the :ref:`limited API <limited-c-api>`.
521529
530+
.. versionchanged:: 3.14
531+
532+
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
533+
using ``Py_tp_vectorcall``. See the field's documentation
534+
for details.
535+
522536
.. c:member:: void *pfunc
523537
524538
The desired value of the slot. In most cases, this is a pointer

Doc/c-api/typeobj.rst

+34-5
Original file line numberDiff line numberDiff line change
@@ -2137,11 +2137,40 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21372137

21382138
.. c:member:: vectorcallfunc PyTypeObject.tp_vectorcall
21392139
2140-
Vectorcall function to use for calls of this type object.
2141-
In other words, it is used to implement
2142-
:ref:`vectorcall <vectorcall>` for ``type.__call__``.
2143-
If ``tp_vectorcall`` is ``NULL``, the default call implementation
2144-
using :meth:`~object.__new__` and :meth:`~object.__init__` is used.
2140+
A :ref:`vectorcall function <vectorcall>` to use for calls of this type
2141+
object (rather than instances).
2142+
In other words, ``tp_vectorcall`` can be used to optimize ``type.__call__``,
2143+
which typically returns a new instance of *type*.
2144+
2145+
As with any vectorcall function, if ``tp_vectorcall`` is ``NULL``,
2146+
the *tp_call* protocol (``Py_TYPE(type)->tp_call``) is used instead.
2147+
2148+
.. note::
2149+
2150+
The :ref:`vectorcall protocol <vectorcall>` requires that the vectorcall
2151+
function has the same behavior as the corresponding ``tp_call``.
2152+
This means that ``type->tp_vectorcall`` must match the behavior of
2153+
``Py_TYPE(type)->tp_call``.
2154+
2155+
Specifically, if *type* uses the default metaclass,
2156+
``type->tp_vectorcall`` must behave the same as
2157+
:c:expr:`PyType_Type->tp_call`, which:
2158+
2159+
- calls ``type->tp_new``,
2160+
2161+
- if the result is a subclass of *type*, calls ``type->tp_init``
2162+
on the result of ``tp_new``, and
2163+
2164+
- returns the result of ``tp_new``.
2165+
2166+
Typically, ``tp_vectorcall`` is overridden to optimize this process
2167+
for specific :c:member:`~PyTypeObject.tp_new` and
2168+
:c:member:`~PyTypeObject.tp_init`.
2169+
When doing this for user-subclassable types, note that both can be
2170+
overridden (using :py:func:`~object.__new__` and
2171+
:py:func:`~object.__init__`, respectively).
2172+
2173+
21452174

21462175
**Inheritance:**
21472176

0 commit comments

Comments
 (0)