8875 Commits

Author SHA1 Message Date
Miss Islington (bot)
27256ca382
[3.14] gh-102809: No longer mention Misc/gdbinit in the code (GH-143980) (#144044)
gh-102809: No longer mention `Misc/gdbinit` in the code (GH-143980)

Fix misleading comment on `PyObject_Dump`.
(cherry picked from commit f84ea1107170988742fbd350123678a5c503c1ad)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-01-19 18:01:21 +00:00
Miss Islington (bot)
601ccb7f89
[3.14] gh-141805: Fix crash after concurrent addition objects with the same hash to set (GH-143815) (GH-143849)
This happens when the set contained several elements with the same hash,
and then some of them were removed.
(cherry picked from commit b8e925b4f8f6c5e28fbebc4f3965bf77610698b3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-01-15 09:31:16 +02:00
Miss Islington (bot)
38f0114ff1
[3.14] gh-143635: Fix crash in ga_repr_items_list (GH-143670) (#143851)
gh-143635: Fix crash in `ga_repr_items_list` (GH-143670)
(cherry picked from commit bdba5f0db2ab29f3deedb9416f3c143d33e4ab66)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-01-15 04:16:46 +00:00
Inada Naoki
5d26a0410e
[3.14] gh-143189: fix insertdict() for non-Unicode key (GH-143285) (#143771) 2026-01-13 11:58:53 +02:00
Miss Islington (bot)
70ddd3ea9a
[3.14] Remove outdated comment about excess_args warning in object.__init__ (GH-143669) (#143680)
Remove outdated comment about `excess_args` warning in `object.__init__` (GH-143669)

The code emitting a warning was removed in 96384b93aae1d1e45dda21c4024d7d083c91626d.
(cherry picked from commit 03e6457096d452859fb4cfd418dc9268c6454c29)

Co-authored-by: Manuel Jacob <me@manueljacob.de>
2026-01-11 07:52:34 +00:00
Miss Islington (bot)
ebe5e216c8
[3.14] gh-143006: Fix and optimize mixed comparison of float and int (GH-143084) (GH-143623)
When comparing negative non-integer float and int with the same number
of bits in the integer part, __neg__() in the int subclass returning
not an int caused an assertion error.

Now the integer is no longer negated. Also, reduced the number of
temporary created Python objects.
(cherry picked from commit 66bca383bd3b12d21e879d991d77b37a4c638f88)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-01-09 17:32:23 +00:00
Miss Islington (bot)
de53bf4168
[3.14] gh-143089: Fix ParamSpec default examples to use list instead of tuple (GH-143179) (#143538)
Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
2026-01-08 11:49:41 +00:00
Stan Ulbrych
9f91278412
[3.14] gh-143003: Fix possible shared buffer overflow in bytearray.extend() (GH-143086) (GH-143447)
When __length_hint__() returns 0 for non-empty iterator, the data can be
written past the shared 0-terminated buffer, corrupting it.
(cherry picked from commit 522563549a49d28e763635c58274a23a6055f041)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-01-06 13:48:45 +02:00
Miss Islington (bot)
fd9db61a25
[3.14] gh-142557: fix UAF in bytearray.__mod__ when object is mutated while formatting %-style arguments (GH-143213) (#143227)
gh-142557: fix UAF in `bytearray.__mod__` when object is mutated while formatting `%`-style arguments (GH-143213)
(cherry picked from commit 61ee04834b096be00678c6819b4957f3f4413a5e)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-27 15:23:08 +00:00
Miss Islington (bot)
bbe9ed95d4
[3.14] gh-142664: fix PyObject_Hash invokation post GH-143217 (GH-143223) (#143224)
gh-142664: fix `PyObject_Hash` invokation post GH-143217 (GH-143223)
(cherry picked from commit 84fcdbd86ecd81f7cc793e22268a029ac6cf29c2)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-27 14:55:45 +00:00
Miss Islington (bot)
93029e45b7
[3.14] gh-143195: fix UAF in {bytearray,memoryview}.hex(sep) via re-entrant sep.__len__ (GH-143209) (#143219)
gh-143195: fix UAF in `{bytearray,memoryview}.hex(sep)` via re-entrant `sep.__len__` (GH-143209)
(cherry picked from commit 9976c2b6349a079ae39931d960b8c147e21c6c3f)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-27 13:57:41 +00:00
Miss Islington (bot)
cb8b96ed25
[3.14] gh-142664: fix UAF in memoryview.__hash__ via re-entrant data's __hash__ (GH-143217) (#143221)
gh-142664: fix UAF in `memoryview.__hash__` via re-entrant data's `__hash__` (GH-143217)
(cherry picked from commit 00e24b80e092e7d36dc189fd260b2a4e730a6e7f)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-27 13:37:32 +00:00
Miss Islington (bot)
dbc7fd61d8
[3.14] gh-142560: prevent use-after-free in search-like methods by exporting buffer in bytearray (GH-142938) (#142983)
gh-142560: prevent use-after-free in search-like methods by exporting buffer in bytearray (GH-142938)
(cherry picked from commit 220f0b107776391201a399c54dd01692c36fcdf4)

Co-authored-by: wangxiaolei <fatelei@gmail.com>
2025-12-19 16:58:24 +00:00
Miss Islington (bot)
25a94708e5
[3.14] gh-142766: Clear frame when generator.close() is called (gh-142838) (#142899)
(cherry picked from commit 25397f9541be89264d35d41a67defcfeaa950844)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-12-17 18:33:15 +00:00
Miss Islington (bot)
b9cbdde80d
[3.14] gh-142737: Handle lost io.open in _Py_FindSourceFile (GH-142747) (GH-142773)
gh-142737: Handle lost `io.open` in `_Py_FindSourceFile` (GH-142747)
(cherry picked from commit f277781bba684322dffffe45cd878f4652ccf7e4)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2025-12-15 23:30:00 +00:00
Miss Islington (bot)
aef4552d04
[3.14] gh-142554: avoid divmod crashes due to bad _pylong.int_divmod (GH-142673) (#142696)
gh-142554: avoid `divmod` crashes due to bad `_pylong.int_divmod` (GH-142673)
(cherry picked from commit 4e4163676add8caab2dec6cdb93e1b317cf02a2e)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-14 09:04:37 +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 0a62f8277e9a0dd9f34b0b070adb83994e81b2a8)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-12-11 21:51:02 +00:00
Sam Gross
12d2b95adf
[3.14] gh-142589: Fix PyUnstable_Object_IsUniqueReferencedTemporary (gh-142593) (#142597)
PyUnstable_Object_IsUniqueReferencedTemporary wasn't handling tagged
ints on the evaluation stack properly.
(cherry picked from commit a26c831bc486b6e607cee6a5923bad52b97c2341)
2025-12-11 20:08:45 +00:00
Petr Viktorin
e09c4deb25
[3.14] gh-123241: Don't modify ref count during visitation (GH-142232) (#142567)
(cherry picked from commit da8199f8842c2830fa4015138725849863523de4)

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2025-12-11 10:51:11 -08:00
Miss Islington (bot)
36d4f67b3c
[3.14] gh-142433: Move deref to below the error when checking for laststring (GH-142402) (#142524)
gh-142433: Move deref to below the error when checking for laststring (GH-142402)

Move deref of laststring to below the error checking so the deref
is applied after the object in strings is replaced.
(cherry picked from commit 785268fdceb0d0fe217aed1d6e43e0231c0e50c3)

Co-authored-by: AZero13 <gfunni234@gmail.com>
2025-12-10 16:07:59 +00:00
Miss Islington (bot)
319c6a2ae1
[3.14] gh-142218: Fix split table dictionary crash (gh-142229) (gh-142244)
This fixes a regression introduced in gh-140558. The interpreter would
crash if we inserted a non `str` key into a split table that matches an
existing key.
(cherry picked from commit 547d8daf780646e2800bec598ed32085817c8606)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-12-04 00:03:18 +00: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)
072eeaf84c
[3.14] gh-132657: optimize PySet_Contains for frozenset (GH-141183) (gh-141773)
(cherry picked from commit 7211a34fe1d9704935342af8c9b46725629f2d97)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-11-19 17:01:49 -08:00
Miss Islington (bot)
c05e71f61e
[3.14] gh-132657: avoid locks and refcounting in frozenset lookups (GH-136107) (gh-141772)
gh-132657: avoid locks and refcounting in `frozenset` lookups (GH-136107)
(cherry picked from commit f58a7c717584241467970623384ce61cbd776f29)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2025-11-19 17:00:42 -08:00
Sam Gross
b7c25eabd6
[3.14] gh-139103: fix free-threading dataclass.__init__ perf issue (gh-141596) (gh-141750)
The dataclasses `__init__` function is generated dynamically by a call to `exec()` and so doesn't have deferred reference counting enabled. Enable deferred reference counting on functions when assigned as an attribute to type objects to avoid reference count contention when creating dataclass instances.
(cherry picked from commit ce791541769a41beabec0f515cd62e504d46ff1c)

Co-authored-by: Edward Xu <xuxiangad@gmail.com>
2025-11-19 15:00:51 +00:00
Miss Islington (bot)
79c136f87b
[3.14] GH-141312: Allow only integers to longrangeiter_setstate state (GH-141317) (GH-141559)
This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c1eb3ee27f490a067426eef452b15f78f9)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
2025-11-15 21:30:25 +02:00
Miss Islington (bot)
e9c11b7495
[3.14] gh-141042: fix sNaN's packing for mixed floating-point formats (GH-141107) (#141459)
gh-141042: fix sNaN's packing for mixed floating-point formats (GH-141107)
(cherry picked from commit 23d85a2a3fb029172ea15c6e596f64f8c2868ed3)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-11-12 10:33:34 +00:00
Stan Ulbrych
ebf54596bf
[3.14] gh-140939: Fix memory leak in _PyBytes_FormatEx error path (GH-140957) (#141154)
(cherry picked from commit d6c89a2df2c8b7603125883494e9058a88348f66)
2025-11-06 16:20:03 +00:00
Miss Islington (bot)
331b4b868c
[3.14] gh-140815: Fix faulthandler for invalid/freed frame (GH-140921) (#140981)
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>
2025-11-04 11:18:23 +00:00
Miss Islington (bot)
788104633c
[3.14] gh-140348: Fix using | on unusual objects plus Unions (GH-140383) (#140948)
gh-140348: Fix using | on unusual objects plus Unions (GH-140383)
(cherry picked from commit 7a9437d98641e3c3749ab2fd9fb54eac7614f9af)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-11-03 15:16:03 +00:00
Mikhail Efimov
5954b5ba92
[3.14] gh-140551: Fix dict crash if clear is called at lookup stage (GH-140558) (#140743)
gh-140551: Fix `dict` crash if `clear` is called at `lookup` stage (#140558)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2025-10-30 22:33:35 +05:30
Miss Islington (bot)
97c59f9d61
[3.14] Remove dead stores to 'size' in UTF-8 decoder (unicodeobject.c) (GH-140637) (#140658)
Remove dead stores to 'size' in UTF-8 decoder (unicodeobject.c) (GH-140637)
(cherry picked from commit 7d70a147f58edabc9691869a0e8b606c9c3ac184)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-27 09:21:43 +00:00
Miss Islington (bot)
3944e9b3b2
[3.14] gh-140431: Fix GC crash due to partially initialized coroutines (gh-140470) (gh-140504)
The `make_gen()` function creates and tracks generator/coro objects, but
doesn't fully initialize all the fields. At a minimum, we need to
initialize all the fields that may be accessed by gen_traverse because
the call to `compute_cr_origin()` can trigger a GC.
(cherry picked from commit 574405c19e9b5de0504be46a3925027ded4495ae)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-10-23 14:44:21 +00:00
Mark Shannon
d1a434f7b2
[3.14] GH-139951: Fix major GC performance regression. Backport of GH-140262 (GH-140447)
* 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.
2025-10-23 15:26:58 +01:00
Miss Islington (bot)
9d547dab0b
[3.14] gh-132835: Add defensive NULL checks to MRO resolution (GH-134763) (GH-140436)
Currently, there are a few places where tp_mro could theoretically
become NULL, but do not in practice. This commit adds defensive checks for
NULL values to ensure that any changes do not introduce a crash and that
state invariants are upheld.

The assertions added in this commit are all instances where a NULL value would get passed to something not expecting a NULL, so it is better to catch an assertion failure than crash later on.

There are a few cases where it is OK for the return of lookup_tp_mro to be NULL, such as when passed to is_subtype_with_mro, which handles this explicitly.
(cherry picked from commit a8edca62fc6d44d16c7f86d49421be1a5ebea3e5)

Co-authored-by: Emma Smith <emma@emmatyping.dev>
2025-10-21 20:45:06 -07:00
Miss Islington (bot)
c0f0eca4da
[3.14] gh-140406: Fix memory leak upon __hash__ returning a non-integer (GH-140411) (GH-140417)
gh-140406: Fix memory leak upon `__hash__` returning a non-integer (GH-140411)
(cherry picked from commit 71db05a12d9953a96f809d84b4d0d452a464e431)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-10-21 12:35:31 +00:00
Miss Islington (bot)
045e34964a
[3.14] gh-140061: Use _PyObject_IsUniquelyReferenced() to check if objects are uniquely referenced (gh-140062) (gh-140157)
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>
2025-10-15 14:49:17 +00:00
Miss Islington (bot)
6b94c7ceeb
[3.14] gh-129559: Remove extra dot in bytearray.resize AC (GH-140134) (#140143)
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
2025-10-15 14:06:18 +03:00
Miss Islington (bot)
2142f4efcf
[3.14] GH-140058: Clear key and value if PyTuple_New fails in dictiter_iternextitem (GH-140059) (#140107)
GH-140058: Clear key and value if `PyTuple_New` fails in `dictiter_iternextitem` (GH-140059)
(cherry picked from commit ded59f7e8e93274488584574ff2336a98bc4eff6)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
2025-10-14 19:10:30 +05:30
Miss Islington (bot)
7a13953bc3
[3.14] gh-140000: Traverse name attribute for TypeVar, TypeVarTuple, TypeAliasType, ParamSpec (GH-140016) (#140063)
gh-140000: Traverse `name` attribute for `TypeVar`, `TypeVarTuple`, `TypeAliasType`, `ParamSpec` (GH-140016)
(cherry picked from commit be60e4b4f34a097d999d337446786ae14e35c964)

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
2025-10-13 20:36:24 +00:00
Kumar Aditya
511078099a
[3.14] gh-125996: fix thread safety of collections.OrderedDict (GH-133734) (#140053)
(cherry picked from commit 6481539a6d9692ddf13ab01baad1bc9133409413)
2025-10-13 23:25:24 +05:30
Miss Islington (bot)
3b9694a8e6
[3.14] gh-139988: fix a leak when failing to create a Union type (GH-139990) (#139993)
gh-139988: fix a leak when failing to create a Union type (GH-139990)
(cherry picked from commit 6710156bd27dd48493d15f515506a0ead5d0328f)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-10-12 11:16:43 +00:00
Miss Islington (bot)
09fdd219a5
[3.14] gh-105487: Fix __dir__ entries of GenericAlias (GH-138578) (GH-138629)
(cherry picked from commit b0420b505e6c9bbc8418e0f6240835ea777137b5)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Emma Smith <emma@emmatyping.dev>
2025-10-07 23:12:13 +02:00
Stan Ulbrych
a893270c6d
[3.14] gh-71648: Optimize PNG files (GH-138842) (GH-138851)
* Only keep > 1 kb savings
(cherry picked from commit 2e8f64c9317a327a2be1ab8031844ef3967c1040)
2025-10-07 20:52:12 +02:00
Miss Islington (bot)
bf397e272c
[3.14] gh-133467: fix data race in type_set_name (GH-137302) (#137303)
gh-133467: fix data race in `type_set_name` (GH-137302)

Fix data race in `type_set_name` by assigning name under stop the world pause making it thread safe in free-threading.
(cherry picked from commit e99bc7fd44bbbf2464c37d5a57777ac0e1264c37)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-07 18:18:23 +00:00
Miss Islington (bot)
bfcd5f25a5
[3.14] gh-138661: fix data race in PyCode_Addr2Line (GH-138664) (#138834)
gh-138661: fix data race in `PyCode_Addr2Line` (GH-138664)
(cherry picked from commit ea26f6da39294b7d3c28873d070a2218bd528b5f)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-07 18:06:45 +00:00
Miss Islington (bot)
fad7bfc282
[3.14] gh-138902: Fix generator send arg name (GH-138905) (#138914)
gh-138902: Fix generator send arg name (GH-138905)
(cherry picked from commit cb07bd24eed43a0ac182e664398398164089f294)

Co-authored-by: Marat Khagazheev <marathagazeev@gmail.com>
Co-authored-by: marat <khagazheev@artlebedev.ru>
2025-10-07 23:27:05 +05:30
Miss Islington (bot)
57c8e3eb8e
[3.14] gh-58124: Avoid CP_UTF8 in UnicodeDecodeError (GH-137415) (#137460)
gh-58124: Avoid CP_UTF8 in UnicodeDecodeError (GH-137415)

Fix name of the Python encoding in Unicode errors of the code page
codec: use "cp65000" and "cp65001" instead of "CP_UTF7" and "CP_UTF8"
which are not valid Python code names.
(cherry picked from commit ce1b747ff68754635b7b12870dfc527184ee3b39)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-07 19:39:31 +02:00
Miss Islington (bot)
b343009377
[3.14] gh-71810: Fix _PyLong_AsByteArray() undefined behavior (GH-138873) (#138883)
gh-71810: Fix _PyLong_AsByteArray() undefined behavior (GH-138873)

Don't read p[-1] when p is an empty string: when n==0.
(cherry picked from commit 8b5ce31c2b44d9bf82e6119e90a52dd530bfd1db)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-07 19:38:40 +02:00
Sam Gross
85dabb9c15
[3.14] gh-137238: Fix data race in _Py_slot_tp_getattr_hook (gh-137240) (#137416)
Replacing the slot isn't thread-safe if the GIL is disabled. Don't
require that the slot has been replaced when specializing.
(cherry picked from commit 485b16b4f7b28cefdfb524c2869d473078e349bf)
2025-10-07 17:36:56 +00:00