[pypy-svn] r20518 - in pypy/branch/somepbc-refactoring/pypy: annotation rpython/test

arigo at codespeak.net arigo at codespeak.net
Thu Dec 1 18:23:30 CET 2005


Author: arigo
Date: Thu Dec  1 18:23:29 2005
New Revision: 20518

Modified:
   pypy/branch/somepbc-refactoring/pypy/annotation/description.py
   pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rdict.py
Log:
(mwh, pedronis, arigo)

Test and fix for a rather obscure bug, caused by a FunctionDesc
being first built at just the wrong time when the policy is not
the expected one.  Fixed by capturing the specializer from the
current policy only when specialize() is first called.



Modified: pypy/branch/somepbc-refactoring/pypy/annotation/description.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/description.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/description.py	Thu Dec  1 18:23:29 2005
@@ -145,10 +145,6 @@
             signature = cpython_code_signature(pyobj.func_code)
         if defaults is None:
             defaults = pyobj.func_defaults
-        if specializer is None:
-            tag = getattr(pyobj, '_annspecialcase_', None)
-            policy = bookkeeper.annotator.policy
-            specializer = policy.get_specializer(tag)
         self.name = name
         self.signature = signature
         self.defaults = defaults or ()
@@ -194,6 +190,12 @@
         return inputcells
 
     def specialize(self, inputcells):
+        if self.specializer is None:
+            # get the specializer based on the tag of the 'pyobj'
+            # (if any), according to the current policy
+            tag = getattr(self.pyobj, '_annspecialcase_', None)
+            policy = self.bookkeeper.annotator.policy
+            self.specializer = policy.get_specializer(tag)
         return self.specializer(self, inputcells)
 
     def pycall(self, schedule, args, s_previous_result):

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rdict.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rdict.py	Thu Dec  1 18:23:29 2005
@@ -515,3 +515,14 @@
 
     res = interpret(f, [])
     assert res == 2    
+
+def test_specific_obscure_bug():
+    class A: pass
+    class B: pass   # unrelated kinds of instances
+    def f():
+        lst = [A()]
+        res1 = A() in lst
+        d2 = {B(): None, B(): None}
+        return res1+len(d2)
+    res = interpret(f, [])
+    assert res == 2



More information about the Pypy-commit mailing list