Skip to content

Commit 72cd269

Browse files
authored
Merge branch 'main' into spi-cache
2 parents aa825d2 + 8a284e1 commit 72cd269

Some content is hidden

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

59 files changed

+661
-673
lines changed

Doc/c-api/code.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ bound into a function.
9696
Return the line number of the instruction that occurs on or before ``byte_offset`` and ends after it.
9797
If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead.
9898
99-
For efficiently iterating over the line numbers in a code object, use `the API described in PEP 626
100-
<https://peps.python.org/pep-0626/#out-of-process-debuggers-and-profilers>`_.
99+
For efficiently iterating over the line numbers in a code object, use :pep:`the API described in PEP 626
100+
<0626#out-of-process-debuggers-and-profilers>`.
101101
102102
.. c:function:: int PyCode_Addr2Location(PyObject *co, int byte_offset, int *start_line, int *start_column, int *end_line, int *end_column)
103103

Doc/c-api/complex.rst

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pointers. This is consistent throughout the API.
7979
If *num* is null and *exp* is not a positive real number,
8080
this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.
8181
82+
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
83+
8284
8385
Complex Numbers as Python Objects
8486
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Doc/c-api/refcounting.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ of Python objects.
6262
``NULL``, use :c:func:`Py_XINCREF`.
6363
6464
Do not expect this function to actually modify *o* in any way.
65-
For at least `some objects <https://peps.python.org/pep-0683/>`_,
65+
For at least :pep:`some objects <0683>`,
6666
this function has no effect.
6767
6868
.. versionchanged:: 3.12
@@ -130,7 +130,7 @@ of Python objects.
130130
use :c:func:`Py_XDECREF`.
131131
132132
Do not expect this function to actually modify *o* in any way.
133-
For at least `some objects <https://peps.python.org/pep-0683/>`_,
133+
For at least :pep:`some objects <683>`,
134134
this function has no effect.
135135
136136
.. warning::

Doc/c-api/type.rst

+67-1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ Type Objects
264264
265265
.. versionadded:: 3.11
266266
267+
.. c:function:: int PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result)
268+
269+
Find the first superclass in *type*'s :term:`method resolution order` whose
270+
:c:macro:`Py_tp_token` token is equal to the given one.
271+
272+
* If found, set *\*result* to a new :term:`strong reference`
273+
to it and return ``1``.
274+
* If not found, set *\*result* to ``NULL`` and return ``0``.
275+
* On error, set *\*result* to ``NULL`` and return ``-1`` with an
276+
exception set.
277+
278+
The *result* argument may be ``NULL``, in which case *\*result* is not set.
279+
Use this if you need only the return value.
280+
281+
The *token* argument may not be ``NULL``.
282+
283+
.. versionadded:: 3.14
284+
267285
.. c:function:: int PyUnstable_Type_AssignVersionTag(PyTypeObject *type)
268286
269287
Attempt to assign a version tag to the given type.
@@ -488,6 +506,11 @@ The following functions and structs are used to create
488506
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
489507
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
490508
509+
An additional slot is supported that does not correspond to a
510+
:c:type:`!PyTypeObject` struct field:
511+
512+
* :c:data:`Py_tp_token`
513+
491514
The following “offset” fields cannot be set using :c:type:`PyType_Slot`:
492515
493516
* :c:member:`~PyTypeObject.tp_weaklistoffset`
@@ -538,4 +561,47 @@ The following functions and structs are used to create
538561
The desired value of the slot. In most cases, this is a pointer
539562
to a function.
540563
541-
Slots other than ``Py_tp_doc`` may not be ``NULL``.
564+
*pfunc* values may not be ``NULL``, except for the following slots:
565+
566+
* ``Py_tp_doc``
567+
* :c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC`
568+
rather than ``NULL``)
569+
570+
.. c:macro:: Py_tp_token
571+
572+
A :c:member:`~PyType_Slot.slot` that records a static memory layout ID
573+
for a class.
574+
575+
If the :c:type:`PyType_Spec` of the class is statically
576+
allocated, the token can be set to the spec using the special value
577+
:c:data:`Py_TP_USE_SPEC`:
578+
579+
.. code-block:: c
580+
581+
static PyType_Slot foo_slots[] = {
582+
{Py_tp_token, Py_TP_USE_SPEC},
583+
584+
It can also be set to an arbitrary pointer, but you must ensure that:
585+
586+
* The pointer outlives the class, so it's not reused for something else
587+
while the class exists.
588+
* It "belongs" to the extension module where the class lives, so it will not
589+
clash with other extensions.
590+
591+
Use :c:func:`PyType_GetBaseByToken` to check if a class's superclass has
592+
a given token -- that is, check whether the memory layout is compatible.
593+
594+
To get the token for a given class (without considering superclasses),
595+
use :c:func:`PyType_GetSlot` with ``Py_tp_token``.
596+
597+
.. versionadded:: 3.14
598+
599+
.. c:namespace:: NULL
600+
601+
.. c:macro:: Py_TP_USE_SPEC
602+
603+
Used as a value with :c:data:`Py_tp_token` to set the token to the
604+
class's :c:type:`PyType_Spec`.
605+
Expands to ``NULL``.
606+
607+
.. versionadded:: 3.14

Doc/data/stable_abi.dat

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

Doc/faq/general.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ releases.
311311
The latest stable releases can always be found on the `Python download page
312312
<https://www.python.org/downloads/>`_. There are two production-ready versions
313313
of Python: 2.x and 3.x. The recommended version is 3.x, which is supported by
314-
most widely used libraries. Although 2.x is still widely used, `it is not
315-
maintained anymore <https://peps.python.org/pep-0373/>`_.
314+
most widely used libraries. Although 2.x is still widely used, :pep:`it is not
315+
maintained anymore <0373>`.
316316

