From: Stefan Behnel Date: Thu, 8 May 2008 06:25:47 +0000 (+0200) Subject: fix for negative compile time int constants X-Git-Tag: 0.9.8rc1~56 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d4d5dc497349bf6ba8b0daec6b6a23d2220e20b6;p=cython.git fix for negative compile time int constants --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 491d0b8b..25140ecb 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2741,7 +2741,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 = -int(operand.value)) + return IntNode(pos = operand.pos, value = str(-int(operand.value, 0))) 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, @@ -4135,4 +4135,4 @@ static inline PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { } } ""","" -] \ No newline at end of file +] diff --git a/tests/run/ct_DEF.pyx b/tests/run/ct_DEF.pyx index d85cfb06..b7edc4ce 100644 --- a/tests/run/ct_DEF.pyx +++ b/tests/run/ct_DEF.pyx @@ -1,12 +1,16 @@ __doc__ = """ >>> c() 120 + >>> i0() == -1 + True >>> i1() == 42 True >>> i2() == 0x42 True >>> i3() == 042 True + >>> i4() == -0x42 + True >>> l() 666 >>> f() @@ -27,9 +31,11 @@ DEF TUPLE = (1, 2, "buckle my shoe") DEF TRUE_FALSE = (True, False) DEF CHAR = c'x' +DEF INT0 = -1 DEF INT1 = 42 DEF INT2 = 0x42 DEF INT3 = 042 +DEF INT4 = -0x42 DEF LONG = 666L DEF FLOAT = 12.5 DEF STR = "spam" @@ -43,6 +49,11 @@ def c(): c = CHAR return c +def i0(): + cdef int i + i = INT0 + return i + def i1(): cdef int i i = INT1 @@ -58,6 +69,11 @@ def i3(): i = INT3 return i +def i4(): + cdef int i + i = INT4 + return i + def l(): cdef long l l = LONG