Skip to content

[3.14] gh-158401: Implement Py_INCREF() as function call in stable ABI (#162120) - #162776

Merged
vstinner merged 1 commit into
python:3.14from
vstinner:limited_incref14
Nov 28, 2026
Merged

vstinner merged 1 commit into
python:3.14from
vstinner:limited_incref14

Conversation

@vstinner

@vstinner vstinner commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Py_INCREF(), Py_XINCREF(), Py_DECREF() and Py_XDECREF() are now implemented as function calls on all limited C API versions. Previously, they were only implemented as function calls on the limited C API version 3.12 or newer.

Previously, if a C extension was built with the limited C API version 3.11 or newer, Py_DECREF() was implemented as "op->ob_refcnt--". But Python 3.12 made Py_DECREF() more complicated to implement immortal objects in an efficient way. "op->ob_refcnt--" can convert an immortal object to a mortal object which causes various kinds of nasty bugs.

Backport to 3.14: mention the change in "Notable changes in 3.14.11" of What's New in Python 3.14.

…python#162120)

Py_INCREF(), Py_XINCREF(), Py_DECREF() and Py_XDECREF() are now
implemented as function calls on all limited C API versions.
Previously, they were only implemented as function calls on the
limited C API version 3.12 or newer.

Previously, if a C extension was built with the limited C API version
3.11 or newer, Py_DECREF() was implemented as "op->ob_refcnt--". But
Python 3.12 made Py_DECREF() more complicated to implement immortal
objects in an efficient way. "op->ob_refcnt--" can convert an
immortal object to a mortal object which causes various kinds of
nasty bugs.

Backport to 3.14: mention the change in "Notable changes in 3.14.11"
of What's New in Python 3.14.

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
@vstinner
vstinner merged commit f09a318 into python:3.14 Nov 28, 2026
53 checks passed
@vstinner
vstinner deleted the limited_incref14 branch November 28, 2026 00:10
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