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
Gwenaël Samain
cython
Commits
ebc3df31
Commit
ebc3df31
authored
Oct 25, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement recursive carray-to-Python coercion
parent
d05cbd9b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
9 deletions
+26
-9
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+0
-1
Cython/Utility/CConvert.pyx
Cython/Utility/CConvert.pyx
+11
-8
tests/run/carray_coercion.pyx
tests/run/carray_coercion.pyx
+15
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
ebc3df31
...
...
@@ -2258,7 +2258,6 @@ class CArrayType(CPointerBaseType):
'cname'
:
to_py_function
,
'to_tuple_cname'
:
to_tuple_function
,
'base_type'
:
base_type
,
'to_py_func'
:
self
.
base_type
.
to_py_function
,
}
env
.
use_utility_code
(
CythonUtilityCode
.
load
(
"carray.to_py"
,
"CConvert.pyx"
,
...
...
Cython/Utility/CConvert.pyx
View file @
ebc3df31
...
...
@@ -66,29 +66,32 @@ cdef int {{cname}}(object o, {{base_type}} *v, Py_ssize_t length) except -1:
#################### carray.to_py ####################
cdef
extern
from
*
:
ctypedef
struct
PyObject
PyObject
*
{{
to_py_func
}}({{
base_type
}})
except
NULL
void
Py_INCREF
(
object
o
)
tuple
PyTuple_New
(
Py_ssize_t
size
)
void
PyTuple_SET_ITEM
(
object
p
,
Py_ssize_t
pos
,
PyObject
*
o
)
list
PyList_New
(
Py_ssize_t
size
)
void
PyList_SET_ITEM
(
object
p
,
Py_ssize_t
pos
,
PyObject
*
o
)
void
PyTuple_SET_ITEM
(
object
p
,
Py_ssize_t
pos
,
object
o
)
void
PyList_SET_ITEM
(
object
p
,
Py_ssize_t
pos
,
object
o
)
@
cname
(
"{{cname}}"
)
cdef
inline
list
{{
cname
}}({{
base_type
}}
*
v
,
Py_ssize_t
length
):
cdef
size_t
i
cdef
object
value
l
=
PyList_New
(
length
)
for
i
in
range
(
<
size_t
>
length
):
PyList_SET_ITEM
(
l
,
i
,
{{
to_py_func
}}(
v
[
i
]))
value
=
v
[
i
]
Py_INCREF
(
value
)
PyList_SET_ITEM
(
l
,
i
,
value
)
return
l
@
cname
(
"{{to_tuple_cname}}"
)
cdef
inline
tuple
{{
to_tuple_cname
}}({{
base_type
}}
*
v
,
Py_ssize_t
length
):
cdef
size_t
i
cdef
object
value
t
=
PyTuple_New
(
length
)
for
i
in
range
(
<
size_t
>
length
):
PyTuple_SET_ITEM
(
t
,
i
,
{{
to_py_func
}}(
v
[
i
]))
value
=
v
[
i
]
Py_INCREF
(
value
)
PyTuple_SET_ITEM
(
t
,
i
,
value
)
return
t
tests/run/carray_coercion.pyx
View file @
ebc3df31
...
...
@@ -52,6 +52,21 @@ cpdef tuple tuple_from_typedef_int_array():
return
v
def
from_int_array_array
():
"""
>>> from_int_array_array()
[[11, 12, 13], [21, 22, 23]]
"""
cdef
int
[
2
][
3
]
v
v
[
0
][
0
]
=
11
v
[
0
][
1
]
=
12
v
[
0
][
2
]
=
13
v
[
1
][
0
]
=
21
v
[
1
][
1
]
=
22
v
[
1
][
2
]
=
23
return
v
ctypedef
struct
MyStructType
:
int
x
double
y
...
...
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