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
c9e107b4
Commit
c9e107b4
authored
Oct 03, 2020
by
da-woods
Committed by
GitHub
Oct 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow creation of wrappers for cdef functions with memoryviews (GH-3856)
Fixes
https://github.com/cython/cython/issues/3843
parent
dfff7441
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
4 deletions
+54
-4
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+6
-4
tests/run/cfunc_convert.pyx
tests/run/cfunc_convert.pyx
+48
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
c9e107b4
...
...
@@ -698,11 +698,10 @@ class MemoryViewSliceType(PyrexType):
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
):
# XXX: we put these guards in for now...
assert
not
pyrex
assert
not
dll_linkage
from
.
import
MemoryView
base_code
=
StringEncoding
.
EncodedString
(
(
str
(
self
))
if
for_display
else
MemoryView
.
memviewslice_cname
)
str
(
self
)
if
pyrex
or
for_display
else
MemoryView
.
memviewslice_cname
)
return
self
.
base_declaration_code
(
base_code
,
entity_code
)
...
...
@@ -3249,7 +3248,7 @@ class CFuncType(CType):
if
not
self
.
can_coerce_to_pyobject
(
env
):
return
False
from
.UtilityCode
import
CythonUtilityCode
safe_typename
=
re
.
sub
(
'[^a-zA-Z0-9]'
,
'__'
,
self
.
declaration_code
(
""
,
pyrex
=
1
))
safe_typename
=
type_identifier_from_declaration
(
self
.
declaration_code
(
""
,
pyrex
=
1
))
to_py_function
=
"__Pyx_CFunc_%s_to_py"
%
safe_typename
for
arg
in
self
.
args
:
...
...
@@ -4987,9 +4986,12 @@ def typecast(to_type, from_type, expr_code):
def
type_list_identifier
(
types
):
return
cap_length
(
'__and_'
.
join
(
type_identifier
(
type
)
for
type
in
types
))
_type_identifier_cache
=
{}
def
type_identifier
(
type
):
decl
=
type
.
empty_declaration_code
()
return
type_identifier_from_declaration
(
decl
)
_type_identifier_cache
=
{}
def
type_identifier_from_declaration
(
decl
):
safe
=
_type_identifier_cache
.
get
(
decl
)
if
safe
is
None
:
safe
=
decl
...
...
tests/run/cfunc_convert.pyx
View file @
c9e107b4
...
...
@@ -229,3 +229,51 @@ def test_cdef_class_params(a, b):
TypeError: Argument 'b' has incorrect type (expected cfunc_convert.B, got cfunc_convert.A)
"""
return
(
<
object
>
test_cdef_class_params_cfunc
)(
a
,
b
)
cdef
void
memoryview_func_a
(
double
[:]
x
):
x
[
0
]
=
1
cdef
void
memoryview_func_b
(
double
[::
1
]
x
):
x
[
0
]
=
2
cdef
void
memoryview_func_c
(
int
[:]
x
):
x
[
0
]
=
1
cdef
void
memoryview_func_d
(
int
[:]
x
):
x
[
0
]
=
2
cdef
void
memoryview_func_e
(
int
[:,::
1
]
x
):
x
[
0
,
0
]
=
4
cdef
void
memoryview_func_f
(
int
[::
1
,:]
x
):
x
[
0
,
0
]
=
4
def
test_memview_wrapping
():
"""
We're mainly concerned that the code compiles without the names clashing
>>> test_memview_wrapping()
1.0
2.0
1
2
"""
cdef
a
=
memoryview_func_a
cdef
b
=
memoryview_func_b
cdef
c
=
memoryview_func_c
cdef
d
=
memoryview_func_d
cdef
e
=
memoryview_func_e
cdef
f
=
memoryview_func_f
cdef
double
[
1
]
double_arr
=
[
0
]
cdef
int
[
1
]
int_arr
=
[
0
]
a
(
<
double
[:
1
]
>
double_arr
)
print
(
double_arr
[
0
])
b
(
<
double
[:
1
:
1
]
>
double_arr
)
print
(
double_arr
[
0
])
c
(
<
int
[:
1
]
>
int_arr
)
print
(
int_arr
[
0
])
d
(
<
int
[:
1
:
1
]
>
int_arr
)
print
(
int_arr
[
0
])
# don't call e and f because it's harder without needing extra dependencies
# it's mostly a compile test for them
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