[pypy-svn] r28191 - in pypy/dist/pypy/rpython: . ootypesystem test

antocuni at codespeak.net antocuni at codespeak.net
Sat Jun 3 19:38:31 CEST 2006


Author: antocuni
Date: Sat Jun  3 19:38:30 2006
New Revision: 28191

Modified:
   pypy/dist/pypy/rpython/callparse.py
   pypy/dist/pypy/rpython/ootypesystem/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
(antocuni, nik, arigo)

Fixed a cornercase for ootypesytem, where methods defined in
superclass are only called in subclasses.



Modified: pypy/dist/pypy/rpython/callparse.py
==============================================================================
--- pypy/dist/pypy/rpython/callparse.py	(original)
+++ pypy/dist/pypy/rpython/callparse.py	Sat Jun  3 19:38:30 2006
@@ -26,7 +26,7 @@
             getrinputs(rtyper, graph),
             getrresult(rtyper, graph))
 
-def callparse(rtyper, graph, hop, opname, is_method=False):
+def callparse(rtyper, graph, hop, opname, r_self=None):
     """Parse the arguments of 'hop' when calling the given 'graph'.
     """
     rinputs = getrinputs(rtyper, graph)
@@ -34,7 +34,11 @@
     def args_h(start):
         return [VarHolder(i, hop.args_s[i])
                         for i in range(start, hop.nb_args)]
-    start = 1 - is_method
+    if r_self is None:
+        start = 1
+    else:
+        start = 0
+        rinputs[0] = r_self
     if opname == "simple_call":
         arguments =  Arguments(space, args_h(start))
     elif opname == "call_args":

Modified: pypy/dist/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py	Sat Jun  3 19:38:30 2006
@@ -123,7 +123,7 @@
         anygraph = row_of_graphs.itervalues().next()  # pick any witness
         hop2 = self.add_instance_arg_to_hop(hop, opname == "call_args")
         vlist = callparse.callparse(self.rtyper, anygraph, hop2, opname,
-                is_method=True)
+                                    r_self = self.r_im_self)
         rresult = callparse.getrresult(self.rtyper, anygraph)
         hop.exception_is_here()
         mangled = mangle(self.methodname)

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Sat Jun  3 19:38:30 2006
@@ -31,6 +31,7 @@
 class MySubclassWithoutMethods(MyBase):
     pass
 
+
 class Freezing:
     def _freeze_(self):
         return True
@@ -141,11 +142,36 @@
         assert self.interpret(f, [42]) == 42
 
     def test_class_method_inherited(self):
-        def f(a):
-            instance = MySubclassWithoutMethods()
-            instance.z = a
-            return instance.m(a)
-        assert self.interpret(f, [42]) == 84
+        # The strange names for this test are taken from richards,
+        # where the problem originally arose.
+        class Task:
+            def waitTask(self, a):
+                return a+1
+
+            def fn(self, a):
+                raise NotImplementedError
+
+            def runTask(self, a):
+                return self.fn(a)
+
+        class HandlerTask(Task):
+            def fn(self, a):
+                return self.waitTask(a)+2
+
+        class DeviceTask(Task):
+            def fn(self, a):
+                return self.waitTask(a)+3
+        
+        def f(a, b):
+            if b:
+                inst = HandlerTask()
+            else:
+                inst = DeviceTask()
+
+            return inst.runTask(a)
+                
+        assert self.interpret(f, [42, True]) == 45
+        assert self.interpret(f, [42, False]) == 46
 
     def test_freezing(self):
         fr1 = Freezing()



More information about the Pypy-commit mailing list