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
12df7f32
Commit
12df7f32
authored
Mar 10, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'molpopgen'
parents
3822c930
b74b9630
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
89 additions
and
12 deletions
+89
-12
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+14
-4
Cython/Includes/libcpp/deque.pxd
Cython/Includes/libcpp/deque.pxd
+1
-1
Cython/Includes/libcpp/list.pxd
Cython/Includes/libcpp/list.pxd
+1
-1
Cython/Includes/libcpp/map.pxd
Cython/Includes/libcpp/map.pxd
+1
-1
Cython/Includes/libcpp/memory.pxd
Cython/Includes/libcpp/memory.pxd
+18
-2
Cython/Includes/libcpp/unordered_set.pxd
Cython/Includes/libcpp/unordered_set.pxd
+1
-1
Cython/Includes/libcpp/vector.pxd
Cython/Includes/libcpp/vector.pxd
+1
-1
tests/run/cpp_smart_ptr.pyx
tests/run/cpp_smart_ptr.pyx
+23
-1
tests/run/cpp_smart_ptr_helper.h
tests/run/cpp_smart_ptr_helper.h
+11
-0
tests/run/libcpp_all.pyx
tests/run/libcpp_all.pyx
+18
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
12df7f32
...
...
@@ -3393,10 +3393,16 @@ class CStructOrUnionType(CType):
cpp_string_conversions
=
(
"std::string"
,)
builtin_cpp_conversions
=
(
"std::pair"
,
"std::vector"
,
"std::list"
,
"std::set"
,
"std::unordered_set"
,
"std::map"
,
"std::unordered_map"
)
builtin_cpp_conversions
=
{
# type element template params
"std::pair"
:
2
,
"std::vector"
:
1
,
"std::list"
:
1
,
"std::set"
:
1
,
"std::unordered_set"
:
1
,
"std::map"
:
2
,
"std::unordered_map"
:
2
,
}
class
CppClassType
(
CType
):
# name string
...
...
@@ -3445,6 +3451,8 @@ class CppClassType(CType):
tags
=
[]
declarations
=
[
"cdef extern from *:"
]
for
ix
,
T
in
enumerate
(
self
.
templates
or
[]):
if
ix
>=
builtin_cpp_conversions
[
self
.
cname
]:
break
if
T
.
is_pyobject
or
not
T
.
create_from_py_utility_code
(
env
):
return
False
tags
.
append
(
T
.
specialization_name
())
...
...
@@ -3507,6 +3515,8 @@ class CppClassType(CType):
tags
=
[]
declarations
=
[
"cdef extern from *:"
]
for
ix
,
T
in
enumerate
(
self
.
templates
or
[]):
if
ix
>=
builtin_cpp_conversions
[
self
.
cname
]:
break
if
not
T
.
create_to_py_utility_code
(
env
):
return
False
tags
.
append
(
T
.
specialization_name
())
...
...
Cython/Includes/libcpp/deque.pxd
View file @
12df7f32
cdef
extern
from
"<deque>"
namespace
"std"
nogil
:
cdef
cppclass
deque
[
T
]:
cdef
cppclass
deque
[
T
,
ALLOCATOR
=*
]:
cppclass
iterator
:
T
&
operator
*
()
iterator
operator
++
()
...
...
Cython/Includes/libcpp/list.pxd
View file @
12df7f32
cdef
extern
from
"<list>"
namespace
"std"
nogil
:
cdef
cppclass
list
[
T
]:
cdef
cppclass
list
[
T
,
ALLOCATOR
=*
]:
cppclass
iterator
:
iterator
()
iterator
(
iterator
&
)
...
...
Cython/Includes/libcpp/map.pxd
View file @
12df7f32
from
.utility
cimport
pair
cdef
extern
from
"<map>"
namespace
"std"
nogil
:
cdef
cppclass
map
[
T
,
U
]:
cdef
cppclass
map
[
T
,
U
,
COMPARE
=*
,
ALLOCATOR
=*
]:
cppclass
iterator
:
pair
[
T
,
U
]
&
operator
*
()
iterator
operator
++
()
...
...
Cython/Includes/libcpp/memory.pxd
View file @
12df7f32
from
libcpp
cimport
bool
,
nullptr_t
,
nullptr
cdef
extern
from
"<memory>"
namespace
"std"
nogil
:
cdef
cppclass
unique_ptr
[
T
]:
cdef
cppclass
default_delete
[
T
]:
default_delete
()
cdef
cppclass
allocator
[
T
]:
allocator
()
allocator
(
const
allocator
&
)
#allocator(const allocator[U] &) #unique_ptr unit tests fail w/this
T
*
address
(
T
&
)
const
T
*
address
(
const
T
&
)
const
T
*
allocate
(
size_t
n
)
# Not to standard. should be a second default argument
void
deallocate
(
T
*
,
size_t
)
size_t
max_size
()
const
void
construct
(
T
*
,
const
T
&
)
#C++98. The C++11 version is variadic AND perfect-forwarding
void
destroy
(
T
*
)
#C++98
void
destroy
[
U
](
U
*
)
#unique_ptr unit tests fail w/this
cdef
cppclass
unique_ptr
[
T
,
DELETER
=*
]:
unique_ptr
()
unique_ptr
(
nullptr_t
)
unique_ptr
(
T
*
)
...
...
Cython/Includes/libcpp/unordered_set.pxd
View file @
12df7f32
from
.utility
cimport
pair
cdef
extern
from
"<unordered_set>"
namespace
"std"
nogil
:
cdef
cppclass
unordered_set
[
T
]:
cdef
cppclass
unordered_set
[
T
,
HASH
=*
,
PRED
=*
,
ALLOCATOR
=*
]:
cppclass
iterator
:
T
&
operator
*
()
iterator
operator
++
()
...
...
Cython/Includes/libcpp/vector.pxd
View file @
12df7f32
cdef
extern
from
"<vector>"
namespace
"std"
nogil
:
cdef
cppclass
vector
[
T
]:
cdef
cppclass
vector
[
T
,
ALLOCATOR
=*
]:
cppclass
iterator
:
T
&
operator
*
()
iterator
operator
++
()
...
...
tests/run/cpp_smart_ptr.pyx
View file @
12df7f32
...
...
@@ -2,12 +2,16 @@
# mode: run
# tag: cpp, werror
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
,
default_delete
from
libcpp
cimport
nullptr
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
cdef
cppclass
CountAllocDealloc
:
CountAllocDealloc
(
int
*
,
int
*
)
cdef
cppclass
FreePtr
[
T
]:
pass
def
test_unique_ptr
():
"""
>>> test_unique_ptr()
...
...
@@ -19,3 +23,21 @@ def test_unique_ptr():
x_ptr
.
reset
()
assert
alloc_count
==
1
assert
dealloc_count
==
1
##Repeat the above test with an explicit default_delete type
alloc_count
=
0
dealloc_count
=
0
cdef
unique_ptr
[
CountAllocDealloc
,
default_delete
[
CountAllocDealloc
]]
x_ptr2
x_ptr2
.
reset
(
new
CountAllocDealloc
(
&
alloc_count
,
&
dealloc_count
))
assert
alloc_count
==
1
x_ptr2
.
reset
()
assert
alloc_count
==
1
assert
dealloc_count
==
1
alloc_count
=
0
dealloc_count
=
0
cdef
unique_ptr
[
CountAllocDealloc
,
FreePtr
[
CountAllocDealloc
]]
x_ptr3
x_ptr3
.
reset
(
new
CountAllocDealloc
(
&
alloc_count
,
&
dealloc_count
))
assert
x_ptr3
.
get
()
!=
nullptr
;
x_ptr3
.
reset
()
assert
x_ptr3
.
get
()
==
nullptr
;
tests/run/cpp_smart_ptr_helper.h
View file @
12df7f32
...
...
@@ -11,3 +11,14 @@ class CountAllocDealloc {
int
*
_alloc_count
;
int
*
_dealloc_count
;
};
template
<
typename
T
>
struct
FreePtr
{
void
operator
()(
T
*
t
)
noexcept
{
if
(
t
!=
nullptr
)
{
delete
t
;
t
=
nullptr
;
}
}
};
tests/run/libcpp_all.pyx
View file @
12df7f32
...
...
@@ -107,3 +107,21 @@ cdef int ieps = numeric_limits[int].epsilon()
cdef
int
iqnan
=
numeric_limits
[
int
].
quiet_NaN
()
cdef
int
isnan
=
numeric_limits
[
int
].
signaling_NaN
()
cdef
int
iinf
=
numeric_limits
[
int
].
infinity
()
#API checks for containers with std::allocator declared
from
libcpp.memory
cimport
allocator
cdef
libcpp
.
vector
.
vector
[
int
,
allocator
[
int
]]
vec_alloc_int
=
libcpp
.
vector
.
vector
[
int
,
allocator
[
int
]](
10
,
1
)
assert
vec_alloc_int
.
size
()
==
10
cdef
libcpp
.
list
.
list
[
int
,
allocator
[
int
]]
list_alloc_int
=
libcpp
.
list
.
list
[
int
,
allocator
[
int
]](
10
,
1
)
assert
list_alloc_int
.
size
()
==
10
##Something about the default params breaks the auto-conversion...
def
convert_to_vector
(
I
):
"""
>>> convert_to_vector([1,2,3,4])
"""
cdef
vector
[
int
]
x
=
I
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