From 5de4e6bd8fad0108a55b1ae5dfd35f669f9bdf97 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 28 Dec 2012 12:27:12 -0800 Subject: [PATCH] More overflow testing. --- tests/run/overflow_check.pxi | 28 +++++++++++++++++++++++----- tests/run/overflow_check_int.pyx | 3 +++ tests/run/overflow_check_longlong.pyx | 3 +++ tests/run/overflow_check_uint.pyx | 3 +++ tests/run/overflow_check_ulonglong.pyx | 3 +++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/tests/run/overflow_check.pxi b/tests/run/overflow_check.pxi index e28ffde..3603f95 100644 --- a/tests/run/overflow_check.pxi +++ b/tests/run/overflow_check.pxi @@ -106,12 +106,12 @@ def test_mul(INT a, INT b): return int(a * b) @cython.overflowcheck(True) -def test_nested(INT a, INT b, INT c): +def test_nested_add(INT a, INT b, INT c): """ - >>> test_nested(1, 2, 3) + >>> test_nested_add(1, 2, 3) 6 - >>> expect_overflow(test_nested, half + 1, half + 1, half + 1) - >>> expect_overflow(test_nested, half - 1, half - 1, half - 1) + >>> expect_overflow(test_nested_add, half + 1, half + 1, half + 1) + >>> expect_overflow(test_nested_add, half - 1, half - 1, half - 1) """ return int(a + b + c) @@ -155,6 +155,25 @@ cdef INT called(INT value): return value @cython.overflowcheck(True) +def test_nested(INT a, INT b, INT c, INT d): + """ + >>> test_nested_func(1, 2, 3) + called(5) + 6 + >>> expect_overflow(test_nested, half, half, 1, 1) + >>> expect_overflow(test_nested, half, 1, half, half) + >>> expect_overflow(test_nested, half, 2, half, 2) + + >>> print(format(test_nested(half, 2, 0, 1))) + half + half - 0 + >>> print(format(test_nested(1, 0, half, 2))) + half + half - 0 + >>> print(format(test_nested(half, 1, 1, half))) + half + half - 0 + """ + return int(a * b + c * d) + +@cython.overflowcheck(True) def test_nested_func(INT a, INT b, INT c): """ >>> test_nested_func(1, 2, 3) @@ -166,7 +185,6 @@ def test_nested_func(INT a, INT b, INT c): >>> print(format(test_nested_func(1, half - 1, half - 1))) called(half + half - 2) half + half - 1 - >>> """ return int(a + called(b + c)) diff --git a/tests/run/overflow_check_int.pyx b/tests/run/overflow_check_int.pyx index 6e8fcf0..51d4056 100644 --- a/tests/run/overflow_check_int.pyx +++ b/tests/run/overflow_check_int.pyx @@ -1,3 +1,6 @@ +# cython: overflowcheck.fold = True + + ctypedef int INT include "overflow_check.pxi" diff --git a/tests/run/overflow_check_longlong.pyx b/tests/run/overflow_check_longlong.pyx index ae7d779..3c5f5f1 100644 --- a/tests/run/overflow_check_longlong.pyx +++ b/tests/run/overflow_check_longlong.pyx @@ -1,3 +1,6 @@ +# cython: overflowcheck.fold = False + + ctypedef long long INT include "overflow_check.pxi" diff --git a/tests/run/overflow_check_uint.pyx b/tests/run/overflow_check_uint.pyx index e6f1bf1..1619695 100644 --- a/tests/run/overflow_check_uint.pyx +++ b/tests/run/overflow_check_uint.pyx @@ -1,3 +1,6 @@ +# cython: overflowcheck.fold = False + + ctypedef unsigned int INT include "overflow_check.pxi" diff --git a/tests/run/overflow_check_ulonglong.pyx b/tests/run/overflow_check_ulonglong.pyx index a4d11d7..958a58b 100644 --- a/tests/run/overflow_check_ulonglong.pyx +++ b/tests/run/overflow_check_ulonglong.pyx @@ -1,3 +1,6 @@ +# cython: overflowcheck.fold = True + + ctypedef unsigned long long INT include "overflow_check.pxi" -- 2.7.4