[pypy-svn] r49238 - in pypy/dist/pypy/rpython: lltypesystem test

arigo at codespeak.net arigo at codespeak.net
Sat Dec 1 11:20:54 CET 2007


Author: arigo
Date: Sat Dec  1 11:20:53 2007
New Revision: 49238

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rclass.py
   pypy/dist/pypy/rpython/test/test_rclass.py
Log:
Use again the invert of the address of the object as its default hash,
for Boehm.


Modified: pypy/dist/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rclass.py	Sat Dec  1 11:20:53 2007
@@ -701,7 +701,11 @@
         return 0    # for None
     cached = ins.hash_cache
     if cached == 0:
-       cached = ins.hash_cache = cast_ptr_to_int(ins)
+        # XXX this should ideally be done in a GC-dependent way: we only
+        # need a hash_cache for moving GCs, and we only need the '~' to
+        # avoid Boehm keeping the object alive if the value is passed
+        # around
+       cached = ins.hash_cache = ~cast_ptr_to_int(ins)
     return cached
 
 def ll_inst_type(obj):

Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py	Sat Dec  1 11:20:53 2007
@@ -399,16 +399,19 @@
         d = D()
         def f():
             d2 = D()
-            # xxx check for this CPython peculiarity for now:
-            # (this is true on top of the llinterp too)
-            x = ((hash(d2) & sys.maxint) ==
-                 (current_object_addr_as_int(d2) & sys.maxint))
-            return x, hash(c)+hash(d)
+            return hash(d2), current_object_addr_as_int(d2), hash(c), hash(d)
 
         res = self.interpret(f, [])
-
-        assert res.item0 == True
-        assert res.item1 == intmask(hash(c)+hash(d))
+        # xxx this is too precise, checking the exact implementation
+        if isinstance(self, OORtypeMixin):
+            assert res.item0 == res.item1
+        else:
+            assert res.item0 == ~res.item1
+        # the following property is essential on top of the lltypesystem
+        # otherwise prebuilt dictionaries are broken.  It's not that
+        # relevant on top of the ootypesystem though.
+        assert res.item2 == hash(c)
+        assert res.item3 == hash(d)
         
     def test_type(self):
         class A:



More information about the Pypy-commit mailing list