From 3173319b237600322a01fb3ec32ec2fb0f740b9a Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Mon, 24 May 2010 16:03:23 -0700 Subject: [PATCH] Allow longer int literals on 64-bit machines. --- Cython/Compiler/Code.py | 4 +++- tests/run/int_literals.pyx | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index bc20ec4a..704e6d61 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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'] diff --git a/tests/run/int_literals.pyx b/tests/run/int_literals.pyx index 0654f931..6dca2dd3 100644 --- a/tests/run/int_literals.pyx +++ b/tests/run/int_literals.pyx @@ -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 -- 2.26.2