[3.14] gh-91048: Refactor and optimize remote debugging module (#134652) (#134673)
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 GH-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 GH-133959 as a side effect, because the buggy behavior in GH-133959 derives from
evaluate_forward_ref().
(cherry picked from commit 57fef27cfc2bdfc1e3a65ef8c8a760198d15b14d)
[3.14] annotationlib docs: note that ForwardRef.evaluate eventually defaults to empty globals (GH-134661) (#134662)
annotationlib docs: note that ForwardRef.evaluate eventually defaults to empty globals (GH-134661)
(cherry picked from commit b51b08a0a5fedde4f74e4cc338b8b5ad9656ad50)
Bénédikt Tran [Sat, 24 May 2025 13:34:31 +0000 (15:34 +0200)]
[3.14] gh-134168: fix `http.server` CLI support for IPv6 and `--directory` when serving over HTTPS (GH-134169) (#134630)
[3.14] gh-134168: fix `http.server` CLI support for IPv6 and `--directory` when serving over HTTPS (GH-134169)
(cherry picked from commit 2fd09b011031f3c00c342b44e02e2817010e507c)
[3.14] gh-80334: fix multiprocessing.freeze_support for other spawn platforms (GH-134462) (#134619)
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: Seth Michael Larson <seth@python.org> 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>
[3.14] gh-133885: Use locks instead of critical sections for _zstd (gh-134289) (gh-134560)
Move from using critical sections to locks for the (de)compression methods.
Since the methods allow other threads to run, we should use a lock rather
than a critical section.
(cherry picked from commit 8dbc11971974a725dc8a11c0dc65d8f6fcb4d902)
[3.14] gh-134451: Converted `asyncio.tools.CycleFoundException` from dataclass to a regular exception type. (GH-134513) (#134564)
gh-134451: Converted `asyncio.tools.CycleFoundException` from dataclass to a regular exception type. (GH-134513)
(cherry picked from commit f9324cb3cb4d9bb9f0aef2e48b8afa895bde4b0d)
[3.14] gh-114177: avoid calling connection lost callbacks when loop is already closed in asyncio subprocess (GH-134508) (#134561)
gh-114177: avoid calling connection lost callbacks when loop is already closed in asyncio subprocess (GH-134508)
(cherry picked from commit 5804ee7b467d86131be3ff7d569443efb0d0f9fd)
[3.14] GH-130397: remove special-casing of C stack depth for WASI (GH-134469) (GH-134547)
GH-130397: remove special-casing of C stack depth for WASI (GH-134469)
Removed special-casing for WASI when setting C stack depth limits. Since WASI has its own C stack checking this isn't a security risk.
Also disabled some tests that stopped passing. They all happened to have already been disabled under Emscripten.
(cherry picked from commit ad42dc1909bdf8ec775b63fb22ed48ff42797a17)
Set the LC_CTYPE locale to the LC_TIME locale even if
nl_langinfo(ALT_DIGITS) result is ASCII. The result is a list
separated by NUL characters and the code only checks the first list
item which can be ASCII whereas following items are non-ASCII.
[3.14] gh-134370: Added clarification on instance annotations (GH-134387) (#134509)
gh-134370: Added clarification on instance annotations (GH-134387)
Instances of classes cannot have annotations,
however sometimes they will erroneously have the
__annotations__ attribute
(cherry picked from commit bd4046f4f869039a1a2ebe2d1d18bfbc2a2951b6)
[3.14] Add notes on nogil & reinitialization to the Opt-Out section in Module Isolation HOWTO (GH-134141) (GH-134492)
Add notes on nogil & reinitialization to the Opt-Out section in Module Isolation HOWTO (GH-134141)
(cherry picked from commit 1f0a294e8c2ff009c6b74ca5aa71da6269aec0dd)
Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Sam Gross <colesbury@gmail.com>
[3.14] gh-134309: Add ``github.actor`` to the GitHub Actions concurrency key (GH-134310) (#134484)
gh-134309: Add ``github.actor`` to the GitHub Actions concurrency key (GH-134310)
When inexperienced users create a PR from their default branch, all of the concurrency keys
collide as there is no namespacing. This becomes an issue at events with many new contributors,
where workflow runs are cancelled on other pull requests.
Disambiguate by adding the username of the relevant 'actor' to the concurrency key.
(cherry picked from commit 979d81a17905e922d32fb1671f9ed394e0ffbda6)
Authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Kira <coldcaption@gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Sviatoslav Sydorenko <sviat@redhat.com> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
[3.14] gh-127960 Fix the REPL to set the correct namespace by setting the correct `__main__` module (gh-134275) (gh-134473)
The `__main__` module imported in the `_pyrepl` module points to the `_pyrepl` module itself when the interpreter was launched without `-m` option and didn't execute a module,
while it's an unexpected behavior that `__main__` can be `_pyrepl` and relative imports such as `from . import *` works based on the `_pyrepl` module.
(cherry picked from commit b1b8962443e7d418601658a4b05347a5a9161910)
gh-132124: improve safety nets for creating AF_UNIX socket files (GH-134085)
* ensure that we can create AF_UNIX socket files
* emit a warning if system-wide temporary directory is used
(cherry picked from commit 1a07a01014bde23acd2684916ef38dc0cd73c2de)
[3.14] gh-62184: Remove _pyio import of _io.FileIO (gh-134192) (gh-134437)
This was added in the add of `_io`, isn't used since bpo-21859 when a
`_pyio` implementation was added which defines `FileIO` lower down in
the file.
(cherry picked from commit 0a68068bd2a5bff98998067a141b17af5be9b750)
[3.14] gh-133982: Run unclosed file test on all io implementations (gh-134165) (gh-134433)
Update `test_io` `_check_warn_on_dealloc` to use `self.` to dispatch to
different I/O implementations.
Update the `_pyio` implementation to match expected behavior, using the
same `_dealloc_warn` design as the C implementation uses to report the
topmost `__del__` object.
The FileIO one now matches all the others, so can use IOBase. There was
a missing check on closing (self._fd must be valid), add that check
(cherry picked from commit 5b0e82752120a5dc66ce6ee778751d71ba2c33b2)
[3.14] gh-132775: Support Fallbacks in _PyObject_GetXIData() (gh-134418)
It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.
There's also room for other fallback modes if that later makes sense.
(cherry picked from commit 88f8102a8f, AKA gh-133482)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
[3.14] gh-132246: Add special buffer methods to C API Type Object docs (gh-132247) (gh-134426)
Two special methods, __buffer__ and __release_buffer__ were added to
Python 3.12 by PEP 688. The C API Type Object documentation for slots
includes `tp_as_buffer`, and sub-slots `bf_getbuffer`, `bf_releasebuffer`
but does not refer to the Python Data Model version of those. Add the
missing references.
Co-authored-by: Emma Smith <emma@emmatyping.dev> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Sumana Harihareswara <sh@changeset.nyc> Co-authored-by: Martin Panter <vadmium@users.noreply.github.com>
[3.14] gh-72680: Fix false positives when using zipfile.is_zipfile() (GH-134250) (#134401)
gh-72680: Fix false positives when using zipfile.is_zipfile() (GH-134250)
bpo-28494: Improve zipfile.is_zipfile reliability
The zipfile.is_zipfile function would only search for the EndOfZipfile
section header. This failed to correctly identify non-zipfiles that
contained this header. Now the zipfile.is_zipfile function verifies
the first central directory entry.
Changes:
* Extended zipfile.is_zipfile to verify zipfile catalog
* Added tests to validate failure of binary non-zipfiles
* Reuse 'concat' handling for is_zipfile
(cherry picked from commit 1298511b41ec0f9be925c12f3830e94fe8f7e7dc)
Co-authored-by: Tim Hatch <timhatch@netflix.com> Co-authored-by: John Jolly <john.jolly@gmail.com>
Co-authored-by: Kevin Hernández <kevin.hernandez@unet.edu.ve> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Tomas R. <tomas.roun8@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
[3.14] gh-134209: use heap-allocated memory in `_curses.window.{instr,getstr}` (GH-134283) (#134391)
gh-134209: use heap-allocated memory in `_curses.window.{instr,getstr}` (GH-134283)
* made curses buffer heap allocated instead of stack
* change docs to explicitly mention the max buffer size
* changing GetStr() function to behave similarly too
* Update Doc/library/curses.rst
* Update instr with proper return error handling
* Update Modules/_cursesmodule.c
* change to strlen and better memory safety
* change from const int to Py_ssize_t
* add mem allocation guard
* update versionchanged to mention it was an increase.
* explicitly use versionchanged 3.14 as that is its own branch now.
[3.14] gh-85045: clarified that the underlying buffer of a TextIOBase can be a RawIOBase (GH-134372) (#134374)
gh-85045: clarified that the underlying buffer of a TextIOBase can be a RawIOBase (GH-134372)
Added a clarification that the underlying binary buffer of a TextIOBase can be a BufferedIOBase OR a RawIOBase
(cherry picked from commit 36eb711d2f26849214774a017fe8c8a5be3eec30)
[3.14] gh-127146: xfail more Emscripten stack overflows (GH-134358) (#134382)
Adds some additional test xfails for Emscripten stack overflows. Also corrects a test skip for test_io.
(cherry picked from commit 91e6a58e2d6fd23e886135457e28dfa980ec49ed)
[3.14] gh-75459: Doc: C API: Improve object life cycle documentation (GH-125962) (GH-134344)
gh-75459: Doc: C API: Improve object life cycle documentation (GH-125962)
* Add "cyclic isolate" to the glossary.
* Add a new "Object Life Cycle" page.
* Improve docs for related API, with special focus on cross-references and warnings
(cherry picked from commit 3246ea514d6da6ff09f411e22b3ba61a7de84a74)
Co-authored-by: Richard Hansen <rhansen@rhansen.org> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
[3.14] gh-128307: Update what's new in 3.13 and 3.14 with create_task changes of asyncio (GH-134304) (#134319)
gh-128307: Update what's new in 3.13 and 3.14 with create_task changes of asyncio (GH-134304)
(cherry picked from commit 28625d4f956f8d30671aba1daaac9735932983db)
Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
[3.14] gh-133890: Handle UnicodeEncodeError in tarfile (GH-134147) (GH-134195)
UnicodeEncodeError is now handled the same way as OSError during
TarFile member extraction.
(cherry picked from commit 9983c7d4416cac8deb2fded1ec9c7daf786c3a02)
[3.14] Clean up test_posixpath (GH-134315) (GH-134316)
* Ensure that created files and dirs are always removed after test.
Now addCleanup() does not conflict with tearDown().
* Use os_helper.unlink() and os_helper.rmdir().
* Import TESTFN from os_helper.
(cherry picked from commit e29171bf8a26b5faf97222e07a7d5f33c9eb272b)