Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
987e27c9
Commit
987e27c9
authored
Dec 19, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support struct attributes names in buffer format string
parent
5ab068d9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+2
-1
tests/run/numpy_memoryview.pyx
tests/run/numpy_memoryview.pyx
+24
-0
No files found.
Cython/Utility/MemoryView.pyx
View file @
987e27c9
...
...
@@ -966,7 +966,8 @@ cdef format_from_typeinfo(__Pyx_TypeInfo *type):
field
=
type
.
fields
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
result
=
alignment
.
join
(
parts
)
+
'}'
...
...
tests/run/numpy_memoryview.pyx
View file @
987e27c9
...
...
@@ -508,3 +508,27 @@ def test_string_invalid_dims():
...
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
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment