[pypy-svn] r47806 - in pypy/dist/pypy/rpython/memory: . gctransform

arigo at codespeak.net arigo at codespeak.net
Wed Oct 24 11:39:27 CEST 2007


Author: arigo
Date: Wed Oct 24 11:39:27 2007
New Revision: 47806

Modified:
   pypy/dist/pypy/rpython/memory/gctransform/framework.py
   pypy/dist/pypy/rpython/memory/gctypelayout.py
   pypy/dist/pypy/rpython/memory/gcwrapper.py
Log:
* zero_gc_pointers wasn't emulated by the gcwrapper.
* the gctransformer must not insert zeroing operations again
  for GCs that give you zero-initialized memory anyway.


Modified: pypy/dist/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform/framework.py	Wed Oct 24 11:39:27 2007
@@ -295,6 +295,7 @@
         s_gc = self.translator.annotator.bookkeeper.valueoftype(GCClass)
         r_gc = self.translator.rtyper.getrepr(s_gc)
         self.c_const_gc = rmodel.inputconst(r_gc, self.gcdata.gc)
+        self.needs_zero_gc_pointers = GCClass.needs_zero_gc_pointers
 
         HDR = self._gc_HDR = self.gcdata.gc.gcheaderbuilder.HDR
         self._gc_fields = fields = []
@@ -533,9 +534,10 @@
         self.pop_roots(hop, livevars)
 
     def gct_zero_gc_pointers_inside(self, hop):
-        v_ob = hop.spaceop.args[0]
-        TYPE = v_ob.concretetype.TO
-        gen_zero_gc_pointers(TYPE, v_ob, hop.llops)
+        if self.needs_zero_gc_pointers:
+            v_ob = hop.spaceop.args[0]
+            TYPE = v_ob.concretetype.TO
+            gen_zero_gc_pointers(TYPE, v_ob, hop.llops)
 
     def gct_weakref_create(self, hop):
         op = hop.spaceop

Modified: pypy/dist/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctypelayout.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctypelayout.py	Wed Oct 24 11:39:27 2007
@@ -220,6 +220,27 @@
                                             adr + llmemory.itemoffsetof(t, i)):
                     yield a
 
+def zero_gc_pointers(p):
+    TYPE = lltype.typeOf(p).TO
+    zero_gc_pointers_inside(p, TYPE)
+
+def zero_gc_pointers_inside(p, TYPE):
+    if isinstance(TYPE, lltype.Struct):
+        for name, FIELD in TYPE._flds.items():
+            if isinstance(FIELD, lltype.Ptr) and FIELD.TO._gckind == 'gc':
+                setattr(p, name, lltype.nullptr(FIELD.TO))
+            elif isinstance(FIELD, lltype.ContainerType):
+                zero_gc_pointers_inside(getattr(p, name), FIELD)
+    elif isinstance(TYPE, lltype.Array):
+        ITEM = TYPE.OF
+        if isinstance(ITEM, lltype.Ptr) and ITEM.TO._gckind == 'gc':
+            null = lltype.nullptr(ITEM.TO)
+            for i in range(p._obj.getlength()):
+                p[i] = null
+        elif isinstance(ITEM, lltype.ContainerType):
+            for i in range(p._obj.getlength()):
+                zero_gc_pointers_inside(p[i], ITEM)
+
 ########## weakrefs ##########
 # framework: weakref objects are small structures containing only an address
 

Modified: pypy/dist/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/dist/pypy/rpython/memory/gcwrapper.py	Wed Oct 24 11:39:27 2007
@@ -51,7 +51,10 @@
         if flavor == 'gc':
             typeid = self.get_type_id(TYPE)
             addr = self.gc.malloc(typeid, n, zero=zero)
-            return llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
+            result = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
+            if self.gc.needs_zero_gc_pointers:
+                gctypelayout.zero_gc_pointers(result)
+            return result
         else:
             return lltype.malloc(TYPE, n, flavor=flavor, zero=zero)
 



More information about the Pypy-commit mailing list