Skip to content

gh-158401: Make CPython more resistant to de-immortalization - #162275

Open
encukou wants to merge 11 commits into
python:mainfrom
encukou:deimmortalization-sr-mask
Open

encukou wants to merge 11 commits into
python:mainfrom
encukou:deimmortalization-sr-mask

Conversation

@encukou

@encukou encukou commented Nov 19, 2026 •

Copy link
Copy Markdown
Member
  • Mask out the deferred bit in PyStackRef_Is[True,False,None].

    This should fix the PyStackRef_Is* checks for de-immortalized constants.

  • Honour _Py_STATICALLY_ALLOCATED_FLAG in _Py_IsImmortal (on 64-bit GIL builds)

    This means static immortals are always treated as immortal.

  • Don't use Py_IsImmortal/_Py_IsStaticImmortal in common_constants_clear

  • Replace immortality assertions with macros that are skipped on builds where the check isn't reliable.

@encukou

encukou commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Hm, I did found other code that relies on immortality. I'll pick this up again next week.

@encukou
encukou marked this pull request as draft November 25, 2026 16:06
Only check immortality in GIL builds, and only check static
immortality if it's flag-based.
Leaving this to a different PR.

This reverts commit fce2c23.
Only check immortality in GIL builds, and only check static
immortality if it's flag-based.
@encukou encukou changed the title gh-158401: Mask out the deferred bit in PyStackRef_Is[True,False,None] gh-158401: Make CPython more resistant to de-immortalization Nov 27, 2026
@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 30, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit bf4a1cb 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F162275%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 30, 2026
@encukou
encukou marked this pull request as ready for review November 30, 2026 16:32
@encukou

encukou commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@vstinner, @markshannon: I'd like to get your opinion on skipping assert(_Py_IsImmortal(...)) on builds where objects can be de-immortalized.

If we do that, I'll work on a follow-up PR for a special build that would inject de-immortalizations, to allow testing this more thoroughly.


The Buildbot failures are existiong/unrelated:

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.

2 participants