From: Stefan Behnel Date: Mon, 29 Apr 2013 17:28:46 +0000 (+0200) Subject: fix negative-index warning on empty slices X-Git-Tag: 0.19.1~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6075a3c6cd3441e2b37de543f0f6327e6d65abb3;p=platform%2Fupstream%2Fpython-cython.git fix negative-index warning on empty slices --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index d8f153b..42d067c 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -106,14 +106,14 @@ def check_negative_indices(*nodes): Used to find (potential) bugs inside of "wraparound=False" sections. """ for node in nodes: - if not isinstance(node.constant_result, (int, float, long)): + if (node is None + or not isinstance(node.constant_result, (int, float, long))): continue - if node.constant_result >= 0: - continue - warning(node.pos, - "the result of using negative indices inside of " - "code sections marked as 'wraparound=False' is " - "undefined", level=1) + if node.constant_result < 0: + warning(node.pos, + "the result of using negative indices inside of " + "code sections marked as 'wraparound=False' is " + "undefined", level=1) class ExprNode(Node): diff --git a/tests/errors/wraparound_warnings.pyx b/tests/errors/wraparound_warnings.pyx index 5d88bed..f8a166d 100644 --- a/tests/errors/wraparound_warnings.pyx +++ b/tests/errors/wraparound_warnings.pyx @@ -7,13 +7,18 @@ s = "abc" l = [1, 2, 3] def normal_wraparound(int i, bytes B not None, list L not None): + a = s[:] a = s[1:2] a = s[-2:-1] a = "abc"[-2:-1] a = "abc"[-2:i] a = B[-2:-1] + a = B[:-1] + a = B[-2:] b = l[1:2] + b = l[:2] + b = l[1:] b = l[-2:-1] b = [1, 2, 3][-2:-1] b = [1, 2, 3][-2:i] @@ -21,27 +26,35 @@ def normal_wraparound(int i, bytes B not None, list L not None): @cython.wraparound(False) def no_wraparound(int i, bytes B not None, list L not None): + a = s[:] a = s[1:2] a = s[-2:-1] - a = "abc"[-2:-1] + a = "abc"[-2:-1] # evaluated at compile time a = "abc"[-2:i] + a = B[:] a = B[-2:-1] + a = B[:-1] + a = B[-2:] b = l[1:2] + b = l[:2] + b = l[1:] b = l[-2:-1] b = [1, 2, 3][-2:i] b = L[-2:-1] _ERRORS = """ -25:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -25:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -27:15: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -28:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -28:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined 31:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined 31:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -32:19: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -33:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined -33:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +33:15: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +35:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +35:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +36:12: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +37:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +42:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +42:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +43:19: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +44:11: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined +44:14: the result of using negative indices inside of code sections marked as 'wraparound=False' is undefined """