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
895da799
Commit
895da799
authored
Feb 22, 2016
by
Kevin R. Thornton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test of unique_ptr with std::default_delete and a custom deleter
parent
6a620200
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-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
No files found.
tests/run/cpp_smart_ptr.pyx
View file @
895da799
...
...
@@ -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 @
895da799
...
...
@@ -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
;
}
}
};
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