Repository navigation
Conversation
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.
Fixes mypyc/mypyc#1235.
native_slot()filledtp_iternextwith the native__next__method itself, which only works if the method returnsPyObject *. With-> int, CPython got the tagged integer, orCPY_INT_TAGafterStopIteration, as an object pointer, sonext(),forloops,list()andobj.__next__()from Python all crashed.float,i64and tuples crashed too. Withbool,Falsecame back as NULL, so the iteration stopped early without an error. MSVC warns about the mismatch (C4047).native_slot()now usesgenerate_dunder_wrapper()when the method returns an unboxed value. That's the wrapper the unary number slots such as__int__and__index__already use. It calls the native method, returns NULL if the method raised (checkingPyErr_Occurred()for types such asfloat, whose error value is also a valid value), and boxes the result. AStopIterationraised by__next__still ends the iteration, because the wrapper returns NULL with it set. Methods that return an object, including the__next__of every native generator, still fill the slot directly, so they don't get an extra call. The other slots that usenative_slot()(__iter__,__str__,__repr__,__await__,__aiter__and__anext__) get the same check, although they normally return objects.