Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-99761: add invalid_index macro#99762
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
sweeneyde commentedNov 24, 2022
I think this is generally a good idea, but I'm not sure this should go in the public API. If it does, its name should probably begin with 'Py...'. Seehttps://devguide.python.org/developer-workflow/c-api/ andhttps://peps.python.org/pep-0007/#naming-conventions . |
eendebakpt commentedNov 25, 2022
Agreed. What would be a good location for the private version? One of the |
rhettinger commentedNov 26, 2022
|
eendebakpt commentedNov 26, 2022
Everywhere in the code the usage is
Done.
With inline functions I think we can never be certain the code gets inlined for all compilers and settings. I changed the static inline to a macro.
The |
vstinner commentedNov 28, 2022
You should not use macro but a static inline functions, see:
See PEP 670 which answers to that and we approved by the Steering Council. A static inline function must be used. |
vstinner 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'm not very excited by a function only used for a micro-optimization, I'm fine with(i < 0 || i >= Py_SIZE(self)) test. But I'm not against this change neither.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
eendebakpt commentedMar 6, 2023
@vstinner Could you have a look at the PR again? |
arhadthedev 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.
All earlier reviews seem to be addressed.
serhiy-storchaka commentedJun 8, 2024
This idea was already discussed and rejected. See#72583. |
Uh oh!
There was an error while loading.Please reload this page.
In
listobject.cthere is anoptimization to check whether an index is valid (e.g.0 <= index < N) using a single comparison. The cast-to-unsigned optimization is used in current main in 3 locations:tupleobject.c,_collectionsmodule.candbytesobject.c.It is a micro optimization, but the code generated is different than the plain
i < 0 || i >= Py_SIZE(a). This PR tries to:i) apply the optimization to more locations
ii) make the code more consistent
By replacing index checks with a single method
_Py_is_valid_indexthat includes the optimization we have consistency in the code and have the optimized check for all index checks.Notes:
bytecodes.cthe optimized expression is used in three places. E.g.With the
_Py_is_valid_indexmethod it looks likewhich is in my opinion not very readable. For these cases a separate PR was created:#100064