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

arigo at codespeak.net arigo at codespeak.net
Sat Feb 23 11:28:01 CET 2008


Author: arigo
Date: Sat Feb 23 11:28:01 2008
New Revision: 51818

Modified:
   pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py
   pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/unified-rtti/pypy/translator/c/database.py
   pypy/branch/unified-rtti/pypy/translator/c/gc.py
   pypy/branch/unified-rtti/pypy/translator/c/node.py
   pypy/branch/unified-rtti/pypy/translator/c/test/test_newgc.py
Log:
Yay!  Kill an obscure hack that was failing anyway.


Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py	(original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py	Sat Feb 23 11:28:01 2008
@@ -182,3 +182,7 @@
         plink = lltype.malloc(WEAKLINK, immortal=True)
         plink[0] = llmemory.cast_ptr_to_adr(targetptr)
         return plink
+
+BoehmGCTransformer.WEAKREFTYPE = WEAKLINK
+BoehmGCTransformer.convert_weakref_to = staticmethod(convert_weakref_to)
+

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 11:28:01 2008
@@ -13,7 +13,7 @@
 from pypy.rpython import annlowlevel
 from pypy.rpython.rbuiltin import gen_cast
 from pypy.rpython.memory.gctypelayout import ll_weakref_deref, WEAKREF
-from pypy.rpython.memory.gctypelayout import convert_weakref_to, WEAKREFPTR
+from pypy.rpython.memory.gctypelayout import WEAKREFPTR
 from pypy.rpython.memory.gctransform.log import log
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rpython.lltypesystem.lloperation import llop
@@ -97,6 +97,9 @@
 
     TYPEINFO = gctypelayout.GCData.TYPE_INFO
 
+    WEAKREFTYPE = WEAKREF
+    convert_weakref_to = staticmethod(gctypelayout.convert_weakref_to)
+
     def __init__(self, translator):
         from pypy.rpython.memory.gc.base import choose_gc_from_config
         if hasattr(self, 'GC_PARAMS'):

Modified: pypy/branch/unified-rtti/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/database.py	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/database.py	Sat Feb 23 11:28:01 2008
@@ -1,9 +1,9 @@
 from pypy.rpython.lltypesystem.lltype import \
-     Primitive, Ptr, typeOf, RuntimeTypeInfo, RuntimeTypeInfoType, \
+     Primitive, Ptr, typeOf, RuntimeTypeInfoType, \
      Struct, Array, FuncType, PyObject, Void, \
      ContainerType, OpaqueType, FixedSizeArray, _uninitialized
 from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.lltypesystem.llmemory import Address, WeakRef, _WeakRefType
+from pypy.rpython.lltypesystem.llmemory import Address, _WeakRefType
 from pypy.rpython.lltypesystem.rffi import CConstant
 from pypy.tool.sourcetools import valid_identifier
 from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
@@ -85,14 +85,12 @@
                     node = ArrayDefNode(self, T, varlength)
             elif isinstance(T, OpaqueType) and T.hints.get("render_structure", False):
                 node = ExtTypeOpaqueDefNode(self, T)
-            elif T == WeakRef:
-                REALT = self.gcpolicy.get_real_weakref_type()
-                node = self.gettypedefnode(REALT)
-            elif T == RuntimeTypeInfo:
-                REALT = self.gcpolicy.get_real_rtti_type()
-                node = self.gettypedefnode(REALT)
             else:
-                raise NoCorrespondingNode("don't know about %r" % (T,))
+                REALT = self.gcpolicy.convert_type(T)
+                if REALT != T:
+                    node = self.gettypedefnode(REALT)
+                else:
+                    raise NoCorrespondingNode("don't know about %r" % (T,))
             self.structdefnodes[key] = node
             self.pendingsetupnodes.append(node)
         return node
@@ -131,9 +129,7 @@
             argtypes = ', '.join(argtypes) or 'void'
             return resulttype.replace('@', '(@)(%s)' % argtypes)
         elif isinstance(T, OpaqueType):
-            if T == RuntimeTypeInfo:
-                return  self.gcpolicy.rtti_type()
-            elif T.hints.get("render_structure", False):
+            if T.hints.get("render_structure", False):
                 node = self.gettypedefnode(T, varlength=varlength)
                 if who_asks is not None:
                     who_asks.dependencies[node] = True
@@ -147,10 +143,12 @@
         else:
             raise Exception("don't know about type %r" % (T,))
 
-    def getcontainernode(self, container, _dont_write_c_code=True, **buildkwds):
+    def getcontainernode(self, container, **buildkwds):
         try:
             node = self.containernodes[container]
         except KeyError:
+            originalcontainer = container
+            container = self.gcpolicy.convert_prebuilt_object(container)
             T = typeOf(container)
             if isinstance(T, (lltype.Array, lltype.Struct)):
                 if self.gctransformer is not None:
@@ -158,10 +156,7 @@
             nodefactory = ContainerNodeFactory[T.__class__]
             node = nodefactory(self, T, container, **buildkwds)
             self.containernodes[container] = node
-            # _dont_write_c_code should only be False for a hack in
-            # weakrefnode_factory()
-            if not _dont_write_c_code:
-                return node
+            self.containernodes[originalcontainer] = node
             kind = getattr(node, 'nodekind', '?')
             self.containerstats[kind] = self.containerstats.get(kind, 0) + 1
             self.containerlist.append(node)

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 11:28:01 2008
@@ -74,12 +74,24 @@
     def gc_startup_code(self):
         return []
 
-    # for rtti node
-    def get_real_rtti_type(self):
-        return self.db.gctransformer.gcheaderbuilder.TYPEINFO
+    # support for mapping weakref and rtti objects and types
 
-    def convert_rtti(self, obj):
-        return self.db.gctransformer.convert_rtti(obj)
+    def convert_type(self, TYPE):
+        if TYPE == lltype.RuntimeTypeInfo:
+            return self.db.gctransformer.gcheaderbuilder.TYPEINFO
+        elif TYPE == llmemory.WeakRef:
+            return self.db.gctransformer.WEAKREFTYPE
+        else:
+            return TYPE
+
+    def convert_prebuilt_object(self, obj):
+        if isinstance(obj, lltype._rtti):
+            return self.db.gctransformer.convert_rtti(obj)._obj
+        elif isinstance(obj, llmemory._wref):
+            ptarget = obj._dereference()
+            return self.db.gctransformer.convert_weakref_to(ptarget)._obj
+        else:
+            return obj
 
     def OP_GC_PUSH_ALIVE_PYOBJ(self, funcgen, op):
         expr = funcgen.expr(op.args[0])
@@ -130,12 +142,6 @@
             yield 'GC_all_interior_pointers = 0;'
         yield 'boehm_gc_startup_code();'
 
-    def get_real_weakref_type(self):
-        return boehm.WEAKLINK
-
-    def convert_weakref_to(self, ptarget):
-        return boehm.convert_weakref_to(ptarget)
-
     def OP_GC__COLLECT(self, funcgen, op):
         return 'GC_gcollect();'
 
@@ -165,12 +171,6 @@
         fnptr = self.db.gctransformer.frameworkgc_setup_ptr.value
         yield '%s();' % (self.db.get(fnptr),)
 
-    def get_real_weakref_type(self):
-        return framework.WEAKREF
-
-    def convert_weakref_to(self, ptarget):
-        return framework.convert_weakref_to(ptarget)
-
     def OP_GC_RELOAD_POSSIBLY_MOVED(self, funcgen, op):
         args = [funcgen.expr(v) for v in op.args]
         return '%s = %s; /* for moving GCs */' % (args[1], args[0])

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 11:28:01 2008
@@ -875,34 +875,6 @@
     def implementation(self):
         return []
 
-def weakrefnode_factory(db, T, obj):
-    assert isinstance(obj, llmemory._wref)
-    ptarget = obj._dereference()
-    wrapper = db.gcpolicy.convert_weakref_to(ptarget)
-    container = wrapper._obj
-    obj._converted_weakref = container     # hack for genllvm :-/
-    return db.getcontainernode(container, _dont_write_c_code=False)
-
-class RttiNode(ContainerNode):
-    nodekind = 'rtti'
-
-    def __init__(self, db, T, obj):
-        assert isinstance(obj, lltype._rtti)
-        wrapper = db.gcpolicy.convert_rtti(obj)
-        self.realobj = wrapper._obj
-        self.realnode = db.getcontainernode(self.realobj,
-                                            _dont_write_c_code=False)
-        ContainerNode.__init__(self, db, T, obj)
-
-    def basename(self):
-        return self.realnode.basename()
-
-    def enum_dependencies(self):
-        return self.realnode.enum_dependencies()
-
-    def initializationexpr(self, decoration=''):
-        return self.realnode.initializationexpr(decoration)
-
 
 ContainerNodeFactory = {
     Struct:       StructNode,
@@ -913,6 +885,4 @@
     FuncType:     FuncNode,
     OpaqueType:   opaquenode_factory,
     PyObjectType: PyObjectNode,
-    llmemory._WeakRefType: weakrefnode_factory,
-    lltype.RuntimeTypeInfoType: RttiNode,
     }

Modified: pypy/branch/unified-rtti/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/test/test_newgc.py	Sat Feb 23 11:28:01 2008
@@ -147,9 +147,8 @@
 
 def test_del_basic():
     for gcpolicy in ["ref"]: #, "framework"]:
-        S = lltype.GcStruct('S', ('x', lltype.Signed))
-        TRASH = lltype.GcStruct('TRASH', ('x', lltype.Signed))
-        lltype.attachRuntimeTypeInfo(S)
+        rtti = lltype.malloc(lltype.RuntimeTypeInfo, immortal=True)
+        S = lltype.GcStruct('S', ('x', lltype.Signed), runtime_type_info=rtti)
         GLOBAL = lltype.Struct('GLOBAL', ('x', lltype.Signed))
         glob = lltype.malloc(GLOBAL, immortal=True)
         def destructor(s):
@@ -170,7 +169,7 @@
         t.buildannotator().build_types(entrypoint, [int])
         rtyper = t.buildrtyper()
         destrptr = rtyper.annotate_helper_fn(destructor, [lltype.Ptr(S)])
-        rtyper.attachRuntimeTypeInfoFunc(S, type_info_S, destrptr=destrptr)
+        rtti.destructor_funcptr = destrptr
         rtyper.specialize()
         fn = compile_func(entrypoint, None, t, gcpolicy=gcpolicy)
 



More information about the Pypy-commit mailing list