Skip to content

python: take a reference to None before passing it to a native callback - #1350

Open
Nussu06 wants to merge 1 commit into
google:masterfrom
Nussu06:python-native-none-refcount
Open

Nussu06 wants to merge 1 commit into
google:masterfrom
Nussu06:python-native-none-refcount

Conversation

@Nussu06

@Nussu06 Nussu06 commented Oct 29, 2026

Copy link
Copy Markdown

cpython_native_callback stores Py_None in the argument tuple with PyTuple_SetItem, which steals a reference that was never taken, so each null argument (e.g. [std.native('f')(null) for i in std.range(1, N)]) drops one reference from None until CPython < 3.12 aborts with "Fatal Python error: none_dealloc: deallocating None"; take the reference first, with a regression test checking that sys.getrefcount(None) is unchanged after 100 null calls (fails with 100 references lost before the fix, passes after on 3.9 and 3.12).

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant