[pypy-svn] r42162 - in pypy/dist/pypy/annotation: . test

afa at codespeak.net afa at codespeak.net
Thu Apr 19 11:05:52 CEST 2007


Author: afa
Date: Thu Apr 19 11:05:51 2007
New Revision: 42162

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
Allow annotation of large unsigned constants like 0xF0000000


Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Thu Apr 19 11:05:51 2007
@@ -316,6 +316,8 @@
             result = SomeBool()
         elif tp is int:
             result = SomeInteger(nonneg = x>=0)
+        elif tp is long and 0 <= x <= (sys.maxint * 2 + 1):
+            result = SomeInteger(unsigned = True)
         elif issubclass(tp, str): # py.lib uses annotated str subclasses
             if len(x) == 1:
                 result = SomeChar()

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	Thu Apr 19 11:05:51 2007
@@ -1,6 +1,7 @@
 
 import autopath
 import py.test
+import sys
 from pypy import conftest
 from pypy.tool.udir import udir
 
@@ -824,6 +825,14 @@
         s = a.build_types(f, [r_uint])
         assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
 
+    def test_large_unsigned(self):
+        large_constant = sys.maxint * 2 + 1 # 0xFFFFFFFF on 32-bit platforms
+        def f():
+            return large_constant
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [])
+        assert s.knowntype == r_uint
+
     def test_pbc_getattr(self):
         class C:
             def __init__(self, v1, v2):



More information about the Pypy-commit mailing list