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
I have a C++ library that uses raw pointers in return values and arguments to indicate transfer of ownership. What is the best approach to wrap this with pybind11? I know that transfer of ownership for return values can be handled with return_value_policy::take_ownership, but what about functions and class methods that take ownership via raw pointers?
The documentation on std::unique_ptr might be relevant here: (link)
While returning unique pointers in this way is allowed, it is illegal to use them as function arguments. For instance, the following function signature cannot be processed by pybind11.
The above signature would imply that Python needs to give up ownership of an object that is passed to this function, which is generally not possible (for instance, the object might be referenced elsewhere).
The semantics are the same here. What is the suggested "workaround" to cope with it, when the C++ API has functions that need to take ownership of the passed objects?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a C++ library that uses raw pointers in return values and arguments to indicate transfer of ownership. What is the best approach to wrap this with pybind11? I know that transfer of ownership for return values can be handled with
return_value_policy::take_ownership
, but what about functions and class methods that take ownership via raw pointers?The documentation on std::unique_ptr might be relevant here: (link)
The semantics are the same here. What is the suggested "workaround" to cope with it, when the C++ API has functions that need to take ownership of the passed objects?
Beta Was this translation helpful? Give feedback.
All reactions