diff --git a/tests/test_class_sh_trampoline_shared_from_this.py b/tests/test_class_sh_trampoline_shared_from_this.py index a80a3ce4f..b4a62275b 100644 --- a/tests/test_class_sh_trampoline_shared_from_this.py +++ b/tests/test_class_sh_trampoline_shared_from_this.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- import pytest +import env # noqa: F401 + +import weakref + import pybind11_tests.class_sh_trampoline_shared_from_this as m @@ -187,6 +191,28 @@ def test_multiple_registered_instances_for_same_pointee_leak(): break # Comment out for manual leak checking (use `top` command). +def test_multiple_registered_instances_for_same_pointee_recursive(): + while True: + obj0 = PySft("PySft") + if not env.PYPY: + obj0_wr = weakref.ref(obj0) + obj = obj0 + # This loop creates a chain of instances linked by shared_ptrs. + for _ in range(10): + obj_next = m.Sft(obj) + assert obj_next is not obj + obj = obj_next + del obj_next + assert obj.history == "PySft" + del obj0 + if not env.PYPY: + assert obj0_wr() is not None + del obj # This releases the chain recursively. + if not env.PYPY: + assert obj0_wr() is None + break # Comment out for manual leak checking (use `top` command). + + def test_std_make_shared_factory(): class PySftMakeShared(m.Sft): def __init__(self, history):