Commit d1170ab8 authored by Stefan Behnel's avatar Stefan Behnel

fix compiler crash in Py3 on negative Py2 octal integer literals (e.g. -012)

parent 2546c8c5
......@@ -5005,7 +5005,7 @@ def unop_node(pos, operator, operand):
# Construct unnop node of appropriate class for
# given operator.
if isinstance(operand, IntNode) and operator == '-':
return IntNode(pos = operand.pos, value = str(-int(operand.value, 0)))
return IntNode(pos = operand.pos, value = str(-Utils.str_to_number(operand.value)))
elif isinstance(operand, UnopNode) and operand.operator == operator:
warning(pos, "Python has no increment/decrement operator: %s%sx = %s(%sx) = x" % ((operator,)*4), 5)
return unop_node_classes[operator](pos,
......
......@@ -59,50 +59,67 @@ def c_long_types():
def c_oct():
"""
>>> c_oct()
(1, 17, 63)
(1, -17, 63)
"""
cdef int a = 0o01
cdef int b = 0o21
cdef int b = -0o21
cdef int c = 0o77
return a,b,c
def c_oct_py2_legacy():
"""
>>> c_oct_py2_legacy()
(1, -17, 63)
"""
cdef int a = 001
cdef int b = -021
cdef int c = 077
return a,b,c
def py_oct():
"""
>>> py_oct()
(1, 17, 63)
(1, -17, 63)
"""
return 0o01, -0o21, 0o77
def py_oct_py2_legacy():
"""
>>> py_oct_py2_legacy()
(1, -17, 63)
"""
return 0o01, 0o21, 0o77
return 001, -021, 077
def c_hex():
"""
>>> c_hex()
(1, 33, 255)
(1, -33, 255)
"""
cdef int a = 0x01
cdef int b = 0x21
cdef int b = -0x21
cdef int c = 0xFF
return a,b,c
def py_hex():
"""
>>> py_hex()
(1, 33, 255)
(1, -33, 255)
"""
return 0x01, 0x21, 0xFF
return 0x01, -0x21, 0xFF
def c_bin():
"""
>>> c_bin()
(1, 2, 15)
(1, -2, 15)
"""
cdef int a = 0b01
cdef int b = 0b10
cdef int b = -0b10
cdef int c = 0b1111
return a,b,c
def py_bin():
"""
>>> py_bin()
(1, 2, 15)
(1, -2, 15)
"""
return 0b01, 0b10, 0b1111
return 0b01, -0b10, 0b1111
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