Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
match_dtype_to_c_struct: Accept more dtypes
  • Loading branch information
inducer committed Aug 17, 2016
1 parent c99e9b3 commit 6d67fcd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pyopencl/tools.py
Expand Up @@ -537,22 +537,24 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
key=lambda name_dtype_offset: name_dtype_offset[1][1])

c_fields = []
for field_name, (field_dtype, offset) in fields:
for field_name, dtype_and_offset in fields:
field_dtype, offset = dtype_and_offset[:2]
c_fields.append(" %s %s;" % (dtype_to_ctype(field_dtype), field_name))

c_decl = "typedef struct {\n%s\n} %s;\n\n" % (
"\n".join(c_fields),
name)

cdl = _CDeclList(device)
for field_name, (field_dtype, offset) in fields:
for field_name, dtype_and_offset in fields:
field_dtype, offset = dtype_and_offset[:2]
cdl.add_dtype(field_dtype)

pre_decls = cdl.get_declarations()

offset_code = "\n".join(
"result[%d] = pycl_offsetof(%s, %s);" % (i+1, name, field_name)
for i, (field_name, (field_dtype, offset)) in enumerate(fields))
for i, (field_name, _) in enumerate(fields))

src = r"""
#define pycl_offsetof(st, m) \
Expand Down Expand Up @@ -598,8 +600,8 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):

if dtype.itemsize == size:
# If sizes match, use numpy's idea of the offsets.
offsets = [offset
for field_name, (field_dtype, offset) in fields]
offsets = [dtype_and_offset[1]
for field_name, dtype_and_offset in fields]
else:
raise RuntimeError(
"cannot discover struct layout on '%s'" % device)
Expand Down

0 comments on commit 6d67fcd

Please sign in to comment.