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
e2d0d129
Commit
e2d0d129
authored
Jul 31, 2018
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add C++11 smart pointer casts.
parent
23c68023
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
3 deletions
+22
-3
Cython/Includes/libcpp/memory.pxd
Cython/Includes/libcpp/memory.pxd
+6
-0
tests/run/cpp_smart_ptr.pyx
tests/run/cpp_smart_ptr.pyx
+15
-2
tests/run/cpp_smart_ptr_helper.h
tests/run/cpp_smart_ptr_helper.h
+1
-1
No files found.
Cython/Includes/libcpp/memory.pxd
View file @
e2d0d129
...
...
@@ -107,3 +107,9 @@ cdef extern from "<memory>" namespace "std" nogil:
# Temporaries used for exception handling break generated code
unique_ptr
[
T
]
make_unique
[
T
](...)
# except +
# No checking on the compatibility of T and U.
cdef
shared_ptr
[
T
]
static_pointer_cast
[
T
,
U
](
const
shared_ptr
[
U
]
&
)
cdef
shared_ptr
[
T
]
dynamic_pointer_cast
[
T
,
U
](
const
shared_ptr
[
U
]
&
)
cdef
shared_ptr
[
T
]
const_pointer_cast
[
T
,
U
](
const
shared_ptr
[
U
]
&
)
cdef
shared_ptr
[
T
]
reinterpret_pointer_cast
[
T
,
U
](
const
shared_ptr
[
U
]
&
)
tests/run/cpp_smart_ptr.pyx
View file @
e2d0d129
...
...
@@ -2,7 +2,7 @@
# tag: cpp, werror, cpp11
# distutils: extra_compile_args=-std=c++0x
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
,
default_delete
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
,
default_delete
,
dynamic_pointer_cast
from
libcpp
cimport
nullptr
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
...
...
@@ -71,6 +71,7 @@ def test_const_shared_ptr():
cdef
cppclass
A
:
void
some_method
():
# Force this to be a polymorphic class for dynamic cast.
pass
cdef
cppclass
B
(
A
):
...
...
@@ -80,3 +81,15 @@ cdef cppclass C(B):
pass
cdef
shared_ptr
[
A
]
holding_subclass
=
shared_ptr
[
A
](
new
C
())
def
test_dynamic_pointer_cast
():
"""
>>> test_dynamic_pointer_cast()
"""
cdef
shared_ptr
[
B
]
b
=
shared_ptr
[
B
](
new
B
())
cdef
shared_ptr
[
A
]
a
=
dynamic_pointer_cast
[
A
,
B
](
b
)
assert
a
.
get
()
==
b
.
get
()
a
=
shared_ptr
[
A
](
new
A
())
b
=
dynamic_pointer_cast
[
B
,
A
](
a
)
assert
b
.
get
()
==
NULL
tests/run/cpp_smart_ptr_helper.h
View file @
e2d0d129
...
...
@@ -14,7 +14,7 @@ class CountAllocDealloc {
template
<
typename
T
>
struct
FreePtr
{
void
operator
()(
T
*
t
)
noexcept
void
operator
()(
T
*
t
)
{
if
(
t
!=
nullptr
)
{
delete
t
;
...
...
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