8000 Merge branch 'main' of https://github.com/python/cpython into slotdefs · python/cpython@f706aed · GitHub
[go: up one dir, main page]

Skip to content

Commit f706aed

Browse files
Merge branch 'main' of https://github.com/python/cpython into slotdefs
2 parents 56cb979 + af6359d commit f706aed

File tree

153 files changed

+4218
-1468
lines changed

Some content is hidden

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

153 files changed

+4218
-1468
lines changed

.azure-pipelines/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
variables:
5858
testRunTitle: '$(build.sourceBranchName)-linux'
5959
testRunPlatform: linux
60-
openssl_version: 1.1.1n
60+
openssl_version: 1.1.1q
6161

6262
steps:
6363
- template: ./posix-steps.yml
@@ -83,7 +83,7 @@ jobs:
8383
variables:
8484
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'
8585
testRunPlatform: linux-coverage
86-
openssl_version: 1.1.1n
86+
openssl_version: 1.1.1q
8787

8888
steps:
8989
- template: ./posix-steps.yml

.azure-pipelines/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
variables:
5858
testRunTitle: '$(system.pullRequest.TargetBranch)-linux'
5959
testRunPlatform: linux
60-
openssl_version: 1.1.1n
60+
openssl_version: 1.1.1q
6161

6262
steps:
6363
- template: ./posix-steps.yml
@@ -83,7 +83,7 @@ jobs:
8383
variables:
8484
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'
8585
testRunPlatform: linux-coverage
86-
openssl_version: 1.1.1n
86+
openssl_version: 1.1.1q
8787

8888
steps:
8989
- template: ./posix-steps.yml

.github/workflows/build.yml

+3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
needs: check_source
176176
if: needs.check_source.outputs.run_tests == 'true'
177177
env:
178-
OPENSSL_VER: 1.1.1n
178+
OPENSSL_VER: 1.1.1q
179179
PYTHONSTRICTEXTENSIONBUILD: 1
180180
steps:
181181
- uses: actions/checkout@v3
@@ -234,7 +234,7 @@ jobs:
234234
strategy:
235235
fail-fast: false
236236
matrix:
237-
openssl_ver: [1.1.1n, 3.0.2]
237+
openssl_ver: [1.1.1q, 3.0.5]
238238
env:
239239
OPENSSL_VER: ${{ matrix.openssl_ver }}
240240
MULTISSL_DIR: ${{ github.workspace }}/multissl
@@ -281,7 +281,7 @@ jobs:
281281
needs: check_source
282282
if: needs.check_source.outputs.run_tests == 'true'
283283
env:
284-
OPENSSL_VER: 1.1.1n
284+
OPENSSL_VER: 1.1.1q
285285
PYTHONSTRICTEXTENSIONBUILD: 1
286286
ASAN_OPTIONS: detect_leaks=0:allocator_may_return_null=1:handle_segv=0
287287
steps:

.github/workflows/project-updater.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ on:
88

99
jobs:
1010
add-to-project:
11-
name: Add to the Release and Deferred Blocker project
11+
name: Add issues to projects
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
include:
16+
# if an issue has any of these labels, it will be added
17+
# to the corresponding project
18+
- { project: 2, label: "release-blocker, deferred-blocker" }
19+
- { project: 3, label: expert-subinterpreters }
20+
- { project: 29, label: expert-asyncio }
21+
1322
steps:
1423
- uses: actions/add-to-project@v0.1.0
1524
with:
16-
project-url: https://github.com/orgs/python/projects/2
25+
project-url: https://github.com/orgs/python/projects/${{ matrix.project }}
1726
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
18-
labeled: release-blocker, deferred-blocker
19-
label-operator: OR
27+
labeled: ${{ matrix.label }}

Doc/c-api/init_config.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,20 @@ PyConfig
11551155
11561156
Default: ``-1`` in Python mode, ``0`` in isolated mode.
11571157
1158+
.. c:member:: int perf_profiling
1159+
1160+
Enable compatibility mode with the perf profiler?
1161+
1162+
If non-zero, initialize the perf trampoline. See :ref:`perf_profiling`
1163+
for more information.
1164+
1165+
Set by :option:`-X perf <-X>` command line option and by the
1166+
:envvar:`PYTHONPERFSUPPORT` environment variable.
1167+
1168+
Default: ``-1``.
1169+
1170+
.. versionadded:: 3.12
1171+
11581172
.. c:member:: int use_environment
11591173
11601174
Use :ref:`environment variables <using-on-envvars>`?

