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
2a6da33b
Commit
2a6da33b
authored
Apr 27, 2018
by
Alex Huszagh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixes for STL lists.
parent
ee1b0219
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
165 additions
and
0 deletions
+165
-0
Cython/Includes/libcpp/list.pxd
Cython/Includes/libcpp/list.pxd
+7
-0
tests/run/cpp_stl_list.pyx
tests/run/cpp_stl_list.pyx
+158
-0
No files found.
Cython/Includes/libcpp/list.pxd
View file @
2a6da33b
...
...
@@ -2,6 +2,13 @@ cdef extern from "<list>" namespace "std" nogil:
cdef
cppclass
list
[
T
,
ALLOCATOR
=*
]:
ctypedef
T
value_type
ctypedef
ALLOCATOR
allocator_type
# these should really be allocator_type.size_type and
# allocator_type.difference_type to be true to the C++ definition
# but cython doesn't support deferred access on template arguments
ctypedef
size_t
size_type
ctypedef
ptrdiff_t
difference_type
cppclass
iterator
:
iterator
()
iterator
(
iterator
&
)
...
...
tests/run/cpp_stl_list.pyx
0 → 100644
View file @
2a6da33b
# mode: run
# tag: cpp, werror
from
cython.operator
cimport
dereference
as
deref
from
cython.operator
cimport
preincrement
as
incr
from
libcpp.list
cimport
list
as
cpp_list
from
libcpp
cimport
bool
as
cbool
def
simple_test
(
double
x
):
"""
>>> simple_test(55)
3
"""
l
=
new
cpp_list
[
double
]()
try
:
l
.
push_back
(
1.0
)
l
.
push_back
(
x
)
from
math
import
pi
l
.
push_back
(
pi
)
return
l
.
size
()
finally
:
del
l
def
pylist_test
(
L
):
"""
>>> pylist_test([1,2,4,8])
(4, 4)
>>> pylist_test([])
(0, 0)
>>> pylist_test([-1] * 1000)
(1000, 1000)
"""
l
=
new
cpp_list
[
int
]()
try
:
for
a
in
L
:
l
.
push_back
(
a
)
return
len
(
L
),
l
.
size
()
finally
:
del
l
def
iteration_test
(
L
):
"""
>>> iteration_test([1,2,4,8])
1
2
4
8
"""
l
=
new
cpp_list
[
int
]()
try
:
for
a
in
L
:
l
.
push_back
(
a
)
it
=
l
.
begin
()
while
it
!=
l
.
end
():
a
=
deref
(
it
)
incr
(
it
)
print
(
a
)
finally
:
del
l
def
reverse_iteration_test
(
L
):
"""
>>> reverse_iteration_test([1,2,4,8])
8
4
2
1
"""
l
=
new
cpp_list
[
int
]()
try
:
for
a
in
L
:
l
.
push_back
(
a
)
it
=
l
.
rbegin
()
while
it
!=
l
.
rend
():
a
=
deref
(
it
)
incr
(
it
)
print
(
a
)
finally
:
del
l
def
nogil_test
(
L
):
"""
>>> nogil_test([1,2,3])
3
"""
cdef
int
a
with
nogil
:
l
=
new
cpp_list
[
int
]()
try
:
for
a
in
L
:
with
nogil
:
l
.
push_back
(
a
)
return
l
.
size
()
finally
:
del
l
cdef
list
to_pylist
(
cpp_list
[
int
]
&
l
):
cdef
list
L
=
[]
it
=
l
.
begin
()
while
it
!=
l
.
end
():
L
.
append
(
deref
(
it
))
incr
(
it
)
return
L
def
item_ptr_test
(
L
,
int
x
):
"""
>>> item_ptr_test(range(10), 100)
[100, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
cdef
cpp_list
[
int
]
l
=
L
cdef
int
*
li_ptr
=
&
l
.
front
()
li_ptr
[
0
]
=
x
return
to_pylist
(
l
)
def
test_value_type
(
x
):
"""
>>> test_value_type(2)
2.0
>>> test_value_type(2.5)
2.5
"""
cdef
cpp_list
[
double
].
value_type
val
=
x
return
val
def
test_value_type_complex
(
x
):
"""
>>> test_value_type_complex(2)
(2+0j)
"""
cdef
cpp_list
[
double
complex
].
value_type
val
=
x
return
val
def
test_insert
():
"""
>>> test_insert()
"""
cdef
cpp_list
[
int
]
l
cdef
cpp_list
[
int
].
size_type
count
=
5
cdef
int
value
=
0
l
.
insert
(
l
.
end
(),
count
,
value
)
assert
l
.
size
()
==
count
for
element
in
l
:
assert
element
==
value
,
'%s != %s'
%
(
element
,
count
)
# Tests GitHub issue #1788.
cdef
cppclass
MyList
[
T
](
cpp_list
):
pass
cdef
cppclass
Ints
(
MyList
[
int
]):
pass
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