Sam James [Fri, 30 May 2025 04:42:19 +0000 (05:42 +0100)]
gh-134768: Fix definition of `mt_continue_should_break()` (#134769)
In 121ed71f4e395948d313249b2ad33e1e21581f8a, mt_continue_should_break
was changed to be guarded by `Py_DEBUG`, but it's used in `compress_mt_continue_lock_held`
with just `assert`, so it needs to be available when `NDEBUG` is undefined
too.
`Py_DEBUG` implies `NDEBUG` is undefined, so we can check just that.
The problem we're fixing here is that we were using PyDict_Size() on "defaults",
which it is actually a tuple. We're also adding some explicit type checks.
Petr Viktorin [Wed, 28 May 2025 13:24:40 +0000 (15:24 +0200)]
gh-128629: Add _Py_PACK_VERSION for CPython's own definitions (GH-134247)
Add _Py_PACK_VERSION for CPython's own definitions
Py_PACK_VERSION was added to limited API in 3.14, so if
Py_LIMITED_API is lower, the macro can't be used.
Add a private version that can be used in CPython headers
for checks like `Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 14)`.
Neil Schemenauer [Wed, 28 May 2025 01:27:41 +0000 (18:27 -0700)]
gh-127266: avoid data races when updating type slots (gh-133177)
In the free-threaded build, avoid data races caused by updating type
slots or type flags after the type was initially created. For those
(typically rare) cases, use the stop-the-world mechanism. Remove the
use of atomics when reading or writing type flags.
Sam Gross [Tue, 27 May 2025 20:21:16 +0000 (16:21 -0400)]
gh-134679: Fix assertion failure in QSBR (gh-134811)
This is the same underlying bug as gh-130519. The destructor may call
arbitrary code, changing the `tstate->qsbr pointer` and invalidating the
old `struct _qsbr_thread_state`.
Rishabh Singh [Tue, 27 May 2025 18:48:04 +0000 (00:18 +0530)]
gh-134789: Document del s[i] operation for mutable sequences (#134804)
[main] Update stdtypes.rst
- Added explicit mention of `del s[i]` (item deletion by index) to the Mutable Sequence Types section.
- Clarified that this operation removes the item at the specified index from the sequence.
- Addresses issue #134789.
Kumar Aditya [Tue, 27 May 2025 16:58:27 +0000 (22:28 +0530)]
gh-134043: use stackrefs in vectorcalling methods (#134044)
Adds `_PyObject_GetMethodStackRef` which uses stackrefs and takes advantage of deferred reference counting in free-threading while calling method objects in vectorcall.
Eric Snow [Tue, 27 May 2025 15:42:24 +0000 (09:42 -0600)]
gh-132775: Always Set __builtins__ In _PyFunction_FromXIData() (gh-134758)
This is a small follow-up to gh-133481. There's a corner case
in the behavior of PyImport_ImportModuleAttrString(), where
it expects __builtins__ to be set if __globals__ is set.
In addition, `curses.window.refresh` and `curses.window.noutrefresh`
now raise a `TypeError` instead of a `curses.error` when called with an
incorrect number of arguments for pads.
Jelle Zijlstra [Mon, 26 May 2025 15:35:04 +0000 (08:35 -0700)]
gh-119180: Updates to PEP 649/749 docs (#134640)
- Mention (again) that `type.__annotations__` is unsafe. It is now safe
when using only classes defined under PEP 649 semantics, but not with
classes defined using `from __future__ import annotations`.
- Mention that annotations on instances no longer work. There was already
an issue about this.
- Mention the general changes in the "Porting to Python 3.14" section.
- `annotationlib` was proposed by PEP-749, not PEP-649.
Co-authored-by: Emma Smith <emma@emmatyping.dev> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Bénédikt Tran [Mon, 26 May 2025 10:12:32 +0000 (12:12 +0200)]
gh-134531: cleanup `_hashopenssl.c` to support `EVP_MAC` (#134626)
Rename components related to `_hashlib.{HASH,HASHXOF}` objects.
- The `EVPobject` structure is renamed `HASHobject`.
- Non-clinic `HASH` methods are now prefixed by `_hashlib_HASH_*`.
A similar change is made for non-clinic `HASHXOF` methods.
- Functions extracting information from `EVP_MD` objects and functions
constructing `EVP_MD` objects now include `openssl_evp_md` in their name.
This change allows us to avoid future ambiguities between the `EVP_MD`
and the `EVP_MAC` APIs (currently, we only use `EVP_MD` for hash functions
and rely on the legacy interface for HMAC instead of using `EVP_MAC`).
R. David Murray [Sun, 25 May 2025 22:09:32 +0000 (18:09 -0400)]
gh-134152: Fix UnboundLocalError in email._header_value_parser _get_ptext_to_endchars (#134233)
Fix an UnboundLocalError that can occur when parsing certain delimited constructs in headers (domain literals, quoted strings, comments). After the fix the _get_ptext_to_endchars returns an empty string if there is no content after the opening delimiter. The calling code is responsible for handling the lack of the trailing delimiter, which it already does; this edge case was the header ending immediately after the opening delimiter.
gh-91048: Refactor and optimize remote debugging module (#134652)
Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.
Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.
Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.
Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.
Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.
Also, make the module compatible with the free threading build as an extra :)
As explained in #133960, this removes most of the behavior differences with ForwardRef.evaluate.
The remaining difference is about recursive evaluation of forwardrefs; this is practically useful
in cases where an annotation refers to a type alias that itself is string-valued.
This also improves several edge cases that were previously not handled optimally. For example,
the function now takes advantage of the partial evaluation behavior of ForwardRef.evaluate() to
evaluate more ForwardRefs in the FORWARDREF format.
This also fixes #133959 as a side effect, because the buggy behavior in #133959 derives from
evaluate_forward_ref().
Eddy Mulyono [Sat, 24 May 2025 03:50:19 +0000 (23:50 -0400)]
gh-80334: fix multiprocessing.freeze_support for other spawn platforms (GH-134462)
Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.
---------
Co-authored-by: Gregory P. Smith <greg@krypto.org>
gh-128840: Limit the number of parts in IPv6 address parsing (GH-128841)
GH-128840: Limit the number of parts in IPv6 address parsing
Limit length of IP address string to 39
---------
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Collin Funk [Fri, 23 May 2025 11:11:04 +0000 (04:11 -0700)]
gh-134486: Fix missing alloca() symbol in _ctypes on NetBSD (#134487)
Previously the module would fail to load because the `alloca()` symbol
was undefined. Now we check for GCC/Clang builtins for systems who do
not define `alloca()` in headers.