[pypy-svn] r20969 - in pypy/dist/pypy/rpython: lltypesystem test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Dec 9 20:20:02 CET 2005


Author: cfbolz
Date: Fri Dec  9 20:20:01 2005
New Revision: 20969

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rclass.py
   pypy/dist/pypy/rpython/test/test_rclass.py
Log:
(johahn, cfbolz):

fixed argument types of the destructor function



Modified: pypy/dist/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rclass.py	Fri Dec  9 20:20:01 2005
@@ -339,10 +339,13 @@
             if (self.classdef is not None and
                 self.classdef.classdesc.lookup('__del__') is not None):
                 s_func = self.classdef.classdesc.s_read_attribute('__del__')
+                source_desc = self.classdef.classdesc.lookup('__del__')
+                source_classdef = source_desc.getclassdef(None)
+                source_repr = getinstancerepr(self.rtyper, source_classdef)
                 assert len(s_func.descriptions) == 1
                 funcdesc = s_func.descriptions.keys()[0]
                 graph = funcdesc.cachedgraph(None)
-                FUNCTYPE = FuncType([Ptr(self.object_type)], Void)
+                FUNCTYPE = FuncType([Ptr(source_repr.object_type)], Void)
                 destrptr = functionptr(FUNCTYPE, graph.name,
                                        graph=graph,
                                        _callable=graph.func)

Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py	Fri Dec  9 20:20:01 2005
@@ -387,5 +387,48 @@
     destrptr = RTTI._obj.destructor_funcptr
     assert destrptr is not None
     
-    
-
+   
+def test_del_inheritance():
+    class State:
+        pass
+    s = State()
+    s.a_dels = 0
+    s.b_dels = 0
+    class A(object):
+        def __del__(self):
+            s.a_dels += 1
+    class B(A):
+        def __del__(self):
+            s.b_dels += 1
+    class C(A):
+        pass
+    def f():
+        A()
+        B()
+        C()
+        A()
+        B()
+        C()
+        return s.a_dels * 10 + s.b_dels
+    res = f()
+    assert res == 42
+    t = TranslationContext()
+    t.buildannotator().build_types(f, [])
+    t.buildrtyper().specialize()
+    graph = graphof(t, f)
+    TYPEA = graph.startblock.operations[0].args[0].value
+    RTTIA = getRuntimeTypeInfo(TYPEA)
+    TYPEB = graph.startblock.operations[3].args[0].value
+    RTTIB = getRuntimeTypeInfo(TYPEB)
+    TYPEC = graph.startblock.operations[6].args[0].value
+    RTTIC = getRuntimeTypeInfo(TYPEC)
+    queryptra = RTTIA._obj.query_funcptr # should not raise
+    queryptrb = RTTIB._obj.query_funcptr # should not raise
+    queryptrc = RTTIC._obj.query_funcptr # should not raise
+    destrptra = RTTIA._obj.destructor_funcptr
+    destrptrb = RTTIB._obj.destructor_funcptr
+    destrptrc = RTTIC._obj.destructor_funcptr
+    assert destrptra == destrptrc
+    assert typeOf(destrptra).TO.ARGS[0] != typeOf(destrptrb).TO.ARGS[0]
+    assert destrptra is not None
+    assert destrptrb is not None



More information about the Pypy-commit mailing list