Stable ABI can strip immortality from Python objects
CPython may backport opaque reference-count calls after extensions built with older limited API headers turn objects such as None mortal.
CPython developers are weighing a backport after finding that some extensions built against the limited C API can turn immortal objects, including None, into ordinary reference-counted ones when they run on newer Python. Victor Stinner said that conversion should never happen and has already produced multiple nasty bugs.
Immortality lets core objects skip ordinary reference counting, but older inlined forms of the increment and decrement macros still adjust the count directly and do not know about it. On Python 3.14 and later, that can strip immortality from objects an extension treats as permanent. Stinner called it a bug in the stable ABI itself, not in how extension authors count references. Walking every explicit decref of None is not a fix: a value that is only sometimes None is affected the same way.
Stinner has a change for Python 3.16 that implements those macros as real function calls for every limited API version, so a build done with 3.16 headers would avoid the de-immortalization even when targeting an older stable ABI. It does not help extensions built with older interpreters. Nathan Goldbaum called the gap a pretty serious issue and asked whether the change should land even in security-fix-only releases, writing that otherwise he fears people may miss out on this for several years. Meson, he noted, tags a wheel for an older Python only if that version was actually used to build it.
Stinner said he is open to backporting the opaque calls to every supported Python and every limited API version, and to noting the change in the release notes. He had previously limited the function-call form to newer limited API versions over performance worries. Which header vintage already avoids the bug is still unsettled: one developer said recent headers inline the immortal check even for older limited API targets, while Phil Thompson said PyQt still needed 3.14 headers and that 3.12 was not enough. Projects such as SciPy, which plan to adopt the limited API, were told the practical fix is how the extension is built, not a manual sweep of call sites.