Repository navigation
Commit b406b4f
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 78b7068 commit b406b4f
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 | |
|---|---|---|---|
| |||
2080 | 2080 | | |
2081 | 2081 | | |
2082 | 2082 | | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
2083 | 2108 | | |
2084 | 2109 | | |
2085 | 2110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2901 | 2901 | | |
2902 | 2902 | | |
2903 | 2903 | | |
2904 | | - | |
| 2904 | + | |
2905 | 2905 | | |
2906 | 2906 | | |
2907 | 2907 | | |
2908 | | - | |
| 2908 | + | |
2909 | 2909 | | |
2910 | 2910 | | |
2911 | 2911 | | |
2912 | | - | |
| 2912 | + | |
2913 | 2913 | | |
2914 | 2914 | | |
2915 | 2915 | | |
| |||
2953 | 2953 | | |
2954 | 2954 | | |
2955 | 2955 | | |
2956 | | - | |
| 2956 | + | |
2957 | 2957 | | |
2958 | 2958 | | |
2959 | 2959 | | |
2960 | | - | |
| 2960 | + | |
2961 | 2961 | | |
2962 | 2962 | | |
2963 | 2963 | | |
2964 | | - | |
| 2964 | + | |
2965 | 2965 | | |
2966 | 2966 | | |
2967 | 2967 | | |
2968 | 2968 | | |
2969 | | - | |
| 2969 | + | |
2970 | 2970 | | |
2971 | 2971 | | |
2972 | 2972 | | |
| |||
0 commit comments