The method manage_new_objectworks as a metafunction class, which converts the argument into a converted result, to which the responsible should respond. With regular call policies, it is used under the hood. We just need to directly use this metaphor class:
struct Foo {
X* x = ...;
void give_up_x(py::object callback) {
py::manage_new_object::apply<X*>::type wrapper;
callback(py::handle<>{wrapper(x)});
}
};
You need it py::handle<>, since the shell returns PyObject*instead py::object. If you want to be more direct, you can skip some of the instances of the intermediate type and just use:
void give_up_x(py::object callback) {
callback(py::handle<>{py::detail::make_owning_holder::execute(x)});
}
I came across the above by checking guesses. Does it seem to work at least?
Barry source
share