Skip to content

Commit 5213757

Browse files
authored
Merge branch 'main' into ft_grpmodule_2
2 parents f51d0d9 + 0240ef4 commit 5213757

File tree

299 files changed

+6481
-3519
lines changed

Some content is hidden

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

299 files changed

+6481
-3519
lines changed

.github/workflows/jit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
- '**jit**'
66
- 'Python/bytecodes.c'
77
- 'Python/optimizer*.c'
8+
- 'Python/executor_cases.c.h'
9+
- 'Python/optimizer_cases.c.h'
810
- '!Python/perf_jit_trampoline.c'
911
- '!**/*.md'
1012
- '!**/*.ini'
@@ -13,6 +15,8 @@ on:
1315
- '**jit**'
1416
- 'Python/bytecodes.c'
1517
- 'Python/optimizer*.c'
18+
- 'Python/executor_cases.c.h'
19+
- 'Python/optimizer_cases.c.h'
1620
- '!Python/perf_jit_trampoline.c'
1721
- '!**/*.md'
1822
- '!**/*.ini'

.github/workflows/posix-deps-apt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ apt-get -yq install \
2525
uuid-dev \
2626
xvfb \
2727
zlib1g-dev
28+
29+
# Workaround missing libmpdec-dev on ubuntu 24.04:
30+
# https://launchpad.net/~ondrej/+archive/ubuntu/php
31+
# https://deb.sury.org/
32+
sudo add-apt-repository ppa:ondrej/php
33+
apt-get update
34+
apt-get -yq install libmpdec-dev

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ repos:
3434
name: Run Black on Tools/jit/
3535
files: ^Tools/jit/
3636

37+
- repo: https://github.com/Lucas-C/pre-commit-hooks
38+
rev: v1.5.5
39+
hooks:
40+
- id: remove-tabs
41+
types: [python]
42+
exclude: ^Tools/c-analyzer/cpython/_parser.py
43+
3744
- repo: https://github.com/pre-commit/pre-commit-hooks
3845
rev: v5.0.0
3946
hooks:

Doc/c-api/capsule.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,19 @@ Refer to :ref:`using-capsules` for more information on using these objects.
105105
``module.attribute``. The *name* stored in the capsule must match this
106106
string exactly.
107107
108+
This function splits *name* on the ``.`` character, and imports the first
109+
element. It then processes further elements using attribute lookups.
110+
108111
Return the capsule's internal *pointer* on success. On failure, set an
109112
exception and return ``NULL``.
110113
114+
.. note::
115+
116+
If *name* points to an attribute of some submodule or subpackage, this
117+
submodule or subpackage must be previously imported using other means
118+
(for example, by using :c:func:`PyImport_ImportModule`) for the
119+
attribute lookups to succeed.
120+
111121
.. versionchanged:: 3.3
112122
*no_block* has no effect anymore.
113123

