Adding test_multiple_registered_instances_for_same_pointee_recursive.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-06-29 15:43:50 -07:00 committed by Ralf W. Grosse-Kunstleve
parent a021e045a9
commit 5af253d66c

View File

@ -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):