Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 037aae4

Browse files
committed
Fix 32-bit overflow tests, also got rid of some warnings.
1 parent 9ec6c57 commit 037aae4

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

Cython/Compiler/PyrexTypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ def overflow_check_binop(self, binop, env, const_rhs=False):
15801580
if binop == "lshift":
15811581
env.use_utility_code(TempitaUtilityCode.load(
15821582
"LeftShift", "Overflow.c",
1583-
context={'TYPE': type, 'NAME': name, 'SIGNED': not self.signed}))
1583+
context={'TYPE': type, 'NAME': name, 'SIGNED': self.signed}))
15841584
else:
15851585
if const_rhs:
15861586
binop += "_const"

Cython/Utility/Overflow.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TODO: Conditionally support 128-bit with intmax_t?
1919

2020
/////////////// Common.proto ///////////////
2121

22-
static int __Pyx_check_twos_complement() {
22+
static int __Pyx_check_twos_complement(void) {
2323
if (-1 != ~0) {
2424
PyErr_SetString(PyExc_RuntimeError, "Two's complement required for overflow checks.");
2525
return 1;
@@ -225,7 +225,7 @@ __Pyx_check_sane_{{NAME}}();
225225

226226
/////////////// SizeCheck.proto ///////////////
227227

228-
static int __Pyx_check_sane_{{NAME}}() {
228+
static int __Pyx_check_sane_{{NAME}}(void) {
229229
if (sizeof({{TYPE}}) <= sizeof(int) ||
230230
sizeof({{TYPE}}) == sizeof(long) ||
231231
sizeof({{TYPE}}) == sizeof(long long)) {
@@ -276,7 +276,7 @@ static CYTHON_INLINE {{TYPE}} __Pyx_lshift_{{NAME}}_checking_overflow({{TYPE}} a
276276
#if {{SIGNED}}
277277
(b < 0) |
278278
#endif
279-
(b > (8 * sizeof({{TYPE}}))) | (a > (__PYX_MAX({{TYPE}}) >> b));
279+
(b > ({{TYPE}}) (8 * sizeof({{TYPE}}))) | (a > (__PYX_MAX({{TYPE}}) >> b));
280280
return a << b;
281281
}
282282
#define __Pyx_lshift_const_{{NAME}}_checking_overflow __Pyx_lshift_{{NAME}}_checking_overflow

tests/run/overflow_check.pxi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cdef int size_in_bits = sizeof(INT) * 8
66
cdef bint is_signed_ = ((<INT>-1) < 0)
77
cdef INT max_value_ = <INT>(two ** (size_in_bits - is_signed_) - 1)
88
cdef INT min_value_ = ~max_value_
9-
cdef INT half_ = max_value_ // 2
9+
cdef INT half_ = max_value_ // <INT>2
1010

1111
# Python visible.
1212
is_signed = is_signed_
@@ -19,7 +19,7 @@ import operator
1919
from libc.math cimport sqrt
2020

2121
cpdef check(func, op, a, b):
22-
cdef INT res, op_res
22+
cdef INT res = 0, op_res = 0
2323
cdef bint func_overflow = False
2424
cdef bint assign_overflow = False
2525
try:
@@ -34,7 +34,7 @@ cpdef check(func, op, a, b):
3434
if not func_overflow:
3535
assert res == op_res, "Inconsistant values: %s(%s, %s) == %s != %s" % (func, a, b, res, op_res)
3636

37-
medium_values = (max_value_ / 2, max_value_ / 3, min_value_ / 2, <INT>sqrt(max_value_) - 1, <INT>sqrt(max_value_) + 1)
37+
medium_values = (max_value_ / 2, max_value_ / 3, min_value_ / 2, <INT>sqrt(max_value_) - <INT>1, <INT>sqrt(max_value_) + 1)
3838
def run_test(func, op):
3939
cdef INT offset, b
4040
check(func, op, 300, 200)
@@ -44,8 +44,8 @@ def run_test(func, op):
4444
check(func, op, min_value_, min_value_)
4545

4646
for offset in range(5):
47-
check(func, op, max_value_ - 1, offset)
48-
check(func, op, min_value_ + 1, offset)
47+
check(func, op, max_value_ - <INT>1, offset)
48+
check(func, op, min_value_ + <INT>1, offset)
4949
if is_signed_:
5050
check(func, op, max_value_ - 1, 2 - offset)
5151
check(func, op, min_value_ + 1, 2 - offset)

0 commit comments

Comments
 (0)