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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
eb3e5e6e
Commit
eb3e5e6e
authored
Jul 02, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't forget std::list.
parent
4a57c2c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
6 deletions
+18
-6
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+1
-1
Cython/Utility/CppConvert.pyx
Cython/Utility/CppConvert.pyx
+8
-5
tests/run/cpp_stl_conversion.pyx
tests/run/cpp_stl_conversion.pyx
+9
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
eb3e5e6e
...
...
@@ -2987,7 +2987,7 @@ class CStructOrUnionType(CType):
return
super
(
CStructOrUnionType
,
self
).
cast_code
(
expr_code
)
builtin_cpp_conversions
=
(
"std::string"
,
"std::vector"
,
"std::set"
,
"std::map"
,
"std::pair"
)
builtin_cpp_conversions
=
(
"std::string"
,
"std::vector"
,
"std::
list"
,
"std::
set"
,
"std::map"
,
"std::pair"
)
class
CppClassType
(
CType
):
# name string
...
...
Cython/Utility/CppConvert.pyx
View file @
eb3e5e6e
...
...
@@ -74,8 +74,8 @@ cdef extern from *:
void
push_back
(
T
&
)
@
cname
(
"{{cname}}"
)
cdef
cpp_list
[
{{
T0
}}
]
{{
cname
}}(
object
o
)
except
*
:
cdef
cpp_list
[
{{
T0
}}
]
l
cdef
cpp_list
[
X
]
{{
cname
}}(
object
o
)
except
*
:
cdef
cpp_list
[
X
]
l
for
item
in
o
:
l
.
push_back
(
X_from_py
(
item
))
return
l
...
...
@@ -83,6 +83,8 @@ cdef cpp_list[{{T0}}] {{cname}}(object o) except *:
#################### list.to_py ####################
cimport
cython
cdef
extern
from
*
:
ctypedef
struct
X
"{{T0}}"
:
pass
...
...
@@ -96,13 +98,14 @@ cdef extern from *:
bint
operator
!=
(
const_iterator
)
const_iterator
begin
()
const_iterator
end
()
cdef
cppclass
const_cpp_list
"const std::list"
[
T
]
(
cpp_list
)
cdef
cppclass
const_cpp_list
"const std::list"
[
T
]
(
cpp_list
):
pass
@
cname
(
"{{cname}}"
)
cdef
object
{{
cname
}}(
const_cpp_list
[
X
]
&
v
):
o
=
[]
cdef
cpp_list
[
X
].
const_iterator
iter
=
s
.
begin
()
while
iter
!=
s
.
end
():
cdef
cpp_list
[
X
].
const_iterator
iter
=
v
.
begin
()
while
iter
!=
v
.
end
():
o
.
append
(
X_to_py
(
cython
.
operator
.
dereference
(
iter
)))
cython
.
operator
.
preincrement
(
iter
)
return
o
...
...
tests/run/cpp_stl_conversion.pyx
View file @
eb3e5e6e
...
...
@@ -6,6 +6,7 @@ from libcpp.set cimport set as cpp_set
from
libcpp.string
cimport
string
from
libcpp.pair
cimport
pair
from
libcpp.vector
cimport
vector
from
libcpp.list
cimport
list
as
cpp_list
py_set
=
set
...
...
@@ -67,6 +68,14 @@ def test_pair(o):
cdef
pair
[
long
,
double
]
p
=
o
return
p
def
test_list
(
o
):
"""
>>> test_list([1, 2, 3])
[1, 2, 3]
"""
cdef
cpp_list
[
int
]
l
=
o
return
l
def
test_set
(
o
):
"""
>>> sorted(test_set([1, 2, 3]))
...
...
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