I'm trying to wrap a function that exposes a raw, heap-allocated pointer, and I want Python to be responsible for its lifetime. This is usually achieved in Boost.Python with using the return_value_policy
of manage_new_object
when wrapping it, is there a similar way to achieve this in nanobind?
What is the nanobind equivalent of the Boost.Python function manage_new_object?
125 views Asked by got here At
1
In nanobind, the equivalent to
return_value_policy::manage_new_object
isrv_policy::take_ownership
.This is the documentation of
manage_new_object
:And this is the documentation for
take_ownership
:Which shows they are functionally equivalent. It is important to note, that this is the default
rv_policy
in nanobind for raw pointers, so you can disregard explicitly defining it:m.def("my_func", &my_func, /*rv_policy::take_ownership*/);