Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/jit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- true
- false
llvm:
- 20
- 21
include:
- target: i686-pc-windows-msvc/msvc
architecture: Win32
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
fail-fast: false
matrix:
llvm:
- 20
- 21
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
fail-fast: false
matrix:
llvm:
- 20
- 21
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -193,7 +193,7 @@ jobs:
fail-fast: false
matrix:
llvm:
- 20
- 21
steps:
- uses: actions/checkout@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion Apple/testbed/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import re
import shlex
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -252,7 +253,7 @@ def update_test_plan(testbed_path, platform, args):
test_plan = json.load(f)

test_plan["defaultOptions"]["commandLineArgumentEntries"] = [
{"argument": arg} for arg in args
{"argument": shlex.quote(arg)} for arg in args
]

with test_plan_path.open("w", encoding="utf-8") as f:
Expand Down
17 changes: 17 additions & 0 deletions Doc/c-api/float.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,37 @@ Floating-Point Objects
the C11 standard ``<math.h>`` header.


.. c:macro:: Py_MATH_E

The definition (accurate for a :c:expr:`double` type) of the :data:`math.e` constant.


.. c:macro:: Py_MATH_El

High precision (long double) definition of :data:`~math.e` constant.

.. deprecated-removed:: 3.15 3.20


.. c:macro:: Py_MATH_PI

The definition (accurate for a :c:expr:`double` type) of the :data:`math.pi` constant.


.. c:macro:: Py_MATH_PIl

High precision (long double) definition of :data:`~math.pi` constant.

.. deprecated-removed:: 3.15 3.20


.. c:macro:: Py_MATH_TAU

The definition (accurate for a :c:expr:`double` type) of the :data:`math.tau` constant.

.. versionadded:: 3.6


.. c:macro:: Py_RETURN_NAN

Return :data:`math.nan` from a function.
Expand Down
26 changes: 26 additions & 0 deletions Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ Type Objects
before initialization) and should be paired with :c:func:`PyObject_Free` in
:c:member:`~PyTypeObject.tp_free`.


.. c:function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)

Generic handler for the :c:member:`~PyTypeObject.tp_new` slot of a type
object. Creates a new instance using the type's
:c:member:`~PyTypeObject.tp_alloc` slot and returns the resulting object.


.. c:function:: int PyType_Ready(PyTypeObject *type)

Finalize a type object. This should be called on all type objects to finish
Expand All @@ -217,13 +219,15 @@ Type Objects
GC protocol itself by at least implementing the
:c:member:`~PyTypeObject.tp_traverse` handle.


.. c:function:: PyObject* PyType_GetName(PyTypeObject *type)

Return the type's name. Equivalent to getting the type's
:attr:`~type.__name__` attribute.

.. versionadded:: 3.11


.. c:function:: PyObject* PyType_GetQualName(PyTypeObject *type)

Return the type's qualified name. Equivalent to getting the
Expand All @@ -239,13 +243,15 @@ Type Objects

.. versionadded:: 3.13


.. c:function:: PyObject* PyType_GetModuleName(PyTypeObject *type)

Return the type's module name. Equivalent to getting the
:attr:`type.__module__` attribute.

.. versionadded:: 3.13


.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)

Return the function pointer stored in the given slot. If the
Expand All @@ -262,6 +268,7 @@ Type Objects
:c:func:`PyType_GetSlot` can now accept all types.
Previously, it was limited to :ref:`heap types <heap-types>`.


.. c:function:: PyObject* PyType_GetModule(PyTypeObject *type)

Return the module object associated with the given type when the type was
Expand All @@ -281,6 +288,7 @@ Type Objects

.. versionadded:: 3.9


.. c:function:: void* PyType_GetModuleState(PyTypeObject *type)

Return the state of the module object associated with the given type.
Expand All @@ -295,6 +303,7 @@ Type Objects

.. versionadded:: 3.9


.. c:function:: PyObject* PyType_GetModuleByDef(PyTypeObject *type, struct PyModuleDef *def)

Find the first superclass whose module was created from
Expand All @@ -314,6 +323,7 @@ Type Objects

.. versionadded:: 3.11


.. c:function:: int PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result)

Find the first superclass in *type*'s :term:`method resolution order` whose
Expand All @@ -332,6 +342,7 @@ Type Objects

.. versionadded:: 3.14


.. c:function:: int PyUnstable_Type_AssignVersionTag(PyTypeObject *type)

Attempt to assign a version tag to the given type.
Expand All @@ -342,6 +353,16 @@ Type Objects
.. versionadded:: 3.12


.. c:function:: int PyType_SUPPORTS_WEAKREFS(PyTypeObject *type)

Return true if instances of *type* support creating weak references, false
otherwise. This function always succeeds. *type* must not be ``NULL``.

.. seealso::
* :ref:`weakrefobjects`
* :py:mod:`weakref`


Creating Heap-Allocated Types
.............................

Expand Down Expand Up @@ -390,6 +411,7 @@ The following functions and structs are used to create

.. versionadded:: 3.12


.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)

Equivalent to ``PyType_FromMetaclass(NULL, module, spec, bases)``.
Expand All @@ -416,6 +438,7 @@ The following functions and structs are used to create
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is no longer allowed.


