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
Kirill Smelkov
cython
Commits
d195c6c3
Commit
d195c6c3
authored
Nov 07, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make const memoryviews of struct dtypes work.
Closes
https://github.com/cython/cython/issues/2251
parent
76ec3b12
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
13 deletions
+69
-13
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+5
-3
tests/memoryview/memslice.pyx
tests/memoryview/memslice.pyx
+64
-10
No files found.
Cython/Compiler/Buffer.py
View file @
d195c6c3
...
...
@@ -668,9 +668,11 @@ def get_type_information_cname(code, dtype, maxdepth=None):
if
dtype
.
is_simple_buffer_dtype
():
structinfo_name
=
"NULL"
elif
dtype
.
is_struct
:
fields
=
dtype
.
scope
.
var_entries
# Must pre-call all used types in order not to recurse utility code
# writing.
struct_scope
=
dtype
.
scope
if
dtype
.
is_cv_qualified
:
struct_scope
=
struct_scope
.
base_type_scope
# Must pre-call all used types in order not to recurse during utility code writing.
fields
=
struct_scope
.
var_entries
assert
len
(
fields
)
>
0
types
=
[
get_type_information_cname
(
code
,
f
.
type
,
maxdepth
-
1
)
for
f
in
fields
]
...
...
tests/memoryview/memslice.pyx
View file @
d195c6c3
...
...
@@ -1155,9 +1155,21 @@ def basic_struct(MyStruct[:] buf):
"""
See also buffmt.pyx
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
# , writable=False))
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ccqii")) # , writable=False))
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ccqii"))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
c
,
buf
[
0
].
d
,
buf
[
0
].
e
@
testcase
def
const_struct
(
const
MyStruct
[:]
buf
):
"""
See also buffmt.pyx
>>> const_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], writable=False))
1 2 3 4 5
>>> const_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ccqii", writable=False))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
c
,
buf
[
0
].
d
,
buf
[
0
].
e
...
...
@@ -1167,9 +1179,21 @@ def nested_struct(NestedStruct[:] buf):
"""
See also buffmt.pyx
>>> nested_struct(NestedStructMockBuffer(None, [(1, 2, 3, 4, 5)])) # , writable=False))
>>> nested_struct(NestedStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
>>> nested_struct(NestedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="T{ii}T{2i}i"))
1 2 3 4 5
"""
print
buf
[
0
].
x
.
a
,
buf
[
0
].
x
.
b
,
buf
[
0
].
y
.
a
,
buf
[
0
].
y
.
b
,
buf
[
0
].
z
@
testcase
def
const_nested_struct
(
const
NestedStruct
[:]
buf
):
"""
See also buffmt.pyx
>>> const_nested_struct(NestedStructMockBuffer(None, [(1, 2, 3, 4, 5)], writable=False))
1 2 3 4 5
>>>
nested_struct(NestedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="T{ii}T{2i}i")) #
, writable=False))
>>>
const_nested_struct(NestedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="T{ii}T{2i}i"
, writable=False))
1 2 3 4 5
"""
print
buf
[
0
].
x
.
a
,
buf
[
0
].
x
.
b
,
buf
[
0
].
y
.
a
,
buf
[
0
].
y
.
b
,
buf
[
0
].
z
...
...
@@ -1179,11 +1203,26 @@ def packed_struct(PackedStruct[:] buf):
"""
See also buffmt.pyx
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)])) # , writable=False))
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)]))
1 2
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c^i}"))
1 2
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c=i}"))
1 2
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
@
testcase
def
const_packed_struct
(
const
PackedStruct
[:]
buf
):
"""
See also buffmt.pyx
>>> const_packed_struct(PackedStructMockBuffer(None, [(1, 2)], writable=False))
1 2
>>>
packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c^i}")) #
, writable=False))
>>>
const_packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c^i}"
, writable=False))
1 2
>>>
packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c=i}")) #
, writable=False))
>>>
const_packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c=i}"
, writable=False))
1 2
"""
...
...
@@ -1194,11 +1233,26 @@ def nested_packed_struct(NestedPackedStruct[:] buf):
"""
See also buffmt.pyx
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)])) # , writable=False))
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ci^ci@i"))
1 2 3 4 5
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="^c@i^ci@i"))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
sub
.
a
,
buf
[
0
].
sub
.
b
,
buf
[
0
].
c
@
testcase
def
const_nested_packed_struct
(
const
NestedPackedStruct
[:]
buf
):
"""
See also buffmt.pyx
>>> const_nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], writable=False))
1 2 3 4 5
>>>
nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ci^ci@i")) #
, writable=False))
>>>
const_nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ci^ci@i"
, writable=False))
1 2 3 4 5
>>>
nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="^c@i^ci@i")) #
, writable=False))
>>>
const_nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="^c@i^ci@i"
, writable=False))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
sub
.
a
,
buf
[
0
].
sub
.
b
,
buf
[
0
].
c
...
...
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