Skip to content

Commit 302cf3e

Browse files
authored
Merge branch 'main' into redesign-const-seq
2 parents 9d3297e + de2f7da commit 302cf3e

File tree

198 files changed

+4013
-1578
lines changed

Some content is hidden

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

198 files changed

+4013
-1578
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,6 @@ Doc/reference/ @willingc @AA-Turner
309309
# Colorize
310310
Lib/_colorize.py @hugovk
311311
Lib/test/test__colorize.py @hugovk
312+
313+
# Fuzzing
314+
Modules/_xxtestfuzz/ @ammaraskar

.github/workflows/tail-call.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ name: Tail calling interpreter
22
on:
33
pull_request:
44
paths:
5+
- '.github/workflows/tail-call.yml'
56
- 'Python/bytecodes.c'
67
- 'Python/ceval.c'
78
- 'Python/ceval_macros.h'
89
- 'Python/generated_cases.c.h'
910
push:
1011
paths:
12+
- '.github/workflows/tail-call.yml'
1113
- 'Python/bytecodes.c'
1214
- 'Python/ceval.c'
1315
- 'Python/ceval_macros.h'
@@ -35,7 +37,7 @@ jobs:
3537
target:
3638
# Un-comment as we add support for more platforms for tail-calling interpreters.
3739
# - i686-pc-windows-msvc/msvc
38-
# - x86_64-pc-windows-msvc/msvc
40+
- x86_64-pc-windows-msvc/msvc
3941
# - aarch64-pc-windows-msvc/msvc
4042
- x86_64-apple-darwin/clang
4143
- aarch64-apple-darwin/clang
@@ -48,9 +50,9 @@ jobs:
4850
# - target: i686-pc-windows-msvc/msvc
4951
# architecture: Win32
5052
# runner: windows-latest
51-
# - target: x86_64-pc-windows-msvc/msvc
52-
# architecture: x64
53-
# runner: windows-latest
53+
- target: x86_64-pc-windows-msvc/msvc
54+
architecture: x64
55+
runner: windows-latest
5456
# - target: aarch64-pc-windows-msvc/msvc
5557
# architecture: ARM64
5658
# runner: windows-latest
@@ -79,23 +81,31 @@ jobs:
7981

8082
- name: Native Windows (debug)
8183
if: runner.os == 'Windows' && matrix.architecture != 'ARM64'
84+
shell: cmd
8285
run: |
83-
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0
86+
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.5
87+
set PlatformToolset=clangcl
88+
set LLVMToolsVersion=${{ matrix.llvm }}.1.5
89+
set LLVMInstallDir=C:\Program Files\LLVM
8490
./PCbuild/build.bat --tail-call-interp -d -p ${{ matrix.architecture }}
8591
./PCbuild/rt.bat -d -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
8692
8793
# No tests (yet):
8894
- name: Emulated Windows (release)
8995
if: runner.os == 'Windows' && matrix.architecture == 'ARM64'
96+
shell: cmd
9097
run: |
91-
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0
98+
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.5
99+
set PlatformToolset=clangcl
100+
set LLVMToolsVersion=${{ matrix.llvm }}.1.5
101+
set LLVMInstallDir=C:\Program Files\LLVM
92102
./PCbuild/build.bat --tail-call-interp -p ${{ matrix.architecture }}
93103
94104
# The `find` line is required as a result of https://github.com/actions/runner-images/issues/9966.
95105
# This is a bug in the macOS runner image where the pre-installed Python is installed in the same
96106
# directory as the Homebrew Python, which causes the build to fail for macos-13. This line removes
97107
# the symlink to the pre-installed Python so that the Homebrew Python is used instead.
98-
- name: Native macOS (debug)
108+
- name: Native macOS (release)
99109
if: runner.os == 'macOS'
100110
run: |
101111
brew update
@@ -104,16 +114,16 @@ jobs:
104114
export SDKROOT="$(xcrun --show-sdk-path)"
105115
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
106116
export PATH="/usr/local/opt/llvm/bin:$PATH"
107-
CC=clang-19 ./configure --with-tail-call-interp --with-pydebug
117+
CC=clang-19 ./configure --with-tail-call-interp
108118
make all --jobs 4
109119
./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
110120
111-
- name: Native Linux (release)
121+
- name: Native Linux (debug)
112122
if: runner.os == 'Linux' && matrix.target != 'free-threading'
113123
run: |
114124
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
115125
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
116-
CC=clang-19 ./configure --with-tail-call-interp
126+
CC=clang-19 ./configure --with-tail-call-interp --with-pydebug
117127
make all --jobs 4
118128
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
119129

Doc/c-api/allocation.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Allocating Objects on the Heap
3535
The size of the memory allocation is determined from the
3636
:c:member:`~PyTypeObject.tp_basicsize` field of the type object.
3737
38+
Note that this function is unsuitable if *typeobj* has
39+
:c:macro:`Py_TPFLAGS_HAVE_GC` set. For such objects,
40+
use :c:func:`PyObject_GC_New` instead.
41+
3842
3943
.. c:macro:: PyObject_NewVar(TYPE, typeobj, size)
4044
@@ -49,6 +53,10 @@ Allocating Objects on the Heap
4953
fields into the same allocation decreases the number of allocations,
5054
improving the memory management efficiency.
5155
56+
Note that this function is unsuitable if *typeobj* has
57+
:c:macro:`Py_TPFLAGS_HAVE_GC` set. For such objects,
58+
use :c:func:`PyObject_GC_NewVar` instead.
59+
5260
5361
.. c:function:: void PyObject_Del(void *op)
5462

Doc/c-api/type.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ The following functions and structs are used to create
456456
class need *in addition* to the superclass.
457457
Use :c:func:`PyObject_GetTypeData` to get a pointer to subclass-specific
458458
memory reserved this way.
459+
For negative :c:member:`!basicsize`, Python will insert padding when
460+
needed to meet :c:member:`~PyTypeObject.tp_basicsize`'s alignment
461+
requirements.
459462
460463
.. versionchanged:: 3.12
461464

Doc/c-api/typeobj.rst

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ PyVarObject Slots
537537
initialized to zero. For :ref:`dynamically allocated type objects
538538
<heap-types>`, this field has a special internal meaning.
539539

540+
This field should be accessed using the :c:func:`Py_SIZE()` and
541+
:c:func:`Py_SET_SIZE()` macros.
542+
540543
**Inheritance:**
541544

542545
This field is not inherited by subtypes.
@@ -587,47 +590,86 @@ and :c:data:`PyType_Type` effectively act as defaults.)
587590

588591

589592
.. c:member:: Py_ssize_t PyTypeObject.tp_basicsize
590-
Py_ssize_t PyTypeObject.tp_itemsize
593+
Py_ssize_t PyTypeObject.tp_itemsize
591594
592595
These fields allow calculating the size in bytes of instances of the type.
593596

594597
There are two kinds of types: types with fixed-length instances have a zero
595-
:c:member:`~PyTypeObject.tp_itemsize` field, types with variable-length instances have a non-zero
596-
:c:member:`~PyTypeObject.tp_itemsize` field. For a type with fixed-length instances, all
597-
instances have the same size, given in :c:member:`~PyTypeObject.tp_basicsize`.
598+
:c:member:`!tp_itemsize` field, types with variable-length instances have a non-zero
599+
:c:member:`!tp_itemsize` field. For a type with fixed-length instances, all
600+
instances have the same size, given in :c:member:`!tp_basicsize`.
601+
(Exceptions to this rule can be made using
602+
:c:func:`PyUnstable_Object_GC_NewWithExtraData`.)
598603

599604
For a type with variable-length instances, the instances must have an
600-
:c:member:`~PyVarObject.ob_size` field, and the instance size is :c:member:`~PyTypeObject.tp_basicsize` plus N
601-
times :c:member:`~PyTypeObject.tp_itemsize`, where N is the "length" of the object. The value of
602-
N is typically stored in the instance's :c:member:`~PyVarObject.ob_size` field. There are
603-
exceptions: for example, ints use a negative :c:member:`~PyVarObject.ob_size` to indicate a
604-
negative number, and N is ``abs(ob_size)`` there. Also, the presence of an
605-
:c:member:`~PyVarObject.ob_size` field in the instance layout doesn't mean that the instance
606-
structure is variable-length (for example, the structure for the list type has
607-
fixed-length instances, yet those instances have a meaningful :c:member:`~PyVarObject.ob_size`
608-
field).
609-
610-
The basic size includes the fields in the instance declared by the macro
611-
:c:macro:`PyObject_HEAD` or :c:macro:`PyObject_VAR_HEAD` (whichever is used to
612-
declare the instance struct) and this in turn includes the :c:member:`~PyObject._ob_prev` and
613-
:c:member:`~PyObject._ob_next` fields if they are present. This means that the only correct
614-
way to get an initializer for the :c:member:`~PyTypeObject.tp_basicsize` is to use the
615-
``sizeof`` operator on the struct used to declare the instance layout.
616-
The basic size does not include the GC header size.
605+
:c:member:`~PyVarObject.ob_size` field, and the instance size is
606+
:c:member:`!tp_basicsize` plus N times :c:member:`!tp_itemsize`,
607+
where N is the "length" of the object.
608+
609+
Functions like :c:func:`PyObject_NewVar` will take the value of N as an
610+
argument, and store in the instance's :c:member:`~PyVarObject.ob_size` field.
611+
Note that the :c:member:`~PyVarObject.ob_size` field may later be used for
612+
other purposes. For example, :py:type:`int` instances use the bits of
613+
:c:member:`~PyVarObject.ob_size` in an implementation-defined
614+
way; the underlying storage and its size should be acessed using
615+
:c:func:`PyLong_Export`.
616+
617+
.. note::
617618

618-
A note about alignment: if the variable items require a particular alignment,
619-
this should be taken care of by the value of :c:member:`~PyTypeObject.tp_basicsize`. Example:
620-
suppose a type implements an array of ``double``. :c:member:`~PyTypeObject.tp_itemsize` is
621-
``sizeof(double)``. It is the programmer's responsibility that
622-
:c:member:`~PyTypeObject.tp_basicsize` is a multiple of ``sizeof(double)`` (assuming this is the
623-
alignment requirement for ``double``).
619+
The :c:member:`~PyVarObject.ob_size` field should be accessed using
620+
the :c:func:`Py_SIZE()` and :c:func:`Py_SET_SIZE()` macros.
624621

625-
For any type with variable-length instances, this field must not be ``NULL``.
622+
Also, the presence of an :c:member:`~PyVarObject.ob_size` field in the
623+
instance layout doesn't mean that the instance structure is variable-length.
624+
For example, the :py:type:`list` type has fixed-length instances, yet those
625+
instances have a :c:member:`~PyVarObject.ob_size` field.
626+
(As with :py:type:`int`, avoid reading lists' :c:member:`!ob_size` directly.
627+
Call :c:func:`PyList_Size` instead.)
628+
629+
The :c:member:`!tp_basicsize` includes size needed for data of the type's
630+
:c:member:`~PyTypeObject.tp_base`, plus any extra data needed
631+
by each instance.
632+
633+
The correct way to set :c:member:`!tp_basicsize` is to use the
634+
``sizeof`` operator on the struct used to declare the instance layout.
635+
This struct must include the struct used to declare the base type.
636+
In other words, :c:member:`!tp_basicsize` must be greater than or equal
637+
to the base's :c:member:`!tp_basicsize`.
638+
639+
Since every type is a subtype of :py:type:`object`, this struct must
640+
include :c:type:`PyObject` or :c:type:`PyVarObject` (depending on
641+
whether :c:member:`~PyVarObject.ob_size` should be included). These are
642+
usually defined by the macro :c:macro:`PyObject_HEAD` or
643+
:c:macro:`PyObject_VAR_HEAD`, respectively.
644+
645+
The basic size does not include the GC header size, as that header is not
646+
part of :c:macro:`PyObject_HEAD`.
647+
648+
For cases where struct used to declare the base type is unknown,
649+
see :c:member:`PyType_Spec.basicsize` and :c:func:`PyType_FromMetaclass`.
650+
651+
Notes about alignment:
652+
653+
- :c:member:`!tp_basicsize` must be a multiple of ``_Alignof(PyObject)``.
654+
When using ``sizeof`` on a ``struct`` that includes
655+
:c:macro:`PyObject_HEAD`, as recommended, the compiler ensures this.
656+
When not using a C ``struct``, or when using compiler
657+
extensions like ``__attribute__((packed))``, it is up to you.
658+
- If the variable items require a particular alignment,
659+
:c:member:`!tp_basicsize` and :c:member:`!tp_itemsize` must each be a
660+
multiple of that alignment.
661+
For example, if a type's variable part stores a ``double``, it is
662+
your responsibility that both fields are a multiple of
663+
``_Alignof(double)``.
626664

627665
**Inheritance:**
628666

629-
These fields are inherited separately by subtypes. If the base type has a
630-
non-zero :c:member:`~PyTypeObject.tp_itemsize`, it is generally not safe to set
667+
These fields are inherited separately by subtypes.
668+
(That is, if the field is set to zero, :c:func:`PyType_Ready` will copy
669+
the value from the base type, indicating that the instances do not
670+
need additional storage.)
671+
672+
If the base type has a non-zero :c:member:`~PyTypeObject.tp_itemsize`, it is generally not safe to set
631673
:c:member:`~PyTypeObject.tp_itemsize` to a different non-zero value in a subtype (though this
632674
depends on the implementation of the base type).
633675

Doc/c-api/unicode.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,23 @@ APIs:
614614
decref'ing the returned objects.
615615
616616
617+
.. c:function:: void PyUnicode_Append(PyObject **p_left, PyObject *right)
618+
619+
Append the string *right* to the end of *p_left*.
620+
*p_left* must point to a :term:`strong reference` to a Unicode object;
621+
:c:func:`!PyUnicode_Append` releases ("steals") this reference.
622+
623+
On error, set *\*p_left* to ``NULL`` and set an exception.
624+
625+
On sucess, set *\*p_left* to a new strong reference to the result.
626+
627+
628+
.. c:function:: void PyUnicode_AppendAndDel(PyObject **p_left, PyObject *right)
629+
630+
The function is similar to :c:func:`PyUnicode_Append`, with the only
631+
difference being that it decrements the reference count of *right* by one.
632+
633+
617634
.. c:function:: const char* PyUnicode_GetDefaultEncoding(void)
618635
619636
Return the name of the default string encoding, ``"utf-8"``.

Doc/data/refcounts.dat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,14 @@ PyUnicode_FromFormatV:PyObject*::+1:
27702770
PyUnicode_FromFormatV:const char*:format::
27712771
PyUnicode_FromFormatV:va_list:args::
27722772

2773+
PyUnicode_Append:void:::
2774+
PyUnicode_Append:PyObject**:p_left:0:
2775+
PyUnicode_Append:PyObject*:right::
2776+
2777+
PyUnicode_AppendAndDel:void:::
2778+
PyUnicode_AppendAndDel:PyObject**:p_left:0:
2779+
PyUnicode_AppendAndDel:PyObject*:right:-1:
2780+
27732781
PyUnicode_GetDefaultEncoding:const char*:::
27742782
PyUnicode_GetDefaultEncoding::void::
27752783

Doc/extending/windows.rst

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ gives you access to spam's names, but does not create a separate copy. On Unix,
9696
linking with a library is more like ``from spam import *``; it does create a
9797
separate copy.
9898

99+
.. c:macro:: Py_NO_LINK_LIB
100+
101+
Turn off the implicit, ``#pragma``-based linkage with the Python
102+
library, performed inside CPython header files.
103+
104+
.. versionadded:: 3.14
105+
99106

100107
.. _win-dlls:
101108

@@ -108,21 +115,46 @@ Using DLLs in Practice
108115
Windows Python is built in Microsoft Visual C++; using other compilers may or
109116
may not work. The rest of this section is MSVC++ specific.
110117

111-
When creating DLLs in Windows, you must pass :file:`pythonXY.lib` to the linker.
112-
To build two DLLs, spam and ni (which uses C functions found in spam), you could
113-
use these commands::
118+
When creating DLLs in Windows, you can use the CPython library in two ways:
119+
120+
1. By default, inclusion of :file:`PC/pyconfig.h` directly or via
121+
:file:`Python.h` triggers an implicit, configure-aware link with the
122+
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
123+
:file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with
124+
the `Limited API <stable-application-binary-interface>`_ enabled.
125+
126+
To build two DLLs, spam and ni (which uses C functions found in spam), you
127+
could use these commands::
128+
129+
cl /LD /I/python/include spam.c
130+
cl /LD /I/python/include ni.c spam.lib
131+
132+
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
133+
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
134+
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
135+
the Python code thanks to the implicitly linked :file:`pythonXY.lib`.
136+
137+
The second command created :file:`ni.dll` (and :file:`.obj` and
138+
:file:`.lib`), which knows how to find the necessary functions from spam,
139+
and also from the Python executable.
140+
141+
2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including
142+
:file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker.
143+
144+
To build two DLLs, spam and ni (which uses C functions found in spam), you
145+
could use these commands::
114146

115-
cl /LD /I/python/include spam.c ../libs/pythonXY.lib
116-
cl /LD /I/python/include ni.c spam.lib ../libs/pythonXY.lib
147+
cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib
148+
cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib
117149

118-
The first command created three files: :file:`spam.obj`, :file:`spam.dll` and
119-
:file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such
120-
as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code
121-
thanks to :file:`pythonXY.lib`.
150+
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
151+
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
152+
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
153+
the Python code thanks to :file:`pythonXY.lib`.
122154

123-
The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`),
124-
which knows how to find the necessary functions from spam, and also from the
125-
Python executable.
155+
The second command created :file:`ni.dll` (and :file:`.obj` and
156+
:file:`.lib`), which knows how to find the necessary functions from spam,
157+
and also from the Python executable.
126158

127159
Not every identifier is exported to the lookup table. If you want any other
128160
modules (including Python) to be able to see your identifiers, you have to say

Doc/howto/perf_profiling.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ the :option:`!-X` option takes precedence over the environment variable.
162162

163163
Example, using the environment variable::
164164

165-
$ PYTHONPERFSUPPORT=1 perf record -F 9999 -g -o perf.data python script.py
165+
$ PYTHONPERFSUPPORT=1 perf record -F 9999 -g -o perf.data python my_script.py
166166
$ perf report -g -i perf.data
167167

168168
Example, using the :option:`!-X` option::
169169

170-
$ perf record -F 9999 -g -o perf.data python -X perf script.py
170+
$ perf record -F 9999 -g -o perf.data python -X perf my_script.py
171171
$ perf report -g -i perf.data
172172

173173
Example, using the :mod:`sys` APIs in file :file:`example.py`:
@@ -236,7 +236,7 @@ When using the perf JIT mode, you need an extra step before you can run ``perf
236236
report``. You need to call the ``perf inject`` command to inject the JIT
237237
information into the ``perf.data`` file.::
238238

239-
$ perf record -F 9999 -g --call-graph dwarf -o perf.data python -Xperf_jit my_script.py
239+
$ perf record -F 9999 -g -k 1 --call-graph dwarf -o perf.data python -Xperf_jit my_script.py
240240
$ perf inject -i perf.data --jit --output perf.jit.data
241241
$ perf report -g -i perf.jit.data
242242

0 commit comments

Comments
 (0)