Skip to content

gh-150868: Fix sum() deallocating a float subclass as an exact float#151063

Open
eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:fix-sum-float-subclass-dealloc
Open

gh-150868: Fix sum() deallocating a float subclass as an exact float#151063
eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:fix-sum-float-subclass-dealloc

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

@eendebakpt eendebakpt commented Jun 7, 2026

…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.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@StanFromIreland StanFromIreland changed the title gh-151060: Fix sum() deallocating a float subclass as an exact float gh-150868: Fix sum() deallocating a float subclass as an exact float Jun 7, 2026
@eendebakpt
Copy link
Copy Markdown
Contributor Author

There was already a PR opened earlier, lets give that a chance to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant