From: Robert Bradshaw Date: Sun, 18 Jul 2010 06:52:29 +0000 (-0700) Subject: Fix #502, handle implicitly unsigned chars. X-Git-Tag: 0.13.beta0~9 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=53e50941793474a23dcf91e9e92497926b18ffbf;p=cython.git Fix #502, handle implicitly unsigned chars. --- diff --git a/tests/run/c_int_types_T255.pyx b/tests/run/c_int_types_T255.pyx index 1468aa13..23220d5a 100644 --- a/tests/run/c_int_types_T255.pyx +++ b/tests/run/c_int_types_T255.pyx @@ -2,55 +2,6 @@ __doc__ = u"" # ------------------------------------------------------------------- -CHAR_MAX = ((-1)>>1) -CHAR_MIN = (-CHAR_MAX-1) - -def test_char(char x): - u""" - >>> test_char(CHAR_MIN-1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - >>> test_char(CHAR_MIN) == CHAR_MIN - True - >>> test_char(-1) - -1 - >>> test_char(0) - 0 - >>> test_char(1) - 1 - >>> test_char(CHAR_MAX) == CHAR_MAX - True - >>> test_char(CHAR_MAX+1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - """ - return x - -def test_add_char(x, y): - u""" - >>> test_add_char(CHAR_MIN, -1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - >>> test_add_char(CHAR_MIN, 0) == CHAR_MIN - True - >>> test_add_char(CHAR_MIN, 1) == CHAR_MIN+1 - True - >>> test_add_char(CHAR_MAX, -1) == CHAR_MAX-1 - True - >>> test_add_char(CHAR_MAX, 0) == CHAR_MAX - True - >>> test_add_char(CHAR_MAX, 1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - """ - cdef char r = x + y - return r - - SCHAR_MAX = ((-1)>>1) SCHAR_MIN = (-SCHAR_MAX-1) @@ -128,6 +79,59 @@ def test_add_uchar(x, y): cdef unsigned char r = x + y return r +# chars may be signed or unsigned +if (-1) < 0: + CHAR_MAX = SCHAR_MAX + CHAR_MIN = SCHAR_MIN +else: + CHAR_MAX = UCHAR_MAX + CHAR_MIN = 0 + +def test_char(char x): + u""" + >>> test_char(CHAR_MIN-1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + >>> test_char(CHAR_MIN) == CHAR_MIN + True + >>> test_char(-1) + -1 + >>> test_char(0) + 0 + >>> test_char(1) + 1 + >>> test_char(CHAR_MAX) == CHAR_MAX + True + >>> test_char(CHAR_MAX+1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + """ + return x + +def test_add_char(x, y): + u""" + >>> test_add_char(CHAR_MIN, -1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + >>> test_add_char(CHAR_MIN, 0) == CHAR_MIN + True + >>> test_add_char(CHAR_MIN, 1) == CHAR_MIN+1 + True + >>> test_add_char(CHAR_MAX, -1) == CHAR_MAX-1 + True + >>> test_add_char(CHAR_MAX, 0) == CHAR_MAX + True + >>> test_add_char(CHAR_MAX, 1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + """ + cdef char r = x + y + return r + # ------------------------------------------------------------------- SHORT_MAX = ((-1)>>1)