.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)

Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, bases)``.
Expand All @@ -437,6 +460,7 @@ The following functions and structs are used to create
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is no longer allowed.


.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)

Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, NULL)``.
Expand All @@ -457,6 +481,7 @@ The following functions and structs are used to create
Creating classes whose metaclass overrides
:c:member:`~PyTypeObject.tp_new` is no longer allowed.


.. c:function:: int PyType_Freeze(PyTypeObject *type)

Make a type immutable: set the :c:macro:`Py_TPFLAGS_IMMUTABLETYPE` flag.
Expand Down Expand Up @@ -628,6 +653,7 @@ The following functions and structs are used to create
* :c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC`
rather than ``NULL``)


.. c:macro:: Py_tp_token

A :c:member:`~PyType_Slot.slot` that records a static memory layout ID
Expand Down
8 changes: 8 additions & 0 deletions Doc/c-api/weakref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ as much as it can.
weakly referenceable object, or if *callback* is not callable, ``None``, or
``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
.. seealso::
:c:func:`PyType_SUPPORTS_WEAKREFS` for checking if *ob* is weakly
referenceable.
.. c:function:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
Expand All @@ -57,6 +61,10 @@ as much as it can.
is not a weakly referenceable object, or if *callback* is not callable,
``None``, or ``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
.. seealso::
:c:func:`PyType_SUPPORTS_WEAKREFS` for checking if *ob* is weakly
referenceable.
.. c:function:: int PyWeakref_GetRef(PyObject *ref, PyObject **pobj)
Expand Down
6 changes: 3 additions & 3 deletions Doc/tutorial/stdlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ protocols. Two of the simplest are :mod:`urllib.request` for retrieving data
from URLs and :mod:`smtplib` for sending mail::

>>> from urllib.request import urlopen
>>> with urlopen('http://worldtimeapi.org/api/timezone/etc/UTC.txt') as response:
>>> with urlopen('https://docs.python.org/3/') as response:
... for line in response:
... line = line.decode() # Convert bytes to a str
... if line.startswith('datetime'):
... if 'updated' in line:
... print(line.rstrip()) # Remove trailing newline
...
datetime: 2022-01-01T01:36:47.689215+00:00
Last updated on Nov 11, 2025 (20:11 UTC).

>>> import smtplib
>>> server = smtplib.SMTP('localhost')
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,25 @@ def f():

f()

def test_interpreter_finalization_with_generator_alive(self):
script_helper.assert_python_ok("-c", textwrap.dedent("""
import sys
t = tuple(range(%d))
def simple_for():
for x in t:
x

def gen():
try:
yield
except:
simple_for()

sys.settrace(lambda *args: None)
simple_for()
g = gen()
next(g)
""" % _testinternalcapi.SPECIALIZATION_THRESHOLD))


def global_identity(x):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update JIT compilation to use LLVM 21 at build time.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The iOS testbed now correctly handles test arguments that contain spaces.
4 changes: 2 additions & 2 deletions PCbuild/get_externals.bat
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if NOT "%IncludeLibffi%"=="false" set binaries=%binaries% libffi-3.4.4
if NOT "%IncludeSSL%"=="false" set binaries=%binaries% openssl-bin-3.0.18
if NOT "%IncludeTkinter%"=="false" set binaries=%binaries% tcltk-8.6.15.0
if NOT "%IncludeSSLSrc%"=="false" set binaries=%binaries% nasm-2.11.06
if NOT "%IncludeLLVM%"=="false" set binaries=%binaries% llvm-20.1.8.0
if NOT "%IncludeLLVM%"=="false" set binaries=%binaries% llvm-21.1.4.0

for %%b in (%binaries%) do (
if exist "%EXTERNALS_DIR%\%%b" (
Expand All @@ -92,7 +92,7 @@ for %%b in (%binaries%) do (
git clone --depth 1 https://github.com/%ORG%/cpython-bin-deps --branch %%b "%EXTERNALS_DIR%\%%b"
) else (
echo.Fetching %%b...
if "%%b"=="llvm-20.1.8.0" (
if "%%b"=="llvm-21.1.4.0" (
%PYTHON% -E "%PCBUILD%\get_external.py" --release --organization %ORG% --externals-dir "%EXTERNALS_DIR%" %%b
) else (
%PYTHON% -E "%PCBUILD%\get_external.py" --binary --organization %ORG% --externals-dir "%EXTERNALS_DIR%" %%b
Expand Down
8 changes: 7 additions & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ _PyOptimizer_Optimize(
{
_PyStackRef *stack_pointer = frame->stackpointer;
PyInterpreterState *interp = _PyInterpreterState_GET();
assert(interp->jit);
if (!interp->jit) {
// gh-140936: It is possible that interp->jit will become false during
// interpreter finalization. However, the specialized JUMP_BACKWARD_JIT
// instruction may still be present. In this case, we should
// return immediately without optimization.
return 0;
}
assert(!interp->compiling);
#ifndef Py_GIL_DISABLED
interp->compiling = true;
Expand Down
Loading
Loading