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
e69df685
Commit
e69df685
authored
Oct 11, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use normal argument type conversion in cfunc wrapper for types that support it
parent
a90dd951
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+25
-14
Cython/Utility/CFuncConvert.pyx
Cython/Utility/CFuncConvert.pyx
+1
-1
No files found.
Cython/Compiler/PyrexTypes.py
View file @
e69df685
...
...
@@ -2659,39 +2659,50 @@ class CFuncType(CType):
for
arg
in
self
.
args
:
if
not
arg
.
type
.
is_pyobject
and
not
arg
.
type
.
create_from_py_utility_code
(
env
):
return
False
if
arg
.
type
.
is_extension_type
or
arg
.
type
.
is_builtin_type
:
if
arg
.
type
.
is_extension_type
:
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"ExtTypeTest"
,
"ObjectHandling.c"
))
def
declared_type
(
ix
,
ctype
):
py_arg_type
=
''
type_convert
=
''
type_name
=
'TYPE%s'
%
ix
type_cname
=
ctype
.
declaration_code
(
""
)
type_displayname
=
str
(
ctype
.
declaration_code
(
""
,
for_display
=
True
))
if
ctype
.
is_builtin_type
:
py_arg_type
=
ctype
.
name
elif
ctype
.
is_extension_type
:
type_convert
=
'<%s>'
%
type_name
elif
ctype
.
is_pyobject
:
type_convert
=
''
elif
ctype
.
is_typedef
or
ctype
.
is_struct_or_union
:
type_convert
=
'%s_to_py'
%
type_name
else
:
type_name
=
py_arg_type
=
type_displayname
return
type_name
,
type_cname
,
py_arg_type
,
type_displayname
,
type_convert
class
Arg
(
object
):
def
__init__
(
self
,
ix
,
arg
):
self
.
ix
=
ix
self
.
name
=
arg
.
name
or
'ARG%s'
%
ix
self
.
type
=
arg
.
type
self
.
type_name
=
'TYPE%s'
%
ix
self
.
type_cname
=
self
.
type
.
declaration_code
(
""
)
self
.
type_displayname
=
str
(
self
.
type
.
declaration_code
(
""
,
for_display
=
True
))
if
self
.
type
.
is_extension_type
or
self
.
type
.
is_builtin_type
:
self
.
type_convert
=
'<%s>'
%
self
.
type_name
elif
self
.
type
.
is_pyobject
:
self
.
type_convert
=
''
else
:
self
.
type_convert
=
'%s_to_py'
%
self
.
type_name
self
.
type_name
,
self
.
type_cname
,
self
.
py_arg_type
,
self
.
type_displayname
,
self
.
type_convert
=
(
declared_type
(
ix
,
self
.
type
))
def
declare_type_def
(
self
):
if
self
.
type
.
is_extension_type
or
self
.
type
.
is_builtin_type
or
not
self
.
type
.
is_pyobject
:
if
self
.
type
.
is_extension_type
or
(
not
self
.
type
.
is_pyobject
and
not
self
.
py_arg_type
)
:
return
'ctypedef void* %s "%s"'
%
(
self
.
type_name
,
self
.
type_cname
)
def
declare_type_convert
(
self
):
if
self
.
type
.
is_extension_type
or
self
.
type
.
is_builtin_type
:
if
self
.
type
.
is_extension_type
:
return
'cdef PyTypeObject* %s_TYPE "%s"'
%
(
self
.
type_name
,
self
.
type
.
typeptr_cname
)
elif
self
.
type
.
is_pyobject
:
return
''
el
s
e
:
el
if
not
self
.
py_arg_typ
e
:
return
'cdef %s %s "%s"(object) except *'
%
(
self
.
type_name
,
self
.
type_convert
,
self
.
type
.
from_py_function
)
def
check_type
(
self
):
if
self
.
type
.
is_extension_type
or
self
.
type
.
is_builtin_type
:
if
self
.
type
.
is_extension_type
:
return
'__Pyx_TypeTest(<PyObject*>%s, %s_TYPE)'
%
(
self
.
name
,
self
.
type_name
)
if
self
.
return_type
.
is_void
:
...
...
Cython/Utility/CFuncConvert.pyx
View file @
e69df685
...
...
@@ -13,7 +13,7 @@ cdef extern from *:
@
cname
(
"{{cname}}"
)
cdef
object
{{
cname
}}({{
return_type
}}
(
*
f
)({{
', '
.
join
(
arg
.
type_name
for
arg
in
args
)
}})
{{
except_clause
}}):
def
wrap
({{
', '
.
join
(
arg
.
name
for
arg
in
args
)
}}):
def
wrap
({{
', '
.
join
(
'{arg.py_arg_type} {arg.name}'
.
format
(
arg
=
arg
)
for
arg
in
args
)
}}):
"""wrap({{', '.join('{arg.name}: {arg.type_displayname!r}'.format(arg=arg) for arg in args)}})"""
{{
for
arg
in
args
}}
{{
arg
.
check_type
()}}
...
...
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