Commit graph

9152 commits

Author SHA1 Message Date
Miss Islington (bot)
140af0fd14
[3.13] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) (#151136)
gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (GH-151127)
(cherry picked from commit 3186547c1e)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-09 10:27:34 +00:00
Miss Islington (bot)
4834b45ee7
[3.13] gh-150633: Properly handle null characters in the name when importing frozen modules (GH-150634) (GH-151102)
(cherry picked from commit 54de5475cd)

Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
2026-06-08 18:55:43 +00:00
Alex Waygood
7c5734c791
[3.13] gh-150319: Replace all documentation which says "See PEP 585" (#150325) (#150814)
gh-150319: Replace all documentation which says "See PEP 585" (#150325)

* Replace all documentation which says "See PEP 585"

The following classes in the stdlib get simple updates:

- array.array
- asyncio.Future
- asyncio.Task
- collections.defaultdict
- collections.deque
- contextvars.ContextVar
- contextvars.Token
- ctypes.Array
- os.DirEntry
- re.Match
- re.Pattern
- string.templatelib.Interpolation
- string.templatelib.Template
- types.MappingProxyType
- queue.SimpleQueue
- weakref.ref

The following classes are documented publicly as functions, and are
therefore updated internally (`__class_getitem__.__doc__`) but not in the
public docs:

- functools.partial
- itertools.chain

The following builtin types have updates to `__class_getitem__.__doc__`
but not to any documentation pages:

- BaseExceptionGroup
- coroutines (from generators)
- dict
- enumerate
- frozendict
- frozenset
- generators (and async generators)
- list
- memoryview
- set
- slice
- tuple

Special cases:

- union objects are now documented as "supporting class-level []",
  rather than anything to do with generics.

- Templates might be generic over a single type (union, in theory) or
  over a TypeVarTuple. As this is not currently fully settled, it is
  marked with a comment and a mild hint that it is a single type is used
  (namely, "type" is singular rather than "types", plural)

* Apply suggestions from code review



* Correct several class getitem docs

And expand the text for tuples.



* Add notes on generic typing of builtins

* Fix typo in tuple.__class_getitem__ docstring

* Typo fix: malformed refs

Fix `generic` links which weren't marked as `:ref:`.

* Strike unnecessary docs on generic-ness



* Apply suggestions from code review

These are applied at both the originally indicated locations and in the
corresponding docstring definitions.



* Update Doc/library/re.rst



* Update Objects/enumobject.c



* Remove tuple generic doc in 'stdtypes' page

This is covered in more detail in the cross-linked typing documentation.
The other copy of this documentation -- in the docstring for
`tuple.__class_getitem__` -- is left in place.

* Fix whitespace around new doc of generics

Per review, do not introduce or remove whitespace such that section
breaks are altered by the introduction of doc on various generic types.

In most cases, this is a removal of an extra line.

In one case (Arrays), it is the reintroduction of a line.

Additionally, two other minor fixes are included:
- incorrect indent on 'defaultdicts'
- make `mappingproxy.__class_getitem__.__doc__` consistent with other
  mapping type generic docs



* Move placement of memoryview generic note

Previous placement was at the end of the main docstring, which is
consistent with other types but places it after a section on various
methods (which makes it read somewhat inconsistently). Moving it up
helps resolve.



* Ensure sphinxdoc does not start sentences lowercase

Lowercase class names at the start of sentences are marked out with the
`class` role. In the case of `deque`, documentation already refers to
these as `Deques`, so this form is preferred.

* Apply suggestions from code review



* Fix line endings and wrap more tightly

Line endings fixed by pre-commit ; also re-wrapped the MappingProxyType
text which was too long.

* Use 'ContextVars' style in sphinx doc

---------

Co-authored-by: Stephen Rosen <sirosen@globus.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 22:26:33 +00:00
Miss Islington (bot)
3eab77f28f
[3.13] gh-150644: Tag Apple system log messages as public. (GH-150645) (#150740)
macOS 26 changed the default visibility of "dynamic" system messages. This
changes the logging strategy to tag all messages as "public" so they are
visible in the system log without special configuration.
(cherry picked from commit 71fc4c66d3)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2026-06-01 22:48:28 +00:00
Miss Islington (bot)
ddd50ab27a
[3.13] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864) (GH-150189) (#150194)
[3.14] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864) (GH-150189)

gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864)

Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S.

The BTI flag must be applied in assembler sources for this class
of attacks to be mitigated on newer aarch64 processors.

See also:
https://sourceware.org/annobin/annobin.html/Test-branch-protection.html
and
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64

The 3.14 backport makes Python/jit_unwind.c changes in
Python/perf_jit_trampoline.c.

(cherry picked from commit da8477b25c)
(cherry picked from commit c863e96455)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: stratakis <cstratak@redhat.com>
2026-05-28 19:10:24 +02:00
Serhiy Storchaka
68840510e3
[3.13] gh-150285: Fix too long docstrings in Argument Clinic code (GH-150338) (GH-150350) (GH-150473) (GH-150526)
(cherry picked from commit 49975a511f)
(cherry picked from commit cf73b17adf)
(cherry picked from commit 287c98f4cb)
2026-05-27 18:06:50 +00:00
Serhiy Storchaka
43b6b483b2
[3.13] gh-150285: Fix too long docstrings in builtins (GH-150293) (GH-150466) (GH-150472)
(cherry picked from commit 730fc6a858)
(cherry picked from commit e1e06be119)
2026-05-26 10:34:50 +00:00
Miss Islington (bot)
ab4df90364
[3.13] gh-149156: Fix perf trampoline crash after fork (GH-150347) (#150393) 2026-05-25 19:19:07 +01:00
Miss Islington (bot)
95c93239be
[3.13] gh-150178: Fix refcount leaks in hamt allocation failure paths (GH-150179) (#150301)
gh-150178: Fix refcount leaks in hamt allocation failure paths (GH-150179)
(cherry picked from commit 32823af153)

Co-authored-by: pengyu lee <lipengyu@kylinos.cn>
2026-05-23 14:54:11 +05:30
Stan Ulbrych
ea8c3e028b
[3.13] gh-145376: Fix various reference leaks (GH-145377) (#148661)
(cherry picked from commit bd13cc09fa)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-05-12 18:35:27 +00:00
Miss Islington (bot)
6d6471b7eb
[3.13] gh-148418: Fix a possible reference leak in a corrupted TYPE_CODE marshal stream (GH-148419) (GH-149364)
(cherry picked from commit c3972f2795)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-05-04 14:06:00 +00:00
Irit Katriel
8da3d39c51
[3.13] gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974) (#148997) 2026-04-25 22:59:40 +01:00
Sam Gross
1b2301c009
[3.13] gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup (gh-148852) (#148885)
_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:56:24 +00:00
Serhiy Storchaka
ac1c1e7ef0
[3.13] gh-148653: Fix some marshal errors related to recursive code objects (GH-148698) (GH-148711) (GH-148713)
(cherry picked from commit d496c637a3)

Forbid marshalling recursive code objects which
cannot be correctly unmarshalled.
Add multiple tests for recursive data structures.
(cherry picked from commit 2e37d83641)
2026-04-18 09:29:38 +00:00
Hugo van Kemenade
8a0993f500
[3.13] GH-146128: Remove the buggy AArch64 "33rx" relocation (#146263) (#148199)
GH-146128: Remove the buggy AArch64 "33rx" relocation (#146263)

(cherry picked from commit 6bb7b33e8f)

Co-authored-by: Brandt Bucher <brandt@python.org>
Co-authored-by: Ken Jin <kenjin@python.org>
2026-04-07 20:10:33 +02:00
sunmy2019
c0eae2a1c3
[3.13] gh-146615: Fix format specifiers in Objects/ directory (GH-146620) (#147705)
* Fix format specifiers in vgetargskeywordsfast_impl for improved error messages.
* Fix f-string syntax error message in tok_get_normal_mode.
2026-04-01 21:52:14 +00:00
Serhiy Storchaka
e726d28a23
[3.13] gh-146615: Fix format specifiers in Python/ directory (GH-146619) (GH-146654)
(cherry picked from commit dcb260eff2)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 09:16:44 +00:00
Miss Islington (bot)
fc4b4221e5
[3.13] gh-146244: Fix initconfig.c SET_ITEM macro leaks dict on expression failure (GH-146246) (GH-146433)
(cherry picked from commit 9343518c6f)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-03-25 19:32:20 +00:00
T. Wouters
684e7af8cd
[3.13] gh-142183: Cache one datachunk per tstate to prevent alloc/dealloc thrashing (GH-145789) (#146123)
* 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)
(cherry picked from commit 19cbcc0f85)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
2026-03-24 02:27:57 +01:00
Sergey Miryanov
eda53e6cf1
[3.13] GH-91636: Clear weakrefs created by finalizers. (GH-136401) (GH-144214)
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>
2026-03-24 00:50:41 +01:00
Miss Islington (bot)
53b544a6a7
[3.13] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124) (GH-146132) (#146138)
[3.14] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124) (GH-146132)

gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124)

* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.
(cherry picked from commit 8eeb800faf)


(cherry picked from commit e1e4852133)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-18 21:23:26 +01:00
Gregory P. Smith
102cd61763
[3.13] gh-145990: sort --help-env first section by name (others and xoptions already sorted) (GH-146003)
* sort `--help-env` sections by environment variable name
  Only needed in the first section, in 3.13 the second section was already sorted.
* regression test for --help-env & --help-xoptions sort order

Manual backport of GH-145997
2026-03-15 22:35:53 +00:00
Miss Islington (bot)
321daaba4e
[3.13] gh-145701: Fix __classdict__ & __conditional_annotations__ in class-scope inlined comprehensions (GH-145702) (#145711)
* gh-145701: Fix `__classdict__` & `__conditional_annotations__` in class-scope inlined comprehensions (GH-145702)
(cherry picked from commit 63eaaf9599)

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

* Add `:oss-fuzz:` macro support

Backports part of 255e79fa95.

---------

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-03-09 14:44:31 -07:00
Ken Jin
85f8e76705
[3.13] gh-145008: Maintain stack consistency in CALL_BOUND_METHOD_EXACT_ARGS (GH-145015) 2026-03-03 04:09:02 +08:00
Miss Islington (bot)
22af3d5104
[3.13] gh-145092: Fix compiler warning for memchr() and wcschr() returning const pointer (GH-145093) (GH-145101)
(cherry picked from commit faea32b729)

Co-authored-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-02-22 08:28:24 +00:00
Peter Bierma
9314ec23a6
[3.13] gh-144601: Avoid sharing exception objects raised in a PyInit function across multiple interpreters (GH-144602) (GH-144880)
(cherry picked from commit fd6b639a49)
2026-02-16 16:05:55 +00:00
Pablo Galindo Salgado
0151abcd9f
[3.13] gh-144766: Fix a crash in fork child process when perf support is enabled. (GH-144795) (#144818)
(cherry picked from commit 5922149a50)

Co-authored-by: Yilei <hi@mangoumbrella.com>
2026-02-14 17:52:42 +00:00
Gregory P. Smith
c117ef1a1c
[3.13] gh-143650: Fix importlib race condition on import failure (GH-143651) (#144697)
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.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

cherry picked from ac8b5b6890
2026-02-11 06:37:25 +00:00
Peter Bierma
78a37d521e
[3.13] gh-144307: Fix a reference leak during module teardown (GH-144308) (GH-144328)
(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:18:39 +00:00
Victor Stinner
e752ea9eb9
[3.13] gh-144194: Fix mmap failure check in perf_jit_trampoline.c (#143713) (#144304)
gh-144194: Fix mmap failure check in perf_jit_trampoline.c (#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 14:15:39 +00:00
Jelle Zijlstra
bc92e7878f
[3.13] gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178) (#144260)
(cherry picked from commit 639c1ad4f1)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-01-27 20:37:35 -08:00
Miss Islington (bot)
e4e36a716a
[3.13] gh-142779: Initialize reserved field for proper padding (GH-142780) (#144160)
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-22 17:29:57 +00:00
Serhiy Storchaka
149ecbb9a9
[3.13] gh-142829: Fix use-after-free in Context.__eq__ via re-entrant ContextVar.set (GH-142905) (GH-143871)
(cherry picked from commit a4086d7f89)

Co-authored-by: A.Ibrahim <abdulrasheedibrahim47@gmail.com>
2026-01-15 15:00:44 +00:00
Miss Islington (bot)
8c6d87693b
[3.13] gh-106287: Do not write objects after an unmarshalling error (GH-132715) (GH-143833)
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:48:52 +00:00
Shamil
ab8224697a
[3.13] gh-140306: Clear uncaught exception info after applying error in subinterpreter (GH-140397) 2026-01-12 18:19:57 +02:00
Bénédikt Tran
733a5cf51c
[3.13] gh-143377: fix crashes in _interpreters.capture_exception (GH-143418) (#143653)
(cherry picked from commit ce6bae92da)
2026-01-10 13:59:14 +00:00
Miss Islington (bot)
57c56b0fb1
[3.13] gh-143547: Fix PyErr_FormatUnraisable() fallback (GH-143557) (GH-143603) (#143612)
[3.14] gh-143547: Fix PyErr_FormatUnraisable() fallback (GH-143557) (GH-143603)

gh-143547: Fix PyErr_FormatUnraisable() fallback (GH-143557)

Hold a strong reference to 'hook' while calling the default
unraisable took to log hook failure.
(cherry picked from commit 1d0baf1ae4)


(cherry picked from commit 39a2bcf949)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-01-09 15:33:25 +00:00
Pablo Galindo Salgado
de34f6d404
[3.13] gh-143228: Fix UAF in perf trampoline during finalization (GH-143233) (#143248) 2025-12-28 14:32:16 +00:00
Stan Ulbrych
e132893cc7
[3.13] gh-143135: Fix sys.flags.inspect when PYTHONINSPECT=0 (GH-143136) (GH-143168)
(cherry picked from commit 3509fa5a12)
2025-12-25 12:57:20 +02:00
Mikhail Efimov
4504ff89d5
[3.13] gh-140373: Correctly emit PY_UNWIND event when generator is closed (GH-140767) (#140821) 2025-12-20 16:21:11 +02:00
stratakis
4b8c9f5a7b
[3.13] gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777) (#142989)
gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777)

(cherry picked from commit 6a4f10325d)
2025-12-20 12:48:42 +05:30
Savannah Ostrowski
8f7c4f1cef
[3.13] GH-100964: Fix reference cycle in exhausted generator frames (G… (#142904)
* [3.13] GH-100964: Fix reference cycle in exhausted generator frames (GH-141112)
(cherry picked from commit 92243dc62c)

Co-authored-by: Savannah Ostrowski <savannah@python.org>
2025-12-17 20:04:53 +00:00
Miss Islington (bot)
5e1a9c8392
[3.13] gh-142873: Do not check for PyContextVar_CheckExact twice in PyContextVar_Set (GH-142874) (#142894)
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>
2025-12-17 17:04:39 +00:00
Bartosz Sławecki
3e45440382
[3.13] gh-142737: Handle lost io.open in _Py_FindSourceFile (GH-142747) (GH-142774)
(cherry picked from commit f277781bba)
2025-12-15 23:27:15 +00:00
Stan Ulbrych
9b24418867
[3.13] gh-142571: Check for errors before calling each syscall in PyUnstable_CopyPerfMapFile() (GH-142460) (#142602)
Co-authored-by: AZero13 <gfunni234@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2025-12-11 22:08:08 +00:00
Kumar Aditya
fda856f368
[3.13] gh-142048: Fix lost gc allocations count on thread cleanup (GH… (#142506)
[3.13] 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>
2025-12-11 15:07:38 +05:30
Serhiy Storchaka
93d5c481af
[3.13] gh-141370: Fix undefined behavior when using Py_ABS() (GH-141548) (#142304)
(cherry picked from commit 706fdda8b3)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-12-05 15:52:12 +00:00
Sam Gross
01393ffbe6
[3.13] gh-142048: Fix quadratically increasing GC delays (gh-142051) (#142167)
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>
2025-12-02 00:31:36 +00:00
Itamar Oren
385688d4b4
[3.13] gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605) (#141987)
gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605)

(cherry picked from commit 27f62eb711)
2025-11-28 23:31:11 -08:00
Victor Stinner
80b752285d
[3.13] gh-116008: Detect freed thread state in faulthandler (#141988) (#142017)
gh-116008: Detect freed thread state in faulthandler (#141988)

Add _PyMem_IsULongFreed() function.

(cherry picked from commit d5d9e89dde)
2025-11-27 17:55:31 +01:00