Commit 7df719ae authored by Xavier Thompson's avatar Xavier Thompson

Add unit test for refcount of cypclass results of subscript operations

parent b4224faf
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment