Allow longer int literals on 64-bit machines.
authorRobert Bradshaw <robertwb@math.washington.edu>
Mon, 24 May 2010 23:03:23 +0000 (16:03 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Mon, 24 May 2010 23:03:23 +0000 (16:03 -0700)
Cython/Compiler/Code.py
tests/run/int_literals.pyx

index bc20ec4ad4a2e26bd138dbfa9ce4593a80665d54..704e6d614fb3e36c0bbe646441c3f60a92f85ac9 100644 (file)
@@ -542,7 +542,7 @@ class GlobalState(object):
     # constant handling at code generation time
 
     def get_int_const(self, str_value, longness=False):
-        longness = bool(longness or Utils.long_literal(str_value))
+        longness = bool(longness)
         try:
             c = self.int_const_index[(str_value, longness)]
         except KeyError:
@@ -722,6 +722,8 @@ class GlobalState(object):
             decls_writer.putln("static PyObject *%s;" % cname)
             if longness:
                 function = '%s = PyLong_FromString((char *)"%s", 0, 0); %s;'
+            elif Utils.long_literal(value):
+                function = '%s = PyInt_FromString((char *)"%s", 0, 0); %s;'
             else:
                 function = "%s = PyInt_FromLong(%s); %s;"
             init_globals = self.parts['init_globals']
index 0654f931b22b58171ace35f18421a2930f76d782..6dca2dd3ed4c93e132936e8e4548d7258827fb5a 100644 (file)
@@ -25,3 +25,13 @@ def c_longs():
     
 def py_longs():
     return 1, 1L, 100000000000000000000000000000000, -100000000000000000000000000000000
+
+def large_literal():
+    """
+    >>> type(large_literal()) is int
+    True
+    """
+    if sys.version_info[0] >= 3 or sys.maxint > 0xFFFFFFFFFFFF:
+        return 0xFFFFFFFFFFFF
+    else:
+        return 0xFFFFFFF