[pypy-svn] r53650 - in pypy/branch/jit-hotpath/pypy/rpython/ootypesystem: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Apr 10 11:14:37 CEST 2008


Author: antocuni
Date: Thu Apr 10 11:14:36 2008
New Revision: 53650

Modified:
   pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/test/test_ootype.py
Log:
add support to call ooidentityhash on ootype.Object values



Modified: pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py	Thu Apr 10 11:14:36 2008
@@ -744,6 +744,15 @@
     def __hash__(self):
         return hash(self.obj)
 
+    def _identityhash(self):
+        if self:
+            try:
+                return self.obj._identityhash()
+            except AttributeError:
+                return intmask(id(self.obj))
+        else:
+            return 0 # for all null objects
+
     def _cast_to_object(self):
         return self
 
@@ -1677,7 +1686,8 @@
     return obj._cast_to(EXPECTED_TYPE)
 
 def ooidentityhash(inst):
-    assert isinstance(typeOf(inst), (Instance, Record))
+    T = typeOf(inst)
+    assert T is Object or isinstance(T, (Instance, Record))
     return inst._identityhash()
 
 def oohash(inst):

Modified: pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/test/test_ootype.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/test/test_ootype.py	Thu Apr 10 11:14:36 2008
@@ -585,3 +585,18 @@
     assert NULL != obj1
     assert obj1 != NULL
     
+def test_object_ooidentityhash():
+    A = Instance("Foo", ROOT)
+    a = new(A)
+    obj1 = cast_to_object(a)
+    obj2 = cast_to_object(a)
+    assert ooidentityhash(obj1) == ooidentityhash(obj2)
+
+def test_object_ooidentityhash_sm():
+    M = StaticMethod([Signed], Signed)
+    def m_(x):
+       return x
+    m = static_meth(M, "m", _callable=m_)
+    obj1 = cast_to_object(m)
+    obj2 = cast_to_object(m)
+    assert ooidentityhash(obj1) == ooidentityhash(obj2)



More information about the Pypy-commit mailing list