Skip to content

Commit 5af253d

Browse files
committed
Adding test_multiple_registered_instances_for_same_pointee_recursive.
1 parent a021e04 commit 5af253d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_class_sh_trampoline_shared_from_this.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22
import pytest
33

4+
import env # noqa: F401
5+
6+
import weakref
7+
48
import pybind11_tests.class_sh_trampoline_shared_from_this as m
59

610

@@ -187,6 +191,28 @@ def test_multiple_registered_instances_for_same_pointee_leak():
187191
break # Comment out for manual leak checking (use `top` command).
188192

189193

194+
def test_multiple_registered_instances_for_same_pointee_recursive():
195+
while True:
196+
obj0 = PySft("PySft")
197+
if not env.PYPY:
198+
obj0_wr = weakref.ref(obj0)
199+
obj = obj0
200+
# This loop creates a chain of instances linked by shared_ptrs.
201+
for _ in range(10):
202+
obj_next = m.Sft(obj)
203+
assert obj_next is not obj
204+
obj = obj_next
205+
del obj_next
206+
assert obj.history == "PySft"
207+
del obj0
208+
if not env.PYPY:
209+
assert obj0_wr() is not None
210+
del obj # This releases the chain recursively.
211+
if not env.PYPY:
212+
assert obj0_wr() is None
213+
break # Comment out for manual leak checking (use `top` command).
214+
215+
190216
def test_std_make_shared_factory():
191217
class PySftMakeShared(m.Sft):
192218
def __init__(self, history):

0 commit comments

Comments
 (0)