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>
(cherry picked from commit 63eaaf9599)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
* Add `:oss-fuzz:` supports
Backports part of 255e79fa95.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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)
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>
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>
gh-142873: Do not check for `PyContextVar_CheckExact` twice in `PyContextVar_Set` (GH-142874)
(cherry picked from commit e61a447d0e)
Co-authored-by: sobolevn <mail@sobolevn.me>
If there are many untracked tuples, the GC will run too often, resulting
in poor performance. The fix is to include untracked tuples in the
"long lived" object count. The number of frozen objects is also now
included since the free-threaded GC must scan those too.
(cherry picked from commit e38967ed60)
gh-142627: Ignore anonymous mappings in Linux remote debugging (GH-142628)
(cherry picked from commit e0bca091a4)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-137007: Track executor before any possible deallocations (GH-137016)
(cherry picked from commit 97e19014dd)
Co-authored-by: Ken Jin <kenjin@python.org>
gh-142048: Fix lost gc allocations count on thread cleanup (GH-142233)
(cherry picked from commit 49b1fb43f6)
Co-authored-by: Kevin Wang <kevmo314@gmail.com>
The GC for the free threaded build would get slower with each collection due
to effectively double counting objects freed by the GC.
(cherry picked from commit eb892868b3)
Co-authored-by: Kevin Wang <kevmo314@gmail.com>
GH-91636: Clear weakrefs created by finalizers. (GH-136401)
Weakrefs to unreachable garbage that are created during running of
finalizers need to be cleared. This avoids exposing objects that
have `tp_clear` called on them to Python-level code.
(cherry picked from commit b6b99bf7f1)
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
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>