You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Importing pybind11 smart_holder PR #2886 from GitHub and adjusting PyCLIF smart_ptrs_test accordingly.
pybind/pybind11#2886
High-level summary of the two critical behavior changes:
* Context: handling of smart pointers for instances of Python-derived classes with pybind11-wrapped bases.
* Keywords: trampoline, also known as alias class, virtual functions with Python overrides.
* Minimal example: `class PyDrvd(m.Abase)` in test_class_sh_with_alias.py
* When a `shared_ptr<base>` is passed from Python to C++ (as a C++ function argument), the `shared_ptr` is built specifically for the function call, using a custom deleter tying the lifetime of the Python instance to the lifetime of the `shared_ptr`. This solves what's sometimes referred to as "inheritance slicing" issue in connection with the pybind11 trampoline feature. Note that there are ~10 open pybind11 issues related to this problem, enumerated in the description of [PR #2839](pybind/pybind11#2839).
* Passing a `unique_ptr<base>` is disabled. A `ValueError` is raised, with message: "Ownership of instance with virtual overrides in Python cannot be transferred to C++."
For full details see the description of PR #2886.
- 97a7fb722a9842cae4d91be82897dd863f6b607d Porting/adapting Dustin's PR #2839 to smart_holder branch... by Ralf W. Grosse-Kunstleve <[email protected]>
PiperOrigin-RevId: 360966763
0 commit comments