[BUG]: std::weak_ptr
expires for derived Python objects using py::smart_holder
#5623
Open
3 tasks done
Labels
triage
New bug, unverified
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
bc4a66d
Problem description
I have a C++ base class that I bind using the trampoline class setup and
py::smart_holder
. I extend the base class with a derived Python class. I also have a C++ class (and bound Python class) that holds astd::weak_ptr<base>
. If I give the holder class a pointer to an instance of the derived Python class, passed withstd::shared_ptr<base>
, when I later check on the status of the weak pointer, I find that it's expired.I've verified this on the latest commit to the master branch (bc4a66d) using both a Mac and running in a Linux container on the Mac. Please see PR #5624 and the code in this issue for buildable examples demonstrating the problem.
With the code below, the expected output is:
The actual output is:
The issue is the last line, which indicates that the weak_ptr is no longer aware that the object still exists.
I tested a these variations:
Reproducible example code
Is this a regression? Put the last known working version here if it is.
Not a regression
The text was updated successfully, but these errors were encountered: