Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
0407171e
Commit
0407171e
authored
Mar 29, 2015
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PyPy: Improve negative overflow error messages in integral type conversion
parent
60f0e2f9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
45 deletions
+54
-45
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+9
-0
tests/run/c_int_types_T255.pyx
tests/run/c_int_types_T255.pyx
+23
-23
tests/run/ctypedef_int_types_T333.pyx
tests/run/ctypedef_int_types_T333.pyx
+22
-22
No files found.
Cython/Utility/TypeConversion.c
View file @
0407171e
...
...
@@ -560,6 +560,15 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
if
(
unlikely
(
Py_SIZE
(
x
)
<
0
))
{
goto
raise_neg_overflow
;
}
#endif
#if CYTHON_COMPILING_IN_PYPY
{
int
result
=
PyObject_RichCompareBool
(
x
,
Py_False
,
Py_LT
);
if
(
unlikely
(
result
<
0
))
return
-
1
;
if
(
unlikely
(
result
==
1
))
goto
raise_neg_overflow
;
}
#endif
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
unsigned
long
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
unsigned
long
,
PyLong_AsUnsignedLong
(
x
))
...
...
tests/run/c_int_types_T255.pyx
View file @
0407171e
...
...
@@ -22,7 +22,7 @@ def test_schar(signed char x):
>>> test_schar(128) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to signed char
"""
return
x
...
...
@@ -43,7 +43,7 @@ def test_add_schar(x, y):
>>> test_add_schar(SCHAR_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to signed char
"""
cdef
signed
char
r
=
x
+
y
return
r
...
...
@@ -55,7 +55,7 @@ def test_uchar(unsigned char x):
>>> test_uchar(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to unsigned char
>>> test_uchar(0)
0
>>> test_uchar(1)
...
...
@@ -65,7 +65,7 @@ def test_uchar(unsigned char x):
>>> test_uchar(UCHAR_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to unsigned char
"""
return
x
...
...
@@ -76,7 +76,7 @@ def test_add_uchar(x, y):
>>> test_add_uchar(UCHAR_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to unsigned char
"""
cdef
unsigned
char
r
=
x
+
y
return
r
...
...
@@ -108,7 +108,7 @@ def test_char(char x):
>>> test_char(CHAR_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to char
"""
return
x
...
...
@@ -129,7 +129,7 @@ def test_add_char(x, y):
>>> test_add_char(CHAR_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to char
"""
cdef
char
r
=
x
+
y
return
r
...
...
@@ -144,7 +144,7 @@ def test_short(short x):
>>> test_short(SHORT_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to short
>>> test_short(SHORT_MIN) == SHORT_MIN
True
>>> test_short(-1)
...
...
@@ -158,7 +158,7 @@ def test_short(short x):
>>> test_short(SHORT_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to short
"""
return
x
...
...
@@ -167,7 +167,7 @@ def test_add_short(x, y):
>>> test_add_short(SHORT_MIN, -1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to short
>>> test_add_short(SHORT_MIN, 0) == SHORT_MIN
True
>>> test_add_short(SHORT_MIN, 1) == SHORT_MIN+1
...
...
@@ -179,7 +179,7 @@ def test_add_short(x, y):
>>> test_add_short(SHORT_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to short
"""
cdef
short
r
=
x
+
y
return
r
...
...
@@ -192,7 +192,7 @@ def test_sshort(short x):
>>> test_sshort(SSHORT_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to short
>>> test_sshort(SSHORT_MIN) == SSHORT_MIN
True
>>> test_sshort(-1)
...
...
@@ -206,7 +206,7 @@ def test_sshort(short x):
>>> test_short(SSHORT_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to short
"""
return
x
...
...
@@ -215,7 +215,7 @@ def test_add_sshort(x, y):
>>> test_add_sshort(SSHORT_MIN, -1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to signed short
>>> test_add_sshort(SSHORT_MIN, 0) == SSHORT_MIN
True
>>> test_add_sshort(SSHORT_MIN, 1) == SSHORT_MIN+1
...
...
@@ -227,7 +227,7 @@ def test_add_sshort(x, y):
>>> test_add_sshort(SSHORT_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to signed short
"""
cdef
signed
short
r
=
x
+
y
return
r
...
...
@@ -239,7 +239,7 @@ def test_ushort(unsigned short x):
>>> test_ushort(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to unsigned short
>>> test_ushort(0)
0
>>> test_ushort(1)
...
...
@@ -260,7 +260,7 @@ def test_add_ushort(x, y):
>>> test_add_ushort(USHORT_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to unsigned short
"""
cdef
unsigned
short
r
=
x
+
y
return
r
...
...
@@ -318,7 +318,7 @@ def test_add_int(x, y):
SINT_MAX
=
<
signed
int
>
((
<
unsigned
int
>-
1
)
>>
1
)
SINT_MIN
=
(
-
SINT_MAX
-
1
)
def
test_sint
(
int
x
):
def
test_sint
(
signed
int
x
):
u"""
>>> test_sint(SINT_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
...
@@ -370,7 +370,7 @@ def test_uint(unsigned int x):
>>> test_uint(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to unsigned int
>>> print(test_uint(0))
0
>>> print(test_uint(1))
...
...
@@ -449,7 +449,7 @@ def test_add_long(x, y):
SLONG_MAX
=
<
signed
long
>
((
<
unsigned
long
>-
1
)
>>
1
)
SLONG_MIN
=
(
-
SLONG_MAX
-
1
)
def
test_slong
(
long
x
):
def
test_slong
(
signed
long
x
):
u"""
>>> test_slong(SLONG_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
...
@@ -501,7 +501,7 @@ def test_ulong(unsigned long x):
>>> test_ulong(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to unsigned long
>>> print(test_ulong(0))
0
>>> print(test_ulong(1))
...
...
@@ -632,7 +632,7 @@ def test_ulonglong(unsigned long long x):
>>> test_ulonglong(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to unsigned PY_LONG_LONG
>>> print(test_ulonglong(0))
0
>>> print(test_ulonglong(1))
...
...
tests/run/ctypedef_int_types_T333.pyx
View file @
0407171e
...
...
@@ -25,7 +25,7 @@ def test_schar(SChar x):
>>> test_schar(-129) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SChar
>>> test_schar(-128)
-128
>>> test_schar(0)
...
...
@@ -35,7 +35,7 @@ def test_schar(SChar x):
>>> test_schar(128) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SChar
"""
return
x
...
...
@@ -44,7 +44,7 @@ def test_add_schar(x, y):
>>> test_add_schar(SCHAR_MIN, -1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SChar
>>> test_add_schar(SCHAR_MIN, 0) == SCHAR_MIN
True
>>> test_add_schar(SCHAR_MIN, 1) == SCHAR_MIN+1
...
...
@@ -56,7 +56,7 @@ def test_add_schar(x, y):
>>> test_add_schar(SCHAR_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SChar
"""
cdef
SChar
r
=
x
+
y
return
r
...
...
@@ -68,7 +68,7 @@ def test_uchar(UChar x):
>>> test_uchar(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to UChar
>>> test_uchar(0)
0
>>> test_uchar(1)
...
...
@@ -78,7 +78,7 @@ def test_uchar(UChar x):
>>> test_uchar(UCHAR_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to UChar
"""
return
x
...
...
@@ -89,7 +89,7 @@ def test_add_uchar(x, y):
>>> test_add_uchar(UCHAR_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to UChar
"""
cdef
UChar
r
=
x
+
y
return
r
...
...
@@ -99,12 +99,12 @@ def test_add_uchar(x, y):
SSHORT_MAX
=
<
SShort
>
((
<
UShort
>-
1
)
>>
1
)
SSHORT_MIN
=
(
-
SSHORT_MAX
-
1
)
def
test_sshort
(
s
hort
x
):
def
test_sshort
(
SS
hort
x
):
u"""
>>> test_sshort(SSHORT_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SShort
>>> test_sshort(SSHORT_MIN) == SSHORT_MIN
True
>>> test_sshort(-1)
...
...
@@ -127,7 +127,7 @@ def test_add_sshort(x, y):
>>> test_add_sshort(SSHORT_MIN, -1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SShort
>>> test_add_sshort(SSHORT_MIN, 0) == SSHORT_MIN
True
>>> test_add_sshort(SSHORT_MIN, 1) == SSHORT_MIN+1
...
...
@@ -139,7 +139,7 @@ def test_add_sshort(x, y):
>>> test_add_sshort(SSHORT_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to SShort
"""
cdef
SShort
r
=
x
+
y
return
r
...
...
@@ -151,7 +151,7 @@ def test_ushort(UShort x):
>>> test_ushort(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to UShort
>>> test_ushort(0)
0
>>> test_ushort(1)
...
...
@@ -161,7 +161,7 @@ def test_ushort(UShort x):
>>> test_ushort(USHORT_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to UShort
"""
return
x
...
...
@@ -172,7 +172,7 @@ def test_add_ushort(x, y):
>>> test_add_ushort(USHORT_MAX, 1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
value too large to convert to UShort
"""
cdef
UShort
r
=
x
+
y
return
r
...
...
@@ -182,7 +182,7 @@ def test_add_ushort(x, y):
SINT_MAX
=
<
SInt
>
((
<
UInt
>-
1
)
>>
1
)
SINT_MIN
=
(
-
SINT_MAX
-
1
)
def
test_sint
(
i
nt
x
):
def
test_sint
(
SI
nt
x
):
u"""
>>> test_sint(SINT_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
...
@@ -234,7 +234,7 @@ def test_uint(UInt x):
>>> test_uint(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to UInt
>>> print(test_uint(0))
0
>>> print(test_uint(1))
...
...
@@ -317,7 +317,7 @@ def test_ulong(ULong x):
>>> test_ulong(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to ULong
>>> print(test_ulong(0))
0
>>> print(test_ulong(1))
...
...
@@ -400,7 +400,7 @@ def test_ulonglong(ULongLong x):
>>> test_ulonglong(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError:
...
OverflowError:
can't convert negative value to ULongLong
>>> print(test_ulonglong(0))
0
>>> print(test_ulonglong(1))
...
...
@@ -554,7 +554,7 @@ def test_MyUInt2(MyUInt2 x):
>>> test_MyUInt2(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
OverflowError:
can't convert negative value to
...
>>> test_MyUInt2(0)
0
>>> test_MyUInt2(1)
...
...
@@ -582,7 +582,7 @@ def test_DefUChar(defs.UChar x):
>>> test_DefUChar(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
OverflowError:
can't convert negative value to
...
>>> test_DefUChar(0)
0
>>> test_DefUChar(1)
...
...
@@ -606,7 +606,7 @@ def test_ExtUInt(defs.ExtUInt x):
>>> test_ExtUInt(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
OverflowError:
can't convert negative value to
...
>>> test_ExtUInt(0)
0
>>> test_ExtUInt(1)
...
...
@@ -634,7 +634,7 @@ def test_LocUInt(LocUInt x):
>>> test_LocUInt(-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
OverflowError:
can't convert negative value to
...
>>> test_LocUInt(0)
0
>>> test_LocUInt(1)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment