Skip to content

Commit

Permalink
Merge branch 'main' into syntax-error
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel authored Sep 16, 2024
2 parents 763b250 + ef530ce commit 167a67c
Show file tree
Hide file tree
Showing 144 changed files with 24,360 additions and 21,745 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Lib/test/cjkencodings/* noeol
Lib/test/tokenizedata/coding20731.py noeol
Lib/test/decimaltestdata/*.decTest noeol
Lib/test/test_email/data/*.txt noeol
Lib/test/test_importlib/resources/data01/* noeol
Lib/test/test_importlib/resources/namespacedata01/* noeol
Lib/test/xmltestdata/* noeol

# Shell scripts should have LF even on Windows because of Cygwin
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Objects/frameobject.c @markshannon
Objects/call.c @markshannon
Python/ceval*.c @markshannon
Python/ceval*.h @markshannon
Python/codegen.c @markshannon @iritkatriel
Python/compile.c @markshannon @iritkatriel
Python/assemble.c @markshannon @iritkatriel
Python/flowgraph.c @markshannon @iritkatriel
Expand Down
26 changes: 14 additions & 12 deletions Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ approachable user experience:

## Prerequisites

Export the `ANDROID_HOME` environment variable to point at your Android SDK. If
you don't already have the SDK, here's how to install it:
First, make sure you have all the usual tools and libraries needed to build
Python for your development machine.

Second, you'll need an Android SDK. If you already have the SDK installed,
export the `ANDROID_HOME` environment variable to point at its location.
Otherwise, here's how to install it:

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

First, make sure you have all the usual tools and libraries needed to build
Python for your development machine. The only Android tool you need to install
is the command line tools package above: the build script will download the
rest.

The easiest way to do a build is to use the `android.py` script. You can either
have it perform the entire build process from start to finish in one step, or
you can do it in discrete steps that mirror running `configure` and `make` for
Expand Down Expand Up @@ -80,12 +79,15 @@ call. For example, if you want a pydebug build that also caches the results from

## Testing

The tests can be run on Linux, macOS, or Windows, although on Windows you'll
have to build the `cross-build/HOST` subdirectory on one of the other platforms
and copy it over.
The test suite can be run on Linux, macOS, or Windows:

* On Linux, the emulator needs access to the KVM virtualization interface, and
a DISPLAY environment variable pointing at an X server.
* On Windows, you won't be able to do the build on the same machine, so you'll
have to copy the `cross-build/HOST` directory from somewhere else.

The test suite can usually be run on a device with 2 GB of RAM, though for some
configurations or test orders you may need to increase this. As of Android
The test suite can usually be run on a device with 2 GB of RAM, but this is
borderline, so you may need to increase it to 4 GB. As of Android
Studio Koala, 2 GB is the default for all emulators, although the user interface
may indicate otherwise. The effective setting is `hw.ramSize` in
~/.android/avd/*.avd/hardware-qemu.ini, whereas Android Studio displays the
Expand Down
25 changes: 20 additions & 5 deletions Android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def setup_testbed():
f"{temp_dir}/{outer_jar}", "gradle-wrapper.jar"])


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

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

# Exclude high-volume messages which are rarely useful.
if context.verbose < 2 and "from python test_syslog" in message:
continue

# Put high-level messages on stderr so they're highlighted in the
# buildbot logs. This will include Python's own stderr.
stream = (
sys.stderr
if level in ["E", "F"] # ERROR and FATAL (aka ASSERT)
if level in ["W", "E", "F"] # WARNING, ERROR, FATAL (aka ASSERT)
else sys.stdout
)

Expand Down Expand Up @@ -573,8 +580,9 @@ def parse_args():
test = subcommands.add_parser(
"test", help="Run the test suite")
test.add_argument(
"-v", "--verbose", action="store_true",
help="Show Gradle output, and non-Python logcat messages")
"-v", "--verbose", action="count", default=0,
help="Show Gradle output, and non-Python logcat messages. "
"Use twice to include high-volume messages which are rarely useful.")
device_group = test.add_mutually_exclusive_group(required=True)
device_group.add_argument(
"--connected", metavar="SERIAL", help="Run on a connected device. "
Expand All @@ -591,6 +599,13 @@ def parse_args():

def main():
install_signal_handler()

# Under the buildbot, stdout is not a TTY, but we must still flush after
# every line to make sure our output appears in the correct order relative
# to the output of our subprocesses.
for stream in [sys.stdout, sys.stderr]:
stream.reconfigure(line_buffering=True)

context = parse_args()
dispatch = {"configure-build": configure_build_python,
"make-build": make_build_python,
Expand Down
22 changes: 19 additions & 3 deletions Android/testbed/app/src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@
import sys

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

sys.argv[1:] = shlex.split(os.environ["PYTHON_ARGS"])
Expand Down
10 changes: 0 additions & 10 deletions Doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,6 @@ dist:
cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
@echo "Build finished and archived!"

# archive the letter latex
@echo "Building LaTeX (US paper)..."
rm -rf build/latex
$(MAKE) latex PAPER=letter
-sed -i 's/: all-$$(FMT)/:/' build/latex/Makefile
(cd build/latex; $(MAKE) clean && $(MAKE) --jobs=$$((`nproc`+1)) --output-sync LATEXMKOPTS='-quiet' all-pdf && $(MAKE) FMT=pdf zip bz2)
cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip
cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2
@echo "Build finished and archived!"

# copy the epub build
@echo "Building EPUB..."
rm -rf build/epub
Expand Down
34 changes: 22 additions & 12 deletions Doc/c-api/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,38 @@ All allocating functions belong to one of three different "domains" (see also
strategies and are optimized for different purposes. The specific details on
how every domain allocates memory or what internal functions each domain calls
is considered an implementation detail, but for debugging purposes a simplified
table can be found at :ref:`here <default-memory-allocators>`. There is no hard
requirement to use the memory returned by the allocation functions belonging to
a given domain for only the purposes hinted by that domain (although this is the
recommended practice). For example, one could use the memory returned by
:c:func:`PyMem_RawMalloc` for allocating Python objects or the memory returned
by :c:func:`PyObject_Malloc` for allocating memory for buffers.
table can be found at :ref:`here <default-memory-allocators>`.
The APIs used to allocate and free a block of memory must be from the same domain.
For example, :c:func:`PyMem_Free` must be used to free memory allocated using :c:func:`PyMem_Malloc`.

The three allocation domains are:

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

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

* Object domain: intended for allocating memory belonging to Python objects. The
memory is taken from the Python private heap.
* Object domain: intended for allocating memory for Python objects. The
memory is taken from the Python private heap. See :ref:`Object allocators <objectinterface>`.

When freeing memory previously allocated by the allocating functions belonging to a
given domain,the matching specific deallocating functions must be used. For example,
:c:func:`PyMem_Free` must be used to free memory allocated using :c:func:`PyMem_Malloc`.
.. note::

The :term:`free-threaded <free threading>` build requires that only Python objects are allocated using the "object" domain
and that all Python objects are allocated using that domain. This differs from the prior Python versions,
where this was only a best practice and not a hard requirement.

For example, buffers (non-Python objects) should be allocated using :c:func:`PyMem_Malloc`,
:c:func:`PyMem_RawMalloc`, or :c:func:`malloc`, but not :c:func:`PyObject_Malloc`.

See :ref:`Memory Allocation APIs <free-threaded-memory-allocation>`.


.. _raw-memoryinterface:

Raw Memory Interface
====================
Expand Down Expand Up @@ -299,6 +307,8 @@ versions and is therefore deprecated in extension modules.
* ``PyMem_DEL(ptr)``
.. _objectinterface:
Object allocators
=================
Expand Down
40 changes: 27 additions & 13 deletions Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,12 @@ The following functions and structs are used to create
The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*.
which may result in incomplete initialization.
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
will be no longer allowed.
:c:member:`~PyTypeObject.tp_new` is deprecated.
.. versionchanged:: 3.14
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
Expand All @@ -362,8 +366,12 @@ The following functions and structs are used to create
The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*.
which may result in incomplete initialization.
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
will be no longer allowed.
:c:member:`~PyTypeObject.tp_new` is deprecated.
.. versionchanged:: 3.14
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
Expand All @@ -378,8 +386,12 @@ The following functions and structs are used to create
The :c:member:`~PyTypeObject.tp_new` of the metaclass is *ignored*.
which may result in incomplete initialization.
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
will be no longer allowed.
:c:member:`~PyTypeObject.tp_new` is deprecated.
.. versionchanged:: 3.14
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
.. raw:: html
Expand Down Expand Up @@ -492,14 +504,10 @@ The following functions and structs are used to create
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
for details.
The following fields cannot be set at all when creating a heap type:
The following internal fields cannot be set at all when creating a heap
type:
* :c:member:`~PyTypeObject.tp_vectorcall`
(use :c:member:`~PyTypeObject.tp_new` and/or
:c:member:`~PyTypeObject.tp_init`)
* Internal fields:
:c:member:`~PyTypeObject.tp_dict`,
* :c:member:`~PyTypeObject.tp_dict`,
:c:member:`~PyTypeObject.tp_mro`,
:c:member:`~PyTypeObject.tp_cache`,
:c:member:`~PyTypeObject.tp_subclasses`, and
Expand All @@ -519,6 +527,12 @@ The following functions and structs are used to create
:c:member:`~PyBufferProcs.bf_releasebuffer` are now available
under the :ref:`limited API <limited-c-api>`.
.. versionchanged:: 3.14
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
using ``Py_tp_vectorcall``. See the field's documentation
for details.
.. c:member:: void *pfunc
The desired value of the slot. In most cases, this is a pointer
Expand Down
39 changes: 34 additions & 5 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2137,11 +2137,40 @@ and :c:data:`PyType_Type` effectively act as defaults.)

.. c:member:: vectorcallfunc PyTypeObject.tp_vectorcall
Vectorcall function to use for calls of this type object.
In other words, it is used to implement
:ref:`vectorcall <vectorcall>` for ``type.__call__``.
If ``tp_vectorcall`` is ``NULL``, the default call implementation
using :meth:`~object.__new__` and :meth:`~object.__init__` is used.
A :ref:`vectorcall function <vectorcall>` to use for calls of this type
object (rather than instances).
In other words, ``tp_vectorcall`` can be used to optimize ``type.__call__``,
which typically returns a new instance of *type*.

As with any vectorcall function, if ``tp_vectorcall`` is ``NULL``,
the *tp_call* protocol (``Py_TYPE(type)->tp_call``) is used instead.

.. note::

The :ref:`vectorcall protocol <vectorcall>` requires that the vectorcall
function has the same behavior as the corresponding ``tp_call``.
This means that ``type->tp_vectorcall`` must match the behavior of
``Py_TYPE(type)->tp_call``.

Specifically, if *type* uses the default metaclass,
``type->tp_vectorcall`` must behave the same as
:c:expr:`PyType_Type->tp_call`, which:

- calls ``type->tp_new``,

- if the result is a subclass of *type*, calls ``type->tp_init``
on the result of ``tp_new``, and

- returns the result of ``tp_new``.

Typically, ``tp_vectorcall`` is overridden to optimize this process
for specific :c:member:`~PyTypeObject.tp_new` and
:c:member:`~PyTypeObject.tp_init`.
When doing this for user-subclassable types, note that both can be
overridden (using :py:func:`~object.__new__` and
:py:func:`~object.__init__`, respectively).



**Inheritance:**

Expand Down
2 changes: 1 addition & 1 deletion Doc/howto/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ And the output:
options:
-h, --help show this help message and exit
-v {0,1,2}, --verbosity {0,1,2}
-v, --verbosity {0,1,2}
increase output verbosity
Note that the change also reflects both in the error message as well as the
Expand Down
Loading

0 comments on commit 167a67c

Please sign in to comment.