Doc/c-api/code.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,71 @@ bound into a function.
211211
.. versionadded:: 3.12
212212
213213
214+
.. _c_codeobject_flags:
215+
216+
Code Object Flags
217+
-----------------
218+
219+
Code objects contain a bit-field of flags, which can be retrieved as the
220+
:attr:`~codeobject.co_flags` Python attribute (for example using
221+
:c:func:`PyObject_GetAttrString`), and set using a *flags* argument to
222+
:c:func:`PyUnstable_Code_New` and similar functions.
223+
224+
Flags whose names start with ``CO_FUTURE_`` correspond to features normally
225+
selectable by :ref:`future statements <future>`. These flags can be used in
226+
:c:member:`PyCompilerFlags.cf_flags`.
227+
Note that many ``CO_FUTURE_`` flags are mandatory in current versions of
228+
Python, and setting them has no effect.
229+
230+
The following flags are available.
231+
For their meaning, see the linked documentation of their Python equivalents.
232+
233+
234+
.. list-table::
235+
:widths: auto
236+
:header-rows: 1
237+
238+
* * Flag
239+
* Meaning
240+
* * .. c:macro:: CO_OPTIMIZED
241+
* :py:data:`inspect.CO_OPTIMIZED`
242+
* * .. c:macro:: CO_NEWLOCALS
243+
* :py:data:`inspect.CO_NEWLOCALS`
244+
* * .. c:macro:: CO_VARARGS
245+
* :py:data:`inspect.CO_VARARGS`
246+
* * .. c:macro:: CO_VARKEYWORDS
247+
* :py:data:`inspect.CO_VARKEYWORDS`
248+
* * .. c:macro:: CO_NESTED
249+
* :py:data:`inspect.CO_NESTED`
250+
* * .. c:macro:: CO_GENERATOR
251+
* :py:data:`inspect.CO_GENERATOR`
252+
* * .. c:macro:: CO_COROUTINE
253+
* :py:data:`inspect.CO_COROUTINE`
254+
* * .. c:macro:: CO_ITERABLE_COROUTINE
255+
* :py:data:`inspect.CO_ITERABLE_COROUTINE`
256+
* * .. c:macro:: CO_ASYNC_GENERATOR
257+
* :py:data:`inspect.CO_ASYNC_GENERATOR`
258+
* * .. c:macro:: CO_HAS_DOCSTRING
259+
* :py:data:`inspect.CO_HAS_DOCSTRING`
260+
* * .. c:macro:: CO_METHOD
261+
* :py:data:`inspect.CO_METHOD`
262+
263+
* * .. c:macro:: CO_FUTURE_DIVISION
264+
* no effect (:py:data:`__future__.division`)
265+
* * .. c:macro:: CO_FUTURE_ABSOLUTE_IMPORT
266+
* no effect (:py:data:`__future__.absolute_import`)
267+
* * .. c:macro:: CO_FUTURE_WITH_STATEMENT
268+
* no effect (:py:data:`__future__.with_statement`)
269+
* * .. c:macro:: CO_FUTURE_PRINT_FUNCTION
270+
* no effect (:py:data:`__future__.print_function`)
271+
* * .. c:macro:: CO_FUTURE_UNICODE_LITERALS
272+
* no effect (:py:data:`__future__.unicode_literals`)
273+
* * .. c:macro:: CO_FUTURE_GENERATOR_STOP
274+
* no effect (:py:data:`__future__.generator_stop`)
275+
* * .. c:macro:: CO_FUTURE_ANNOTATIONS
276+
* :py:data:`__future__.annotations`
277+
278+
214279
Extra information
215280
-----------------
216281

Doc/c-api/init.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12501250
.. c:function:: void PyInterpreterState_Clear(PyInterpreterState *interp)
12511251
12521252
Reset all information in an interpreter state object. There must be
1253-
an :term:`attached thread state` for the the interpreter.
1253+
an :term:`attached thread state` for the interpreter.
12541254
12551255
.. audit-event:: cpython.PyInterpreterState_Clear "" c.PyInterpreterState_Clear
12561256
@@ -2277,6 +2277,18 @@ The C-API provides a basic mutual exclusion lock.
22772277
22782278
.. versionadded:: 3.13
22792279
2280+
.. c:function:: int PyMutex_IsLocked(PyMutex *m)
2281+
2282+
Returns non-zero if the mutex *m* is currently locked, zero otherwise.
2283+
2284+
.. note::
2285+
2286+
This function is intended for use in assertions and debugging only and
2287+
should not be used to make concurrency control decisions, as the lock
2288+
state may change immediately after the check.
2289+
2290+
.. versionadded:: next
2291+
22802292
.. _python-critical-section-api:
22812293
22822294
Python Critical Section API

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
439439
All *n_bytes* of the buffer are written: large buffers are padded with
440440
zeroes.
441441
442-
If the returned value is greater than than *n_bytes*, the value was
442+
If the returned value is greater than *n_bytes*, the value was
443443
truncated: as many of the lowest bits of the value as could fit are written,
444444
and the higher bits are ignored. This matches the typical behavior
445445
of a C-style downcast.

