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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
037aae45
Commit
037aae45
authored
Nov 07, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 32-bit overflow tests, also got rid of some warnings.
parent
9ec6c57a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
9 deletions
+9
-9
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+1
-1
Cython/Utility/Overflow.c
Cython/Utility/Overflow.c
+3
-3
tests/run/overflow_check.pxi
tests/run/overflow_check.pxi
+5
-5
No files found.
Cython/Compiler/PyrexTypes.py
View file @
037aae45
...
...
@@ -1580,7 +1580,7 @@ class CIntType(CNumericType):
if
binop
==
"lshift"
:
env
.
use_utility_code
(
TempitaUtilityCode
.
load
(
"LeftShift"
,
"Overflow.c"
,
context
=
{
'TYPE'
:
type
,
'NAME'
:
name
,
'SIGNED'
:
not
self
.
signed
}))
context
=
{
'TYPE'
:
type
,
'NAME'
:
name
,
'SIGNED'
:
self
.
signed
}))
else
:
if
const_rhs
:
binop
+=
"_const"
...
...
Cython/Utility/Overflow.c
View file @
037aae45
...
...
@@ -19,7 +19,7 @@ TODO: Conditionally support 128-bit with intmax_t?
/////////////// Common.proto ///////////////
static
int
__Pyx_check_twos_complement
()
{
static
int
__Pyx_check_twos_complement
(
void
)
{
if
(
-
1
!=
~
0
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Two's complement required for overflow checks."
);
return
1
;
...
...
@@ -225,7 +225,7 @@ __Pyx_check_sane_{{NAME}}();
/////////////// SizeCheck.proto ///////////////
static
int
__Pyx_check_sane_
{{
NAME
}}()
{
static
int
__Pyx_check_sane_
{{
NAME
}}(
void
)
{
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
int
)
||
sizeof
({{
TYPE
}})
==
sizeof
(
long
)
||
sizeof
({{
TYPE
}})
==
sizeof
(
long
long
))
{
...
...
@@ -276,7 +276,7 @@ static CYTHON_INLINE {{TYPE}} __Pyx_lshift_{{NAME}}_checking_overflow({{TYPE}} a
#if {{SIGNED}}
(
b
<
0
)
|
#endif
(
b
>
(
8
*
sizeof
({{
TYPE
}})))
|
(
a
>
(
__PYX_MAX
({{
TYPE
}})
>>
b
));
(
b
>
(
{{
TYPE
}})
(
8
*
sizeof
({{
TYPE
}})))
|
(
a
>
(
__PYX_MAX
({{
TYPE
}})
>>
b
));
return
a
<<
b
;
}
#define __Pyx_lshift_const_{{NAME}}_checking_overflow __Pyx_lshift_{{NAME}}_checking_overflow
...
...
tests/run/overflow_check.pxi
View file @
037aae45
...
...
@@ -6,7 +6,7 @@ cdef int size_in_bits = sizeof(INT) * 8
cdef
bint
is_signed_
=
((
<
INT
>-
1
)
<
0
)
cdef
INT
max_value_
=
<
INT
>
(
two
**
(
size_in_bits
-
is_signed_
)
-
1
)
cdef
INT
min_value_
=
~
max_value_
cdef
INT
half_
=
max_value_
//
2
cdef
INT
half_
=
max_value_
//
<
INT
>
2
# Python visible.
is_signed
=
is_signed_
...
...
@@ -19,7 +19,7 @@ import operator
from
libc.math
cimport
sqrt
cpdef
check
(
func
,
op
,
a
,
b
):
cdef
INT
res
,
op_res
cdef
INT
res
=
0
,
op_res
=
0
cdef
bint
func_overflow
=
False
cdef
bint
assign_overflow
=
False
try
:
...
...
@@ -34,7 +34,7 @@ cpdef check(func, op, a, b):
if
not
func_overflow
:
assert
res
==
op_res
,
"Inconsistant values: %s(%s, %s) == %s != %s"
%
(
func
,
a
,
b
,
res
,
op_res
)
medium_values
=
(
max_value_
/
2
,
max_value_
/
3
,
min_value_
/
2
,
<
INT
>
sqrt
(
max_value_
)
-
1
,
<
INT
>
sqrt
(
max_value_
)
+
1
)
medium_values
=
(
max_value_
/
2
,
max_value_
/
3
,
min_value_
/
2
,
<
INT
>
sqrt
(
max_value_
)
-
<
INT
>
1
,
<
INT
>
sqrt
(
max_value_
)
+
1
)
def
run_test
(
func
,
op
):
cdef
INT
offset
,
b
check
(
func
,
op
,
300
,
200
)
...
...
@@ -44,8 +44,8 @@ def run_test(func, op):
check
(
func
,
op
,
min_value_
,
min_value_
)
for
offset
in
range
(
5
):
check
(
func
,
op
,
max_value_
-
1
,
offset
)
check
(
func
,
op
,
min_value_
+
1
,
offset
)
check
(
func
,
op
,
max_value_
-
<
INT
>
1
,
offset
)
check
(
func
,
op
,
min_value_
+
<
INT
>
1
,
offset
)
if
is_signed_
:
check
(
func
,
op
,
max_value_
-
1
,
2
-
offset
)
check
(
func
,
op
,
min_value_
+
1
,
2
-
offset
)
...
...
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