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
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
Hide 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:
...
@@ -107,3 +107,9 @@ cdef extern from "<memory>" namespace "std" nogil:
# Temporaries used for exception handling break generated code
# Temporaries used for exception handling break generated code
unique_ptr
[
T
]
make_unique
[
T
](...)
# except +
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 @@
...
@@ -2,7 +2,7 @@
# tag: cpp, werror, cpp11
# tag: cpp, werror, cpp11
# distutils: extra_compile_args=-std=c++0x
# 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
from
libcpp
cimport
nullptr
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
...
@@ -71,7 +71,8 @@ def test_const_shared_ptr():
...
@@ -71,7 +71,8 @@ def test_const_shared_ptr():
cdef
cppclass
A
:
cdef
cppclass
A
:
pass
void
some_method
():
# Force this to be a polymorphic class for dynamic cast.
pass
cdef
cppclass
B
(
A
):
cdef
cppclass
B
(
A
):
pass
pass
...
@@ -80,3 +81,15 @@ cdef cppclass C(B):
...
@@ -80,3 +81,15 @@ cdef cppclass C(B):
pass
pass
cdef
shared_ptr
[
A
]
holding_subclass
=
shared_ptr
[
A
](
new
C
())
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 {
...
@@ -14,7 +14,7 @@ class CountAllocDealloc {
template
<
typename
T
>
template
<
typename
T
>
struct
FreePtr
{
struct
FreePtr
{
void
operator
()(
T
*
t
)
noexcept
void
operator
()(
T
*
t
)
{
{
if
(
t
!=
nullptr
)
{
if
(
t
!=
nullptr
)
{
delete
t
;
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