Commit 3173319b authored by Robert Bradshaw's avatar Robert Bradshaw

Allow longer int literals on 64-bit machines.

parent 9d5aaeab
...@@ -542,7 +542,7 @@ class GlobalState(object): ...@@ -542,7 +542,7 @@ class GlobalState(object):
# constant handling at code generation time # constant handling at code generation time
def get_int_const(self, str_value, longness=False): def get_int_const(self, str_value, longness=False):
longness = bool(longness or Utils.long_literal(str_value)) longness = bool(longness)
try: try:
c = self.int_const_index[(str_value, longness)] c = self.int_const_index[(str_value, longness)]
except KeyError: except KeyError:
...@@ -722,6 +722,8 @@ class GlobalState(object): ...@@ -722,6 +722,8 @@ class GlobalState(object):
decls_writer.putln("static PyObject *%s;" % cname) decls_writer.putln("static PyObject *%s;" % cname)
if longness: if longness:
function = '%s = PyLong_FromString((char *)"%s", 0, 0); %s;' function = '%s = PyLong_FromString((char *)"%s", 0, 0); %s;'
elif Utils.long_literal(value):
function = '%s = PyInt_FromString((char *)"%s", 0, 0); %s;'
else: else:
function = "%s = PyInt_FromLong(%s); %s;" function = "%s = PyInt_FromLong(%s); %s;"
init_globals = self.parts['init_globals'] init_globals = self.parts['init_globals']
......
...@@ -25,3 +25,13 @@ def c_longs(): ...@@ -25,3 +25,13 @@ def c_longs():
def py_longs(): def py_longs():
return 1, 1L, 100000000000000000000000000000000, -100000000000000000000000000000000 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment