Skip to content

Commit f7352ca

Browse files
committed
compiler: fix printing of nd pointers
1 parent 39f2b57 commit f7352ca

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

devito/ir/cgen/printer.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Utilities to turn SymPy objects into C strings.
33
"""
44
from contextlib import suppress
5+
from ctypes import _Pointer
56

67
import numpy as np
78
import sympy
@@ -110,11 +111,17 @@ def parenthesize(self, item, level, strict=False):
110111
return super().parenthesize(item, level, strict=strict)
111112

112113
def _print_PyCPointerType(self, expr):
113-
ctype = f'{self._print_type(expr._type_)}'
114+
base_type, nstart = expr, 0
115+
while issubclass(base_type, _Pointer):
116+
base_type = base_type._type_
117+
nstart += 1
118+
119+
ctype = f'{self._print_type(base_type)}'
120+
stars = '*' * nstart
114121
if ctype.endswith('*'):
115-
return f'{ctype}*'
122+
return f'{ctype}{stars}'
116123
else:
117-
return f'{ctype} *'
124+
return f'{ctype} {stars}'
118125

119126
def _print_type(self, expr):
120127
with suppress(TypeError):

0 commit comments

Comments
 (0)