Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
nexedi
cython
Commits
7df719ae
Commit
7df719ae
authored
4 years ago
by
Xavier Thompson
Browse files
Options
Download
Email Patches
Plain Diff
Add unit test for refcount of cypclass results of subscript operations
parent
b4224faf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
tests/run/cypclass_subscript_refcounting.pyx
tests/run/cypclass_subscript_refcounting.pyx
+60
-0
No files found.
tests/run/cypclass_subscript_refcounting.pyx
0 → 100644
View file @
7df719ae
# mode: run
# tag: cpp, cpp11, pthread
# cython: experimental_cpp_class_def=True, language_level=2
from
libcpp.vector
cimport
vector
cdef
cypclass
Value
:
__dealloc__
(
self
)
with
gil
:
print
(
"Value destroyed"
)
def
test_cpp_index_refcounting
():
"""
>>> test_cpp_index_refcounting()
Value destroyed
0
"""
cdef
vector
[
Value
]
vec
vec
.
push_back
(
Value
())
a
=
vec
[
0
]
if
Cy_GETREF
(
a
)
!=
3
:
return
-
1
return
0
cdef
cypclass
Vector
[
T
]:
vector
[
T
]
vec
T
__getitem__
(
self
,
int
index
):
return
vec
[
index
]
def
test_cyp_template_index_refcounting
():
"""
>>> test_cyp_template_index_refcounting()
Value destroyed
0
"""
v
=
Vector
[
Value
]()
v
.
vec
.
push_back
(
Value
())
a
=
v
[
0
]
if
Cy_GETREF
(
a
)
!=
3
:
return
-
1
return
0
cdef
cypclass
ValueVector
:
vector
[
Value
]
vec
Value
__getitem__
(
self
,
int
index
):
return
vec
[
index
]
def
test_cyp_index_refcounting
():
"""
>>> test_cyp_index_refcounting()
Value destroyed
0
"""
v
=
ValueVector
()
v
.
vec
.
push_back
(
Value
())
a
=
v
[
0
]
if
Cy_GETREF
(
a
)
!=
3
:
return
-
1
return
0
This diff is collapsed.
Click to expand it.
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