-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-143300: implement PyUnstable_SetImmortal
#144543
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
base: main
Are you sure you want to change the base?
Conversation
ZeroIntensity
left a comment
There was a problem hiding this comment.
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"))Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
ZeroIntensity
left a comment
There was a problem hiding this comment.
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).
| creates it, such as in the object's :c:member:`~PyTypeObject.tp_new` slot. | ||
| Returns 1 if the object was made immortal and returns 0 if it was not. | ||
| This function cannot fail. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to you, but it's likely worth mentioning that this is useful for avoiding reference count contention.
I'd like to keep it aligned with |
| made mortal once again. Immortal objects do not participate in reference counting | ||
| and will never be garbage collected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we also need to note that op will be GC-untracked if it's tracked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it the same as never garbage collected?
📚 Documentation preview 📚: https://cpython-previews--144543.org.readthedocs.build/