-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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-128198: Add missing error checks for usages of PyIter_Next
#128199
gh-128198: Add missing error checks for usages of PyIter_Next
#128199
Conversation
1c58e95
to
ca54407
Compare
ca54407
to
c6d319f
Compare
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.
In 3.14, we have a new PyIter_NextItem
for exactly this problem. I think it's worth migrating to that in this PR instead of trying to adapt to the bad design choices of PyIter_Next
.
👍 Will check it out and update the PR |
@ZeroIntensity I can see |
I don't think we need to replace
Nah, just update the PR title. |
@ZeroIntensity so if this is inevitable (otherwise why would new |
PyIter_Next
PyIter_Next
If older Python versions have the same code, it will be needed to backport these changes. In such case it is better to use the older API, unless you want to add a work for yourself and for reviewers. |
Ah, right. I would be in favor of a follow-up PR to switch to |
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.
LGTM (I'll just run the refleaks build bots since the previous run was interrupted, just in case)
Regarding migration to |
Yes, you can just request my review. But before creating the issue, you should locally verify that:
FTR, changing the usages could perhaps make future backports harder, so I don't know whether it's worth the shot. |
Yes, my initial thought was to create top level issue to track all sub issues for each file separately to make review process easier.
I presume this is not first time of migrating to newer API. How were those cases handled? |
One more question. When comparing code for Lines 2914 to 2919 in d9ed42b
and PyIter_NextItem :Lines 2891 to 2903 in d9ed42b
I can see that latter has Py_TYPE(iter)->tp_iternext == NULL check while former does not. Is it intentional? If so - what is the reason?
|
Yes it's intentional. Docs (https://docs.python.org/3/c-api/iter.html#c.PyIter_Next) say:
The reason is to make the call more efficient when the caller knows that the object is a correct iterator. OTOH I don't know how less (or more?) efficient it would be but it might not necessarily by much. If you're really interested in preserving performance, we could first glance at the assembly and benchmarks some simple statements, though I suspect that naive benchmarks would hide too much noise (but maybe not?). Now, if the caller is checking the input to
I don't know, I only became active with CPython in June :') |
We migrate to newer API if it is faster, safer or more convenient. Or if there are plans to remove the older API. There are no plans to remove I would recommend to use a newer API in a new code if it makes the code clearer, and do not touch existing code (unless you have other reasons to rewrite it). |
Thanks @WolframAlph for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Thanks @WolframAlph for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @WolframAlph and @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @WolframAlph and @serhiy-storchaka, I could not cleanly backport this to
|
…_Next() (pythonGH-128199) (cherry picked from commit 5c814c8) Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
GH-128272 is a backport of this pull request to the 3.13 branch. |
…_Next() (pythonGH-128199) (cherry picked from commit 5c814c8) Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
GH-128273 is a backport of this pull request to the 3.12 branch. |
PyIter_Next
#128198