WIP: Support ownership transfer between C++ and Python with shared_ptr<T>
and unique_ptr<T>
for pure C++ instances and single-inheritance instances by EricCousineau-TRI · Pull Request #1146 · pybind/pybind11 (original) (raw)
I understand on the commit scale. I can certainly break this into smaller components to take this out of a WIP stage. (I can also collapse the commits - those were me just prototyping small tests as I was learning some of the internals of pybind11
.)
For moving unique_ptr<>
, can I ask what part does not make sense? (Well, aside from the bloat of the implementation, and the oddity of signaling a move via a list
is a tad kludgy...)
This permits the equivalent of #971, but a with a few more checks, and supporting single inheritance.
This also includes preventing Python-subclass aliasing that would arise from passing shared_ptr<>
s from Python to C++, which at present would fail silently. (This is my main focus at present, but I would still like to enable cast
ing unique_ptr<>
-held instances to permit full ownership transfer.) The solution shares an implementation with the unique_ptr<>
approach.
Additionally, it addresses #1138 more robustly, and provides some limited mixing of compatible holder types (unique_ptr<T>
-> shared_ptr<T>
).