Skip to content

gh-143300: implement PyUnstable_SetImmortal - #144543

Merged
kumaraditya303 merged 11 commits into
python:mainfrom
kumaraditya303:immortal
Feb 11, 2026
Merged

kumaraditya303 merged 11 commits into
python:mainfrom
kumaraditya303:immortal

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor
Comment thread Doc/c-api/object.rst Resolved
Comment thread Doc/c-api/object.rst Resolved
Comment thread Objects/object.c Resolved

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to document the guarantees regarding which objects may be made immortal. For example, the following results in an assertion failure:

from ctypes import pythonapi, py_object, c_int

set_immortal = pythonapi.PyUnstable_SetImmortal
set_immortal.argtypes = (py_object,)
set_immortal.restype = c_int

print(set_immortal("Hello world"))
Comment thread Doc/c-api/object.rst Resolved
Comment thread Doc/c-api/object.rst Resolved
Comment thread Doc/c-api/object.rst Resolved
Comment thread Objects/object.c Resolved

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good.

Bikeshedding: Should this be named PyUnstable_Object_SetImmortal? The Py[Unstable]_ prefix is generally reserved for runtime operations (though it seems PyUnstable_TryIncRef didn't follow that rule).

Comment thread Doc/c-api/object.rst Resolved
@kumaraditya303

Copy link
Copy Markdown
Contributor Author

Should this be named PyUnstable_Object_SetImmortal?

I'd like to keep it aligned with PyObject_IsImmortal and avoid introducing the Object in between.

@kumaraditya303
kumaraditya303 marked this pull request as ready for review February 10, 2026 14:11
Comment thread Doc/c-api/object.rst Resolved

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kumaraditya303
kumaraditya303 merged commit 347d359 into python:main Feb 11, 2026
47 checks passed
@kumaraditya303
kumaraditya303 deleted the immortal branch February 11, 2026 15:29
@vstinner

Copy link
Copy Markdown
Member

Kumar also added PyUnstable_SetImmortal() function for Python 3.13 and 3.14 in pythoncapi-compat: python/pythoncapi-compat#164.

thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants