Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-128198: Add missing error checks for usages ofPyIter_Next#128199
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
gh-128198: Add missing error checks for usages ofPyIter_Next#128199
Uh oh!
There was an error while loading.Please reload this page.
Conversation
1c58e95 toca54407Compareca54407 toc6d319fCompare
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.
In 3.14, we have a newPyIter_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 ofPyIter_Next.
WolframAlph commentedDec 23, 2024
👍 Will check it out and update the PR |
WolframAlph commentedDec 23, 2024
@ZeroIntensity I can see |
ZeroIntensity commentedDec 23, 2024
I don't think we need to replace
Nah, just update the PR title. |
WolframAlph commentedDec 24, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@ZeroIntensity so if this is inevitable (otherwise why would new |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PyIter_NextPyIter_Nextserhiy-storchaka commentedDec 24, 2024
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. |
ZeroIntensity commentedDec 24, 2024
Ah, right. I would be in favor of a follow-up PR to switch to |
picnixz 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.
LGTM (I'll just run the refleaks build bots since the previous run was interrupted, just in case)
bedevere-bot commentedDec 25, 2024
WolframAlph commentedDec 25, 2024
Regarding migration to |
picnixz commentedDec 25, 2024
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. |
WolframAlph commentedDec 25, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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? |
WolframAlph commentedDec 25, 2024
One more question. When comparing code for Lines 2914 to 2919 ind9ed42b
and PyIter_NextItem:Lines 2891 to 2903 ind9ed42b
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? |
picnixz commentedDec 25, 2024
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 :') |
serhiy-storchaka commentedDec 25, 2024
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). |
5c814c8 intopython:mainUh oh!
There was an error while loading.Please reload this page.
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 commit5c814c8)Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
GH-128272 is a backport of this pull request to the3.13 branch. |
…_Next() (pythonGH-128199)(cherry picked from commit5c814c8)Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
GH-128273 is a backport of this pull request to the3.12 branch. |
Uh oh!
There was an error while loading.Please reload this page.
PyIter_Next#128198