Commit 53e50941 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix #502, handle implicitly unsigned chars.

parent 8f8ef5cd
...@@ -2,55 +2,6 @@ __doc__ = u"" ...@@ -2,55 +2,6 @@ __doc__ = u""
# ------------------------------------------------------------------- # -------------------------------------------------------------------
CHAR_MAX = <char>((<unsigned char>-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 = <signed char>((<unsigned char>-1)>>1) SCHAR_MAX = <signed char>((<unsigned char>-1)>>1)
SCHAR_MIN = (-SCHAR_MAX-1) SCHAR_MIN = (-SCHAR_MAX-1)
...@@ -128,6 +79,59 @@ def test_add_uchar(x, y): ...@@ -128,6 +79,59 @@ def test_add_uchar(x, y):
cdef unsigned char r = x + y cdef unsigned char r = x + y
return r return r
# chars may be signed or unsigned
if (<char>-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 = <short>((<unsigned short>-1)>>1) SHORT_MAX = <short>((<unsigned short>-1)>>1)
......
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