Doc/c-api/structures.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,21 @@ Accessing attributes of extension types
469469
.. _pymemberdef-offsets:
470470
471471
Heap allocated types (created using :c:func:`PyType_FromSpec` or similar),
472-
``PyMemberDef`` may contain definitions for the special members
473-
``__dictoffset__``, ``__weaklistoffset__`` and ``__vectorcalloffset__``,
474-
corresponding to
475-
:c:member:`~PyTypeObject.tp_dictoffset`,
476-
:c:member:`~PyTypeObject.tp_weaklistoffset` and
472+
``PyMemberDef`` may contain definitions for the special member
473+
``__vectorcalloffset__``, corresponding to
477474
:c:member:`~PyTypeObject.tp_vectorcall_offset` in type objects.
478475
These must be defined with ``T_PYSSIZET`` and ``READONLY``, for example::
479476
480477
static PyMemberDef spam_type_members[] = {
481-
{"__dictoffset__", T_PYSSIZET, offsetof(Spam_object, dict), READONLY},
478+
{"__vectorcalloffset__", T_PYSSIZET, offsetof(Spam_object, vectorcall), READONLY},
482479
{NULL} /* Sentinel */
483480
};
484481
482+
The legacy offsets :c:member:`~PyTypeObject.tp_dictoffset` and
483+
:c:member:`~PyTypeObject.tp_weaklistoffset` are still supported, but extensions are
484+
strongly encouraged to use ``Py_TPFLAGS_MANAGED_DICT`` and
485+
``Py_TPFLAGS_MANAGED_WEAKREF`` instead.
486+
485487
486488
.. c:function:: PyObject* PyMember_GetOne(const char *obj_addr, struct PyMemberDef *m)
487489

Doc/c-api/type.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ The following functions and structs are used to create
327327
* :c:member:`~PyTypeObject.tp_weaklist`
328328
* :c:member:`~PyTypeObject.tp_vectorcall`
329329
* :c:member:`~PyTypeObject.tp_weaklistoffset`
330-
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
330+
(use :const:`Py_TPFLAGS_MANAGED_WEAKREF` instead)
331331
* :c:member:`~PyTypeObject.tp_dictoffset`
332-
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
332+
(use :const:`Py_TPFLAGS_MANAGED_DICT` instead)
333333
* :c:member:`~PyTypeObject.tp_vectorcall_offset`
334334
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
335335

