pybind11/tests/test_class_sh_trampoline_shared_from_this.py
Ralf W. Grosse-Kunstleve bf8d6a2900 First fully successful attempt to make shared_from_this and trampolines play nicely.
Now also passes the open_spiel iterated_prisoners_dilemma_test ASAN clean, in addition to all pybind11 and PyCLIF unit tests.

The problem was that calling `std::shared_ptr<void>::reset()` with a `void` pointer cannot possibly update the `shared_from_this` `weak_ptr`.

The solution is to store a `shd_ptr_reset` function pointer in `guarded_deleter` (similar in idea to the stored function pointer for calling `delete`).

This commit still includes all debugging code, i.e. is "dirty". The code will be cleaned up after the GitHub CI is fully successful.
2021-06-30 07:04:31 -07:00

20 lines
426 B
Python

# -*- coding: utf-8 -*-
import pybind11_tests.class_sh_trampoline_shared_from_this as m
class PyWithSft(m.WithSft):
pass
def test_pass_shared_ptr():
m.to_cout("")
m.to_cout(">>> obj = PyWithSft()")
obj = PyWithSft()
m.to_cout(">>> m.pass_shared_ptr(obj) #1")
m.pass_shared_ptr(obj)
m.to_cout(">>> m.pass_shared_ptr(obj) #2")
m.pass_shared_ptr(obj)
m.to_cout(">>> del obj")
del obj