Skip to content

Commit

Permalink
Merge branch 'main' into spi-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou authored Sep 18, 2024
2 parents aa825d2 + 8a284e1 commit 72cd269
Show file tree
Hide file tree
Showing 59 changed files with 661 additions and 673 deletions.
4 changes: 2 additions & 2 deletions Doc/c-api/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ bound into a function.
Return the line number of the instruction that occurs on or before ``byte_offset`` and ends after it.
If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead.
For efficiently iterating over the line numbers in a code object, use `the API described in PEP 626
<https://peps.python.org/pep-0626/#out-of-process-debuggers-and-profilers>`_.
For efficiently iterating over the line numbers in a code object, use :pep:`the API described in PEP 626
<0626#out-of-process-debuggers-and-profilers>`.
.. c:function:: int PyCode_Addr2Location(PyObject *co, int byte_offset, int *start_line, int *start_column, int *end_line, int *end_column)
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pointers. This is consistent throughout the API.
If *num* is null and *exp* is not a positive real number,
this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
Complex Numbers as Python Objects
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/refcounting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ of Python objects.
``NULL``, use :c:func:`Py_XINCREF`.
Do not expect this function to actually modify *o* in any way.
For at least `some objects <https://peps.python.org/pep-0683/>`_,
For at least :pep:`some objects <0683>`,
this function has no effect.
.. versionchanged:: 3.12
Expand Down Expand Up @@ -130,7 +130,7 @@ of Python objects.
use :c:func:`Py_XDECREF`.
Do not expect this function to actually modify *o* in any way.
For at least `some objects <https://peps.python.org/pep-0683/>`_,
For at least :pep:`some objects <683>`,
this function has no effect.
.. warning::
Expand Down
68 changes: 67 additions & 1 deletion Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ Type Objects
.. versionadded:: 3.11
.. c:function:: int PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result)
Find the first superclass in *type*'s :term:`method resolution order` whose
:c:macro:`Py_tp_token` token is equal to the given one.
* If found, set *\*result* to a new :term:`strong reference`
to it and return ``1``.
* If not found, set *\*result* to ``NULL`` and return ``0``.
* On error, set *\*result* to ``NULL`` and return ``-1`` with an
exception set.
The *result* argument may be ``NULL``, in which case *\*result* is not set.
Use this if you need only the return value.
The *token* argument may not be ``NULL``.
.. versionadded:: 3.14
.. c:function:: int PyUnstable_Type_AssignVersionTag(PyTypeObject *type)
Attempt to assign a version tag to the given type.
Expand Down Expand Up @@ -488,6 +506,11 @@ The following functions and structs are used to create
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
An additional slot is supported that does not correspond to a
:c:type:`!PyTypeObject` struct field:
* :c:data:`Py_tp_token`
The following “offset” fields cannot be set using :c:type:`PyType_Slot`:
* :c:member:`~PyTypeObject.tp_weaklistoffset`
Expand Down Expand Up @@ -538,4 +561,47 @@ The following functions and structs are used to create
The desired value of the slot. In most cases, this is a pointer
to a function.
Slots other than ``Py_tp_doc`` may not be ``NULL``.
*pfunc* values may not be ``NULL``, except for the following slots:
* ``Py_tp_doc``
* :c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC`
rather than ``NULL``)
.. c:macro:: Py_tp_token
A :c:member:`~PyType_Slot.slot` that records a static memory layout ID
for a class.
If the :c:type:`PyType_Spec` of the class is statically
allocated, the token can be set to the spec using the special value
:c:data:`Py_TP_USE_SPEC`:
.. code-block:: c
static PyType_Slot foo_slots[] = {
{Py_tp_token, Py_TP_USE_SPEC},
It can also be set to an arbitrary pointer, but you must ensure that:
* The pointer outlives the class, so it's not reused for something else
while the class exists.
* It "belongs" to the extension module where the class lives, so it will not
clash with other extensions.
Use :c:func:`PyType_GetBaseByToken` to check if a class's superclass has
a given token -- that is, check whether the memory layout is compatible.
To get the token for a given class (without considering superclasses),
use :c:func:`PyType_GetSlot` with ``Py_tp_token``.
.. versionadded:: 3.14
.. c:namespace:: NULL
.. c:macro:: Py_TP_USE_SPEC
Used as a value with :c:data:`Py_tp_token` to set the token to the
class's :c:type:`PyType_Spec`.
Expands to ``NULL``.
.. versionadded:: 3.14
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Doc/faq/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ releases.
The latest stable releases can always be found on the `Python download page
<https://www.python.org/downloads/>`_. There are two production-ready versions
of Python: 2.x and 3.x. The recommended version is 3.x, which is supported by
most widely used libraries. Although 2.x is still widely used, `it is not
maintained anymore <https://peps.python.org/pep-0373/>`_.
most widely used libraries. Although 2.x is still widely used, :pep:`it is not
maintained anymore <0373>`.

How many people are using Python?
---------------------------------
Expand Down
3 changes: 1 addition & 2 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2033,8 +2033,7 @@ Function and class definitions
* ``name`` is a raw string for the class name
* ``bases`` is a list of nodes for explicitly specified base classes.
* ``keywords`` is a list of :class:`.keyword` nodes, principally for 'metaclass'.
Other keywords will be passed to the metaclass, as per `PEP-3115
<https://peps.python.org/pep-3115/>`_.
Other keywords will be passed to the metaclass, as per :pep:`3115`.
* ``body`` is a list of nodes representing the code within the class
definition.
* ``decorator_list`` is a list of nodes, as in :class:`FunctionDef`.
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ The :mod:`functools` module defines the following functions:
cache. See :ref:`faq-cache-method-calls`

An `LRU (least recently used) cache
<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>`_
<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_(LRU)>`_
works best when the most recent calls are the best predictors of upcoming
calls (for example, the most popular articles on a news server tend to
change each day). The cache's size limit assures that the cache does not
Expand Down
29 changes: 14 additions & 15 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -525,21 +525,20 @@ Module constants
The mappings from SQLite threading modes to DB-API 2.0 threadsafety levels
are as follows:

+------------------+-----------------+----------------------+-------------------------------+
| SQLite threading | `threadsafety`_ | `SQLITE_THREADSAFE`_ | DB-API 2.0 meaning |
| mode | | | |
+==================+=================+======================+===============================+
| single-thread | 0 | 0 | Threads may not share the |
| | | | module |
+------------------+-----------------+----------------------+-------------------------------+
| multi-thread | 1 | 2 | Threads may share the module, |
| | | | but not connections |
+------------------+-----------------+----------------------+-------------------------------+
| serialized | 3 | 1 | Threads may share the module, |
| | | | connections and cursors |
+------------------+-----------------+----------------------+-------------------------------+

.. _threadsafety: https://peps.python.org/pep-0249/#threadsafety
+------------------+----------------------+----------------------+-------------------------------+
| SQLite threading | :pep:`threadsafety | `SQLITE_THREADSAFE`_ | DB-API 2.0 meaning |
| mode | <0249#threadsafety>` | | |
+==================+======================+======================+===============================+
| single-thread | 0 | 0 | Threads may not share the |
| | | | module |
+------------------+----------------------+----------------------+-------------------------------+
| multi-thread | 1 | 2 | Threads may share the module, |
| | | | but not connections |
+------------------+----------------------+----------------------+-------------------------------+
| serialized | 3 | 1 | Threads may share the module, |
| | | | connections and cursors |
+------------------+----------------------+----------------------+-------------------------------+

.. _SQLITE_THREADSAFE: https://sqlite.org/compile.html#threadsafe

.. versionchanged:: 3.11
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/ssl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2759,7 +2759,7 @@ enabled when negotiating a SSL session is possible through the
:meth:`SSLContext.set_ciphers` method. Starting from Python 3.2.3, the
ssl module disables certain weak ciphers by default, but you may want
to further restrict the cipher choice. Be sure to read OpenSSL's documentation
about the `cipher list format <https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT>`_.
about the `cipher list format <https://docs.openssl.org/1.1.1/man1/ciphers/#cipher-list-format>`_.
If you want to check which ciphers are enabled by a given cipher list, use
:meth:`SSLContext.get_ciphers` or the ``openssl ciphers`` command on your
system.
Expand Down
16 changes: 8 additions & 8 deletions Doc/library/wsgiref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,8 @@ in :pep:`3333`.

.. class:: StartResponse()

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

.. data:: WSGIEnvironment
Expand All @@ -797,18 +797,18 @@ in :pep:`3333`.

.. class:: InputStream()

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

.. class:: ErrorStream()

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