Doc/c-api/typeobj.rst

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Quick Reference
9696
| | | __gt__, | | | | |
9797
| | | __ge__ | | | | |
9898
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
99-
| :c:member:`~PyTypeObject.tp_weaklistoffset` | :c:type:`Py_ssize_t` | | | X | | ? |
99+
| (:c:member:`~PyTypeObject.tp_weaklistoffset`) | :c:type:`Py_ssize_t` | | | X | | ? |
100100
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
101101
| :c:member:`~PyTypeObject.tp_iter` | :c:type:`getiterfunc` | __iter__ | | | | X |
102102
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
@@ -117,7 +117,7 @@ Quick Reference
117117
| :c:member:`~PyTypeObject.tp_descr_set` | :c:type:`descrsetfunc` | __set__, | | | | X |
118118
| | | __delete__ | | | | |
119119
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
120-
| :c:member:`~PyTypeObject.tp_dictoffset` | :c:type:`Py_ssize_t` | | | X | | ? |
120+
| (:c:member:`~PyTypeObject.tp_dictoffset`) | :c:type:`Py_ssize_t` | | | X | | ? |
121121
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
122122
| :c:member:`~PyTypeObject.tp_init` | :c:type:`initproc` | __init__ | X | X | | X |
123123
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
@@ -1018,7 +1018,6 @@ and :c:type:`PyType_Type` effectively act as defaults.)
10181018
:const:`Py_TPFLAGS_HAVE_GC` flag bit is clear in the subtype and the
10191019
:c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear` fields in the subtype exist and have
10201020
``NULL`` values.
1021-
10221021
.. XXX are most flag bits *really* inherited individually?
10231022
10241023
**Default:**
@@ -1135,6 +1134,33 @@ and :c:type:`PyType_Type` effectively act as defaults.)
11351134
:const:`Py_TPFLAGS_IMMUTABLETYPE` flag set. For extension types, it is
11361135
inherited whenever :c:member:`~PyTypeObject.tp_descr_get` is inherited.
11371136

1137+
.. data:: Py_TPFLAGS_MANAGED_DICT
1138+
1139+
This bit indicates that instances of the class have a ``__dict___``
1140+
attribute, and that the space for the dictionary is managed by the VM.
1141+
1142+
If this flag is set, :const:`Py_TPFLAGS_HAVE_GC` should also be set.
1143+
1144+
.. versionadded:: 3.12
1145+
1146+
**Inheritance:**
1147+
1148+
This flag is inherited unless the
1149+
:c:member:`~PyTypeObject.tp_dictoffset` field is set in a superclass.
1150+
1151+
1152+
.. data:: Py_TPFLAGS_MANAGED_WEAKREF
1153+
1154+
This bit indicates that instances of the class should be weakly
1155+
referenceable.
1156+
1157+
.. versionadded:: 3.12
1158+
1159+
**Inheritance:**
1160+
1161+
This flag is inherited unless the
1162+
:c:member:`~PyTypeObject.tp_weaklistoffset` field is set in a superclass.
1163+
11381164

11391165
.. XXX Document more flags here?
11401166
@@ -1487,6 +1513,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
14871513

14881514
.. c:member:: Py_ssize_t PyTypeObject.tp_weaklistoffset
14891515
1516+
While this field is still supported, :const:`Py_TPFLAGS_MANAGED_WEAKREF`
1517+
should be used instead, if at all possible.
1518+
14901519
If the instances of this type are weakly referenceable, this field is greater
14911520
than zero and contains the offset in the instance structure of the weak
14921521
reference list head (ignoring the GC header, if present); this offset is used by
@@ -1497,26 +1526,22 @@ and :c:type:`PyType_Type` effectively act as defaults.)
14971526
Do not confuse this field with :c:member:`~PyTypeObject.tp_weaklist`; that is the list head for
14981527
weak references to the type object itself.
14991528

1529+
It is an error to set both the :const:`Py_TPFLAGS_MANAGED_WEAKREF` bit and
1530+
:c:member:`~PyTypeObject.tp_weaklist`.
1531+
15001532
**Inheritance:**
15011533

15021534
This field is inherited by subtypes, but see the rules listed below. A subtype
15031535
may override this offset; this means that the subtype uses a different weak
15041536
reference list head than the base type. Since the list head is always found via
15051537
:c:member:`~PyTypeObject.tp_weaklistoffset`, this should not be a problem.
15061538

1507-
When a type defined by a class statement has no :attr:`~object.__slots__` declaration,
1508-
and none of its base types are weakly referenceable, the type is made weakly
1509-
referenceable by adding a weak reference list head slot to the instance layout
1510-
and setting the :c:member:`~PyTypeObject.tp_weaklistoffset` of that slot's offset.
1511-
1512-
When a type's :attr:`__slots__` declaration contains a slot named
1513-
:attr:`__weakref__`, that slot becomes the weak reference list head for
1514-
instances of the type, and the slot's offset is stored in the type's
1515-
:c:member:`~PyTypeObject.tp_weaklistoffset`.
1539+
**Default:**
15161540

1517-
When a type's :attr:`__slots__` declaration does not contain a slot named
1518-
:attr:`__weakref__`, the type inherits its :c:member:`~PyTypeObject.tp_weaklistoffset` from its
1519-
base type.
1541+
If the :const:`Py_TPFLAGS_MANAGED_WEAKREF` bit is set in the
1542+
:c:member:`~PyTypeObject.tp_dict` field, then
1543+
:c:member:`~PyTypeObject.tp_weaklistoffset` will be set to a negative value,
1544+
to indicate that it is unsafe to use this field.
15201545

15211546

15221547
.. c:member:: getiterfunc PyTypeObject.tp_iter
@@ -1695,6 +1720,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
16951720

16961721
.. c:member:: Py_ssize_t PyTypeObject.tp_dictoffset
16971722
1723+
While this field is still supported, :const:`Py_TPFLAGS_MANAGED_DICT` should be
1724+
used instead, if at all possible.
1725+
16981726
If the instances of this type have a dictionary containing instance variables,
16991727
this field is non-zero and contains the offset in the instances of the type of
17001728
the instance variable dictionary; this offset is used by
@@ -1703,48 +1731,34 @@ and :c:type:`PyType_Type` effectively act as defaults.)
17031731
Do not confuse this field with :c:member:`~PyTypeObject.tp_dict`; that is the dictionary for
17041732
attributes of the type object itself.
17051733

1706-
If the value of this field is greater than zero, it specifies the offset from
1707-
the start of the instance structure. If the value is less than zero, it
1708-
specifies the offset from the *end* of the instance structure. A negative
1709-
offset is more expensive to use, and should only be used when the instance
1710-
structure contains a variable-length part. This is used for example to add an
1711-
instance variable dictionary to subtypes of :class:`str` or :class:`tuple`. Note
1712-
that the :c:member:`~PyTypeObject.tp_basicsize` field should account for the dictionary added to
1713-
the end in that case, even though the dictionary is not included in the basic
1714-
object layout. On a system with a pointer size of 4 bytes,
1715-
:c:member:`~PyTypeObject.tp_dictoffset` should be set to ``-4`` to indicate that the dictionary is
1716-
at the very end of the structure.
1734+
The value specifies the offset of the dictionary from the start of the instance structure.
17171735

17181736
The :c:member:`~PyTypeObject.tp_dictoffset` should be regarded as write-only.
17191737
To get the pointer to the dictionary call :c:func:`PyObject_GenericGetDict`.
17201738
Calling :c:func:`PyObject_GenericGetDict` may need to allocate memory for the
17211739
dictionary, so it is may be more efficient to call :c:func:`PyObject_GetAttr`
17221740
when accessing an attribute on the object.
17231741

1724-
**Inheritance:**
1725-
1726-
This field is inherited by subtypes, but see the rules listed below. A subtype
1727-
may override this offset; this means that the subtype instances store the
1728-
dictionary at a difference offset than the base type. Since the dictionary is
1729-
always found via :c:member:`~PyTypeObject.tp_dictoffset`, this should not be a problem.
1742+
It is an error to set both the :const:`Py_TPFLAGS_MANAGED_WEAKREF` bit and
1743+
:c:member:`~PyTypeObject.tp_dictoffset`.
17301744

1731-
When a type defined by a class statement has no :attr:`~object.__slots__` declaration,
1732-
and none of its base types has an instance variable dictionary, a dictionary
1733-
slot is added to the instance layout and the :c:member:`~PyTypeObject.tp_dictoffset` is set to
1734-
that slot's offset.
1735-
1736-
When a type defined by a class statement has a :attr:`__slots__` declaration,
1737-
the type inherits its :c:member:`~PyTypeObject.tp_dictoffset` from its base type.
1745+
**Inheritance:**
17381746

1739-
(Adding a slot named :attr:`~object.__dict__` to the :attr:`__slots__` declaration does
1740-
not have the expected effect, it just causes confusion. Maybe this should be
1741-
added as a feature just like :attr:`__weakref__` though.)
1747+
This field is inherited by subtypes. A subtype should not override this offset;
1748+
doing so could be unsafe, if C code tries to access the dictionary at the
1749+
previous offset.
1750+
To properly support inheritance, use :const:`Py_TPFLAGS_MANAGED_DICT`.
17421751

17431752
**Default:**
17441753

17451754
This slot has no default. For :ref:`static types <static-types>`, if the
17461755
field is ``NULL`` then no :attr:`__dict__` gets created for instances.
17471756

1757+
If the :const:`Py_TPFLAGS_MANAGED_DICT` bit is set in the
1758+
:c:member:`~PyTypeObject.tp_dict` field, then
1759+
:c:member:`~PyTypeObject.tp_dictoffset` will be set to ``-1``, to indicate
1760+
that it is unsafe to use this field.
1761+
17481762

17491763
.. c:member:: initproc PyTypeObject.tp_init
17501764
@@ -2005,9 +2019,6 @@ and :c:type:`PyType_Type` effectively act as defaults.)
20052019
PyErr_Restore(error_type, error_value, error_traceback);
20062020
}
20072021

2008-
For this field to be taken into account (even through inheritance),
2009-
you must also set the :const:`Py_TPFLAGS_HAVE_FINALIZE` flags bit.
2010-
20112022
Also, note that, in a garbage collected Python,
20122023
:c:member:`~PyTypeObject.tp_dealloc` may be called from
20132024
any Python thread, not just the thread which created the object (if the object
@@ -2025,6 +2036,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
20252036

20262037
.. versionadded:: 3.4
20272038

2039+
.. versionchanged:: 3.8
2040+
2041+
Before version 3.8 it was necessary to set the
2042+
:const:`Py_TPFLAGS_HAVE_FINALIZE` flags bit in order for this field to be
2043+
used. This is no longer required.
2044+
20282045
.. seealso:: "Safe object finalization" (:pep:`442`)
20292046

20302047

@@ -2660,18 +2677,16 @@ A type that supports weakrefs, instance dicts, and hashing::
26602677
typedef struct {
26612678
PyObject_HEAD
26622679
const char *data;
2663-
PyObject *inst_dict;
2664-
PyObject *weakreflist;
26652680
} MyObject;
26662681

26672682
static PyTypeObject MyObject_Type = {
26682683
PyVarObject_HEAD_INIT(NULL, 0)
26692684
.tp_name = "mymod.MyObject",
26702685
.tp_basicsize = sizeof(MyObject),
26712686
.tp_doc = PyDoc_STR("My objects"),
2672-
.tp_weaklistoffset = offsetof(MyObject, weakreflist),
2673-
.tp_dictoffset = offsetof(MyObject, inst_dict),
2674-
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
2687+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
2688+
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_MANAGED_DICT |
2689+
Py_TPFLAGS_MANAGED_WEAKREF,
26752690
.tp_new = myobj_new,
26762691
.tp_traverse = (traverseproc)myobj_traverse,
26772692
.tp_clear = (inquiry)myobj_clear,

0 commit comments

Comments
 (0)
0