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
e87d4e98
Commit
e87d4e98
authored
Sep 09, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for refcounting of iterated-over cypclass
parent
f7c09e2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
0 deletions
+120
-0
tests/run/cypclass_builtin_dict.pyx
tests/run/cypclass_builtin_dict.pyx
+26
-0
tests/run/cypclass_iteration.pyx
tests/run/cypclass_iteration.pyx
+94
-0
No files found.
tests/run/cypclass_builtin_dict.pyx
View file @
e87d4e98
...
...
@@ -744,3 +744,29 @@ def test_iterator_refcount():
return
-
11
return
0
cdef
cypdict
[
Index
,
Value
]
pass_along
(
cypdict
[
Index
,
Value
]
d
):
return
d
def
test_iteration_refcount
():
"""
>>> test_iteration_refcount()
0
"""
d
=
cypdict
[
Index
,
Value
]()
if
Cy_GETREF
(
d
)
!=
2
:
return
-
1
for
key
in
d
:
pass
if
Cy_GETREF
(
d
)
!=
2
:
return
-
2
for
key
in
pass_along
(
d
):
pass
if
Cy_GETREF
(
d
)
!=
2
:
return
-
3
return
0
tests/run/cypclass_iteration.pyx
0 → 100644
View file @
e87d4e98
# 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"
)
cdef
cypclass
Stack
:
vector
[
Value
]
vec
void
push
(
self
,
Value
v
):
self
.
vec
.
push_back
(
v
)
Value
pop
(
self
)
except
NULL
:
if
self
.
vec
.
size
()
>
0
:
value
=
self
.
vec
.
back
()
self
.
vec
.
pop_back
()
return
value
else
:
with
gil
:
raise
IndexError
(
"Stack is empty"
)
vector
[
Value
].
iterator
begin
(
self
):
return
vec
.
begin
()
vector
[
Value
].
iterator
end
(
self
):
return
vec
.
end
()
def
test_value_refcount
():
"""
>>> test_value_refcount()
Value destroyed
0
"""
v
=
Value
()
s
=
Stack
()
if
Cy_GETREF
(
v
)
!=
2
:
return
-
1
s
.
push
(
v
)
if
Cy_GETREF
(
v
)
!=
3
:
return
-
2
s
.
push
(
v
)
if
Cy_GETREF
(
v
)
!=
4
:
return
-
3
s
.
push
(
v
)
if
Cy_GETREF
(
v
)
!=
5
:
return
-
4
v2
=
s
.
pop
()
if
Cy_GETREF
(
v
)
!=
5
:
return
-
5
del
v2
if
Cy_GETREF
(
v
)
!=
4
:
return
-
5
v2
=
s
.
pop
()
del
v2
if
Cy_GETREF
(
v
)
!=
3
:
return
-
6
v2
=
s
.
pop
()
if
Cy_GETREF
(
v
)
!=
3
:
return
-
7
del
v2
if
Cy_GETREF
(
v
)
!=
2
:
return
-
8
try
:
v2
=
s
.
pop
()
return
-
9
except
IndexError
as
e
:
pass
return
0
cdef
Stack
pass_along
(
Stack
s
):
return
s
def
test_stack_refcount
():
"""
>>> test_stack_refcount()
0
"""
s
=
Stack
()
if
Cy_GETREF
(
s
)
!=
2
:
return
-
1
for
key
in
s
:
pass
if
Cy_GETREF
(
s
)
!=
2
:
return
-
2
for
key
in
pass_along
(
s
):
pass
if
Cy_GETREF
(
s
)
!=
2
:
return
-
3
return
0
\ No newline at end of file
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