Skip to content

Commit 34b6065

Browse files
committed
Merge branch 'main' into pythongh-114271-remove-tstate_lock
2 parents 4ed1083 + 90a1e98 commit 34b6065

File tree

701 files changed

+25774
-9497
lines changed

Some content is hidden

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

701 files changed

+25774
-9497
lines changed

.gitattributes

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Include/internal/pycore_opcode.h generated
7777
Include/internal/pycore_opcode_metadata.h generated
7878
Include/internal/pycore_*_generated.h generated
7979
Include/internal/pycore_uop_ids.h generated
80+
Include/internal/pycore_uop_metadata.h generated
8081
Include/opcode.h generated
8182
Include/opcode_ids.h generated
8283
Include/token.h generated
@@ -94,7 +95,7 @@ Programs/test_frozenmain.h generated
9495
Python/Python-ast.c generated
9596
Python/executor_cases.c.h generated
9697
Python/generated_cases.c.h generated
97-
Python/tier2_redundancy_eliminator_bytecodes.c.h generated
98+
Python/optimizer_cases.c.h generated
9899
Python/opcode_targets.h generated
99100
Python/stdlib_module_names.h generated
100101
Tools/peg_generator/pegen/grammar_parser.py generated

.github/CODEOWNERS

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Python/ast_opt.c @isidentical
3838
Python/bytecodes.c @markshannon @gvanrossum
3939
Python/optimizer*.c @markshannon @gvanrossum
4040
Python/optimizer_analysis.c @Fidget-Spinner
41-
Python/tier2_redundancy_eliminator_bytecodes.c @Fidget-Spinner
41+
Python/optimizer_bytecodes.c @Fidget-Spinner
4242
Lib/test/test_patma.py @brandtbucher
4343
Lib/test/test_type_*.py @JelleZijlstra
4444
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum
@@ -247,5 +247,10 @@ Lib/test/test_interpreters/ @ericsnowcurrently
247247
/Tools/wasm/ @brettcannon
248248

249249
# SBOM
250+
/Misc/externals.spdx.json @sethmlarson
250251
/Misc/sbom.spdx.json @sethmlarson
251252
/Tools/build/generate_sbom.py @sethmlarson
253+
254+
# Config Parser
255+
Lib/configparser.py @jaraco
256+
Lib/test/test_configparser.py @jaraco

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
- name: Build CPython
163163
run: |
164164
make -j4 regen-all
165-
make regen-stdlib-module-names
165+
make regen-stdlib-module-names regen-sbom
166166
- name: Check for changes
167167
run: |
168168
git add -u

.github/workflows/jit.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ on:
44
paths:
55
- '**jit**'
66
- 'Python/bytecodes.c'
7+
- 'Python/optimizer*.c'
8+
- 'Python/optimizer_bytecodes.c'
79
push:
810
paths:
911
- '**jit**'
1012
- 'Python/bytecodes.c'
13+
- 'Python/optimizer*.c'
14+
- 'Python/optimizer_bytecodes.c'
1115
workflow_dispatch:
1216

1317
concurrency:
@@ -66,13 +70,13 @@ jobs:
6670
runner: ubuntu-latest
6771
compiler: gcc
6872
# These fail because of emulation, not because of the JIT:
69-
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv
73+
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
7074
- target: aarch64-unknown-linux-gnu/clang
7175
architecture: aarch64
7276
runner: ubuntu-latest
7377
compiler: clang
7478
# These fail because of emulation, not because of the JIT:
75-
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv
79+
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
7680
env:
7781
CC: ${{ matrix.compiler }}
7882
steps:

