From d1170ab8540f6d7f2fdbc4862fac01bad5aaa263 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 12 Nov 2010 10:41:59 +0100 Subject: [PATCH] fix compiler crash in Py3 on negative Py2 octal integer literals (e.g. -012) --- Cython/Compiler/ExprNodes.py | 2 +- tests/run/int_literals.pyx | 41 +++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 94dca417..4204785f 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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, diff --git a/tests/run/int_literals.pyx b/tests/run/int_literals.pyx index 2ff8351b..b5aa67cb 100644 --- a/tests/run/int_literals.pyx +++ b/tests/run/int_literals.pyx @@ -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 -- 2.26.2