Commit 371b92f2 authored by Stefan Behnel's avatar Stefan Behnel

merged in latest cython-devel

parents 0ca78ef8 d8952731
...@@ -537,7 +537,7 @@ class GlobalState(object): ...@@ -537,7 +537,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:
...@@ -717,6 +717,8 @@ class GlobalState(object): ...@@ -717,6 +717,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']
......
...@@ -1308,7 +1308,7 @@ def p_for_bounds(s, allow_testlist=True): ...@@ -1308,7 +1308,7 @@ def p_for_bounds(s, allow_testlist=True):
s.next() s.next()
iterator = p_for_iterator(s, allow_testlist) iterator = p_for_iterator(s, allow_testlist)
return { 'target': target, 'iterator': iterator } return { 'target': target, 'iterator': iterator }
else: elif not s.in_python_file:
if s.sy == 'from': if s.sy == 'from':
s.next() s.next()
bound1 = p_bit_expr(s) bound1 = p_bit_expr(s)
...@@ -1340,6 +1340,9 @@ def p_for_bounds(s, allow_testlist=True): ...@@ -1340,6 +1340,9 @@ def p_for_bounds(s, allow_testlist=True):
'relation2': rel2, 'relation2': rel2,
'bound2': bound2, 'bound2': bound2,
'step': step } 'step': step }
else:
s.expect('in')
return {}
def p_for_from_relation(s): def p_for_from_relation(s):
if s.sy in inequality_relations: if s.sy in inequality_relations:
...@@ -1641,7 +1644,7 @@ def p_statement(s, ctx, first_statement = 0): ...@@ -1641,7 +1644,7 @@ def p_statement(s, ctx, first_statement = 0):
return node return node
else: else:
if ctx.api: if ctx.api:
error(s.pos, "'api' not allowed with this statement") s.error("'api' not allowed with this statement")
elif s.sy == 'def': elif s.sy == 'def':
# def statements aren't allowed in pxd files, except # def statements aren't allowed in pxd files, except
# as part of a cdef class # as part of a cdef class
...@@ -1704,7 +1707,7 @@ def p_suite(s, ctx = Ctx(), with_doc = 0, with_pseudo_doc = 0): ...@@ -1704,7 +1707,7 @@ def p_suite(s, ctx = Ctx(), with_doc = 0, with_pseudo_doc = 0):
s.expect_dedent() s.expect_dedent()
else: else:
if ctx.api: if ctx.api:
error(s.pos, "'api' not allowed with this statement") s.error("'api' not allowed with this statement")
if ctx.level in ('module', 'class', 'function', 'other'): if ctx.level in ('module', 'class', 'function', 'other'):
body = p_simple_statement_list(s, ctx) body = p_simple_statement_list(s, ctx)
else: else:
...@@ -2428,7 +2431,7 @@ def p_c_func_or_var_declaration(s, pos, ctx): ...@@ -2428,7 +2431,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
overridable = ctx.overridable) overridable = ctx.overridable)
else: else:
#if api: #if api:
# error(s.pos, "'api' not allowed with variable declaration") # s.error("'api' not allowed with variable declaration")
declarators = [declarator] declarators = [declarator]
while s.sy == ',': while s.sy == ',':
s.next() s.next()
......
...@@ -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