File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22import pytest
33
4+ import env # noqa: F401
5+
6+ import weakref
7+
48import 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+
190216def test_std_make_shared_factory ():
191217 class PySftMakeShared (m .Sft ):
192218 def __init__ (self , history ):
You can’t perform that action at this time.
0 commit comments