317317
How many people are using Python?
318318
---------------------------------

Doc/library/ast.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,7 @@ Function and class definitions
20332033
* ``name`` is a raw string for the class name
20342034
* ``bases`` is a list of nodes for explicitly specified base classes.
20352035
* ``keywords`` is a list of :class:`.keyword` nodes, principally for 'metaclass'.
2036-
Other keywords will be passed to the metaclass, as per `PEP-3115
2037-
<https://peps.python.org/pep-3115/>`_.
2036+
Other keywords will be passed to the metaclass, as per :pep:`3115`.
20382037
* ``body`` is a list of nodes representing the code within the class
20392038
definition.
20402039
* ``decorator_list`` is a list of nodes, as in :class:`FunctionDef`.

Doc/library/functools.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ The :mod:`functools` module defines the following functions:
218218
cache. See :ref:`faq-cache-method-calls`
219219

220220
An `LRU (least recently used) cache
221-
<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>`_
221+
<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_(LRU)>`_
222222
works best when the most recent calls are the best predictors of upcoming
223223
calls (for example, the most popular articles on a news server tend to
224224
change each day). The cache's size limit assures that the cache does not

Doc/library/sqlite3.rst

+14-15
Original file line numberDiff line numberDiff line change
@@ -525,21 +525,20 @@ Module constants
525525
The mappings from SQLite threading modes to DB-API 2.0 threadsafety levels
526526
are as follows:
527527

528-
+------------------+-----------------+----------------------+-------------------------------+
529-
| SQLite threading | `threadsafety`_ | `SQLITE_THREADSAFE`_ | DB-API 2.0 meaning |
530-
| mode | | | |
531-
+==================+=================+======================+===============================+
532-
| single-thread | 0 | 0 | Threads may not share the |
533-
| | | | module |
534-
+------------------+-----------------+----------------------+-------------------------------+
535-
| multi-thread | 1 | 2 | Threads may share the module, |
536-
| | | | but not connections |
537-
+------------------+-----------------+----------------------+-------------------------------+
538-
| serialized | 3 | 1 | Threads may share the module, |
539-
| | | | connections and cursors |
540-
+------------------+-----------------+----------------------+-------------------------------+
541-
542-
.. _threadsafety: https://peps.python.org/pep-0249/#threadsafety
528+
+------------------+----------------------+----------------------+-------------------------------+
529+
| SQLite threading | :pep:`threadsafety | `SQLITE_THREADSAFE`_ | DB-API 2.0 meaning |
530+
| mode | <0249#threadsafety>` | | |
531+
+==================+======================+======================+===============================+
532+
| single-thread | 0 | 0 | Threads may not share the |
533+
| | | | module |
534+
+------------------+----------------------+----------------------+-------------------------------+
535+
| multi-thread | 1 | 2 | Threads may share the module, |
536+
| | | | but not connections |
537+
+------------------+----------------------+----------------------+-------------------------------+
538+
| serialized | 3 | 1 | Threads may share the module, |
539+
| | | | connections and cursors |
540+
+------------------+----------------------+----------------------+-------------------------------+
541+
543542
.. _SQLITE_THREADSAFE: https://sqlite.org/compile.html#threadsafe
544543

545544
.. versionchanged:: 3.11

Doc/library/ssl.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,7 @@ enabled when negotiating a SSL session is possible through the
27592759
:meth:`SSLContext.set_ciphers` method. Starting from Python 3.2.3, the
27602760
ssl module disables certain weak ciphers by default, but you may want
27612761
to further restrict the cipher choice. Be sure to read OpenSSL's documentation
2762-
about the `cipher list format <https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT>`_.
2762+
about the `cipher list format <https://docs.openssl.org/1.1.1/man1/ciphers/#cipher-list-format>`_.
27632763
If you want to check which ciphers are enabled by a given cipher list, use
27642764
:meth:`SSLContext.get_ciphers` or the ``openssl ciphers`` command on your
27652765
system.

Doc/library/wsgiref.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,8 @@ in :pep:`3333`.
783783

784784
.. class:: StartResponse()
785785

786-
A :class:`typing.Protocol` describing `start_response()
787-
<https://peps.python.org/pep-3333/#the-start-response-callable>`_
786+
A :class:`typing.Protocol` describing :pep:`start_response()
787+
<3333#the-start-response-callable>`
788788
callables (:pep:`3333`).
789789

790790
.. data:: WSGIEnvironment
@@ -797,18 +797,18 @@ in :pep:`3333`.
797797

798798
.. class:: InputStream()
799799

800-
A :class:`typing.Protocol` describing a `WSGI Input Stream
801-
<https://peps.python.org/pep-3333/#input-and-error-streams>`_.
800+
A :class:`typing.Protocol` describing a :pep:`WSGI Input Stream
801+
<3333#input-and-error-streams>`.
802802

803803
.. class:: ErrorStream()
804804

805-
A :class:`typing.Protocol` describing a `WSGI Error Stream
806-
<https://peps.python.org/pep-3333/#input-and-error-streams>`_.
805+
A :class:`typing.Protocol` describing a :pep:`WSGI Error Stream
806+
<3333#input-and-error-streams>`.
807807

808808
.. class:: FileWrapper()
809809

810-
A :class:`typing.Protocol` describing a `file wrapper
811-
<https://peps.python.org/pep-3333/#optional-platform-specific-file-handling>`_.
810+
A :class:`typing.Protocol` describing a :pep:`file wrapper
811+
<3333#optional-platform-specific-file-handling>`.
812812
See :class:`wsgiref.util.FileWrapper` for a concrete implementation of this
813813
protocol.
814814

Doc/whatsnew/2.4.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ API that perform ASCII-only conversions, ignoring the locale setting:
757757
:c:expr:`double` to an ASCII string.
758758

759759
The code for these functions came from the GLib library
760-
(https://developer-old.gnome.org/glib/2.26/), whose developers kindly
760+
(`https://developer-old.gnome.org/glib/2.26/ <http://web.archive.org/web/20210306104320/https://developer.gnome.org/glib/2.26/>`__), whose developers kindly
761761
relicensed the relevant functions and donated them to the Python Software
762762
Foundation. The :mod:`locale` module can now change the numeric locale,
763763
letting extensions such as GTK+ produce the correct results.

Doc/whatsnew/2.7.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -2680,14 +2680,12 @@ automatic ``PATH`` modifications to have ``pip`` available from the command
26802680
line by default, otherwise it can still be accessed through the Python
26812681
launcher for Windows as ``py -m pip``.
26822682

2683-
As `discussed in the PEP`__, platform packagers may choose not to install
2683+
As :pep:`discussed in the PEP <0477#disabling-ensurepip-by-downstream-distributors>`,
2684+
platform packagers may choose not to install
26842685
these commands by default, as long as, when invoked, they provide clear and
26852686
simple directions on how to install them on that platform (usually using
26862687
the system package manager).
26872688

2688-
__ https://peps.python.org/pep-0477/#disabling-ensurepip-by-downstream-distributors
2689-
2690-
26912689
Documentation Changes
26922690
~~~~~~~~~~~~~~~~~~~~~
26932691

Doc/whatsnew/3.12.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Important deprecations, removals or restrictions:
154154
reducing the size of every :class:`str` object by at least 8 bytes.
155155

156156
* :pep:`632`: Remove the :mod:`!distutils` package.
157-
See `the migration guide <https://peps.python.org/pep-0632/#migration-advice>`_
157+
See :pep:`the migration guide <0632#migration-advice>`
158158
for advice replacing the APIs it provided.
159159
The third-party `Setuptools <https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html>`__
160160
package continues to provide :mod:`!distutils`,
@@ -359,7 +359,7 @@ create an interpreter with its own GIL:
359359
/* The new interpreter is now active in the current thread. */
360360
361361
For further examples how to use the C-API for sub-interpreters with a
362-
per-interpreter GIL, see :source:`Modules/_xxsubinterpretersmodule.c`.
362+
per-interpreter GIL, see ``Modules/_xxsubinterpretersmodule.c``.
363363

364364
(Contributed by Eric Snow in :gh:`104210`, etc.)
365365

Doc/whatsnew/3.14.rst

+5
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ New Features
554554

555555
(Contributed by Victor Stinner in :gh:`107954`.)
556556

557+
* Add :c:func:`PyType_GetBaseByToken` and :c:data:`Py_tp_token` slot for easier
558+
superclass identification, which attempts to resolve the `type checking issue
559+
<https://peps.python.org/pep-0630/#type-checking>`__ mentioned in :pep:`630`
560+
(:gh:`124153`).
561+
557562

558563
Porting to Python 3.14
559564
----------------------

Doc/whatsnew/3.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ for secure (encrypted, authenticated) internet connections:
16501650
* The :func:`ssl.wrap_socket() <ssl.SSLContext.wrap_socket>` constructor function now takes a *ciphers*
16511651
argument. The *ciphers* string lists the allowed encryption algorithms using
16521652
the format described in the `OpenSSL documentation
1653-
<https://www.openssl.org/docs/man1.0.2/man1/ciphers.html#CIPHER-LIST-FORMAT>`__.
1653+
<https://docs.openssl.org/1.0.2/man1/ciphers/#cipher-list-format>`__.
16541654

16551655
* When linked against recent versions of OpenSSL, the :mod:`ssl` module now
16561656
supports the Server Name Indication extension to the TLS protocol, allowing

Doc/whatsnew/3.4.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,12 @@ automatic ``PATH`` modifications to have ``pip`` available from the command
215215
line by default, otherwise it can still be accessed through the Python
216216
launcher for Windows as ``py -m pip``.
217217

218-
As `discussed in the PEP`__, platform packagers may choose not to install
218+
As :pep:`discussed in the PEP <0453#recommendations-for-downstream-distributors>`
219+
platform packagers may choose not to install
219220
these commands by default, as long as, when invoked, they provide clear and
220221
simple directions on how to install them on that platform (usually using
221222
the system package manager).
222223

223-
__ https://peps.python.org/pep-0453/#recommendations-for-downstream-distributors
224-
225224
.. note::
226225

227226
To avoid conflicts between parallel Python 2 and Python 3 installations,
@@ -1963,7 +1962,7 @@ Other Improvements
19631962
<https://devguide.python.org/coverage/#measuring-coverage-of-c-code-with-gcov-and-lcov>`_
19641963
will build python, run the test suite, and generate an HTML coverage report
19651964
for the C codebase using ``gcov`` and `lcov
1966-
<https://ltp.sourceforge.net/coverage/lcov.php>`_.
1965+
<https://github.com/linux-test-project/lcov>`_.
19671966

19681967
* The ``-R`` option to the :ref:`python regression test suite <regrtest>` now
19691968
also checks for memory allocation leaks, using

Doc/whatsnew/3.7.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ module:
353353

354354
The new functions return the number of nanoseconds as an integer value.
355355

356-
`Measurements <https://peps.python.org/pep-0564/#annex-clocks-resolution-in-python>`_
356+
:pep:`Measurements <0564#annex-clocks-resolution-in-python>`
357357
show that on Linux and Windows the resolution of :func:`time.time_ns` is
358358
approximately 3 times better than that of :func:`time.time`.
359359

Doc/whatsnew/3.8.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ The following features and APIs have been removed from Python 3.8:
17551755
* Starting with Python 3.3, importing ABCs from :mod:`collections` was
17561756
deprecated, and importing should be done from :mod:`collections.abc`. Being
17571757
able to import from collections was marked for removal in 3.8, but has been
1758-
delayed to 3.9. (See :issue:`36952`.)
1758+
delayed to 3.9. (See :gh:`81134`.)
17591759

17601760
* The :mod:`macpath` module, deprecated in Python 3.7, has been removed.
17611761
(Contributed by Victor Stinner in :issue:`35471`.)

Include/cpython/object.h

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ typedef struct _heaptypeobject {
269269
struct _dictkeysobject *ht_cached_keys;
270270
PyObject *ht_module;
271271
char *_ht_tpname; // Storage for "tp_name"; see PyType_FromModuleAndSpec
272+
void *ht_token; // Storage for the "Py_tp_token" slot
272273
struct _specialization_cache _spec_cache; // For use by the specializer.
273274
#ifdef Py_GIL_DISABLED
274275
Py_ssize_t unique_id; // ID used for thread-local refcounting

Include/internal/pycore_gc.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ static inline void _PyObject_GC_SET_SHARED_INLINE(PyObject *op) {
140140

141141
/* Bit flags for _gc_prev */
142142
/* Bit 0 is set when tp_finalize is called */
143-
#define _PyGC_PREV_MASK_FINALIZED 1
143+
#define _PyGC_PREV_MASK_FINALIZED ((uintptr_t)1)
144144
/* Bit 1 is set when the object is in generation which is GCed currently. */
145-
#define _PyGC_PREV_MASK_COLLECTING 2
145+
#define _PyGC_PREV_MASK_COLLECTING ((uintptr_t)2)
146146

147147
/* Bit 0 in _gc_next is the old space bit.
148148
* It is set as follows:

Include/internal/pycore_list.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ _Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src)
4545
Py_ssize_t copied = len_src;
4646
while (copied < len_dest) {
4747
Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied);
48-
memcpy(dest + copied, dest, bytes_to_copy);
48+
memcpy(dest + copied, dest, (size_t)bytes_to_copy);
4949
copied += bytes_to_copy;
5050
}
5151
}

0 commit comments

Comments
 (0)