Doc/c-api/object.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ Object Protocol
197197
in favour of using :c:func:`PyObject_DelAttr`, but there are currently no
198198
plans to remove it.
199199
200+
The function must not be called with ``NULL`` *v* and an an exception set.
201+
This case can arise from forgetting ``NULL`` checks and would delete the
202+
attribute.
203+
204+
.. versionchanged:: next
205+
Must not be called with NULL value if an exception is set.
206+
200207
201208
.. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)
202209
@@ -207,6 +214,10 @@ Object Protocol
207214
If *v* is ``NULL``, the attribute is deleted, but this feature is
208215
deprecated in favour of using :c:func:`PyObject_DelAttrString`.
209216
217+
The function must not be called with ``NULL`` *v* and an an exception set.
218+
This case can arise from forgetting ``NULL`` checks and would delete the
219+
attribute.
220+
210221
The number of different attribute names passed to this function
211222
should be kept small, usually by using a statically allocated string
212223
as *attr_name*.
@@ -215,6 +226,10 @@ Object Protocol
215226
For more details, see :c:func:`PyUnicode_InternFromString`, which may be
216227
used internally to create a key object.
217228
229+
.. versionchanged:: next
230+
Must not be called with NULL value if an exception is set.
231+
232+
218233
.. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)
219234
220235
Generic attribute setter and deleter function that is meant

Doc/c-api/structures.rst

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,52 @@ under :ref:`reference counting <countingrefs>`.
2828
object. In a normal "release" build, it contains only the object's
2929
reference count and a pointer to the corresponding type object.
3030
Nothing is actually declared to be a :c:type:`PyObject`, but every pointer
31-
to a Python object can be cast to a :c:expr:`PyObject*`. Access to the
32-
members must be done by using the macros :c:macro:`Py_REFCNT` and
33-
:c:macro:`Py_TYPE`.
31+
to a Python object can be cast to a :c:expr:`PyObject*`.
32+
33+
The members must not be accessed directly; instead use macros such as
34+
:c:macro:`Py_REFCNT` and :c:macro:`Py_TYPE`.
35+
36+
.. c:member:: Py_ssize_t ob_refcnt
37+
38+
The object's reference count, as returned by :c:macro:`Py_REFCNT`.
39+
Do not use this field directly; instead use functions and macros such as
40+
:c:macro:`!Py_REFCNT`, :c:func:`Py_INCREF` and :c:func:`Py_DecRef`.
41+
42+
The field type may be different from ``Py_ssize_t``, depending on
43+
build configuration and platform.
44+
45+
.. c:member:: PyTypeObject* ob_type
46+
47+
The object's type.
48+
Do not use this field directly; use :c:macro:`Py_TYPE` and
49+
:c:func:`Py_SET_TYPE` instead.
3450

3551

3652
.. c:type:: PyVarObject
3753
38-
This is an extension of :c:type:`PyObject` that adds the :c:member:`~PyVarObject.ob_size`
39-
field. This is only used for objects that have some notion of *length*.
40-
This type does not often appear in the Python/C API.
41-
Access to the members must be done by using the macros
42-
:c:macro:`Py_REFCNT`, :c:macro:`Py_TYPE`, and :c:macro:`Py_SIZE`.
54+
An extension of :c:type:`PyObject` that adds the
55+
:c:member:`~PyVarObject.ob_size` field.
56+
This is intended for objects that have some notion of *length*.
57+
58+
As with :c:type:`!PyObject`, the members must not be accessed directly;
59+
instead use macros such as :c:macro:`Py_SIZE`, :c:macro:`Py_REFCNT` and
60+
:c:macro:`Py_TYPE`.
61+
62+
.. c:member:: Py_ssize_t ob_size
63+
64+
A size field, whose contents should be considered an object's internal
65+
implementation detail.
66+
67+
Do not use this field directly; use :c:macro:`Py_SIZE` instead.
68+
69+
Object creation functions such as :c:func:`PyObject_NewVar` will
70+
generally set this field to the requested size (number of items).
71+
After creation, arbitrary values can be stored in :c:member:`!ob_size`
72+
using :c:macro:`Py_SET_SIZE`.
73+
74+
To get an object's publicly exposed length, as returned by
75+
the Python function :py:func:`len`, use :c:func:`PyObject_Length`
76+
instead.
4377

