[pypy-svn] r51734 - in pypy/branch/unified-rtti/pypy/rpython/memory/gctransform: . test

arigo at codespeak.net arigo at codespeak.net
Thu Feb 21 17:01:28 CET 2008


Author: arigo
Date: Thu Feb 21 17:01:28 2008
New Revision: 51734

Modified:
   pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/boehm.py
   pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/test/test_boehm.py
Log:
Fix the Boehm transformer.


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	Thu Feb 21 17:01:28 2008
@@ -9,10 +9,12 @@
 
 class BoehmGCTransformer(GCTransformer):
     FINALIZER_PTR = lltype.Ptr(lltype.FuncType([llmemory.Address], lltype.Void))
+    TYPEINFO = lltype.Struct('typeinfo')   # empty
 
     def __init__(self, translator, inline=False):
         super(BoehmGCTransformer, self).__init__(translator, inline=inline)
         self.finalizer_funcptrs = {}
+        self.rtticache = {}
 
         atomic_mh = mallocHelpers()
         atomic_mh.allocate = lambda size: llop.boehm_malloc_atomic(llmemory.Address, size)
@@ -43,6 +45,10 @@
             self.mixlevelannotator.finish()   # for now
             self.mixlevelannotator.backend_optimize()
 
+    def convert_rtti(self, rtti):
+        # no information in the TYPEINFO
+        return lltype.malloc(self.TYPEINFO, immortal=True)
+
     def push_alive_nopyobj(self, var, llops):
         pass
 
@@ -84,12 +90,11 @@
         if TYPE in self.finalizer_funcptrs:
             return self.finalizer_funcptrs[TYPE]
 
-        rtti = get_rtti(TYPE)
-        if rtti is not None and hasattr(rtti._obj, 'destructor_funcptr'):
-            destrptr = rtti._obj.destructor_funcptr
+        rtti = lltype.getRuntimeTypeInfo(TYPE, self.rtticache)
+        destrptr = rtti.destructor_funcptr
+        if destrptr is not None:
             DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
         else:
-            destrptr = None
             DESTR_ARG = None
 
         if type_contains_pyobjs(TYPE):

Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/test/test_boehm.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/test/test_boehm.py	(original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/test/test_boehm.py	Thu Feb 21 17:01:28 2008
@@ -40,36 +40,28 @@
     assert f is not None
 
 def test_boehm_finalizer___del__():
-    S = lltype.GcStruct("S", ('x', lltype.Signed))
+    pinf = lltype.malloc(lltype.RuntimeTypeInfo, immortal=True)
+    S = lltype.GcStruct("S", ('x', lltype.Signed), runtime_type_info=pinf)
     def f(s):
         s.x = 1
-    def type_info_S(p):
-        return lltype.getRuntimeTypeInfo(S)
-    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
-                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
-                            "type_info_S",
-                            _callable=type_info_S)
     dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                             lltype.Void),
                             "destructor_funcptr",
                             _callable=f)
-    pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
+    pinf.destructor_funcptr = dp
     f, t = make_boehm_finalizer(S)
     assert f is not None
 
 def test_boehm_finalizer_nomix___del___and_pyobj():
-    S = lltype.GcStruct("S", ('x', lltype.Signed), ('y', lltype.Ptr(lltype.PyObject)))
+    pinf = lltype.malloc(lltype.RuntimeTypeInfo, immortal=True)
+    S = lltype.GcStruct("S", ('x', lltype.Signed),
+                             ('y', lltype.Ptr(lltype.PyObject)),
+                        runtime_type_info=pinf)
     def f(s):
         s.x = 1
-    def type_info_S(p):
-        return lltype.getRuntimeTypeInfo(S)
-    qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
-                                            lltype.Ptr(lltype.RuntimeTypeInfo)),
-                            "type_info_S",
-                            _callable=type_info_S)
     dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)],
                                             lltype.Void),
                             "destructor_funcptr",
                             _callable=f)
-    pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp)
+    pinf.destructor_funcptr = dp
     py.test.raises(Exception, "make_boehm_finalizer(S)")



More information about the Pypy-commit mailing list