Commit Graph

9893 Commits

Author SHA1 Message Date
Gregory P. Smith bb8d6a0863 [3.14] Improve hash() builtin docstring with caveats. (GH-125229) (#149054)
Improve  `hash()` builtin docstring with caveats.

Mention its return type and that the value can be expected to change between
processes (hash randomization).

Why? The `hash` builtin gets reached for and used by a lot of people whether it
is the right tool or not. IDEs surface docstrings and people use pydoc and
`help(hash)`.
(cherry picked from commit 665b7dfcfa)
2026-04-27 16:17:30 +00: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
Miss Islington (bot) 78c5e54b4f [3.14] gh-146455: Fix O(N²) in add_const() after constant folding moved to CFG (GH-146456) (#149011)
gh-146455: Fix O(N²) in add_const() after constant folding moved to CFG (GH-146456)

The add_const() function in flowgraph.c uses a linear search over the
consts list to find the index of a constant. After gh-126835 moved
constant folding from the AST optimizer to the CFG optimizer, this
function is now called N times for N inner tuple elements during
fold_tuple_of_constants(), resulting in O(N²) total time.

Fix by maintaining an auxiliary _Py_hashtable_t that maps object
pointers to their indices in the consts list, providing O(1) lookup.

For a file with 100,000 constant 2-tuples:
- Before: 10.38s (add_const occupies 83.76% of CPU time)
- After:  1.48s
(cherry picked from commit 5d416324c5)

Co-authored-by: zSirius <107359899+zSirius@users.noreply.github.com>
2026-04-26 18:45:38 +03:00
Miss Islington (bot) 8acb98a1c2 [3.14] gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974) (#148980)
gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974)
(cherry picked from commit c650b51c32)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2026-04-25 13:53:42 +01:00
Sam Gross e5d5541683 [3.14] gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup (gh-148852) (#148884)
_PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then
calls _PySemaphore_Wakeup, with no handshake. If _PySemaphore_Wait
returns Py_PARK_INTR, the waiter can destroy its stack-allocated
semaphore before the unlocker's Wakeup runs, causing a fatal error from
ReleaseSemaphore / sem_post.

Loop in _PyRawMutex_LockSlow until _PySemaphore_Wait returns Py_PARK_OK,
which is only signalled when a matching Wakeup has been observed.

Also include GetLastError() and the handle in the Windows fatal messages
in _PySemaphore_Init, _PySemaphore_Wait, and _PySemaphore_Wakeup to make
similar races easier to diagnose in the future.

(cherry picked from commit ad3c5b7958)
2026-04-22 18:59:58 +00:00
Serhiy Storchaka d496c637a3 [3.14] gh-148653: Fix some marshal errors related to recursive immutable objects (GH-148698) (GH-148711)
Forbid marshalling recursive code and slice objects which
cannot be correctly unmarshalled.
Add multiple tests for recursive data structures.
(cherry picked from commit 2e37d83641)
2026-04-18 08:57:55 +00: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) 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 383c2919b1 [3.14] GH-146128: Remove the buggy AArch64 "33rx" relocation (GH-146263) (#148198)
Co-authored-by: Brandt Bucher <brandt@python.org>
2026-04-07 14:05:47 +03: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) 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
Miss Islington (bot) 9ac758e6a4 [3.14] gh-146615: Fix format specifiers in Python/ directory (GH-146619) (GH-146650)
(cherry picked from commit dcb260eff2)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 08:25:07 +00:00
Miss Islington (bot) d7e04e7b8d [3.14] gh-146480: Override the exception in _PyErr_SetKeyError() (GH-146486) (#146511)
gh-146480: Override the exception in _PyErr_SetKeyError() (GH-146486)

If _PyErr_SetKeyError() is called with an exception set, it now
replaces the current exception with KeyError (as expected), instead
of setting a SystemError or failing with a fatal error (in debug
mode).
(cherry picked from commit d4153a9f76)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-27 11:48:29 +00:00
Miss Islington (bot) 4d61fd6b7a [3.14] gh-146244: Fix initconfig.c SET_ITEM macro leaks dict on expression failure (GH-146246) (GH-146432)
(cherry picked from commit 9343518c6f)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-03-27 02:37:53 +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
Victor Stinner 7f29c1d0da [3.14] gh-146092: Fix error handling in _BINARY_OP_ADD_FLOAT opcode (#146119)
Fix error handling in _PyFloat_FromDouble_ConsumeInputs() used by
_BINARY_OP_ADD_FLOAT, _BINARY_OP_SUBTRACT_FLOAT and
_BINARY_OP_MULTIPLY_FLOAT opcodes. PyStackRef_FromPyObjectSteal()
must not be called with a NULL pointer.

Fix also _BINARY_OP_INPLACE_ADD_UNICODE opcode.
2026-03-19 12:14:33 +01:00
Victor Stinner 8eeb800faf [3.14] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124) (#146132)
gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124)

* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.

(cherry picked from commit e1e4852133)
2026-03-18 17:57:08 +00: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
Gregory P. Smith b8cb83703f [3.14] gh-145990: sort --help-env sections by environment variable name (GH-146001)
* sort --help-env alphabetically by name.
* add a sorting regression test in test_help_env.

manual backport of GH-145997
2026-03-15 22:55:08 +00:00
Gregory P. Smith 36805f6e44 [3.14] gh-145990: Sort python --help-xoptions by option name (GH-145993)
* Sort --help-xoptions alphabetically by name.
* add a sorting regression test in test_help_xoptions

manual backport of GH-145991
2026-03-15 15:17:07 -07:00
Miss Islington (bot) d9c26676b2 [3.14] gh-145792: Fix incorrect alloca allocation size in traceback.c (GH-145814) (#145909)
gh-145792: Fix incorrect alloca allocation size in traceback.c (GH-145814)
(cherry picked from commit 59d97683c1)

Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
2026-03-13 12:45:18 +00:00
Sergey Miryanov 705e3ea9d1 [3.14] GH-91636: Clear weakrefs created by finalizers. (GH-136401) (#144444)
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-03-12 14:10:29 +02:00
Stan Ulbrych 6d9221c7d1 [3.14] gh-145376: Fix various reference leaks (GH-145377) (GH-145712)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-03-10 16:31:02 +01:00
Miss Islington (bot) 0db2beee6b [3.14] gh-145701: Fix __classdict__ & __conditional_annotations__ in class-scope inlined comprehensions (GH-145702) (#145710)
(cherry picked from commit 63eaaf9599)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>

* Add `:oss-fuzz:` supports

Backports part of https://github.com/python/cpython/commit/255e79fa955ac5ffef9eb27087e8b1373e98e3bd.

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-03-09 20:26:52 +00:00
Sam Gross 7b9508f4b0 [3.14] gh-144513: Skip critical section locking during stop-the-world (gh-144524) (#145570) 2026-03-06 12:00:17 -05: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
Pablo Galindo Salgado ded533b1fa [3.14] gh-144316: Fix missing exception in _remote_debugging with debug=False (GH-144442) (#145280) 2026-02-26 22:39:48 +00:00
Miss Islington (bot) 12092af02e [3.14] gh-145187: Fix crash on invalid type parameter bound expression in conditional block (GH-145188) (#145196)
gh-145187: Fix crash on invalid type parameter bound expression in conditional block (GH-145188)

Fix parsing crash found by oss-fuzz
(cherry picked from commit 5e61a16c10)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-02-24 21:13:08 +00:00
Miss Islington (bot) 06b6243084 [3.14] gh-145092: Fix compiler warning for memchr() and wcschr() returning const pointer (GH-145093) (GH-145102)
(cherry picked from commit faea32b729)

Co-authored-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-02-22 08:28:17 +00:00
Victor Stinner f67cf83a4e [3.14] gh-144763: Fix race conditions in tracemalloc (#144779) (#144965)
gh-144763: Fix race conditions in tracemalloc (#144779)

Avoid PyUnstable_InterpreterFrame_GetLine() since it uses a critical
section which can lead to a deadlock.

_PyTraceMalloc_Stop() now also calls PyRefTracer_SetTracer() without
holding TABLES_LOCK() to prevent another deadlock.

(cherry picked from commit 83f4fffe3d)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-02-18 20:55:38 +01:00
Miss Islington (bot) 907958c4ba [3.14] gh-144601: Avoid sharing exception objects raised in a PyInit function across multiple interpreters (GH-144602) (GH-144633)
gh-144601: Avoid sharing exception objects raised in a `PyInit` function across multiple interpreters (GH-144602)
(cherry picked from commit fd6b639a49)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-02-16 10:37:46 -05:00
Miss Islington (bot) 77b71ac793 [3.14] gh-144766: Fix a crash in fork child process when perf support is enabled. (GH-144795) (#144816) 2026-02-14 12:09:00 +00:00
Miss Islington (bot) 7d074702eb [3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) (#144662)
gh-143650: Fix importlib race condition on import failure (GH-143651)

Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:

1. Thread 1 starts importing, adds module to sys.modules
2. Thread 2 sees the module in sys.modules via the fast path
3. Thread 1's import fails, removes module from sys.modules
4. Thread 2 returns a stale module reference not in sys.modules

The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.
(cherry picked from commit ac8b5b6890)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 06:06:51 +00:00
Bartosz Sławecki 616e611844 [3.14] gh-144563: Fix remote debugging with duplicate libpython mappings from ctypes (GH-144595) (#144655) 2026-02-10 14:31:49 +00:00
Miss Islington (bot) 6006005893 [3.14] gh-144446: Fix some frame object thread-safety issues (gh-144479) (#144546)
Fix thread-safety issues when accessing frame attributes while another
thread is executing the frame:

- Add critical section to frame_repr() to prevent races when accessing
  the frame's code object and line number

- Add _Py_NO_SANITIZE_THREAD to PyUnstable_InterpreterFrame_GetLasti()
  to allow intentional racy reads of instr_ptr.

- Fix take_ownership() to not write to the original frame's f_executable
(cherry picked from commit 5bb3bbb9c6)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-02-06 15:25:36 +00:00
Miss Islington (bot) 49ce23f2d7 [3.14] gh-144307: Fix a reference leak during module teardown (GH-144308) (GH-144327)
gh-144307: Fix a reference leak during module teardown (GH-144308)
(cherry picked from commit 219b7ac9d5)

Signed-off-by: Yongtao Huang <yongtaoh2022@gamil.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-01-29 19:19:14 +00:00
Miss Islington (bot) 157e946d78 [3.14] gh-144194: Fix mmap failure check in perf_jit_trampoline.c (GH-143713) (#144301)
gh-144194: Fix mmap failure check in perf_jit_trampoline.c (GH-143713)

mmap() returns MAP_FAILED ((void*)-1) on error, not NULL. The current
check never detects mmap failures, so jitdump initialization proceeds
even when the memory mapping fails.
(cherry picked from commit 8fe8a94a7c)

Co-authored-by: stratakis <cstratak@redhat.com>
2026-01-28 13:57:19 +00:00
Miss Islington (bot) 7ae9a479cf [3.14] gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178) (#144227)
gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178)
(cherry picked from commit 639c1ad4f1)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-01-26 12:14:39 +00:00
Miss Islington (bot) 4f4c20412b [3.14] gh-142779: Initialize reserved field for proper padding (GH-142780) (#144159)
gh-142779: Initialize reserved field for proper padding (GH-142780)

The jitdump specification specifies a reserved field for padding.

Initialize it so no garbage data is embedded in the jitdump files.
(cherry picked from commit 77bf4ba732)

Co-authored-by: stratakis <cstratak@redhat.com>
2026-01-25 17:44:33 +00: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
Miss Islington (bot) ae5760527a [3.14] gh-106287: Do not write objects after an unmarshalling error (GH-132715) (GH-143832)
Writing out an object may involve a slot lookup, which is not safe to do with
an exception raised. In debug mode an assertion failure will occur if this
happens.
(cherry picked from commit ce8f5f98c6)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
2026-01-14 11:52:20 +00:00
Miss Islington (bot) ea70d16406 [3.14] gh-143377: fix crashes in _interpreters.capture_exception (GH-143418) (#143652)
gh-143377: fix crashes in `_interpreters.capture_exception` (GH-143418)
(cherry picked from commit ce6bae92da)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-01-10 12:05:42 +00:00
Miss Islington (bot) 16efe85129 [3.14] gh-142829: Fix use-after-free in Context.__eq__ via re-entrant ContextVar.set (GH-142905) (#143627)
gh-142829: Fix use-after-free in `Context.__eq__` via re-entrant `ContextVar.set` (GH-142905)
(cherry picked from commit a4086d7f89)

Co-authored-by: A.Ibrahim <abdulrasheedibrahim47@gmail.com>
2026-01-10 12:21:37 +05:30
Miss Islington (bot) fca010da50 [3.14] Fix dunder name typo in compiler code comment (GH-143374) (#143386)
Fix dunder name typo in compiler code comment (GH-143374)
(cherry picked from commit 6d05e55de0)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-01-10 12:21:09 +05:30
Victor Stinner 1d0baf1ae4 [3.14] gh-143547: Fix PyErr_FormatUnraisable() fallback (#143557) (#143603)
gh-143547: Fix PyErr_FormatUnraisable() fallback (#143557)

Hold a strong reference to 'hook' while calling the default
unraisable took to log hook failure.

(cherry picked from commit 39a2bcf949)
2026-01-09 16:10:50 +01:00
Miss Islington (bot) 6583951e7d [3.14] gh-131421: Fix ASDL kw_defaults being expr* instead of expr?* (GH-133773) (GH-143269)
Also fix docs ASDL highlighting.
(cherry picked from commit f37f57dfe6)

Co-authored-by: Samuel <samuel@knutsen.co>
2025-12-29 12:09:11 +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) 8a61b71eee [3.14] gh-142975: During GC, mark frozen objects with a merged zero refcount for destruction (GH-143156) (GH-143175)
gh-142975: During GC, mark frozen objects with a merged zero refcount for destruction (GH-143156)
(cherry picked from commit 8611f74e08)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-12-25 12:00:42 -05:00