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#1253
The
tp_hashslot of a native class converted the value returned by__hash__withCPyTagged_AsSsize_t(), so an int that doesn't fit inPy_hash_tmadehash()raiseOverflowError. CPython'sslot_tp_hash, which a class defined in Python uses, accepts any int and hashes one that doesn't fit again withint.__hash__.generate_hash_wrapper()now does the same:CPy_HashFromResult()ingeneric_ops.c, which does whatslot_tp_hashdoes with the result: an int that fits in
Py_hash_tis used as is, a larger one is hashed again, andanything that isn't an int raises
TypeError: __hash__ method should return an integer.CPy_HashFromResult(). With-> Any, a result thatisn't an int used to raise
TypeError: an integer is required. A__hash__declared to return a native inttype such as
i64segfaulted (or raisedSystemErrorif it returned 0), because the slot passed the C valueto
PyLong_AsSsize_t()as an object pointer.The new run test
testDundersHashResultcovers-> intand-> Anywith values that fit inPy_hash_t, -1, values that don't fit, a long int that fits only on 64-bit platforms (2**62),Trueand results that aren't ints, plus an-> i64method that returns -1. The expected results are the same on 32-bit platforms.