[pypy-svn] r37422 - in pypy/dist/pypy: annotation/test objspace/flow

arigo at codespeak.net arigo at codespeak.net
Sat Jan 27 11:49:14 CET 2007


Author: arigo
Date: Sat Jan 27 11:49:11 2007
New Revision: 37422

Modified:
   pypy/dist/pypy/annotation/test/test_annrpython.py
   pypy/dist/pypy/objspace/flow/objspace.py
Log:
- fix flow space crash when geninterp'ing: globals containing constants
  of type long have got very confused because of r37394.
- add a test that shows why r37394 was introduced in the first place.
- don't each the traceback in an except:reraise.


Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Sat Jan 27 11:49:11 2007
@@ -2578,6 +2578,21 @@
         s = a.build_types(fun, [bool])
         assert isinstance(s, annmodel.SomeBool)
 
+    def test_long_as_intermediate_value(self):
+        from sys import maxint
+        from pypy.rlib.rarithmetic import intmask
+        def fun(x):
+            if x > 0:
+                v = maxint
+            else:
+                v = -maxint
+            return intmask(v * 10)
+        P = policy.AnnotatorPolicy()
+        P.allow_someobjects = False
+        a = self.RPythonAnnotator(policy=P)
+        s = a.build_types(fun, [bool])
+        assert isinstance(s, annmodel.SomeInteger)
+
 def g(n):
     return [0,1,2,n]
 

Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/objspace.py	Sat Jan 27 11:49:11 2007
@@ -261,7 +261,9 @@
             ec.build_flow()
         except FlowingError, a:
             # attach additional source info to AnnotatorError
-            raise FlowingError(format_global_error(ec.graph, ec.crnt_offset, str(a)))
+            _, _, tb = sys.exc_info()
+            e = FlowingError(format_global_error(ec.graph, ec.crnt_offset, str(a)))
+            raise FlowingError, e, tb
         checkgraph(graph)
         return graph
 
@@ -575,6 +577,7 @@
 
     op = None
     skip = False
+    arithmetic = False
 
     if name.startswith('del') or name.startswith('set') or name.startswith('inplace_'):
         # skip potential mutators
@@ -593,6 +596,7 @@
             return s
     else:
         op = FunctionByName[name]
+        arithmetic = (name + '_ovf') in FunctionByName
 
     if not op:
         if not skip:
@@ -627,7 +631,9 @@
                     # result.  The result is probably meant to be sent to
                     # an intmask(), but the 'long' constant confuses the
                     # annotator a lot.
-                    if type(result) is not long:
+                    if arithmetic and type(result) is long:
+                        pass
+                    else:
                         try:
                             return self.wrap(result)
                         except WrapException:



More information about the Pypy-commit mailing list