gh-91927: Add helpers for obtaining new references to various singletons#91925
Closed
hvenev wants to merge 9 commits into
Closed
gh-91927: Add helpers for obtaining new references to various singletons#91925hvenev wants to merge 9 commits into
hvenev wants to merge 9 commits into
Conversation
While at it, fix a few refcount bugs.
Helpers are defined for the following singletons: - None - NotImplemented - Ellipsis - False - True
They are now simply calls to Py_Ref{True,False}.
The function body is quite small and already open-coded in lots of places. The original `PyBool_FromLong` is retained for ABI compatibility. A new inline `_PyBool_FromLong` is added and a macro is used so that calls to `PyBool_FromLong` use it instead.
Now that it is inline, there shouldn't be a performance penalty.
Contributor
|
-1 From my point of view, this doesn't make anything better. The code would be slightly more consistent (but in an unimportant way) and the new functions are less readable — in particular, my mind rebels at the sight of Py_RefFalse. If immortals do come to fruition, this can be revisited, but I can see any real value coming from it unless all third-party code could be converted as well (otherwise, you have a mix of old and new calls). |
Contributor
|
If another coredev wants to champion this one, feel free to reopen. |
Member
|
I agree with @rhettinger. It is too soon to consider any API like this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are lots of places where a new reference to a singleton is needed. This is done in a variety of ways:
The helpers implemented here add another way that can hopefully become more idiomatic:
One advantage of using the new helpers is that it abstracts away the necessity to increment the reference count if immortal instances are implemented.
Alternatively, if immortal instances aren't implemented and all singletons are made per-interpreter, it will slightly reduce the performance overhead by making sure that the singletons are only obtained once (compared to patterns 3, 4, and 5, where the singetons are obtained twice).