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
2ffe0aa6
Commit
2ffe0aa6
authored
Sep 08, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for refcounting of elements of cypclass arrays
parent
4d1306cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
0 deletions
+151
-0
tests/run/cypclass_array_refcounting.pyx
tests/run/cypclass_array_refcounting.pyx
+151
-0
No files found.
tests/run/cypclass_array_refcounting.pyx
0 → 100644
View file @
2ffe0aa6
# mode: run
# tag: cpp, cpp11, pthread
# cython: experimental_cpp_class_def=True, language_level=2
cdef
cypclass
Refcounted
:
int
index
__init__
(
self
,
int
index
):
self
.
index
=
index
__dealloc__
(
self
)
with
gil
:
print
(
"destroyed: %d"
%
index
)
cdef
Refcounted
global_array
[
10
]
def
test_global_array_init
():
"""
>>> test_global_array_init()
0
"""
for
i
in
range
(
10
):
if
global_array
[
i
]
is
not
NULL
:
return
-
(
i
+
1
)
return
0
def
test_local_array_init
():
"""
>>> test_local_array_init()
0
"""
cdef
Refcounted
local_array
[
10
]
for
i
in
range
(
10
):
if
local_array
[
i
]
is
not
NULL
:
return
-
(
i
+
1
)
return
0
def
test_global_array_refcount
():
"""
>>> test_global_array_refcount()
destroyed: 0
0
"""
obj
=
Refcounted
(
0
)
if
Cy_GETREF
(
obj
)
!=
2
:
return
-
1
for
i
in
range
(
10
):
global_array
[
i
]
=
obj
if
Cy_GETREF
(
obj
)
!=
2
+
i
+
1
:
return
-
(
i
+
2
)
for
i
in
range
(
10
):
del
global_array
[
i
]
if
Cy_GETREF
(
obj
)
!=
12
-
i
-
1
:
return
-
(
i
+
12
)
if
Cy_GETREF
(
obj
)
!=
2
:
return
-
22
return
0
def
test_local_array_refcount
():
"""
>>> test_local_array_refcount()
destroyed: 0
0
"""
cdef
Refcounted
local_array
[
10
]
obj
=
Refcounted
(
0
)
if
Cy_GETREF
(
obj
)
!=
2
:
return
-
1
for
i
in
range
(
10
):
local_array
[
i
]
=
obj
if
Cy_GETREF
(
obj
)
!=
2
+
i
+
1
:
return
-
(
i
+
2
)
for
i
in
range
(
10
):
del
local_array
[
i
]
if
Cy_GETREF
(
obj
)
!=
12
-
i
-
1
:
return
-
(
i
+
12
)
if
Cy_GETREF
(
obj
)
!=
2
:
return
-
22
return
0
def
test_local_array_destruction
():
"""
>>> test_local_array_destruction()
destroyed: 0
destroyed: 1
destroyed: 2
destroyed: 3
destroyed: 4
destroyed: 5
destroyed: 6
destroyed: 7
destroyed: 8
destroyed: 9
"""
cdef
Refcounted
local_array
[
10
]
for
i
in
range
(
10
):
local_array
[
i
]
=
Refcounted
(
i
)
def
test_local_array_assignment_destruction
():
"""
>>> test_local_array_assignment_destruction()
destroyed: 0
destroyed: 1
destroyed: 2
destroyed: 3
destroyed: 4
destroyed: 5
destroyed: 6
destroyed: 7
destroyed: 8
destroyed: 9
destroyed: 10
destroyed: 11
destroyed: 12
destroyed: 13
destroyed: 14
destroyed: 15
destroyed: 16
destroyed: 17
destroyed: 18
destroyed: 19
"""
cdef
Refcounted
local_array
[
10
]
cdef
Refcounted
local_array2
[
10
]
for
i
in
range
(
10
):
local_array
[
i
]
=
Refcounted
(
i
)
for
i
in
range
(
10
):
local_array2
[
i
]
=
Refcounted
(
i
+
10
)
local_array
=
local_array2
cdef
int
test_array_as_argument
(
Refcounted
*
array
,
int
size
):
obj
=
Refcounted
(
0
)
if
Cy_GETREF
(
obj
)
!=
2
:
return
-
1
for
i
in
range
(
size
):
array
[
i
]
=
obj
if
Cy_GETREF
(
obj
)
!=
2
+
i
+
1
:
return
-
(
i
+
2
)
for
i
in
range
(
10
):
del
array
[
i
]
if
Cy_GETREF
(
obj
)
!=
12
-
i
-
1
:
return
-
(
i
+
size
+
2
)
if
Cy_GETREF
(
obj
)
!=
2
:
return
-
(
2
*
size
+
2
)
return
0
def
test_array_argument_refcount
():
"""
>>> test_array_argument_refcount()
destroyed: 0
0
"""
cdef
Refcounted
local_array
[
10
]
return
test_array_as_argument
(
local_array
,
10
)
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