Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r60501:811fe28a50d5
Date: 2013-01-25 23:39 +0100
http://bitbucket.org/pypy/pypy/changeset/811fe28a50d5/

Log:    Let rpython's float.__hash__ be different from interp-level
        W_FloatObject, and revert the rpython one to the default branch.

diff --git a/pypy/module/sys/system.py b/pypy/module/sys/system.py
--- a/pypy/module/sys/system.py
+++ b/pypy/module/sys/system.py
@@ -2,7 +2,8 @@
 from pypy.interpreter import gateway
 from rpython.rlib import rfloat, rbigint
 from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib.objectmodel import HASH_INF, HASH_NAN, HASH_IMAG
+from pypy.objspace.std.floatobject import HASH_INF, HASH_NAN
+from pypy.objspace.std.complexobject import HASH_IMAG
 
 
 app = gateway.applevel("""
diff --git a/pypy/objspace/std/complexobject.py 
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -8,12 +8,13 @@
 from rpython.rlib.rbigint import rbigint
 from rpython.rlib.rfloat import (
     formatd, DTSF_STR_PRECISION, isinf, isnan, copysign)
-from rpython.rlib.objectmodel import HASH_IMAG
 from rpython.rlib import jit, rcomplex
 from rpython.rlib.rarithmetic import intmask
 
 import math
 
+HASH_IMAG = 1000003
+
 
 class W_AbstractComplexObject(W_Object):
     __slots__ = ()
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -12,7 +12,6 @@
     isinf, isnan, isfinite, INFINITY, NAN, copysign, formatd,
     DTSF_ADD_DOT_0, DTSF_STR_PRECISION)
 from rpython.rlib.rbigint import rbigint
-from rpython.rlib.objectmodel import HASH_INF, HASH_NAN
 from rpython.rlib import rfloat
 from rpython.tool.sourcetools import func_with_new_name
 
@@ -20,6 +19,9 @@
 import math
 from pypy.objspace.std.intobject import W_IntObject
 
+HASH_INF  = 314159
+HASH_NAN  = 0
+
 class W_AbstractFloatObject(W_Object):
     __slots__ = ()
 
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -451,10 +451,6 @@
     x ^= length
     return intmask(x)
 
-HASH_INF  = 314159
-HASH_NAN  = 0
-HASH_IMAG = 1000003
-
 def _hash_float(f):
     """The algorithm behind compute_hash() for a float.
     This implementation is identical to the CPython implementation,
@@ -466,11 +462,11 @@
     if not isfinite(f):
         if isinf(f):
             if f < 0.0:
-                return -HASH_INF
+                return -271828
             else:
-                return HASH_INF
+                return 314159
         else: #isnan(f):
-            return HASH_NAN
+            return 0
     v, expo = math.frexp(f)
     v *= TAKE_NEXT
     hipart = int(v)
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -163,8 +163,8 @@
 
 def test_compute_hash_float():
     from rpython.rlib.rfloat import INFINITY, NAN
-    assert compute_hash(INFINITY) == HASH_INF
-    assert compute_hash(-INFINITY) == -HASH_INF
+    assert compute_hash(INFINITY) == 314159
+    assert compute_hash(-INFINITY) == -271828
     assert compute_hash(NAN) == 0
 
 def test_compute_identity_hash():
@@ -335,8 +335,8 @@
             q = Foo()
             assert compute_hash(q) == compute_identity_hash(q)
             from rpython.rlib.rfloat import INFINITY, NAN
-            assert compute_hash(INFINITY) == HASH_INF
-            assert compute_hash(-INFINITY) == -HASH_INF
+            assert compute_hash(INFINITY) == 314159
+            assert compute_hash(-INFINITY) == -271828
             assert compute_hash(NAN) == 0
             return i*2
         res = self.interpret(f, [42])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to