From 5a8d5aaf2e74e41d248b11b74f05496e9424dca4 Mon Sep 17 00:00:00 2001 From: Callie LeFave <antymew@gmail.com> Date: Mon, 16 Apr 2018 15:09:04 -0400 Subject: [PATCH] Fix `fused_pointer_except_null` test undefined behavior Signed-off-by: Stefan Behnel <stefan_ml@behnel.de> --- tests/run/fused_types.pyx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/run/fused_types.pyx b/tests/run/fused_types.pyx index 2c05c516d..f7493a79f 100644 --- a/tests/run/fused_types.pyx +++ b/tests/run/fused_types.pyx @@ -119,12 +119,12 @@ def test_fused_with_pointer(): print print fused_with_pointer(string_array).decode('ascii') -cdef fused_type1* fused_pointer_except_null(fused_type1 x) except NULL: +cdef fused_type1* fused_pointer_except_null(fused_type1* x) except NULL: if fused_type1 is string_t: - assert(bool(x)) + assert(bool(x[0])) else: - assert(x < 10) - return &x + assert(x[0] < 10) + return x def test_fused_pointer_except_null(value): """ @@ -145,11 +145,14 @@ def test_fused_pointer_except_null(value): AssertionError """ if isinstance(value, int): - print fused_pointer_except_null(<cython.int>value)[0] + test_int = cython.declare(cython.int, value) + print fused_pointer_except_null(&test_int)[0] elif isinstance(value, float): - print fused_pointer_except_null(<cython.float>value)[0] + test_float = cython.declare(cython.float, value) + print fused_pointer_except_null(&test_float)[0] elif isinstance(value, bytes): - print fused_pointer_except_null(<string_t>value)[0].decode('ascii') + test_str = cython.declare(string_t, value) + print fused_pointer_except_null(&test_str)[0].decode('ascii') include "cythonarrayutil.pxi" -- 2.30.9