Commit 987e27c9 authored by Mark Florisson's avatar Mark Florisson

Support struct attributes names in buffer format string

parent 5ab068d9
...@@ -966,7 +966,8 @@ cdef format_from_typeinfo(__Pyx_TypeInfo *type): ...@@ -966,7 +966,8 @@ cdef format_from_typeinfo(__Pyx_TypeInfo *type):
field = type.fields field = type.fields
while field.type: while field.type:
parts.append(format_from_typeinfo(field.type).decode('ascii')) part = format_from_typeinfo(field.type).decode('ascii')
parts.append('%s:%s:' % (part, field.name))
field += 1 field += 1
result = alignment.join(parts) + '}' result = alignment.join(parts) + '}'
......
...@@ -508,3 +508,27 @@ def test_string_invalid_dims(): ...@@ -508,3 +508,27 @@ def test_string_invalid_dims():
... ...
ValueError: Expected 2 dimensions, got 1 ValueError: Expected 2 dimensions, got 1
""" """
ctypedef struct AttributesStruct:
int attrib1
float attrib2
StringStruct attrib3
@testcase_numpy_1_5
def test_struct_attributes():
"""
>>> test_struct_attributes()
1
2.0
c
"""
cdef AttributesStruct[10] a
cdef AttributesStruct[:] myslice = a
myslice[0].attrib1 = 1
myslice[0].attrib2 = 2.0
myslice[0].attrib3.c[0][0] = 'c'
array = np.asarray(myslice)
print array[0]['attrib1']
print array[0]['attrib2']
print chr(array[0]['attrib3']['c'][0][0])
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