Skip to content

gh-123091: Use more _Py_IsImmortalLoose() - #123602

Merged
encukou merged 1 commit into
python:mainfrom
encukou:immortal-loose
Sep 2, 2024
Merged

encukou merged 1 commit into
python:mainfrom
encukou:immortal-loose

Conversation

@encukou

@encukou encukou commented Sep 2, 2024 •

Copy link
Copy Markdown
Member

Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...), to account for stable-ABI extensions changing the refcount of immortal objects (similar to the _Py_IMMORTAL_BIT/_Py_IMMORTAL_REFCNT design that was approved in PEP-683 but never implemented).

The remaining calls to _Py_IsImmortal are in free-threaded-only code, initialization of core objects, tests, and guards that fall back to code that works with mortal objects.

Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.
@vstinner

vstinner commented Sep 2, 2024

Copy link
Copy Markdown
Member

The remaining calls to _Py_IsImmortal are in free-threaded-only code, initialization of core objects, tests, and guards that fall back to code that works with mortal objects.

Remaining calls:

$ git grep 'assert.*Py_IsImmortal'|grep -v Loose

Include/internal/pycore_stackref.h:    assert(_Py_IsImmortal(obj));
Modules/_testcapi/immortal.c:    assert(_Py_IsImmortal(object));
Objects/codeobject.c:    assert(_Py_IsImmortal(entry->value));
Objects/object.c:    assert(!_Py_IsImmortal(op));
Objects/object.c:        assert(_Py_IsImmortal(constants[i]));
Objects/structseq.c:        assert(_Py_IsImmortal(type));
Objects/typeobject.c:    assert(_Py_IsImmortal((PyObject *)self));
Objects/unicodeobject.c:    assert(!_Py_IsImmortal(s));
Programs/_testembed.c:        assert(_Py_IsImmortal(str1));
Python/crossinterp.c:        assert(_Py_IsImmortal((PyObject *)type));
Python/crossinterp.c:        assert(_Py_IsImmortal((PyObject *)info->builtin));
Python/optimizer_symbols.c:    assert(_Py_IsImmortal(val_42));
Python/optimizer_symbols.c:    assert(_Py_IsImmortal(val_43));

@vstinner vstinner 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. IMO it should be backported to 3.13.

@vstinner vstinner added needs backport to 3.13 only security fixes and removed awaiting merge labels Sep 2, 2024
@encukou
encukou merged commit 57c471a into python:main Sep 2, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@encukou
encukou deleted the immortal-loose branch September 2, 2024 16:17
@miss-islington-app

Copy link
Copy Markdown

Sorry, @encukou, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 57c471a6880956338549380fc5fb35c986937901 3.13
encukou added a commit to encukou/cpython that referenced this pull request Sep 3, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(cherry picked from commit 57c471a)
@bedevere-app

bedevere-app Bot commented Sep 3, 2024

Copy link
Copy Markdown

GH-123622 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Sep 3, 2024
encukou added a commit that referenced this pull request Sep 3, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(cherry picked from commit 57c471a)
encukou added a commit to encukou/cpython that referenced this pull request Oct 3, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(For this 3.12 backport commit, I re-checked all calls to _Py_IsImmortal;
the changed calls are different from the commits to 3.13 & 3.14.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants