[pypy-commit] pypy py3k: merge kunalgrover05/pypy/py3.3-hashfix (pull request #402)
pjenvey
pypy.commits at gmail.com
Fri Apr 15 21:55:10 EDT 2016
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r83701:32e47f04869f
Date: 2016-04-15 18:52 -0700
http://bitbucket.org/pypy/pypy/changeset/32e47f04869f/
Log: merge kunalgrover05/pypy/py3.3-hashfix (pull request #402)
use intobject hash function for specialisedtuple
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -520,21 +520,7 @@
return _new_int(space, w_inttype, w_x, w_base)
def descr_hash(self, space):
- a = self.intval
- sign = 1
- if a < 0:
- sign = -1
- a = -a
-
- x = r_uint(a)
- # efficient x % HASH_MODULUS: as HASH_MODULUS is a Mersenne
- # prime
- x = (x & HASH_MODULUS) + (x >> HASH_BITS)
- if x >= HASH_MODULUS:
- x -= HASH_MODULUS
-
- x = intmask(intmask(x) * sign)
- return wrapint(space, -2 if x == -1 else x)
+ return space.wrap(_hash_int(self.intval))
def as_w_long(self, space):
# XXX: should try smalllong
@@ -1028,3 +1014,20 @@
__pow__ = interpindirect2app(W_AbstractIntObject.descr_pow),
__rpow__ = interpindirect2app(W_AbstractIntObject.descr_rpow),
)
+
+
+def _hash_int(a):
+ sign = 1
+ if a < 0:
+ sign = -1
+ a = -a
+
+ x = r_uint(a)
+ # efficient x % HASH_MODULUS: as HASH_MODULUS is a Mersenne
+ # prime
+ x = (x & HASH_MODULUS) + (x >> HASH_BITS)
+ if x >= HASH_MODULUS:
+ x -= HASH_MODULUS
+
+ x = intmask(intmask(x) * sign)
+ return -2 if x == -1 else x
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -1,7 +1,7 @@
from pypy.interpreter.error import OperationError
from pypy.objspace.std.tupleobject import W_AbstractTupleObject
from pypy.objspace.std.util import negate
-from rpython.rlib.objectmodel import compute_hash, specialize
+from rpython.rlib.objectmodel import specialize
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.unroll import unrolling_iterable
from rpython.tool.sourcetools import func_with_new_name
@@ -67,8 +67,14 @@
# integer & other less frequent cases
from pypy.objspace.std.floatobject import _hash_float
y = _hash_float(space, value)
+ elif typetuple[i] == int:
+ # hash for int which is different from the hash
+ # given by rpython
+ from pypy.objspace.std.intobject import _hash_int
+ y = _hash_int(value)
else:
- y = compute_hash(value)
+ raise NotImplementedError
+
x = (x ^ y) * mult
z -= 1
mult += 82520 + z + z
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -177,6 +177,11 @@
assert hash(a) == hash((1, 2)) == hash((1.0, 2.0)) == hash((1.0, 2))
+ d = tuple([-1, 1])
+ e = (-1, 1)
+ assert d == e
+ assert hash(d) == hash(e)
+
def test_getitem(self):
t = (5, 3)
assert (t)[0] == 5
More information about the pypy-commit
mailing list