10575 Commits

Author SHA1 Message Date
Miss Islington (bot)
055e6b2891
[3.15] gh-148891: prevent crash in HAMT caused by GC during traverse (GH-148928) (#161593)
gh-148891: prevent crash in HAMT caused by GC during traverse (GH-148928)

`_PyHamt_Assoc` allocates HAMT nodes, which can trigger GC. A weakref callback or finaliser fired during GC could re-enter `contextvar_set`, replacing `ctx->ctx_vars` via `Py_SETREF` and freeing the old HAMT while `_PyHamt_Assoc` was still traversing it, causing a use-after-free.

Hold a strong reference to `ctx->ctx_vars` during the `_PyHamt_Assoc` call, so that a re-entrant free cannot affect the HAMT being traversed.
(cherry picked from commit 1798d4fb3ca0e1cd8f9e6ab0ac99a0a9fb1f7527)

Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
2026-11-08 00:01:24 +00:00
Miss Islington (bot)
bc29f96a8c
[3.15] gh-161288: Fix perf trampoline crash on UBSan builds (GH-161294) (#161348)
gh-161288: Fix perf trampoline crash on UBSan builds (GH-161294)
(cherry picked from commit a14cccbaa4787860ede0945ffaf67cf14b34c8e2)

Co-authored-by: Neko Asakura <neko.asakura@outlook.com>
2026-11-05 00:51:22 +01:00
Miss Islington (bot)
ae86660de3
[3.15] gh-161229: Accept None for globals and locals in __lazy_import__() (GH-161231) (#161315)
gh-161229: Accept `None` for `globals` and `locals` in `__lazy_import__()` (GH-161231)
(cherry picked from commit 1941319efb6fa4184b7fa14a8638a870530ffe20)

Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com>
2026-11-04 14:28:37 +00:00
Miss Islington (bot)
22bc41d3c2
[3.15] gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258) (#161291)
gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258)

Previously, passing NULL to an optional string option crashed.

Document optional string options.

Add more tests on the PyInitConfig API.
(cherry picked from commit 6d69297b2b1007991640310e8699979a2ef66287)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-11-04 03:41:35 +01:00
Miss Islington (bot)
c391d1a764
[3.15] gh-150868: Fix sum() deallocating a float subclass as an exact float (GH-151063) (#161048)
gh-150868: Fix sum() deallocating a float subclass as an exact float (GH-151063)

* gh-151060: Fix sum() deallocating a float subclass as an exact float

The complex-total fast path in builtin_sum_impl() guarded with
PyFloat_Check() (which accepts subclasses) but freed the item with
_Py_DECREF_SPECIALIZED(item, _PyFloat_ExactDealloc), which assumes an
exact float. A float subclass instance reaching refcount 0 in that loop
aborts on an assertion in debug builds, and in release builds skips the
subclass tp_dealloc (type refcount leak, __del__ never runs, subclass
object pushed onto the float freelist).

Use PyFloat_CheckExact() instead, matching the float-total branch, so
subclass instances fall through to the generic PyNumber_Add() path.



* gh-150868: Also use exact-type checks for ints in the fast sum() loops

Per review: use PyLong_CheckExact with the specialized exact-int
deallocator in the float and complex fast-sum loops, so int subclasses
take the generic path.



---------
(cherry picked from commit 47c249adf3bc2ae3264a7373f7f1f5e7c4d84955)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-11-01 21:27:29 +01:00
Neil Schemenauer
cdba68e563
[3.15] gh-159136: Avoid stop-the-world when setting function name attributes (gh-159269) (gh-159725)
Setting __name__, __qualname__, __doc__ or __module__ on a function
stopped the world in the free-threaded build since gh-154826 and
gh-154851, making functools.wraps() orders of magnitude slower with
multiple threads.

Use the per-object critical section and _PyObject_XSetRefDelayed()
instead, as gen_set_name() already does.  Use acquire loads in the
readers and hold strong references across error reporting, tracing, and
eval-frame recording that may execute Python or detach the thread.  The
__code__, __defaults__, __kwdefaults__ and __closure__ setters still
stop the world to clear func_version.

Document synchronization requirements for direct field access and the
lifetime of borrowed function attributes.

(cherry picked from commit 010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20)
2026-10-29 15:17:50 -07:00
Miss Islington (bot)
e60e7bdc92
[3.15] gh-159652: Fix import lock leak when the C stack is nearly exhausted (GH-159660) (GH-160779)
gh-159652: Fix import lock leak when the C stack is nearly exhausted (GH-159660)

When an import failed with a stack overflow RecursionError, releasing the import locks on the error path could itself raise RecursionError, because the cleanup runs in a new C frame. This left the global import lock or a module lock held forever, and later imports in other threads blocked indefinitely.

_imp.acquire_lock() now raises RecursionError when there is not enough stack left to release the lock. importlib calls it before taking any import lock, so this covers the per-module locks too. The module lock weakref callback skips cleanup in that case instead of
reporting an unraisable exception.
(cherry picked from commit 926b0bf3110bf86550ef248cf911e24fc123ec64)

Co-authored-by: Cary Hawkins <hawkinscary23@gmail.com>
2026-10-27 22:17:27 +00:00
Stan Ulbrych
33bb297b43
[3.15] Fix ignored error returns in sys initialization, _ctypes and _interpchannels (GH-160614) (#160711)
(cherry picked from commit c5d09789ea28f34b9f150a4d033945e0eccaeabf)
2026-10-26 19:49:41 +00:00
Pablo Galindo Salgado
e243e46142
[3.15] gh-128883: Store ELF perf trampoline templates in read-only data (GH-160366) (#160490)
CPython copies the trampoline templates into executable memory. Keep the
ELF source in .rodata so BOLT preserves its bytes and boundaries.
(cherry picked from commit 1ff83ad7addf96fffdca863ac0f02f86538bb757)

Co-authored-by: Zanie Blue <contact@zanie.dev>
2026-10-23 21:01:06 +00:00
Carl Meyer
cc3a0c9d3a
[3.15] gh-160299: Preserve references from inlined comprehensions (GH-156819) (#160413)
Adapt the reference-flag propagation from GH-156819 to fix gh-160299 without backporting the comprehensive changes to comprehension scope representation and compilation.
2026-10-23 10:41:48 -07:00
Miss Islington (bot)
47667b8d0d
[3.15] gh-159739: Hold the codec registry lock while unregistering (GH-160168) (#160292)
Concurrent calls to codecs.unregister() can shrink the search path between its length check and indexed lookup in a free-threaded build. The lookup then returns NULL and an unconditional decref crashes the interpreter; hold the registry mutex across the scan and removal. Also reported in gh-157078. Backport to 3.15 and 3.14.
(cherry picked from commit 784b305df8821d57fb6fb6c52794ef67bda0a75d)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-22 15:26:02 -07:00
Miss Islington (bot)
1526be662c
[3.15] gh-159739: Preserve ContextVar cache updates from finalizers (GH-160197) (#160330)
Resetting a ContextVar can finalize the replaced value, whose finalizer may set the variable again. Updating the lookup cache after releasing the old context root overwrites that newer cached value, so get() can return a stale value or use a freed object. Update the cache before the old root can be released. Backport to 3.15 and 3.14.
(cherry picked from commit f4f8b933e3cf73c1ec8ca1d33ff62faee9f0ffd8)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-22 15:22:23 -07:00
Miss Islington (bot)
9986943124
[3.15] gh-159739: Skip context watchers cleared during notification (GH-160164) (#160291)
A context watcher callback can clear a later watcher while a context-switch notification is being dispatched. The dispatcher still uses its earlier snapshot of active watchers, so it calls a NULL callback and crashes; check that each callback is still registered before invoking it. Backport to 3.15 and 3.14.
(cherry picked from commit 0a5762621ff6b4110fae01caf2f85ea93c54a238)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-22 15:20:44 -07:00
Stan Ulbrych
230cc89994
[3.15] Fix unchecked NULL returns in several C modules (GH-160213) (#160262)
(cherry picked from commit a930e524cbe7cd3a35f27a1c33e7d684909d765a)
2026-10-22 21:38:32 +01:00
Donghee Na
86e3b9fd53
[3.15] gh-159111: Update vendored mimalloc to v2.5.2 (gh-159112) (gh-160178) 2026-10-22 09:55:05 -07:00
Jelle Zijlstra
f8672b4ef4
[3.15] gh-151818: Fix double-free in _CALL_LIST_APPEND on allocation failure (GH-151826) (#160200)
On allocation failure, close the remaining live inputs and pop all three
inputs before unwinding, so the consumed argument is not closed twice.

Backport the regression test and regenerate the interpreter files using
the 3.15 cases generator.

(cherry picked from commit 4ecf6ca1b3d1eb8bb9afd0c0b9dfdbebdc9e05fc)

Co-authored-by: Timur Mamedov <timurmamedov742@gmail.com>
2026-10-22 06:23:06 -07:00
Miss Islington (bot)
8fad07c0f1
[3.15] gh-159739: Clear free-threaded GC worklists after early errors (GH-159979) (#160016)
(cherry picked from commit 2315d94664f0a1c93ef43272b9c200ad4b04c709)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-21 12:22:28 -07:00
Miss Islington (bot)
2c17c77546
[3.15] gh-159739: Fix reference and error handling in warnings (GH-159758) (#160022)
Do not release the borrowed skip_file_prefixes argument, and stop if
allocation of the fallback filename fails.
(cherry picked from commit fab1405da8c93429ab1a1d3d3e1779d15b7223a2)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-21 11:55:12 -07:00
Victor Stinner
b62f612a26
[3.15] gh-159603: Use pthread_attr_get_np() on FreeBSD (#159604) (#159928)
gh-159603: Use pthread_attr_get_np() on FreeBSD (#159604)

Use pthread_attr_get_np() on FreeBSD to get the stack size (and guard
size) of the current thread.

Check if pthread_attr_get_np() function and <pthread_np.h> header are
available in configure.

Update test_json.test_recursion. On FreeBSD 16 with a default stack size of
512 MB, the json C implementation no longer raises RecursionError in
test_highly_nested_objects_encoding(). Reduce also max_depth from 5,000 to
2,000 so test_highly_nested_objects_encoding() of the Python implementation
only takes 1.6 seconds, instead of 12 seconds.

(cherry picked from commit 71ba39dc057941fb8ea032b813862a215bb3d5aa)
2026-10-20 14:49:48 -05:00
Miss Islington (bot)
c75c72b64a
[3.15] gh-159739: Avoid leaking references during free-threaded GC enumeration (GH-159781) (#159907)
(cherry picked from commit 7652a6daccc39d7fb051d54d9f804df535bb17b0)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-10-20 18:37:02 +00:00
Miss Islington (bot)
73358fca05
[3.15] gh-159739: Bound encoding-name lookahead in surrogatepass (GH-159785) (#159911)
(cherry picked from commit 905aab60f72ec5aa9183ec0b74b5eda8f9ca188d)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-10-20 18:25:38 +00:00
Miss Islington (bot)
83fc8e8d48
[3.15] gh-159739: Handle interpreter configuration encoding errors (GH-159747) (#159843)
Propagate UTF-8 conversion errors before copying a string configuration
value.
(cherry picked from commit 626394e0a38bdf7734567f00a09837f09e653bff)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-20 11:12:17 -07:00
Miss Islington (bot)
9f13436ef0
[3.15] gh-159739: Release replaced PyInitConfig strings (GH-159769) (#159809)
gh-159739: Release replaced PyInitConfig strings (GH-159769)

* gh-159739: Release replaced PyInitConfig strings

Backport to 3.15 and 3.14.

---------
(cherry picked from commit 395d766d4f44e45ca4e9053b4761f115de122317)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-10-20 00:18:08 +00:00
Neil Schemenauer
81fe70e966
[3.15] gh-158973: Reset the warnings lock after fork in the child (gh-158974) (gh-159614)
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
2026-10-19 14:54:15 -07:00
Miss Islington (bot)
64e7708753
[3.15] gh-158121: Preserve instruction events when line monitoring is disabled (GH-158456) (#159733)
gh-158121: Preserve instruction events when line monitoring is disabled (GH-158456)
(cherry picked from commit f0f76de0c8521e51c2e5c1da6de23373ec39231c)

Co-authored-by: limadog9 <jakewallin42@gmail.com>
2026-10-19 19:47:56 +00:00
Miss Islington (bot)
7d95f0d09c
[3.15] gh-130279: Fix missing exception handlers for jumps in loops (GH-159460) (#159698)
gh-130279: Fix missing exception handlers for jumps in loops (GH-159460)
(cherry picked from commit 036d309cf542986a39eeba5ca805b2ec7619731d)

Co-authored-by: Han <180024497+LH-and-FPGA@users.noreply.github.com>
2026-10-19 08:43:26 +00:00
Miss Islington (bot)
faf16ef256
[3.15] gh-159041: Fix use-after-free in asyncio task tracking during thread state cleanup (GH-159073) (#159694)
gh-159041: Fix use-after-free in asyncio task tracking during thread state cleanup (GH-159073)
(cherry picked from commit 999855b07f9b795ca88ac3349060a06c116a1037)

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
2026-10-19 11:35:08 +05:30
Miss Islington (bot)
a73827e5bc
[3.15] gh-157906: fix an incorrect architecture macro check in free-threaded GC (gh-157907) (gh-159427)
Fix typo in free-threaded GC prefetch check for 32-bit x86 MSVC.
(cherry picked from commit 1b015e66f058f29de4d97031b465587ec15cace9)

Co-authored-by: Pengyu Lee <lipengyu@kylinos.cn>
2026-10-16 20:09:46 -07:00
Miss Islington (bot)
b6d63f1877
[3.15] gh-159320: Enable stack size detection on Android (GH-159321) (#159409)
gh-159320: Enable stack size detection on Android (GH-159321)

Extend the use of pthread_getattr_np in stack size detection from any glibc linux to any glibc *or* android linux. Update tests for android's new recursion limit.
(cherry picked from commit 8ff41c2ae723a62abace675b058dd4da8f90a397)

Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: Malcolm Smith <smith@chaquo.com>
2026-10-14 12:44:05 +00:00
Miss Islington (bot)
33a05de00a
[3.15] gh-157384: Set package context in PyImport_CreateModuleFromInitfunc() (GH-157387) (GH-159316)
A single-phase init function that creates its module using only the
last component of a dotted name (as pybind11 does for submodules) got
a module whose __name__ was the short name.  Set the package context
while calling the init function, as the dynamic loader does, so the
module gets the full name from the spec.
(cherry picked from commit 04862280a2ccbf9be9883eb4bce886f6b1bc4ca0)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
2026-10-14 13:49:31 +02:00
Neil Schemenauer
ef498e0336
[3.15] Fix _PyThreadState_ResumeDetached() assertion with attach waiters (GH-159372)
Make _PyThreadState_ResumeDetached() waiter-aware and use it from
start_the_world(), matching main branch.  Remove tstate_resume().
2026-10-13 12:43:19 -07:00
Trent Nelson
ed4f3bccbd
[3.15] gh-151518: Avoid STW starvation of attaching threads (GH-152826) (GH-158186)
Preserve active attach waiters across successive stop-the-world pauses
so a tight collection loop cannot keep them from making progress.

Keep the waiter-aware resume operation local to pystate.c because this
branch does not have the newer BRC suspend and resume helpers.

(cherry picked from commit f1565109603123c39bd2a0c6002f5ea15a62b6e7)
2026-10-13 17:44:50 +02:00
Irit Katriel
8870e26718
[3.15] gh-143493: fix cleanup on errors in codegen_comprehension (GH-156374) (GH-156962) 2026-10-13 11:51:33 +02:00
Miss Islington (bot)
6a67945f32
[3.15] gh-155823: Fix stale stack on _SEND_VIRTUAL_TIER_TWO exhausted exit (GH-155844) (GH-158559)
(cherry picked from commit 1071f7400ec6f3ffb63b48310440b2ae73c632b4)

Co-authored-by: An Long <aisk@users.noreply.github.com>
2026-10-13 11:20:24 +02:00
Victor Stinner
18e0bcb85f
[3.15] gh-157415: Fix data race in pthread wrapper (#157430) (#159277)
gh-157415: Fix data race in pthread wrapper (#157430)

Use free() instead of PyMem_RawFree() in pythread_wrapper() to avoid
a data race if another thread calls PyMem_SetAllocator() in parallel.

Reenable @nomemtest tests on TSAN.


(cherry picked from commit d1878ccb44999bfa30f5a0e84b4383e6068e5b72)

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
2026-10-12 23:32:24 +00:00
Irit Katriel
689c420973
[3.15] gh-156466: fix cleanup on error in codegen_leave_annotations_scope (#156520) 2026-10-12 15:54:04 -07:00
John
4df287d276
[3.15] gh-157468: Validate correct builtins used under JIT (GH-157766) (GH-159048)
* Expose two possible builtin JIT gaps

* Add trace and runtime guard for builtin dict

* Check _GUARD_BUILTINS_IS_CANONICAL once per frame

* Add check and fix for globals being folded
(cherry picked from commit 0906d2ab93fc9f4c7e0db031c965e7d8a0db7d37)
2026-10-12 16:31:15 +02:00
Miss Islington (bot)
9de85b0d10
[3.15] gh-158072: Fix JIT crash with omitted default arguments (GH-158128) (GH-158543)
(cherry picked from commit 83de667b25f9e0f3dd7a37b6f3d136a444cd6a0d)

Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
2026-10-12 16:07:29 +02:00
Miss Islington (bot)
e96bd136eb
[3.15] gh-149816: #96 Fix a race condition in invoke_gc_callback with free threading (GH-150029) (GH-156119)
(cherry picked from commit 91d71dd67074d4599b6bd49cc933f41f8bd57058)

Co-authored-by: dzaramelcone <134235821+dzaramelcone@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-10-12 14:51:04 +02:00
Irit Katriel
2cab3197a5
[3.15] gh-156466: fix cleanup on error in codegen_setup_annotations_scope (#156473) (GH-156498)
(cherry picked from commit 24e5a55ccb0c5db68136d29f4c16c0bc21407db2)
2026-10-12 14:21:42 +02:00
Bartosz Sławecki
ad0a18a17d
[3.15] gh-156909: Fix AST.__repr__ call getting the _fields attribute (GH-157490) (GH-157596)
(cherry picked from commit 1bfcc3cc871d3fab21b77cdc47cdbfcf89fd8b5b)
2026-10-12 14:08:25 +02:00
Gregory P. Smith
8c7ac5733f
[3.15] gh-159184: Do not compare set elements when marshalling a set (GH-159196) (#159205)
Set elements are written in the order of their dumps.  They were sorted
as (dump, element) pairs, so elements with the same dump were compared.
That failed for a set of several complex NaNs, which the compiler can
produce by constant folding, making the module impossible to marshal.
On this branch the failure was reported as MemoryError.

Sort (dump, index, element) tuples, in which the indexes are all
different.  Elements with the same dump stay in the order of the set,
as float NaNs did before.

(cherry picked from commit 1967a87ad395552dbd1e16fd3f13d3b4b2f694de)
2026-10-11 23:27:49 +00:00
Gregory P. Smith
4c2433f310
[3.15] gh-159185: Fix marshalling of a set modified while its elements are marshalled (GH-159195) (#159199)
Marshalling a set element can run Python code (__buffer__, an audit
hook) which changes the set.  The number of elements was read before
the loop, so a set which grew was written past the end of the list and
one which shrank left NULL items in the list which was then sorted.
Raise RuntimeError("set changed size during iteration") instead.

(cherry picked from commit cd71799c47802f87e1469cc97cc99f5ce6cea27c)
2026-10-11 21:55:14 +00:00
Pablo Galindo Salgado
4ceb3faf2c
[3.15] Restore deferred backports for 3.15.1, including GH-158874 (#158882)
* [3.15] gh-153364: Make frame, coroutine, and task-waiter chain walks iterative and bounded (GH-153365) (#158813)

gh-153364: Make frame, coroutine, and task-waiter chain walks iterative and bounded (GH-153365)

* let me declare single limit

* use our new limit in process_frame_chain()

* add it in parse_async_frame_chain()

* parse_coro_chain()

* NEWS

* async in the message?

* test

* no race

* process_task_awaited_by

* process_task_awaited_by limit test

* NEWS

* MAX_TASK_WAITER_CHAIN_DEPTH

* TASK_WAITER_CHAIN_DEPTH in test

* TASK_WAITER_CHAIN_DEPTH 256

* prevent the drift with the comment

* better naming, better style

* MAX_TASK_WAITER_CHAIN_DEPTH comment

* task-waiter iterative bfs walk

* iterative coro-walk

* nicer news

* 1 << 14

* comment

* unused read_Py_ssize_t

* fix tombstones

* simplify

* correct msg

* better test

* news for tombstones

* left-over from when testing buggy version

* redundant new line
(cherry picked from commit e0861c6ae70c7e6f16c28399bd2b28c521e11e84)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
(cherry picked from commit 9e401cf7f5a53d8b46702e6c4bcb8849b9bf2829)

* [3.15] gh-155811: Add a seqcount to `gc_stats` to prevent torn reads (GH-155828) (#158829)

* update_seq

* no need for XCHGL, MOVL is enough?

* gh-155811: Retry an inconsistent GC snapshot once

---------
(cherry picked from commit 5fecd448bb120378978a37dde65dfce233d88c0d)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 028124039c276f73fbc26036f1629c91be4c2891)

* [3.15] gh-151292: `_remote_debugging`: Do not corrupt the binary file when hitting `OverflowError` (GH-152892) (#158830)

gh-151292: `_remote_debugging`: Do not corrupt the binary file when hitting `OverflowError` (GH-152892)

* the kolektor

* test

* better test

* news

* =Q, move const to the base, not self.running

* gh-151292: Track binary writer finalization state

---------
(cherry picked from commit f839c061d383bc87c3456d19bbdcbc1c30ed399b)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
(cherry picked from commit 8a7c23f316a6bdb3cc60c6920d465d2a81d3cf35)

* [3.15] gh-158583: Fix uninitialized memory read in bytes.fromhex() (GH-158584) (#158691)

gh-158583: Fix uninitialized memory read in bytes.fromhex() (GH-158584)
(cherry picked from commit 9d22a5334bd5273962adceeb697a1337e9a0ca21)

Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 4f7af46e25f09bf54b6f499c5c40b661786f0d69)

* [3.15] gh-154194: Degrade frames in Tachyon instead of failing the sample (GH-154195) (#158831)

* gh-154194: Degrade frames in Tachyon instead of failing the sample (#154195)

* degrade gracefully

* news

* better NEWS wording

* do not raise on MAX_REMOTE_STR_READ

* bye MAX_REMOTE_STR_READ

* fix -m asyncio ps|pstree

* test truncation and linetable sentinel

* simpler

* simpler

* redundant now

* respect #157790 in the news

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
(cherry picked from commit 7d25916b41de4fc28e04b4944864ad1094a9e8e0)

* Preserve the stable ABI when creating fallback frame names

---------

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
(cherry picked from commit c27f4940612b094fe225875a815f8ee6a4f7f9ec)

* [3.15] Add MSan to CI (GH-158625) (#158832)

Run a job that the test suite with MSan to the CI (#158625)

* Run the test suite with MSan in CI

* Additional fixes

* Add `_Py_MSAN_UNPOISON_STRING`

* Apply Victor's suggestions

* Apply Victor's suggestions

---------

(cherry picked from commit b93fb19a6e3118857d9a1dc4ffcc179b632a88c1)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
(cherry picked from commit 1bc78dea18dfaff6900eeac5edb1ca651ff700d7)

* [3.15] gh-156810: Write the profiler's collapsed-stack export as UTF-8 (GH-156811) (#156814)

gh-156810: Write the profiler's collapsed-stack export as UTF-8 (GH-156811)
(cherry picked from commit c3706f4c687d76b85702c1f946abd3f3d3eafcb8)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
(cherry picked from commit fce28da9b75d429a7b65eec450df8e804fada001)

* [3.15] gh-158552: Wait for Windows threads to suspend before blocking sampling (GH-158802) (#158845)

gh-158552: Wait for Windows threads to suspend before blocking sampling (GH-158802)

* gh-158552: Wait for Windows threads to suspend before blocking sampling

* Use a named Windows thread enumeration status constant
(cherry picked from commit 1643525f0f89438d87daf4cdbb1cbb1de9df08e8)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
(cherry picked from commit 31288da21d4536eccd8df2e8222687919164e867)

* [3.15] gh-152721: Fix quadratic RLE replay time in the profiling binary reader (GH-152722) (#158850)

Backport of GH-152722.

Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
(cherry picked from commit ebaca2ac2d3ac29cd2760b6a5e4617c3fc5f6333)

* [3.15] gh-156545: Fix flamegraph export RecursionError on deeply recursive programs (GH-156546) (#158851)

Backport of GH-156546.

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
(cherry picked from commit 0ac721704092d8f96720c6fd1d68c5941a4a530a)

* [3.15] gh-158540: Add the profiled script's directory to sys.path (GH-158548) (#158844)

gh-158540: Add the profiled script's directory to sys.path (GH-158548)

* gh-158540: Add the profiled script's directory to sys.path

When a script is profiled with ``python -m profiling.sampling run
script.py`` from another directory, the script cannot import modules
placed next to it, because ``_sync_coordinator._execute_script()``
executes it with the working directory (added by
``_setup_environment()`` for the module case) as ``sys.path[0]``
instead of the script's own directory.

Make the script's directory importable in ``_execute_script()``,
matching the behavior of ``python script.py``.

Add a regression test that runs the coordinator on a script importing
a sibling module.

* Update _sync_coordinator.py Comment simplified

* gh-158540: Resolve symlinks when adding the script directory to sys.path

``python script.py`` resolves symlinks when computing ``sys.path[0]``, so
a script reached through a symlink (``link.py -> sub/where.py``) imports
modules from the real script's directory.  Apply ``os.path.realpath()``
before taking the directory name, and make sure the result is placed at
the front of ``sys.path`` even if it was already listed.

Add a regression test for a symlinked script.

---------
(cherry picked from commit 3f02aab9faa338853425da23541e44e4bd24d478)

Co-authored-by: he_tao <53343436+hetaozdh@users.noreply.github.com>
Co-authored-by: Eduardo Villalpando Mello <eduardo.villalpando.mello@gmail.com>
(cherry picked from commit f52d831397ec77cf969c71c1ef339c1e28494eca)

* [3.15] gh-153838: Skip non-regular source files in the heatmap exporter (GH-153839) (#158853)

Backport of GH-153839.

Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
(cherry picked from commit 48998df2510c0daa837f98bbbbe6cc49ef60dc43)

* [3.15] gh-158539: Fix exception mode missing handlers in generators/coroutines (GH-158581) (#158852)

* [3.15] gh-158539: Fix exception mode missing handlers in generators/coroutines (GH-158581)

Backport of GH-158581.

Co-authored-by: LucasZhou <donghao.zhou@outlook.com>

* [3.15] gh-158539: Use portable static assertion messages

* [3.15] gh-158539: Keep layout assertions with debug-offset validation

* [3.15] gh-158539: Use the platform guard for in-process inspection tests

---------

Co-authored-by: LucasZhou <donghao.zhou@outlook.com>
(cherry picked from commit d625ecbb8d36b7dd26c61b13d1c97de117d36642)

* [3.15] gh-158522: Fix truncated stack for a task whose coroutine recurses (GH-158526) (#158870)

Co-authored-by: Timofei Ivankov <128279579+deadlovelll@users.noreply.github.com>
(cherry picked from commit a904b397ed324e404a8abd682b056c146cb48263)

* gh-156545, gh-158539: Fix deep flamegraph export on small C stacks and macOS runtime lookup (#158874)

(cherry picked from commit 114de198c0a05d8169cdbbd8f1e0976dc1319284)

Include the C-stack test helper from main, introduced by
ce5ae29ef9b8ccb32683c922d135339311c36c9d, which the regression test
requires but 3.15 does not yet provide.

---------

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: he_tao <53343436+hetaozdh@users.noreply.github.com>
Co-authored-by: Eduardo Villalpando Mello <eduardo.villalpando.mello@gmail.com>
Co-authored-by: LucasZhou <donghao.zhou@outlook.com>
Co-authored-by: Timofei Ivankov <128279579+deadlovelll@users.noreply.github.com>
2026-10-11 15:42:59 +01:00
Miss Islington (bot)
ae21cb7ccf
[3.15] gh-156204: Guard recursion in PyErr_GivenExceptionMatches (GH-156205) (GH-158622)
(cherry picked from commit 20d5e67fc51eee8cbf7e38d75830e5edd140d37e)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-10-11 07:20:28 +00:00
Victor Stinner
c774d1526f
[3.15] gh-158893: Make os.strerror() thread-safe (#159120)
* gh-157695: Parse also _Py_HAVE_xxx variables in sysconfig (#158926)

Add parse_config_h() tests to test_sysconfig.

(cherry picked from commit 978a8befa5ec9b28b161a56b16d326330aef4733)

* gh-158893: Make os.strerror() thread-safe (#158927)

Make os.strerror() thread-safe: use the reentrant strerror_r()
function if available.

* The configure script now checks if strerror_r() is supported.
* Add a stress test to test_free_threading.test_os (new module).
* Add a comment on decode_current_locale() assertion which fails if
  the input string is mutated.
* Add an assertion to _Py_DecodeLocale() to detect if the input
  string was mutated during the function call.

* gh-158893: Add internal _Py_strerror() function (#158982)

Add a new internal _Py_strerror() function to Python/fileutils.c. It
uses strerror_r() if available, or use strerror() otherwise.

Replace all strerror(code) calls with _Py_strerror(code).

(cherry picked from commit 15dd7356f300733b9c3fcc35f0d75e61a6ef3e05)
2026-10-10 22:08:49 +02:00
Miss Islington (bot)
f7523edbb1
[3.15] gh-156466: fix cleanup on error after Enter in codegen_enter_scope (GH-156467) (GH-156616)
(cherry picked from commit 41b3f0af266b408438cab36625c6ad71040d38e5)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2026-10-10 14:00:18 +03:00
Miss Islington (bot)
e2d4d04afb
[3.15] gh-156466: fix cleanup on error in codegen_function_body (GH-156511) (GH-156578)
(cherry picked from commit d94c4ad1b65b102d10634b43bea61d35dae7baeb)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2026-10-10 13:59:36 +03:00
Miss Islington (bot)
6295a17865
[3.15] gh-156459: Fix cleanup on error in compiler_set_qualname (GH-156462) (GH-156574)
(cherry picked from commit 8b082aa405101ab806433cd4d7305b19397271cf)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2026-10-10 13:58:08 +03:00
Miss Islington (bot)
35c77f2c00
[3.15] gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720) (#158905)
gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720)

Under high thread concurrency in free-threaded builds, `_Py_Specialize_LoadGlobal` suffers from lock contention when acquiring the critical section mutexes for the `globals` and `builtins` dictionaries during bytecode specialization.

This PR skips LOAD_GLOBAL bytecode specialization if acquiring the two object mutexes would block.
(cherry picked from commit ac8ba0ca5a04cd7b27b44822d31df640e817fd78)

Co-authored-by: Peter Hawkins <phawkins@google.com>
2026-10-10 16:03:02 +05:30