Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-123091: Use more _Py_IsImmortalLoose() #123602

Merged
merged 1 commit into from
Sep 2, 2024
Merged

Conversation

encukou
Copy link
Member

@encukou encukou commented Sep 2, 2024

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
Copy link
Member

vstinner commented Sep 2, 2024

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));

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

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

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

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
Copy link

bedevere-app bot commented Sep 3, 2024

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 bugs and 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants