PEP-734 has been accepted (for 3.14).
(FTR, I'm opposed to putting this under the concurrent package, but
doing so is the SC condition under which the module can land in 3.14.)
(cherry picked from commit 62143736b, AKA gh-133958)
gh-135410: use a critical section around `StringIO.__next__` (GH-135412)
(cherry picked from commit e6c3039cb39e68ae9af9ddcaca341c5af8f9cf23)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* gh-91048: Reorder result tuple of parse_code_object (GH-134898)
Reorder result tuple of parse_code_object
The standard followed by APIs like pstat.Stats is to take a file, line,
function triplet. The parse_code_object function (and callers exposing
this in Python like RemoteUnwinder.get_stack_trace) return function,
file, line triplets which requires the caller to reorder these when
using it in classes like pstat.Stats.
(cherry picked from commit 8e8786f8986353e20c1c4406c34409a6139fa073)
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
* Reorder asyncio
---------
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().
(cherry picked from commit f49a07b531543dd8a42d90f5b1c89c0312fbf806)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174)
(cherry picked from commit 1adca08d658ee2d520f3193960eaf3ae2ead1cef)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
The `getlogin` function is not thread-safe: replace with `getlogin_r` where
available.
(cherry picked from commit 1ffe913c2017b44804aca18befd45689df06c069)
Co-authored-by: Duane Griffin <duaneg@dghda.com>
Make them similar to PyArg_Parse error messages, mention None as
a possible value, show a wrong type and the string length.
(cherry picked from commit df98a47a61a274eb7427c6201ddabec9ffd30b0a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
The `textiowrapper_iternext` function called `_textiowrapper_writeflush`, but did not
use a critical section, making it racy in free-threaded builds.
(cherry picked from commit 44fb7c361cb24dcf9989a7a1cfee4f6aad5c81aa)
Co-authored-by: Duane Griffin <duaneg@dghda.com>
OpenSSL and HACL*-based hash functions constructors now support both `data` and `string` parameters.
Previously these constructor functions inconsistently supported sometimes `data` and sometimes `string`,
while the documentation expected `data` to be given in all cases.
(cherry picked from commit c6e63d9d351f6d952000ec3bf84b3a7607989f92)
(cherry picked from commit 379d0bc95646dfe923e7ea05fb7f1befbd85572d)
gh-133489: Remove size restrictions on getrandbits() and randbytes() (GH-133658)
random.getrandbits() can now generate more that 2**31 bits.
random.randbytes() can now generate more that 256 MiB.
(cherry picked from commit 68784fed78aa297f0de0d038742495709185bef5)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
It now supports most callables, full args, and return values.
(cherry picked from commit 52deabe, AKA gh-133484)
Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
gh-134768: Fix definition of `mt_continue_should_break()` (GH-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.
(cherry picked from commit 2f2bee21118adce653ee5bc4eb31d30327465966)
Fixes: 121ed71f4e395948d313249b2ad33e1e21581f8a
Co-authored-by: Sam James <sam@gentoo.org>
gh-132983: Convert dict_content to take Py_buffer in ``ZstdDict()`` (GH-133924)
(cherry picked from commit f2ce4bbdfdfa2b658fbeef66f414be2ecf7981dd)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
gh-134637: Fix performance regression in calling `ctypes` function pointer in `free threading`. (GH-134702)
Fix performance regression in calling `ctypes` function pointer in `free threading`.
(cherry picked from commit 3c0525126ef95efe2f578e93db09f3282e3ca08f)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
gh-132876: workaround broken ldexp() on Windows 10 (GH-133135)
* gh-132876: workaround broken ldexp() on Windows 10
ldexp() fails to round subnormal results before Windows 11,
so hide their bug.
(cherry picked from commit cf8941c60356acdd00055e5583a2d64761c34af4)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Tim Peters <tim.peters@gmail.com>
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 :)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 42b25ad4d3d6bcdc28ddfe07d2bf8831378bb0d1)
gh-132983: Make _zstd C code PEP 7 compliant (GH-134605)
Make _zstd C code PEP 7 compliant
(cherry picked from commit 973b8f69d31b4d86c37e0b7194a209f4f2efff06)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
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)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
This is mostly a refactor to clean things up a bit, most notably the "XI namespace" code.
Making the session opaque requires adding the following internal-only functions:
* _PyXI_NewSession()
* _PyXI_FreeSession()
* _PyXI_GetMainNamespace()
(cherry picked from commit 4a4ac3ab4d, gh-134452)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
gh-134322: Fix `repr(threading.RLock)` (GH-134389)
Fix the `__repr__` value of `threading.RLock` from `_thread` module, when just created.
(cherry picked from commit fade146cfb1616ad7b3b918bedb86756dedf79e6)
Co-authored-by: Duprat <yduprat@gmail.com>
gh-133740: Fix locale.nl_langinfo(ALT_DIGITS) (GH-134468)
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.
Fix test__locale for the uk_UA locale on RHEL 7.
(cherry picked from commit 899c7dc283cb899fdfd79fb479b38352f48e454a)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This change includes some semi-related refactoring of queues and channels.
(cherry picked from commit d0eedfa10e, gh-134440)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
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)
Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
gh-132983: Refactor shared code in train_dict and finalize_dict (GH-134432)
Refactor shared code in train_dict and finalize_dict
(cherry picked from commit c64a21454b3c139af9e88941a286885fc4828a7e)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
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>
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.
TESTED: `python -m test -u curses test_curses`
---------
(cherry picked from commit aadda87b3d3d99cb9e8c8791bb9715a3f0209195)
Co-authored-by: tigerding <43339228+zydtiger@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>