Commit 42a187c5 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

prange: Fix NaN-initialization for mismatching external typedefs

parent c92189e7
...@@ -210,6 +210,9 @@ class CTypedefType(BaseType): ...@@ -210,6 +210,9 @@ class CTypedefType(BaseType):
self.typedef_base_type = base_type self.typedef_base_type = base_type
self.typedef_is_external = is_external self.typedef_is_external = is_external
def invalid_value(self):
return self.typedef_base_type.invalid_value()
def resolve(self): def resolve(self):
return self.typedef_base_type.resolve() return self.typedef_base_type.resolve()
...@@ -913,7 +916,13 @@ class CIntType(CNumericType): ...@@ -913,7 +916,13 @@ class CIntType(CNumericType):
return src_type.is_int or src_type.is_enum or src_type is error_type return src_type.is_int or src_type.is_enum or src_type is error_type
def invalid_value(self): def invalid_value(self):
return typename_to_maxval[rank_to_type_name[self.rank]][not self.signed] if rank_to_type_name[self.rank] == 'char':
return "'?'"
else:
# We do not really know the size of the type, so return
# a 32-bit literal and rely on casting to final type. It will
# be negative for signed ints, which is good.
return "0xbad0bad0";
class CAnonEnumType(CIntType): class CAnonEnumType(CIntType):
...@@ -2369,15 +2378,6 @@ rank_to_type_name = ( ...@@ -2369,15 +2378,6 @@ rank_to_type_name = (
"long double", # 7 "long double", # 7
) )
typename_to_maxval = {
"char" : ("'?'", "'?'"),
"short": ("0xbad", "0xbad0"),
"int" : ("0xbad", "0xbad0"),
"long" : ("0xbad0bad", "0xbad0bad0"),
"PY_LONG_LONG" : ("0xbad0bad0bad0bad", "0xbad0bad0bad0bad0"),
# CFloatType overrides invalid_value
}
RANK_INT = list(rank_to_type_name).index('int') RANK_INT = list(rank_to_type_name).index('int')
RANK_LONG = list(rank_to_type_name).index('long') RANK_LONG = list(rank_to_type_name).index('long')
UNSIGNED = 0 UNSIGNED = 0
......
...@@ -174,6 +174,12 @@ def test_pure_mode(): ...@@ -174,6 +174,12 @@ def test_pure_mode():
with pure_parallel.parallel(): with pure_parallel.parallel():
print pure_parallel.threadid() print pure_parallel.threadid()
cdef extern from "types.h":
ctypedef short actually_long_t
ctypedef long actually_short_t
ctypedef int myint_t
def test_nan_init(): def test_nan_init():
""" """
>>> test_nan_init() >>> test_nan_init()
...@@ -192,6 +198,10 @@ def test_nan_init(): ...@@ -192,6 +198,10 @@ def test_nan_init():
cdef unsigned long d2 = 10 cdef unsigned long d2 = 10
cdef long long e1 = 10 cdef long long e1 = 10
cdef unsigned long long e2 = 10 cdef unsigned long long e2 = 10
cdef actually_long_t miss1 = 10
cdef actually_short_t miss2 = 10
cdef myint_t typedef1 = 10
cdef float f = 10.0 cdef float f = 10.0
cdef double g = 10.0 cdef double g = 10.0
...@@ -207,6 +217,7 @@ def test_nan_init(): ...@@ -207,6 +217,7 @@ def test_nan_init():
a1 = a2 = b1 = b2 = c1 = c2 = d1 = d2 = e1 = e2 = 0 a1 = a2 = b1 = b2 = c1 = c2 = d1 = d2 = e1 = e2 = 0
f = g = h = 0.0 f = g = h = 0.0
p = NULL p = NULL
miss1 = miss2 = typedef1 = 0
if (a1 == 10 or a2 == 10 or if (a1 == 10 or a2 == 10 or
b1 == 10 or b2 == 10 or b1 == 10 or b2 == 10 or
...@@ -214,10 +225,10 @@ def test_nan_init(): ...@@ -214,10 +225,10 @@ def test_nan_init():
d1 == 10 or d2 == 10 or d1 == 10 or d2 == 10 or
e1 == 10 or e2 == 10 or e1 == 10 or e2 == 10 or
f == 10.0 or g == 10.0 or h == 10.0 or f == 10.0 or g == 10.0 or h == 10.0 or
p == <void *> 10): p == <void *> 10 or miss1 == 10 or miss2 == 10
or typedef1 == 10):
errp[0] = 1 errp[0] = 1
if err: if err:
raise Exception("One of the values was not initiazed to a maximum " raise Exception("One of the values was not initialized to a maximum "
"or NaN value") "or NaN value")
/*
This header is present to test effects of misdeclaring
types Cython-side.
*/
typedef long actually_long_t;
typedef short actually_short_t;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment