Repository navigation
Commit c391d1a
gh-150868: Fix sum() deallocating a float subclass as an exact float (GH-151063)
* gh-151060: Fix sum() deallocating a float subclass as an exact float
The complex-total fast path in builtin_sum_impl() guarded with
PyFloat_Check() (which accepts subclasses) but freed the item with
_Py_DECREF_SPECIALIZED(item, _PyFloat_ExactDealloc), which assumes an
exact float. A float subclass instance reaching refcount 0 in that loop
aborts on an assertion in debug builds, and in release builds skips the
subclass tp_dealloc (type refcount leak, __del__ never runs, subclass
object pushed onto the float freelist).
Use PyFloat_CheckExact() instead, matching the float-total branch, so
subclass instances fall through to the generic PyNumber_Add() path.
* gh-150868: Also use exact-type checks for ints in the fast sum() loops
Per review: use PyLong_CheckExact with the specialized exact-int
deallocator in the float and complex fast-sum loops, so int subclasses
take the generic path.
---------
(cherry picked from commit 47c249a)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7b426f9 commit c391d1a
3 files changed
Lines changed: 34 additions & 7 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2252 | 2252 | | |
2253 | 2253 | | |
2254 | 2254 | | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
2255 | 2280 | | |
2256 | 2281 | | |
2257 | 2282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2987 | 2987 | | |
2988 | 2988 | | |
2989 | 2989 | | |
2990 | | - | |
| 2990 | + | |
2991 | 2991 | | |
2992 | 2992 | | |
2993 | 2993 | | |
2994 | | - | |
| 2994 | + | |
2995 | 2995 | | |
2996 | 2996 | | |
2997 | 2997 | | |
2998 | | - | |
| 2998 | + | |
2999 | 2999 | | |
3000 | 3000 | | |
3001 | 3001 | | |
| |||
3039 | 3039 | | |
3040 | 3040 | | |
3041 | 3041 | | |
3042 | | - | |
| 3042 | + | |
3043 | 3043 | | |
3044 | 3044 | | |
3045 | 3045 | | |
3046 | | - | |
| 3046 | + | |
3047 | 3047 | | |
3048 | 3048 | | |
3049 | 3049 | | |
3050 | | - | |
| 3050 | + | |
3051 | 3051 | | |
3052 | 3052 | | |
3053 | 3053 | | |
3054 | 3054 | | |
3055 | | - | |
| 3055 | + | |
3056 | 3056 | | |
3057 | 3057 | | |
3058 | 3058 | | |
| |||
0 commit comments