6051 Commits

Author SHA1 Message Date
Victor Stinner 690b2bb615 [3.14] gh-137030: Fix YIELD_VALUE bytecode assertion (#149184) (#149383)
gh-137030: Fix YIELD_VALUE bytecode assertion (#149184)


(cherry picked from commit 952784af47)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2026-05-04 23:41:19 +02:00
Hugo van Kemenade 1ee324262d Post 3.14.5rc1 2026-05-04 23:00:33 +03:00
Hugo van Kemenade a68a919049 Python 3.14.5rc1 2026-05-04 18:31:40 +03:00
Dino Viehland 312a596bcf [3.14] gh-149242: Heap size should be added at end of the struct (#149241)
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-05-01 12:56:30 -07:00
Sergey Miryanov 4d0ae4cba9 [3.14] GH-148726: Add heap_size to _gc_runtime_state (#149025) 2026-04-29 13:04:11 +03:00
Sergey Miryanov 9a7e205e46 [3.14] GH-148726: Forward-port generational GC (#148720)
Co-authored-by: Neil Schemenauer <nas@arctrix.com>
Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Zanie Blue <contact@zanie.dev>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-04-26 21:12:52 +03:00
Jelle Zijlstra 1c9de6bbaa [3.14] gh-137814: Fix __qualname__ of __annotate__ functions in the interpreter (#148221)
gh-137814: [3.14] Fix __qualname__ of __annotate__ functions in the interpreter

I'd still like to do #137842 on 3.15+, but that requires changing bytecode and we can't
really afford to do that in 3.14. So to fix this in 3.14, let's patch things up in the
ceval loop instead.

This is safe because the compiler only sets __annotate__ to just-created dedicated
annotate functions.
2026-04-15 21:52:43 -07:00
Miss Islington (bot) 1fa52c3c84 [3.14] gh-148393: Use acquire load for _ma_watcher_tag in dict notify event (gh-148509) (#148512)
The watcher-bits read in _PyDict_NotifyEvent needs to use acquire to
synchronize with the release from PyDict_Watch so that the callback
publication is visible before the callback is invoked.
(cherry picked from commit 19f96f99fe)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-04-13 18:38:15 +00:00
Miss Islington (bot) a89b2419e0 [3.14] gh-148393: Use atomic ops on _ma_watcher_tag in free threading build (gh-148397) (#148451)
Fixes data races between dict mutation and watch/unwatch on the same dict.
(cherry picked from commit 3ab94d6842)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-04-12 15:05:34 +00:00
Kumar Aditya f36da66c71 [3.14] gh-148037: remove critical section from PyCode_Addr2Line (GH… (#148353)
[3.14] gh-148037: remove critical section from `PyCode_Addr2Line` (GH-148103)
(cherry picked from commit d3b7b93cbb)
2026-04-10 23:59:38 +05:30
Hugo van Kemenade 3da4e0910c Post 3.14.4 2026-04-07 20:46:24 +03:00
Hugo van Kemenade 23116f998f Python 3.14.4 2026-04-07 16:13:20 +03:00
Miss Islington (bot) 636946f413 [3.14] gh-148144: Initialize visited on copied interpreter frames (GH-148143) (#148147)
gh-148144: Initialize visited on copied interpreter frames (GH-148143)

_PyFrame_Copy() copied interpreter frames into generator and
frame-object storage without initializing the visited byte. Incremental
GC later reads frame->visited in mark_stacks() on non-start passes, so
copied frames could expose an uninitialized value once they became live
on a thread stack again.

Reset visited when copying a frame so copied frames start with defined
GC bookkeeping state. Preserve lltrace in Py_DEBUG builds.
(cherry picked from commit fbfc6ccb0a)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-04-05 23:49:47 +00:00
Sam Gross 6ea4f842fb [3.14] gh-144438: Fix false sharing between QSBR and tlbc_index (gh-144554) (#144923)
Align the QSBR thread state array to a 64-byte cache line boundary
and add padding at the end of _PyThreadStateImpl. Depending on heap
layout, the QSBR array could end up sharing a cache line with a
thread's tlbc_index, causing QSBR quiescent state updates to contend
with reads of tlbc_index in RESUME_CHECK. This is sensitive to
earlier allocations during interpreter init and can appear or
disappear with seemingly unrelated changes.

Either change alone is sufficient to fix the specific issue, but both
are worthwhile to avoid similar problems in the future.

(cherry picked from commit 6577d870b0)
2026-03-31 19:20:24 +00:00
Miss Islington (bot) 25b48b84b8 [3.14] gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (GH-145901) (#147331)
gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (GH-145901)

The long_from_string_base() might return a small integer, when the
_pylong.py is used to do conversion.  Hence, we must be careful here to
not smash it "small int" bit by using the _PyLong_FlipSign().
(cherry picked from commit db5936c5b8)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-31 16:14:12 +02:00
Miss Islington (bot) e387bac1a4 [3.14] gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631) (#147187)
gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631)
(cherry picked from commit adf2c47911)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-31 13:27:11 +00:00
dr-carlos dd4ea46917 [3.14] gh-141732: Fix ExceptionGroup repr changing when original exception sequence is mutated (GH-141736) (GH-144445)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2026-03-23 23:31:32 +01:00
Sam Gross 73e74eeb2f [3.14] gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (gh-146229) (#146232)
Also fix a few related issues in the pyatomic headers:

* Fix _Py_atomic_store_uint_release in pyatomic_msc.h to use __stlr32
  on ARM64 instead of a plain volatile store (which is only relaxed on
  ARM64).

* Add missing _Py_atomic_store_uint_release to pyatomic_gcc.h.

* Fix pseudo-code comment for _Py_atomic_store_ptr_release in
  pyatomic.h.

(cherry picked from commit 1eff27f2c0)
2026-03-20 20:08:20 +00:00
Sam Gross fa3143a1d2 [3.14] gh-145779: Improve classmethod/staticmethod scaling in free-threaded build (gh-145826) (#146088)
Add special cases for classmethod and staticmethod descriptors in
_PyObject_GetMethodStackRef() to avoid calling tp_descr_get, which
avoids reference count contention on the bound method and underlying
callable. This improves scaling when calling classmethods and
staticmethods from multiple threads.

Also refactor method_vectorcall in classobject.c into a new
_PyObject_VectorcallPrepend() helper so that it can be used by
PyObject_VectorcallMethod as well.

(cherry picked from commit e0f7c1097e)
2026-03-19 10:49:12 -04:00
Miss Islington (bot) 19cbcc0f85 [3.14] gh-142183: Cache one datachunk per tstate to prevent alloc/dealloc thrashing (GH-145789) (#145828)
Cache one datachunk per tstate to prevent alloc/dealloc thrashing when repeatedly hitting the same call depth at exactly the wrong boundary.

Move new _ts member to the end to not mess up remote debuggers' ideas of the
struct's layout. (The struct is only created by the runtime, and the new
field only used by the runtime, so it should be safe.)

(cherry picked from commit 706fd4ec08)
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-03-18 16:47:36 +01:00
Sam Gross b3c2ef5f31 [3.14] gh-134043: use stackrefs for dict lookup in _PyObject_GetMethodStackRef (GH-136412) (#146077)
(cherry picked from commit cbe6ebe15b)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-17 16:59:26 -04:00
Miss Islington (bot) cedff2d617 [3.14] gh-145685: Improve scaling of type attribute lookups (gh-145774) (#145874)
Avoid locking in the PyType_Lookup cache-miss path if the type's
tp_version_tag is already valid.

(cherry picked from commit cd52172831)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-03-12 14:33:05 -04:00
Sam Gross 6d28aaf24d [3.14] gh-145685: Avoid contention on TYPE_LOCK in super() lookups (gh-145775) (#145804)
(cherry picked from commit bdf6de8c3f)
2026-03-11 11:50:13 +00:00
Miss Islington (bot) e12cc26616 [3.14] gh-145010: Fix Python.h compilation with -masm=intel (GH-145011) (#145776)
(cherry picked from commit 9c1c71066e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-03-10 18:07:17 +00:00
Miss Islington (bot) 7b3e6bde26 [3.14] gh-144981: Make PyUnstable_Code_SetExtra/GetExtra thread-safe (GH-144980) (#145052)
Co-authored-by: Alper <alperyoney@fb.com>
2026-03-05 08:26:09 -05:00
Miss Islington (bot) a58ea8c212 [3.14] gh-145037: Fix Emscripten trampoline with emcc >= 4.0.19 (GH-145038) (#145283)
This undoes a change made as a part of PR 137470, for compatibility with EMSDK
4.0.19. It adds `emscripten_trampoline` field in `pycore_runtime_structs.h`
and initializes it from JS initialization code with the wasm-gc based trampoline
if possible. Otherwise we fall back to the JS trampoline.
(cherry picked from commit 43fdb7037e)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2026-02-27 08:55:59 +08:00
Miss Islington (bot) 60d4281352 [3.14] gh-144490: Fix C++ compatibility in pycore_cell.h (GH-144482) (GH-144555)
gh-144490: Fix C++ compatibility in pycore_cell.h (GH-144482)
(cherry picked from commit a2495ff1e7)

Co-authored-by: Alper <alperyoney@fb.com>
2026-02-07 03:37:41 +00:00
Hugo van Kemenade 360214e257 Post 3.14.3 2026-02-03 20:27:58 +02:00
Hugo van Kemenade 323c59a5e3 Python 3.14.3 2026-02-03 17:32:20 +02:00
AN Long f7567b44a1 [3.14] gh-144012: Check null binary op extend (GH-144014) (GH-144038)
(cherry picked from commit 54bedcf714)
2026-01-20 18:05:56 +00:00
Pablo Galindo Salgado 892757f056 [3.14] gh-143228: Fix UAF in perf trampoline during finalization (GH-143233) (#143247) 2025-12-28 14:32:11 +00:00
Miss Islington (bot) 98f6db7e82 [3.14] gh-143057: avoid locking in tracemalloc C-APIs when it is not enabled (GH-143065) (#143071)
gh-143057: avoid locking in `tracemalloc` C-APIs when it is not enabled (GH-143065)
(cherry picked from commit e728b006de)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-12-22 16:04:24 +00:00
Miss Islington (bot) ebeb07f132 [3.14] gh-141370: Fix undefined behavior when using Py_ABS() (GH-141548) (GH-142301)
(cherry picked from commit 706fdda8b3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-12-12 15:11:43 +00:00
Miss Islington (bot) b868f1414c [3.14] gh-142534: Avoid TSan warnings in dictobject.c (gh-142544) (gh-142603)
There are places we use "relaxed" loads where C11 requires "consume" or
stronger. Unfortunately, compilers don't really implement "consume" so
fake it for our use in a way that avoids upsetting TSan.
(cherry picked from commit 0a62f8277e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-12-11 21:51:02 +00:00
Petr Viktorin e09c4deb25 [3.14] gh-123241: Don't modify ref count during visitation (GH-142232) (#142567)
(cherry picked from commit da8199f884)

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2025-12-11 10:51:11 -08:00
Miss Islington (bot) 04ecff52c3 [3.14] gh-140222: Increase stack margin on debug build (GH-142452) (#142471)
gh-140222: Increase stack margin on debug build (GH-142452)

Increase _PyOS_MIN_STACK_SIZE if Python is built in debug mode.
(cherry picked from commit 49207a5226)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-12-09 15:59:42 +00:00
Miss Islington (bot) 43f696d942 [3.14] gh-142342: Fix m68k assembler operand constraints for %fpcr access (gh-142343) (#142458)
On m68k, an fmove instruction accessing %fpcr may only move from
or to a data register or a memory operand. The constraint "g" also
permits the use of address registers, which is invalid. The correct
constraint is "dm". Beginning with GCC 15, the register allocator
picks an address register in the code which causes SIGILL during
runtime.
(cherry picked from commit 02c085d48b)

Co-authored-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Co-authored-by: Michael Karcher <github@mkarcher.dialup.fu-berlin.de>
2025-12-09 14:13:31 +00:00
Sam Gross 378b24b54e [3.14] gh-133932: Tagged ints are heap-safe (free threading) (gh-142431)
The previous fix (gh-134494) didn't fix the free threading build.
2025-12-08 18:16:28 -05:00
Hugo van Kemenade 160ca1c8c3 Post 3.14.2 2025-12-05 21:59:38 +02:00
Hugo van Kemenade df793163d5 Python 3.14.2 2025-12-05 18:49:16 +02:00
Hugo van Kemenade 206f1966ec Post 3.14.1 2025-12-02 18:16:07 +02:00
Hugo van Kemenade 57e0d177c2 Python 3.14.1 2025-12-02 14:51:37 +02:00
Miss Islington (bot) 52731c4e62 [3.14] gh-140373: Correctly emit PY_UNWIND event when generator is closed (GH-140767) (#140816)
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
2025-11-30 14:35:14 +02:00
Miss Islington (bot) a1dd248022 [3.14] gh-116008: Detect freed thread state in faulthandler (GH-141988) (#142013)
gh-116008: Detect freed thread state in faulthandler (GH-141988)

Add _PyMem_IsULongFreed() function.
(cherry picked from commit d5d9e89dde)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-11-27 20:34:00 +00:00
Victor Stinner ad60d8963e [3.14] gh-125434: Display thread name in faulthandler on Windows (#142011)
* gh-125434: Display thread name in faulthandler on Windows (#140675)

(cherry picked from commit 313145eab5)

* gh-125434: Fix non-ASCII thread names in faulthandler on Windows (#140700)

Add _Py_DumpWideString() function to dump a wide string as ASCII. It
supports surrogate pairs.

Replace _Py_EncodeLocaleRaw() with _Py_DumpWideString()
in write_thread_name().

(cherry picked from commit 80f20f58b2)
2025-11-27 12:05:37 +00:00
Miss Islington (bot) f47e928574 [3.14] gh-116738: Fix thread-safety issue in re module for free threading (gh-141923) (gh-141990)
Added atomic operations to `scanner_begin()` and `scanner_end()` to prevent
race conditions on the `executing` flag in free-threaded builds. Also added
tests for concurrent usage of the `re` module.

Without the atomic operations, `test_scanner_concurrent_access()` triggers
`assert(self->executing)` failures, or a thread sanitizer run emits errors.
(cherry picked from commit bc9e63dd9d)

Co-authored-by: Alper <alperyoney@fb.com>
2025-11-26 21:08:39 +00:00
Petr Viktorin 69021e9acf [3.14] GH-139653: Only raise an exception (or fatal error) when the stack pointer is about to overflow the stack. (GH-141711) (GH-141944)
Only raises if the stack pointer is both below the limit *and* above the stack base.
This prevents false positives for user-space threads, as the stack pointer will be outside those bounds
if the stack has been swapped.

Cherry-picked from commit c25a070759

Co-authored-by: Mark Shannon <mark@hotpy.org>
2025-11-26 12:54:56 +01:00
Petr Viktorin 32a38a2523 [3.14] gh-139653: Add PyUnstable_ThreadState_SetStackProtection() (GH-139668) (#141661)
Co-authored-by: Rok Mandeljc <rok.mandeljc@gmail.com>
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-11-25 14:21:53 +01:00
Miss Islington (bot) cabaa47668 [3.14] gh-116749: Fix code comment for _PyConfig_GIL_DEFAULT (gh-141804) (gh-141911)
(cherry picked from commit c490ffb7ac)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-11-24 16:10:59 +00:00
Stefano Rivera 394db662a5 [3.14] GH-139914: Handle stack growth direction on HPPA (GH-140028) (#141404)
* [3.14] GH-139914: Handle stack growth direction on HPPA (GH-140028)

Adapted from a patch for Python 3.14 submitted to the Debian BTS by John David Anglin https://bugs.debian.org/1105111#20

* Forgot to update test_call

* WTF typo
2025-11-23 15:55:33 -08:00