[pypy-svn] r30339 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 21 23:13:07 CEST 2006


Author: antocuni
Date: Fri Jul 21 23:13:02 2006
New Revision: 30339

Modified:
   pypy/dist/pypy/translator/cli/class_.py
   pypy/dist/pypy/translator/cli/test/test_class.py
Log:
When using 'specialize:ctr_location' it could happen that INSTANCE
contains a method whose first argument is of a type not related to
INSTANCE. Don't render such a method, else peverify fails.



Modified: pypy/dist/pypy/translator/cli/class_.py
==============================================================================
--- pypy/dist/pypy/translator/cli/class_.py	(original)
+++ pypy/dist/pypy/translator/cli/class_.py	Fri Jul 21 23:13:02 2006
@@ -83,13 +83,13 @@
 
         for m_name, m_meth in self.INSTANCE._methods.iteritems():
             if hasattr(m_meth, 'graph'):
-                # if the first argument of the method is a strict subclass
-                # of this class, then this method is not really used by
-                # the class: don't render it, else there would be a type
-                # mismatch.
+                # if the first argument's type is not a supertype of
+                # this class it means that this method this method is
+                # not really used by the class: don't render it, else
+                # there would be a type mismatch.
                 args =  m_meth.graph.getargs()
                 SELF = args[0].concretetype
-                if SELF is not self.INSTANCE and ootype.isSubclass(SELF, self.INSTANCE):
+                if not ootype.isSubclass(self.INSTANCE, SELF):
                     continue
                 f = self.db.function_class(self.db, m_meth.graph, m_name, is_method = True)
                 f.render(ilasm)

Modified: pypy/dist/pypy/translator/cli/test/test_class.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_class.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_class.py	Fri Jul 21 23:13:02 2006
@@ -54,5 +54,16 @@
             return obj1.x + obj2.y
         assert self.interpret(fn, [1, 2]) == 3
 
+    def test_ctr_location(self):
+        class A:
+            _annspecialcase_ = "specialize:ctr_location"
+            def __init__(self, x):
+                self.x = x
+        def fn(x, y):
+            a = A(x)
+            b = A(y)
+            return a.x + b.x
+        assert self.interpret(fn, [1, 2]) == 3
+
 class TestCliSpecialCase(CliTest, BaseTestRspecialcase):
     pass



More information about the Pypy-commit mailing list