[pypy-svn] r68514 - in pypy/branch/gc-hash/pypy: rpython/lltypesystem translator/c

arigo at codespeak.net arigo at codespeak.net
Thu Oct 15 21:38:09 CEST 2009


Author: arigo
Date: Thu Oct 15 21:38:08 2009
New Revision: 68514

Modified:
   pypy/branch/gc-hash/pypy/rpython/lltypesystem/lltype.py
   pypy/branch/gc-hash/pypy/translator/c/gc.py
Log:
In tests that run the C backend successively with Boehm
and with the framework GC, all objects have suddenly
grown a hash.  Fix.


Modified: pypy/branch/gc-hash/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/gc-hash/pypy/rpython/lltypesystem/lltype.py	Thu Oct 15 21:38:08 2009
@@ -1119,16 +1119,17 @@
             return callb(*args)
         raise TypeError("%r instance is not a function" % (self._T,))
 
-    def _identityhash(self):
+    def _identityhash(self, cache=True):
         p = normalizeptr(self)
         try:
             return p._obj._hash_cache_
         except AttributeError:
             result = hash(p._obj)
-            try:
-                p._obj._hash_cache_ = result
-            except AttributeError:
-                pass
+            if cache:
+                try:
+                    p._obj._hash_cache_ = result
+                except AttributeError:
+                    pass
             return result
 
 class _ptr(_abstract_ptr):
@@ -1869,6 +1870,8 @@
         raise ValueError("cannot change hash(NULL)!")
     if hasattr(p._obj, '_hash_cache_'):
         raise ValueError("the hash of %r was already computed" % (p,))
+    if typeOf(p).TO._is_varsize():
+        raise ValueError("init_identity_hash(): not for varsized types")
     p._obj._hash_cache_ = intmask(value)
 
 def isCompatibleType(TYPE1, TYPE2):

Modified: pypy/branch/gc-hash/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/gc-hash/pypy/translator/c/gc.py	(original)
+++ pypy/branch/gc-hash/pypy/translator/c/gc.py	Thu Oct 15 21:38:08 2009
@@ -196,13 +196,10 @@
 
     def common_gcheader_initdata(self, defnode):
         if defnode.db.gctransformer is not None:
-            return [lltype.identityhash(defnode.obj._as_ptr())]
+            return [defnode.obj._as_ptr()._identityhash(cache=False)]
         else:
             return []
 
-    def get_header_fields(self, obj):
-        return [lltype.identityhash(obj._as_ptr())]
-
     def array_setup(self, arraydefnode):
         pass
 
@@ -346,7 +343,8 @@
         # restored.  Note that only structures that are StructNodes all
         # the way have their hash stored (and not e.g. structs with var-
         # sized arrays at the end).  'obj' must be the top_container.
-        if not isinstance(typeOf(obj), lltype.GcStruct):
+        TYPE = typeOf(obj)
+        if not isinstance(TYPE, lltype.GcStruct):
             return None
         return getattr(obj, '_hash_cache_', None)
 



More information about the Pypy-commit mailing list