gh-142975: During GC, mark frozen objects with a merged zero refcount for destruction (GH-143156)
(cherry picked from commit 8611f74e089d9ac9de84dd42be9d251db27889aa)
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 e728b006de984ab11532f5c9cf60c57671ec37ab)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777)
(cherry picked from commit 6a4f10325d58deb1906b39d68dc8e84f4c2bf5a4)
gh-142873: Do not check for `PyContextVar_CheckExact` twice in `PyContextVar_Set` (GH-142874)
(cherry picked from commit e61a447d0e0753621e8fc347e99dfc87884d68ab)
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 e38967ed60778146050cc88dd16b70bfd867fde7)
gh-142627: Ignore anonymous mappings in Linux remote debugging (GH-142628)
(cherry picked from commit e0bca091a4f112b9f0beb4ce19dfac2a7fc50342)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-137007: Track executor before any possible deallocations (GH-137016)
(cherry picked from commit 97e19014ddc652beae58e7eceb591f5d65a875e6)
Co-authored-by: Ken Jin <kenjin@python.org>
gh-142048: Fix lost gc allocations count on thread cleanup (GH-142233)
(cherry picked from commit 49b1fb43f65290dadeb83ed6f7c0c74995fda7a1)
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 eb892868b31322d7cf271bc25923e14b1f67ae38)
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 b6b99bf7f1edab77c485faf4e23da868f3a7b68c)
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 d5d9e89dde9843a61b46872b1914c5b75ad05998)
Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-125434: Display thread name in faulthandler on Windows (#140675)
(cherry picked from commit 313145eab5f6ebca21d2e3c80c130980d3bcdc88)
* 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 80f20f58b2b8368ed8451a0161036dda94d8d33a)
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 c25a070759952b13f97ecc37ca2991c2669aee47
Co-authored-by: Mark Shannon <mark@hotpy.org>
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>
* [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
If we overflowed the global version counter (i.e., after 2*24 calls to
`_PyMonitoring_SetEvents`), we bailed out after setting global monitoring
events but before instrumenting code objects, which led to assertion errors
later on.
Also add a `time.sleep()` to `test_free_threading.test_monitoring` to avoid
overflowing the global version counter.
(cherry picked from commit e457d60daafe66534283e0f79c81517634408e57)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-140530: fix a reference leak in an error path for `raise exc from cause` (GH-140908)
Fix a reference leak in `raise E from T` when `T` is an exception
subtype for which `T.__new__` does not return an exception instance.
(cherry picked from commit 0c77e7c23b5c270a3142105542c56c59b59c52a0)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Fix compiler warnings in remote debugging (#141060)
Example of fixed warnings on 32-bit Windows:
Python\remote_debugging.c(24,53): warning C4244: 'function':
conversion from 'uint64_t' to 'uintptr_t', possible loss of data
Modules\_remote_debugging_module.c(789,44): warning C4244:
'function': conversion from 'uint64_t' to 'size_t', possible loss
of data
(cherry picked from commit f458ac01ba522cc7f94c0c0ee9a00c82f1be6d69)
gh-140513: Fail to compile if `_Py_TAIL_CALL_INTERP` is set but `preserve_none` and `musttail` do not exist. (GH-140548)
(cherry picked from commit 2f60b8f02fe7cb83dd589d9664460082c13e85ef)
Co-authored-by: Krishna Chaitanya <141550576+XChaitanyaX@users.noreply.github.com>
gh-140815: Fix faulthandler for invalid/freed frame (GH-140921)
faulthandler now detects if a frame or a code object is invalid or
freed.
Add helper functions:
* _PyCode_SafeAddr2Line()
* _PyFrame_SafeGetCode()
* _PyFrame_SafeGetLasti()
_PyMem_IsPtrFreed() now detects pointers in [-0xff, 0xff] range
as freed.
(cherry picked from commit a84181c31bfc45a1d6bcb1296bd298ad612c54d0)
Co-authored-by: Victor Stinner <vstinner@python.org>
Revert "[3.14] gh-140104: Set next_instr properly in the JIT during exceptions (GH-140233) (GH-140687)"
This reverts commit 2e216728038a03d387231f39ded091ec318ba61b.
ast.parse() no longer emits syntax warnings for
return/break/continue in finally (see PEP-765) -- they are only
emitted during compilation.
(cherry picked from commit ad0a3f733b23e7fc69aff13055c7fac8ab9dcd66)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
* 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.
* [3.14] gh-140067: Fix memory leak in sub-interpreter creation (GH-140111)
Fix memory leak in sub-interpreter creation caused by overwriting of the previously used `_malloced` field. Now the pointer is stored in the first word of the memory block to avoid it being overwritten accidentally.
(cherry picked from commit 59547a251f7069dc6e08cb6082dd21872671e381)
Co-authored-by: Shamil <ashm.tech@proton.me>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
gh-140257: fix data race on eval_breaker during finalization (GH-140265)
(cherry picked from commit c8729c9909e150989050ce2a435d018955bea41d)
Co-authored-by: Shamil <ashm.tech@proton.me>
The previous `Py_REFCNT(x) == 1` checks can have data races in the free
threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative
check that is safe in the free threaded build and is identical to
`Py_REFCNT(x) == 1` in the default GIL-enabled build.
(cherry picked from commit 32c264982ec67460642b907dabc3304019318291)
Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Revert GH-131993.
Fix swallowing some syntax warnings in different modules if they accidentally
have the same message and are emitted from the same line.
Fix duplicated warnings in the "finally" block.
(cherry picked from commit 279db6bede30be3a1b86803585eb4404d27800da)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* Update 2025-10-06-10-03-37.gh-issue-139640.gY5oTb.rst
---------
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>