4478

4579
.. c:macro:: PyObject_HEAD
@@ -103,9 +137,8 @@ under :ref:`reference counting <countingrefs>`.
103137
104138
Get the type of the Python object *o*.
105139
106-
Return a :term:`borrowed reference`.
107-
108-
Use the :c:func:`Py_SET_TYPE` function to set an object type.
140+
The returned reference is :term:`borrowed <borrowed reference>` from *o*.
141+
Do not release it with :c:func:`Py_DECREF` or similar.
109142
110143
.. versionchanged:: 3.11
111144
:c:func:`Py_TYPE()` is changed to an inline static function.
@@ -122,16 +155,26 @@ under :ref:`reference counting <countingrefs>`.
122155
123156
.. c:function:: void Py_SET_TYPE(PyObject *o, PyTypeObject *type)
124157
125-
Set the object *o* type to *type*.
158+
Set the type of object *o* to *type*, without any checking or reference
159+
counting.
160+
161+
This is a very low-level operation.
162+
Consider instead setting the Python attribute :attr:`~object.__class__`
163+
using :c:func:`PyObject_SetAttrString` or similar.
164+
165+
Note that assigning an incompatible type can lead to undefined behavior.
166+
167+
If *type* is a :ref:`heap type <heap-types>`, the caller must create a
168+
new reference to it.
169+
Similarly, if the old type of *o* is a heap type, the caller must release
170+
a reference to that type.
126171
127172
.. versionadded:: 3.9
128173
129174
130175
.. c:function:: Py_ssize_t Py_SIZE(PyVarObject *o)
131176
132-
Get the size of the Python object *o*.
133-
134-
Use the :c:func:`Py_SET_SIZE` function to set an object size.
177+
Get the :c:member:`~PyVarObject.ob_size` field of *o*.
135178
136179
.. versionchanged:: 3.11
137180
:c:func:`Py_SIZE()` is changed to an inline static function.
@@ -140,7 +183,7 @@ under :ref:`reference counting <countingrefs>`.
140183
141184
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)
142185
143-
Set the object *o* size to *size*.
186+
Set the :c:member:`~PyVarObject.ob_size` field of *o* to *size*.
144187
145188
.. versionadded:: 3.9
146189

Doc/c-api/typeobj.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,9 @@ metatype) initializes :c:member:`~PyTypeObject.tp_itemsize`, which means that it
492492
type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
493493

494494

495-
.. c:member:: Py_ssize_t PyObject.ob_refcnt
495+
:c:member:`PyObject.ob_refcnt`
496496

497-
This is the type object's reference count, initialized to ``1`` by the
497+
The type object's reference count is initialized to ``1`` by the
498498
``PyObject_HEAD_INIT`` macro. Note that for :ref:`statically allocated type
499499
objects <static-types>`, the type's instances (objects whose :c:member:`~PyObject.ob_type`
500500
points back to the type) do *not* count as references. But for
@@ -506,7 +506,7 @@ type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
506506
This field is not inherited by subtypes.
507507

508508

509-
.. c:member:: PyTypeObject* PyObject.ob_type
509+
:c:member:`PyObject.ob_type`
510510

511511
This is the type's type, in other words its metatype. It is initialized by the
512512
argument to the ``PyObject_HEAD_INIT`` macro, and its value should normally be
@@ -532,14 +532,13 @@ type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
532532
PyVarObject Slots
533533
-----------------
534534

535-
.. c:member:: Py_ssize_t PyVarObject.ob_size
535+
:c:member:`PyVarObject.ob_size`
536536

537537
For :ref:`statically allocated type objects <static-types>`, this should be
538538
initialized to zero. For :ref:`dynamically allocated type objects
539539
<heap-types>`, this field has a special internal meaning.
540540

541-
This field should be accessed using the :c:func:`Py_SIZE()` and
542-
:c:func:`Py_SET_SIZE()` macros.
541+
This field should be accessed using the :c:func:`Py_SIZE()` macro.
543542

544543
**Inheritance:**
545544

0 commit comments

Comments
 (0)