Skip to content

Add PyUnstable_SetImmortal#164

Merged
vstinner merged 8 commits intopython:mainfrom
kumaraditya303:main
Feb 12, 2026
Merged

Add PyUnstable_SetImmortal#164
vstinner merged 8 commits intopython:mainfrom
kumaraditya303:main

Conversation

@kumaraditya303
Copy link
Contributor

No description provided.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Please document the new function in docs/changelog.rst and docs/api.rst.

@kumaraditya303 kumaraditya303 marked this pull request as ready for review February 12, 2026 12:32
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I agree to not add Python 3.12 support.

It's tempting to add Python 3.12 support, but Python 3.12 semantics is different:

static inline void _Py_SetImmortal(PyObject *op)
{
    if (op) {
        op->ob_refcnt = _Py_IMMORTAL_REFCNT;
    }
}
  • Different API: it has no return value (void)!
  • It doesn't reject Unicode objects.
  • It doesn't untrack objects in the GC.
// Immortal objects were implemented in Python 3.12, however there is no easy API
// to make objects immortal until 3.14 which has _Py_SetImmortal(). Since
// immortal objects are primarily needed for free-threading, this API is implemented
// for 3.14 using _Py_SetImmortal() and uses private macros on 3.13.

I agree that PyUnstable_SetImmortal() is mostly useful on free-threaded builds, so it's ok to skip Python 3.12.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@vstinner
Copy link
Member

Good, the tests passed successfully on Python 3.13 on regular build and free-threaded build:

  • Build / build (macos-latest, 3.13) (pull_request)
  • Build / build (macos-latest, 3.13t) (pull_request)

@vstinner vstinner merged commit 8636bcc into python:main Feb 12, 2026
36 checks passed
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.

3 participants