From 2bbb557b0f077f8c8b571148e0368472bbbbf5ea Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Jun 2023 16:22:04 +0200 Subject: [3.12] gh-102304: Fix Py_INCREF() stable ABI in debug mode (#104763) (#105352) gh-102304: Fix Py_INCREF() stable ABI in debug mode (#104763) When Python is built in debug mode (if the Py_REF_DEBUG macro is defined), the Py_INCREF() and Py_DECREF() function are now always implemented as opaque functions to avoid leaking implementation details like the "_Py_RefTotal" variable or the _Py_DecRefTotal_DO_NOT_USE_THIS() function. * Remove _Py_IncRefTotal_DO_NOT_USE_THIS() and _Py_DecRefTotal_DO_NOT_USE_THIS() from the stable ABI. * Remove _Py_NegativeRefcount() from limited C API. (cherry picked from commit 92022d8416d9e175800b65c4d71d4e4fb47adcb0) --- Doc/whatsnew/3.12.rst | 9 +++++++++ Include/object.h | 22 ++++++++-------------- Lib/test/test_stable_abi_ctypes.py | 2 -- Misc/stable_abi.toml | 9 --------- PC/python3dll.c | 2 -- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 287549f..4a75597 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -1535,6 +1535,15 @@ Build Changes :file:`!configure`. (Contributed by Christian Heimes in :gh:`89886`.) +* C extensions built with the :ref:`limited C API ` + on :ref:`Python build in debug mode ` no longer support Python + 3.9 and older. In this configuration, :c:func:`Py_INCREF` and + :c:func:`Py_DECREF` are now always implemented as opaque function calls, + but the called functions were added to Python 3.10. Build C extensions + with a release build of Python or with Python 3.12 and older, to keep support + for Python 3.9 and older. + (Contributed by Victor Stinner in :gh:`102304`.) + C API Changes ============= diff --git a/Include/object.h b/Include/object.h index c2fee85..dc5b087 100644 --- a/Include/object.h +++ b/Include/object.h @@ -585,20 +585,14 @@ decision that's up to the implementer of each new type so if you want, you can count such references to the type object.) */ -#ifdef Py_REF_DEBUG -# if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030A0000 -extern Py_ssize_t _Py_RefTotal; -# define _Py_INC_REFTOTAL() _Py_RefTotal++ -# define _Py_DEC_REFTOTAL() _Py_RefTotal-- -# elif !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000 +#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API) +PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno, + PyObject *op); PyAPI_FUNC(void) _Py_IncRefTotal_DO_NOT_USE_THIS(void); PyAPI_FUNC(void) _Py_DecRefTotal_DO_NOT_USE_THIS(void); # define _Py_INC_REFTOTAL() _Py_IncRefTotal_DO_NOT_USE_THIS() # define _Py_DEC_REFTOTAL() _Py_DecRefTotal_DO_NOT_USE_THIS() -# endif -PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno, - PyObject *op); -#endif /* Py_REF_DEBUG */ +#endif // Py_REF_DEBUG && !Py_LIMITED_API PyAPI_FUNC(void) _Py_Dealloc(PyObject *); @@ -616,8 +610,8 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *); static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) { -#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000 - // Stable ABI for Python 3.10 built in debug mode. +#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) + // Stable ABI for Python built in debug mode _Py_IncRef(op); #else // Non-limited C API and limited C API for Python 3.9 and older access @@ -647,8 +641,8 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) # define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op)) #endif -#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000 -// Stable ABI for limited C API version 3.10 of Python debug build +#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) +// Stable ABI for Python built in debug mode static inline void Py_DECREF(PyObject *op) { _Py_DecRef(op); } diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index 6898367..8cad71c 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -917,8 +917,6 @@ if feature_macros['PY_HAVE_THREAD_NATIVE_ID']: ) if feature_macros['Py_REF_DEBUG']: SYMBOL_NAMES += ( - '_Py_DecRefTotal_DO_NOT_USE_THIS', - '_Py_IncRefTotal_DO_NOT_USE_THIS', '_Py_NegativeRefcount', '_Py_RefTotal', ) diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 1db9848..48299e9 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -2406,12 +2406,3 @@ added = '3.12' [const.Py_TPFLAGS_ITEMS_AT_END] added = '3.12' - -[function._Py_IncRefTotal_DO_NOT_USE_THIS] - added = '3.12' - ifdef = 'Py_REF_DEBUG' - abi_only = true -[function._Py_DecRefTotal_DO_NOT_USE_THIS] - added = '3.12' - ifdef = 'Py_REF_DEBUG' - abi_only = true diff --git a/PC/python3dll.c b/PC/python3dll.c index 5665d55..505feef 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -17,9 +17,7 @@ EXPORT_FUNC(_Py_BuildValue_SizeT) EXPORT_FUNC(_Py_CheckRecursiveCall) EXPORT_FUNC(_Py_Dealloc) EXPORT_FUNC(_Py_DecRef) -EXPORT_FUNC(_Py_DecRefTotal_DO_NOT_USE_THIS) EXPORT_FUNC(_Py_IncRef) -EXPORT_FUNC(_Py_IncRefTotal_DO_NOT_USE_THIS) EXPORT_FUNC(_Py_NegativeRefcount) EXPORT_FUNC(_Py_VaBuildValue_SizeT) EXPORT_FUNC(_PyArg_Parse_SizeT) -- cgit v0.12 From bf62e06e597ddc8179b9b2bf5c9304f81606e104 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:14:55 -0700 Subject: [3.12] gh-94172: Update keyfile removal documentation (GH-105392) (#105402) gh-94172: Update keyfile removal documentation (GH-105392) Remove the "deprecated:: 3.6" markup, since the parameters (like keyfile and certfile) got removed in Python 3.12. (cherry picked from commit 2b8e6e5712a83657333948bc387c81db02549b13) Co-authored-by: Victor Stinner --- Doc/library/ftplib.rst | 8 +------- Doc/library/http.client.rst | 14 ++------------ Doc/library/imaplib.rst | 9 +-------- Doc/library/poplib.rst | 9 +-------- Doc/library/smtplib.rst | 18 ++---------------- 5 files changed, 7 insertions(+), 51 deletions(-) diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst index 4705481..e7fb5b1 100644 --- a/Doc/library/ftplib.rst +++ b/Doc/library/ftplib.rst @@ -107,12 +107,6 @@ The module defines the following items: :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see :data:`ssl.HAS_SNI`). - .. deprecated:: 3.6 - *keyfile* and *certfile* are deprecated in favor of *context*. - Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let - :func:`ssl.create_default_context` select the system's trusted CA - certificates for you. - .. versionchanged:: 3.9 If the *timeout* parameter is set to be zero, it will raise a :class:`ValueError` to prevent the creation of a non-blocking socket. @@ -120,7 +114,7 @@ The module defines the following items: Latin-1 to UTF-8 to follow :rfc:`2640`. .. versionchanged:: 3.12 - The deprecated *keyfile* and *certfile* parameters have been removed. + The deprecated *keyfile* and *certfile* parameters have been removed. Here's a sample session using the :class:`FTP_TLS` class:: diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst index 46d616a..4529193 100644 --- a/Doc/library/http.client.rst +++ b/Doc/library/http.client.rst @@ -95,16 +95,6 @@ The module provides the following classes: :func:`ssl._create_unverified_context` can be passed to the *context* parameter. - .. deprecated:: 3.6 - *key_file* and *cert_file* are deprecated in favor of *context*. - Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let - :func:`ssl.create_default_context` select the system's trusted CA - certificates for you. - - The *check_hostname* parameter is also deprecated; the - :attr:`ssl.SSLContext.check_hostname` attribute of *context* should - be used instead. - .. versionchanged:: 3.8 This class now enables TLS 1.3 :attr:`ssl.SSLContext.post_handshake_auth` for the default *context* or @@ -116,8 +106,8 @@ The module provides the following classes: ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`. .. versionchanged:: 3.12 - The deprecated *key_file*, *cert_file* and *check_hostname* parameters - have been removed. + The deprecated *key_file*, *cert_file* and *check_hostname* parameters + have been removed. .. class:: HTTPResponse(sock, debuglevel=0, method=None, url=None) diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst index f1344ae..59d7711 100644 --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -108,18 +108,11 @@ There's also a subclass for secure connections: :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see :data:`ssl.HAS_SNI`). - .. deprecated:: 3.6 - - *keyfile* and *certfile* are deprecated in favor of *ssl_context*. - Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let - :func:`ssl.create_default_context` select the system's trusted CA - certificates for you. - .. versionchanged:: 3.9 The optional *timeout* parameter was added. .. versionchanged:: 3.12 - The deprecated *keyfile* and *certfile* parameters have been removed. + The deprecated *keyfile* and *certfile* parameters have been removed. The second subclass allows for connections created by a child process: diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst index d8618ce..260c4a6 100644 --- a/Doc/library/poplib.rst +++ b/Doc/library/poplib.rst @@ -79,19 +79,12 @@ The :mod:`poplib` module provides two classes: :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see :data:`ssl.HAS_SNI`). - .. deprecated:: 3.6 - - *keyfile* and *certfile* are deprecated in favor of *context*. - Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let - :func:`ssl.create_default_context` select the system's trusted CA - certificates for you. - .. versionchanged:: 3.9 If the *timeout* parameter is set to be zero, it will raise a :class:`ValueError` to prevent the creation of a non-blocking socket. .. versionchanged:: 3.12 - The deprecated *keyfile* and *certfile* parameters have been removed. + The deprecated *keyfile* and *certfile* parameters have been removed. One exception is defined as an attribute of the :mod:`poplib` module: diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index 4686232..f90274f 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -100,19 +100,12 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see :data:`ssl.HAS_SNI`). - .. deprecated:: 3.6 - - *keyfile* and *certfile* are deprecated in favor of *context*. - Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let - :func:`ssl.create_default_context` select the system's trusted CA - certificates for you. - .. versionchanged:: 3.9 If the *timeout* parameter is set to be zero, it will raise a :class:`ValueError` to prevent the creation of a non-blocking socket .. versionchanged:: 3.12 - The deprecated *keyfile* and *certfile* parameters have been removed. + The deprecated *keyfile* and *certfile* parameters have been removed. .. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None, \ source_address=None[, timeout]) @@ -407,15 +400,8 @@ An :class:`SMTP` instance has the following methods: If there has been no previous ``EHLO`` or ``HELO`` command this session, this method tries ESMTP ``EHLO`` first. - .. deprecated:: 3.6 - - *keyfile* and *certfile* are deprecated in favor of *context*. - Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let - :func:`ssl.create_default_context` select the system's trusted CA - certificates for you. - .. versionchanged:: 3.12 - The deprecated *keyfile* and *certfile* parameters have been removed. + The deprecated *keyfile* and *certfile* parameters have been removed. :exc:`SMTPHeloError` The server didn't reply properly to the ``HELO`` greeting. -- cgit v0.12 From 6fe0a6ba73adb4bc4060ddd0a132072339758c6b Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 6 Jun 2023 12:00:17 -0700 Subject: [3.12] sliding_window() recipe: Raise ValueError for non-positive window sizes. Add more tests. (GH-105403) (GH-105405) --- Doc/library/itertools.rst | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index b3decae..56d6599 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -929,9 +929,7 @@ which incur interpreter overhead. def sliding_window(iterable, n): # sliding_window('ABCDEFG', 4) --> ABCD BCDE CDEF DEFG it = iter(iterable) - window = collections.deque(islice(it, n), maxlen=n) - if len(window) == n: - yield tuple(window) + window = collections.deque(islice(it, n-1), maxlen=n) for x in it: window.append(x) yield tuple(window) @@ -1420,8 +1418,34 @@ The following recipes have a more mathematical flavor: >>> list(grouper('abcdefg', n=3, incomplete='ignore')) [('a', 'b', 'c'), ('d', 'e', 'f')] + >>> list(sliding_window('ABCDEFG', 1)) + [('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',)] + >>> list(sliding_window('ABCDEFG', 2)) + [('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E'), ('E', 'F'), ('F', 'G')] + >>> list(sliding_window('ABCDEFG', 3)) + [('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E'), ('D', 'E', 'F'), ('E', 'F', 'G')] >>> list(sliding_window('ABCDEFG', 4)) [('A', 'B', 'C', 'D'), ('B', 'C', 'D', 'E'), ('C', 'D', 'E', 'F'), ('D', 'E', 'F', 'G')] + >>> list(sliding_window('ABCDEFG', 5)) + [('A', 'B', 'C', 'D', 'E'), ('B', 'C', 'D', 'E', 'F'), ('C', 'D', 'E', 'F', 'G')] + >>> list(sliding_window('ABCDEFG', 6)) + [('A', 'B', 'C', 'D', 'E', 'F'), ('B', 'C', 'D', 'E', 'F', 'G')] + >>> list(sliding_window('ABCDEFG', 7)) + [('A', 'B', 'C', 'D', 'E', 'F', 'G')] + >>> list(sliding_window('ABCDEFG', 8)) + [] + >>> try: + ... list(sliding_window('ABCDEFG', -1)) + ... except ValueError: + ... 'zero or negative n not supported' + ... + 'zero or negative n not supported' + >>> try: + ... list(sliding_window('ABCDEFG', 0)) + ... except ValueError: + ... 'zero or negative n not supported' + ... + 'zero or negative n not supported' >>> list(roundrobin('abc', 'd', 'ef')) ['a', 'd', 'e', 'b', 'f', 'c'] -- cgit v0.12 From e33add429f8f16340b4c186501bb1e436e66b4cc Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 6 Jun 2023 12:27:10 -0700 Subject: gh-92658: Fix typo in docs and tests for `HV_GUID_PARENT` (GH-105267) (cherry picked from commit 3907de12b57b14f674cdcc80ae64350a23af53a0) Co-authored-by: Nikita Sobolev --- Doc/library/socket.rst | 2 +- Lib/test/test_socket.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 5f795af..f2408cb 100644 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -666,7 +666,7 @@ Constants HV_GUID_BROADCAST HV_GUID_CHILDREN HV_GUID_LOOPBACK - HV_GUID_LOOPBACK + HV_GUID_PARENT Constants for Windows Hyper-V sockets for host/guest communications. diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 68cdc6e..0eaf642 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -2566,7 +2566,7 @@ class BasicHyperVTest(unittest.TestCase): socket.HV_GUID_BROADCAST socket.HV_GUID_CHILDREN socket.HV_GUID_LOOPBACK - socket.HV_GUID_LOOPBACK + socket.HV_GUID_PARENT def testCreateHyperVSocketWithUnknownProtoFailure(self): expected = r"\[WinError 10041\]" -- cgit v0.12