Skip to content

Commit f1a082d

Browse files
committed
compiler: make sure complex ctype is handled properly for typedata
1 parent 58e6310 commit f1a082d

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

devito/symbolics/extended_dtypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class c_complex(NoDeclStruct):
3434

3535
_fields_ = [('real', ctypes.c_float), ('imag', ctypes.c_float)]
3636

37+
_base_dtype = True
38+
3739
@classmethod
3840
def from_param(cls, val):
3941
return cls(val.real, val.imag)
@@ -44,6 +46,8 @@ class c_double_complex(NoDeclStruct):
4446

4547
_fields_ = [('real', ctypes.c_double), ('imag', ctypes.c_double)]
4648

49+
_base_dtype = True
50+
4751
@classmethod
4852
def from_param(cls, val):
4953
return cls(val.real, val.imag)

devito/types/basic.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,20 @@ def _C_typedata(self):
8787
if isinstance(_type, CustomDtype):
8888
return _type
8989

90-
_pointer = False
9190
while issubclass(_type, _Pointer):
92-
_pointer = True
9391
_type = _type._type_
9492

9593
# `ctypes` treats C strings specially
9694
if _type is c_char_p:
9795
_type = c_char
9896

99-
if issubclass(_type, Structure) and _pointer:
100-
_type = f'struct {_type.__name__}'
97+
try:
98+
# We have internal types such as c_complex that are
99+
# Structure too but should be treated as plain c_type
100+
_type._base_dtype
101+
except AttributeError:
102+
if issubclass(_type, Structure):
103+
_type = f'struct {_type.__name__}'
101104

102105
return _type
103106

0 commit comments

Comments
 (0)