[pypy-svn] r51815 - in pypy/branch/unified-rtti/pypy: rpython/memory/gc rpython/memory/gctransform translator/c

arigo at codespeak.net arigo at codespeak.net
Sat Feb 23 10:53:41 CET 2008


Author: arigo
Date: Sat Feb 23 10:53:39 2008
New Revision: 51815

Modified:
   pypy/branch/unified-rtti/pypy/rpython/memory/gc/base.py
   pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py
   pypy/branch/unified-rtti/pypy/translator/c/gc.py
   pypy/branch/unified-rtti/pypy/translator/c/node.py
Log:
* Type fixes.
* Database ordering issues, as usual.


Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gc/base.py	Sat Feb 23 10:53:39 2008
@@ -224,8 +224,9 @@
             if not target:
                 freeentry = i
             else:
-                ll_assert(self.get_type_id(llmemory.cast_ptr_to_adr(target))
-                             > 0, "bogus weakref in compute_id()")
+                targetadr = llmemory.cast_ptr_to_adr(target)
+                ll_assert(bool(self.get_type_id(targetadr)),
+                          "bogus weakref in compute_id()")
                 # record this entry in the dict
                 adr = llmemory.cast_ptr_to_adr(target)
                 self.object_id_dict[adr] = i

Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py	Sat Feb 23 10:53:39 2008
@@ -233,7 +233,7 @@
             s_True  = annmodel.SomeBool(); s_True .const = True
             self.malloc_fast_ptr = getfn(
                 malloc_fast,
-                [s_gc, annmodel.SomeInteger(nonneg=True),
+                [s_gc, annmodel.SomePtr(RTTIPTR),
                  annmodel.SomeInteger(nonneg=True),
                  s_True, s_False,
                  s_False], s_gcref,
@@ -284,13 +284,13 @@
             self.coalloc_clear_ptr = getfn(
                 GCClass.coalloc_fixedsize_clear.im_func,
                 [s_gc, annmodel.SomeAddress(),
-                 annmodel.SomeInteger(nonneg=True),
+                 annmodel.SomePtr(RTTIPTR),
                  annmodel.SomeInteger(nonneg=True)],
                 s_gcref, inline=True)
             self.coalloc_varsize_clear_ptr = getfn(
                 GCClass.coalloc_varsize_clear.im_func,
-                [s_gc, annmodel.SomeAddress()] +
-                [annmodel.SomeInteger(nonneg=True) for i in range(5)],
+                [s_gc, annmodel.SomeAddress(), annmodel.SomePtr(RTTIPTR)] +
+                [annmodel.SomeInteger(nonneg=True) for i in range(4)],
                 s_gcref, inline=True)
         else:
             self.coalloc_clear_ptr = self.coalloc_varsize_clear_ptr = None
@@ -329,9 +329,23 @@
     def consider_constant(self, TYPE, value):
         self.layoutbuilder.consider_constant(TYPE, value, self.gcdata.gc)
 
-    def initialize_typeinfo(self, typeinfo, rtti, TYPE):
-        raise Exception("for now, the layoutbuilder should have found "
-                        "all possible GC types - got %r" % (TYPE,))
+    def convert_rtti(self, rtti):
+        # xxx a bit indirect
+        rtti = rtti._as_ptr()
+        try:
+            return self.gcheaderbuilder.typeinfo_from_rtti(rtti)
+        except KeyError:
+            try:
+                TYPE = lltype.getGcTypeForRtti(rtti)
+            except ValueError:
+                # ignore rtti's not attached anywhere, e.g. in the
+                # vtable of raw-flavored RPython classes
+                typeinfo = self.gcheaderbuilder.new_typeinfo(rtti)
+            else:
+                rtti1 = self.layoutbuilder.get_type_id(TYPE)
+                assert rtti1 == rtti
+                typeinfo = self.gcheaderbuilder.typeinfo_from_rtti(rtti)
+            return typeinfo
 
     #def get_type_id(self, TYPE):
     #    this method is attached to the instance and redirects to

Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/transform.py	Sat Feb 23 10:53:39 2008
@@ -481,6 +481,8 @@
         # A bit of manual inlining...
         hdraddr = objaddr - gc_header_offset
         rtti = llmemory.cast_adr_to_ptr(hdraddr, HDRPTR).typeptr
+        if lltype.typeOf(rtti) is llmemory.Address:
+            rtti = llmemory.cast_adr_to_ptr(rtti, RTTIPTR)
         ll_assert(bool(rtti), "NULL rtti")
         return rtti
     gh.gc_runtime_type_info = gc_runtime_type_info
@@ -491,6 +493,8 @@
         # A bit of manual inlining...
         hdraddr = objaddr - gc_header_offset
         rtti = llmemory.cast_adr_to_ptr(hdraddr, HDRPTR).typeptr
+        if lltype.typeOf(rtti) is llmemory.Address:
+            rtti = llmemory.cast_adr_to_ptr(rtti, RTTIPTR)
         ll_assert(bool(rtti), "NULL rtti")
         return gcheaderbuilder.cast_rtti_to_typeinfo(rtti)
     gh.typeof = typeof
@@ -679,7 +683,10 @@
             p = value._as_ptr()
             if not self.gcheaderbuilder.get_header(p):
                 hdr = self.gcheaderbuilder.new_header(p)
-                hdr.typeptr = self.gcheaderbuilder.getRtti(TYPE)
+                rtti = self.gcheaderbuilder.getRtti(TYPE)
+                if lltype.typeOf(hdr).TO.typeptr is llmemory.Address:
+                    rtti = llmemory.cast_ptr_to_adr(rtti)
+                hdr.typeptr = rtti
                 self.initialize_constant_header(hdr, TYPE, value)
 
     def initialize_constant_header(self, hdr, TYPE, value):

Modified: pypy/branch/unified-rtti/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/gc.py	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/gc.py	Sat Feb 23 10:53:39 2008
@@ -42,6 +42,23 @@
     def array_gcheader_initdata(self, defnode):
         return self.common_gcheader_initdata(defnode)
 
+    def enum_gcheader_dependencies(self, TYPE):
+        if TYPE._gckind != 'gc':
+            return []
+        # make sure that the rtti object of the TYPE is seen by the
+        # database early, i.e. before finish_helpers() on the
+        # gctransformer.  In particular, this should follow the
+        # ll_finalizer helper function stored in the typeinfo.
+        gct = self.db.gctransformer
+        rtti = gct.gcheaderbuilder.getRtti(TYPE)
+        result = [rtti]
+        # The ll_finalizer helpers are delayed func pointers computed
+        # only in finish_helpers().  But we need to follow the regular
+        # destructor before finish_helpers(), in case it uses new types.
+        if rtti is not None and rtti.destructor_funcptr is not None:
+            result.append(rtti.destructor_funcptr)
+        return result
+
     def struct_after_definition(self, defnode):
         return []
 

Modified: pypy/branch/unified-rtti/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/node.py	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/node.py	Sat Feb 23 10:53:39 2008
@@ -68,6 +68,8 @@
         db = self.db
         STRUCT = self.STRUCT
         varlength = self.varlength
+        for ptr in db.gcpolicy.enum_gcheader_dependencies(STRUCT):
+            db.get(ptr)
         if needs_gcheader(self.STRUCT):
             for fname, T in db.gcpolicy.struct_gcheader_definition(self):
                 self.fields.append((fname, db.gettype(T, who_asks=self)))
@@ -196,6 +198,8 @@
             return      # setup() was already called, likely by __init__
         db = self.db
         ARRAY = self.ARRAY
+        for ptr in db.gcpolicy.enum_gcheader_dependencies(ARRAY):
+            db.get(ptr)
         if needs_gcheader(ARRAY):
             for fname, T in db.gcpolicy.array_gcheader_definition(self):
                 self.gcfields.append((fname, db.gettype(T, who_asks=self)))



More information about the Pypy-commit mailing list