Pybind11: is make_tuple() owns wrapped pointers?

829 views Asked by At

Suppose I have a function like this, which I'm wrapping in Pybind11:

void func(){
  SomeCppType* var1 = new SomeCppType();
  SomeCppType* var2 = new SomeCppType();
  return py::make_tuple(var1,var2)
}

What will happen with ownership of pointers? Is it posisble to tell pybind11::tuple to own the pointers and call delete on them? What is the correct way of writing this?

1

There are 1 answers

0
David Braun On

py::make_tuple is a templated function so you can do

return py::make_tuple<py::return_value_policy::take_ownership>(var1,var2); with any return policy.