.github/workflows/reusable-macos.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
HOMEBREW_NO_ANALYTICS: 1
1818
HOMEBREW_NO_AUTO_UPDATE: 1
1919
HOMEBREW_NO_INSTALL_CLEANUP: 1
20+
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
2021
PYTHONSTRICTEXTENSIONBUILD: 1
2122
strategy:
2223
fail-fast: false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Lib/test/data/*
6969
/_bootstrap_python
7070
/Makefile
7171
/Makefile.pre
72+
iOS/Resources/Info.plist
7273
Mac/Makefile
7374
Mac/PythonLauncher/Info.plist
7475
Mac/PythonLauncher/Makefile

Doc/c-api/code.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ bound into a function.
3030
Return true if *co* is a :ref:`code object <code-objects>`.
3131
This function always succeeds.
3232
33-
.. c:function:: int PyCode_GetNumFree(PyCodeObject *co)
33+
.. c:function:: Py_ssize_t PyCode_GetNumFree(PyCodeObject *co)
3434
35-
Return the number of free variables in *co*.
35+
Return the number of free variables in a code object.
36+
37+
.. c:function:: int PyCode_GetFirstFree(PyCodeObject *co)
38+
39+
Return the position of the first free variable in a code object.
3640
3741
.. c:function:: PyCodeObject* PyUnstable_Code_New(int argcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, PyObject *qualname, int firstlineno, PyObject *linetable, PyObject *exceptiontable)
3842

Doc/c-api/exceptions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Printing and clearing
105105
parameters help format the warning message; they have the same meaning and
106106
values as in :c:func:`PyUnicode_FromFormat`.
107107
``PyErr_WriteUnraisable(obj)`` is roughtly equivalent to
108-
``PyErr_FormatUnraisable("Exception ignored in: %R, obj)``.
108+
``PyErr_FormatUnraisable("Exception ignored in: %R", obj)``.
109109
If *format* is ``NULL``, only the traceback is printed.
110110
111111
.. versionadded:: 3.13

Doc/c-api/long.rst

+57-17
Original file line numberDiff line numberDiff line change
@@ -358,46 +358,86 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
358358
359359
Copy the Python integer value to a native *buffer* of size *n_bytes*::
360360
361-
int value;
362-
Py_ssize_t bytes = PyLong_AsNativeBytes(v, &value, sizeof(value), -1);
361+
int32_t value;
362+
Py_ssize_t bytes = PyLong_AsNativeBits(pylong, &value, sizeof(value), -1);
363363
if (bytes < 0) {
364-
// Error occurred
364+
// A Python exception was set with the reason.
365365
return NULL;
366366
}
367367
else if (bytes <= (Py_ssize_t)sizeof(value)) {
368368
// Success!
369369
}
370370
else {
371-
// Overflow occurred, but 'value' contains truncated value
371+
// Overflow occurred, but 'value' contains the truncated
372+
// lowest bits of pylong.
372373
}
373374
375+
The above example may look *similar* to
376+
:c:func:`PyLong_As* <PyLong_AsSize_t>`
377+
but instead fills in a specific caller defined type and never raises an
378+
error about of the :class:`int` *pylong*'s value regardless of *n_bytes*
379+
or the returned byte count.
380+
381+
To get at the entire potentially big Python value, this can be used to
382+
reserve enough space and copy it::
383+
384+
// Ask how much space we need.
385+
Py_ssize_t expected = PyLong_AsNativeBits(pylong, NULL, 0, -1);
386+
if (expected < 0) {
387+
// A Python exception was set with the reason.
388+
return NULL;
389+
}
390+
assert(expected != 0); // Impossible per the API definition.
391+
uint8_t *bignum = malloc(expected);
392+
if (!bignum) {
393+
PyErr_SetString(PyExc_MemoryError, "bignum malloc failed.");
394+
return NULL;
395+
}
396+
// Safely get the entire value.
397+
Py_ssize_t bytes = PyLong_AsNativeBits(pylong, bignum, expected, -1);
398+
if (bytes < 0) { // Exception set.
399+
free(bignum);
400+
return NULL;
401+
}
402+
else if (bytes > expected) { // Be safe, should not be possible.
403+
PyErr_SetString(PyExc_RuntimeError,
404+
"Unexpected bignum truncation after a size check.");
405+
free(bignum);
406+
return NULL;
407+
}
408+
// The expected success given the above pre-check.
409+
// ... use bignum ...
410+
free(bignum);
411+
374412
*endianness* may be passed ``-1`` for the native endian that CPython was
375413
compiled with, or ``0`` for big endian and ``1`` for little.
376414
377-
Return ``-1`` with an exception raised if *pylong* cannot be interpreted as
415+
Returns ``-1`` with an exception raised if *pylong* cannot be interpreted as
378416
an integer. Otherwise, return the size of the buffer required to store the
379417
value. If this is equal to or less than *n_bytes*, the entire value was
380-
copied.
418+
copied. ``0`` will never be returned.
381419
382-
Unless an exception is raised, all *n_bytes* of the buffer will be written
383-
with as much of the value as can fit. This allows the caller to ignore all
384-
non-negative results if the intent is to match the typical behavior of a
385-
C-style downcast. No exception is set for this case.
420+
Unless an exception is raised, all *n_bytes* of the buffer will always be
421+
written. In the case of truncation, as many of the lowest bits of the value
422+
as could fit are written. This allows the caller to ignore all non-negative
423+
results if the intent is to match the typical behavior of a C-style
424+
downcast. No exception is set on truncation.
386425
387-
Values are always copied as two's-complement, and sufficient buffer will be
426+
Values are always copied as two's-complement and sufficient buffer will be
388427
requested to include a sign bit. For example, this may cause an value that
389428
fits into 8 bytes when treated as unsigned to request 9 bytes, even though
390429
all eight bytes were copied into the buffer. What has been omitted is the
391-
zero sign bit, which is redundant when the intention is to treat the value as
392-
unsigned.
430+
zero sign bit -- redundant if the caller's intention is to treat the value
431+
as unsigned.
393432
394-
Passing zero to *n_bytes* will return the requested buffer size.
433+
Passing zero to *n_bytes* will return the size of a buffer that would
434+
be large enough to hold the value. This may be larger than technically
435+
necessary, but not unreasonably so.
395436
396437
.. note::
397438
398-
When the value does not fit in the provided buffer, the requested size
399-
returned from the function may be larger than necessary. Passing 0 to this
400-
function is not an accurate way to determine the bit length of a value.
439+
Passing *n_bytes=0* to this function is not an accurate way to determine
440+
the bit length of a value.
401441
402442
.. versionadded:: 3.13
403443

Doc/c-api/structures.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -187,26 +187,26 @@ Implementing functions and methods
187187
PyObject *kwargs);
188188
189189
190-
.. c:type:: _PyCFunctionFast
190+
.. c:type:: PyCFunctionFast
191191
192192
Type of the functions used to implement Python callables in C
193193
with signature :c:macro:`METH_FASTCALL`.
194194
The function signature is::
195195
196-
PyObject *_PyCFunctionFast(PyObject *self,
197-
PyObject *const *args,
198-
Py_ssize_t nargs);
196+
PyObject *PyCFunctionFast(PyObject *self,
197+
PyObject *const *args,
198+
Py_ssize_t nargs);
199199
200-
.. c:type:: _PyCFunctionFastWithKeywords
200+
.. c:type:: PyCFunctionFastWithKeywords
201201
202202
Type of the functions used to implement Python callables in C
203203
with signature :ref:`METH_FASTCALL | METH_KEYWORDS <METH_FASTCALL-METH_KEYWORDS>`.
204204
The function signature is::
205205
206-
PyObject *_PyCFunctionFastWithKeywords(PyObject *self,
207-
PyObject *const *args,
208-
Py_ssize_t nargs,
209-
PyObject *kwnames);
206+
PyObject *PyCFunctionFastWithKeywords(PyObject *self,
207+
PyObject *const *args,
208+
Py_ssize_t nargs,
209+
PyObject *kwnames);
210210
211211
.. c:type:: PyCMethod
212212
@@ -290,7 +290,7 @@ There are these calling conventions:
290290
.. c:macro:: METH_FASTCALL
291291
292292
Fast calling convention supporting only positional arguments.
293-
The methods have the type :c:type:`_PyCFunctionFast`.
293+
The methods have the type :c:type:`PyCFunctionFast`.
294294
The first parameter is *self*, the second parameter is a C array
295295
of :c:expr:`PyObject*` values indicating the arguments and the third
296296
parameter is the number of arguments (the length of the array).
@@ -306,7 +306,7 @@ There are these calling conventions:
306306
307307
:c:expr:`METH_FASTCALL | METH_KEYWORDS`
308308
Extension of :c:macro:`METH_FASTCALL` supporting also keyword arguments,
309-
with methods of type :c:type:`_PyCFunctionFastWithKeywords`.
309+
with methods of type :c:type:`PyCFunctionFastWithKeywords`.
310310
Keyword arguments are passed the same way as in the
311311
:ref:`vectorcall protocol <vectorcall>`:
312312
there is an additional fourth :c:expr:`PyObject*` parameter

Doc/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@
101101
('c:func', 'dlopen'),
102102
('c:func', 'exec'),
103103
('c:func', 'fcntl'),
104+
('c:func', 'flock'),
104105
('c:func', 'fork'),
105106
('c:func', 'free'),
106107
('c:func', 'gettimeofday'),
107108
('c:func', 'gmtime'),
108109
('c:func', 'grantpt'),
110+
('c:func', 'ioctl'),
109111
('c:func', 'localeconv'),
110112
('c:func', 'localtime'),
111113
('c:func', 'main'),
@@ -275,6 +277,7 @@
275277
('py:attr', '__annotations__'),
276278
('py:meth', '__missing__'),
277279
('py:attr', '__wrapped__'),
280+
('py:attr', 'decimal.Context.clamp'),
278281
('py:meth', 'index'), # list.index, tuple.index, etc.
279282
]
280283

Doc/data/stable_abi.dat

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/howto/descriptor.rst

+36-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _descriptorhowto:
22

3-
======================
4-
Descriptor HowTo Guide
5-
======================
3+
================
4+
Descriptor Guide
5+
================
66

77
:Author: Raymond Hettinger
88
:Contact: <python at rcn dot com>
@@ -1004,31 +1004,42 @@ here is a pure Python equivalent:
10041004
if doc is None and fget is not None:
10051005
doc = fget.__doc__
10061006
self.__doc__ = doc
1007-
self._name = ''
1007+
self._name = None
10081008

10091009
def __set_name__(self, owner, name):
10101010
self._name = name
10111011

1012+
@property
1013+
def __name__(self):
1014+
return self._name if self._name is not None else self.fget.__name__
1015+
1016+
@__name__.setter
1017+
def __name__(self, value):
1018+
self._name = value
1019+
10121020
def __get__(self, obj, objtype=None):
10131021
if obj is None:
10141022
return self
10151023
if self.fget is None:
10161024
raise AttributeError(
1017-
f'property {self._name!r} of {type(obj).__name__!r} object has no getter'
1025+
f'property {self.__name__!r} of {type(obj).__name__!r} '
1026+
'object has no getter'
10181027
)
10191028
return self.fget(obj)
10201029

10211030
def __set__(self, obj, value):
10221031
if self.fset is None:
10231032
raise AttributeError(
1024-
f'property {self._name!r} of {type(obj).__name__!r} object has no setter'
1033+
f'property {self.__name__!r} of {type(obj).__name__!r} '
1034+
'object has no setter'
10251035
)
10261036
self.fset(obj, value)
10271037

10281038
def __delete__(self, obj):
10291039
if self.fdel is None:
10301040
raise AttributeError(
1031-
f'property {self._name!r} of {type(obj).__name__!r} object has no deleter'
1041+
f'property {self.__name__!r} of {type(obj).__name__!r} '
1042+
'object has no deleter'
10321043
)
10331044
self.fdel(obj)
10341045

@@ -1192,6 +1203,10 @@ roughly equivalent to:
11921203
"Emulate method_getattro() in Objects/classobject.c"
11931204
return getattr(self.__func__, name)
11941205

1206+
def __get__(self, obj, objtype=None):
1207+
"Emulate method_descr_get() in Objects/classobject.c"
1208+
return self
1209+
11951210
To support automatic creation of methods, functions include the
11961211
:meth:`__get__` method for binding methods during attribute access. This
11971212
means that functions are non-data descriptors that return bound methods
@@ -1214,8 +1229,20 @@ descriptor works in practice:
12141229
.. testcode::
12151230

12161231
class D:
1217-
def f(self, x):
1218-
return x
1232+
def f(self):
1233+
return self
1234+
1235+
class D2:
1236+
pass
1237+
1238+
.. doctest::
1239+
:hide:
1240+
1241+
>>> d = D()
1242+
>>> d2 = D2()
1243+
>>> d2.f = d.f.__get__(d2, D2)
1244+
>>> d2.f() is d
1245+
True
12191246

12201247
The function has a :term:`qualified name` attribute to support introspection:
12211248

0 commit comments

Comments
 (0)