Cody Maloney [Mon, 27 Oct 2025 18:06:46 +0000 (11:06 -0700)]
gh-140607: Validate returned byte count in RawIOBase.read (#140611)
While `RawIOBase.readinto` should return a count of bytes between 0 and
the length of the given buffer, it is not required to. Add validation
inside RawIOBase.read() that the returned byte count is valid.
Co-authored-by: Shamil <ashm.tech@proton.me> Co-authored-by: Victor Stinner <vstinner@python.org>
Alper [Mon, 27 Oct 2025 13:52:30 +0000 (06:52 -0700)]
gh-116738: Use PyMutex for bz2 module (gh-140555)
The methods are already wrapped with a lock, which makes them thread-safe in
free-threaded build. This replaces `PyThread_acquire_lock` with `PyMutex` and
removes some macros and allocation handling code.
Also add a test for free-threading to ensure we aren't getting data races and
that the locking is working.
Stan Ulbrych [Sun, 26 Oct 2025 11:01:04 +0000 (11:01 +0000)]
gh-76007: Deprecate `__version__` attribute in `decimal` (#140302)
Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Kumar Aditya [Fri, 24 Oct 2025 14:32:17 +0000 (20:02 +0530)]
gh-140414: add fastpath for current running loop in `asyncio.all_tasks` (#140542)
Optimize `asyncio.all_tasks()` for the common case where the event loop is running in the current thread by avoiding stop-the-world pauses and locking.
This optimization is already present for `asyncio.current_task()` so we do the same for `asyncio.all_tasks()`.
Victor Stinner [Thu, 23 Oct 2025 20:35:17 +0000 (22:35 +0200)]
gh-83714: Set os.statx().stx_mode to None if missing from stx_mask (#140484)
* Set stx_mode to None if STATX_TYPE|STATX_MODE is missing from
stx_mask.
* Enhance os.statx() tests.
* statx_result structure: remove atime_sec, btime_sec, ctime_sec and
mtime_sec members. Compute them on demand when stx_atime,
stx_btime, stx_ctime and stx_mtime are read.
* Doc: fix statx members sorting.
Abhishek Tiwari [Thu, 23 Oct 2025 17:05:12 +0000 (22:35 +0530)]
gh-140443: Use `fma` in `loghelper` to improve accuracy of log for very large integers (#140469)
* gh-140443:use fma in loghelper to improve accuracy of log for very large integers
Use fused multiply-add in log_helper() for huge ints.
Saving a rounding here is remarkably effective. Across some millions
of randomized test cases with ints up to a billion bits, on Windows
and using log10, the ULP error distribution was dramatically
flattened, and its range was nearly cut in half. In fact, the largest
error Tim saw was under 0.6 ULP.
---------
Co-authored-by: abhi210 <27881020+Abhi210@users.noreply.github.com> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Sam Gross [Thu, 23 Oct 2025 14:18:13 +0000 (10:18 -0400)]
gh-140431: Fix GC crash due to partially initialized coroutines (gh-140470)
The `make_gen()` function creates and tracks generator/coro objects, but
doesn't fully initialize all the fields. At a minimum, we need to
initialize all the fields that may be accessed by gen_traverse because
the call to `compute_cr_origin()` can trigger a GC.
Stefano Rivera [Wed, 22 Oct 2025 16:36:12 +0000 (09:36 -0700)]
gh-130317: Fix SNaN broken tests on HP PA RISC (#140452)
While looking at #140028, I found some unrelated test regressions in the
3.14 cycle. These seem to all come from #130317. From what I can tell,
that made Python more correct than it was before. According to [0], HP PA
RISC uses 1 for SNaN and thus a 0 for QNaN.
Emma Smith [Tue, 21 Oct 2025 21:48:29 +0000 (14:48 -0700)]
gh-132835: Add defensive NULL checks to MRO resolution (GH-134763)
Currently, there are a few places where tp_mro could theoretically
become NULL, but do not in practice. This commit adds defensive checks for
NULL values to ensure that any changes do not introduce a crash and that
state invariants are upheld.
The assertions added in this commit are all instances where a NULL value would get passed to something not expecting a NULL, so it is better to catch an assertion failure than crash later on.
There are a few cases where it is OK for the return of lookup_tp_mro to be NULL, such as when passed to is_subtype_with_mro, which handles this explicitly.
Jeffrey Bosboom [Tue, 21 Oct 2025 16:13:14 +0000 (09:13 -0700)]
gh-83714: Check for struct statx members in configure (#140402)
Some systems have the definitions of the mask bits without having the
corresponding members in struct statx. Add configure checks for members
added after Linux 4.11 (when statx itself was added).
David Ellis [Tue, 21 Oct 2025 15:57:43 +0000 (16:57 +0100)]
gh-138764: annotationlib: Make `call_annotate_function` fallback to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (#138803)
Jeffrey Bosboom [Tue, 21 Oct 2025 15:54:00 +0000 (08:54 -0700)]
gh-140239: Check for statx on Android (#140395)
Android has Linux's statx, but MACHDEP is "android" on Android, so
configure doesn't check for statx on Android. Base the check for statx
on ac_sys_system instead, which is "Linux-android" on Android, "Linux"
on other Linux distributions, and "AIX" on AIX (which has an
incompatible function named statx).
Mark Shannon [Tue, 21 Oct 2025 14:22:15 +0000 (15:22 +0100)]
GH-139951: Fix major GC performance regression (GH-140262)
* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead
* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
* Support non-UTF-8 shebang and comments if non-UTF-8 encoding is specified.
* Detect decoding error for non-UTF-8 encoding.
* Detect null bytes in source code.