.. class:: FileWrapper()

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

Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/2.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ API that perform ASCII-only conversions, ignoring the locale setting:
:c:expr:`double` to an ASCII string.

The code for these functions came from the GLib library
(https://developer-old.gnome.org/glib/2.26/), whose developers kindly
(`https://developer-old.gnome.org/glib/2.26/ <http://web.archive.org/web/20210306104320/https://developer.gnome.org/glib/2.26/>`__), whose developers kindly
relicensed the relevant functions and donated them to the Python Software
Foundation. The :mod:`locale` module can now change the numeric locale,
letting extensions such as GTK+ produce the correct results.
Expand Down
6 changes: 2 additions & 4 deletions Doc/whatsnew/2.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2680,14 +2680,12 @@ automatic ``PATH`` modifications to have ``pip`` available from the command
line by default, otherwise it can still be accessed through the Python
launcher for Windows as ``py -m pip``.

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

__ https://peps.python.org/pep-0477/#disabling-ensurepip-by-downstream-distributors


Documentation Changes
~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Important deprecations, removals or restrictions:
reducing the size of every :class:`str` object by at least 8 bytes.

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

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

Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@ New Features

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

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


Porting to Python 3.14
----------------------
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ for secure (encrypted, authenticated) internet connections:
* The :func:`ssl.wrap_socket() <ssl.SSLContext.wrap_socket>` constructor function now takes a *ciphers*
argument. The *ciphers* string lists the allowed encryption algorithms using
the format described in the `OpenSSL documentation
<https://www.openssl.org/docs/man1.0.2/man1/ciphers.html#CIPHER-LIST-FORMAT>`__.
<https://docs.openssl.org/1.0.2/man1/ciphers/#cipher-list-format>`__.

* When linked against recent versions of OpenSSL, the :mod:`ssl` module now
supports the Server Name Indication extension to the TLS protocol, allowing
Expand Down
7 changes: 3 additions & 4 deletions Doc/whatsnew/3.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,12 @@ automatic ``PATH`` modifications to have ``pip`` available from the command
line by default, otherwise it can still be accessed through the Python
launcher for Windows as ``py -m pip``.

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

__ https://peps.python.org/pep-0453/#recommendations-for-downstream-distributors

.. note::

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

* The ``-R`` option to the :ref:`python regression test suite <regrtest>` now
also checks for memory allocation leaks, using
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ module:

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

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

Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ The following features and APIs have been removed from Python 3.8:
* Starting with Python 3.3, importing ABCs from :mod:`collections` was
deprecated, and importing should be done from :mod:`collections.abc`. Being
able to import from collections was marked for removal in 3.8, but has been
delayed to 3.9. (See :issue:`36952`.)
delayed to 3.9. (See :gh:`81134`.)

* The :mod:`macpath` module, deprecated in Python 3.7, has been removed.
(Contributed by Victor Stinner in :issue:`35471`.)
Expand Down
1 change: 1 addition & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ typedef struct _heaptypeobject {
struct _dictkeysobject *ht_cached_keys;
PyObject *ht_module;
char *_ht_tpname; // Storage for "tp_name"; see PyType_FromModuleAndSpec
void *ht_token; // Storage for the "Py_tp_token" slot
struct _specialization_cache _spec_cache; // For use by the specializer.
#ifdef Py_GIL_DISABLED
Py_ssize_t unique_id; // ID used for thread-local refcounting
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ static inline void _PyObject_GC_SET_SHARED_INLINE(PyObject *op) {

/* Bit flags for _gc_prev */
/* Bit 0 is set when tp_finalize is called */
#define _PyGC_PREV_MASK_FINALIZED 1
#define _PyGC_PREV_MASK_FINALIZED ((uintptr_t)1)
/* Bit 1 is set when the object is in generation which is GCed currently. */
#define _PyGC_PREV_MASK_COLLECTING 2
#define _PyGC_PREV_MASK_COLLECTING ((uintptr_t)2)

/* Bit 0 in _gc_next is the old space bit.
* It is set as follows:
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src)
Py_ssize_t copied = len_src;
while (copied < len_dest) {
Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied);
memcpy(dest + copied, dest, bytes_to_copy);
memcpy(dest + copied, dest, (size_t)bytes_to_copy);
copied += bytes_to_copy;
}
}
Expand Down
Loading

0 comments on commit 72cd269

Please sign in to comment.