Add cast(const std::unique_ptr<type, deleter> &, ...). Remove the last 3 remaining BAKEIN_BREAK in test_class_sh_basic.cpp

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-04 16:09:01 -07:00
parent ebbe066841
commit 874f69d898
2 changed files with 17 additions and 4 deletions

View File

@ -988,6 +988,20 @@ public:
std::move(src), policy, parent);
}
static handle
cast(const std::unique_ptr<type, deleter> &src, return_value_policy policy, handle parent) {
if (!src) {
return none().release();
}
if (policy == return_value_policy::automatic) {
policy = return_value_policy::reference_internal;
}
if (policy != return_value_policy::reference_internal) {
throw cast_error("Invalid return_value_policy for unique_ptr&");
}
return type_caster_base<type>::cast(src.get(), policy, parent);
}
bool load(handle src, bool convert) {
return base::template load_impl<
move_only_holder_caster<type, std::unique_ptr<type, deleter>>>(src, convert);

View File

@ -202,9 +202,8 @@ TEST_SUBMODULE(class_sh_basic, m) {
.def("pass_valu", &uconsumer::pass_valu)
.def("pass_rref", &uconsumer::pass_rref)
.def("rtrn_valu", &uconsumer::rtrn_valu)
// BAKEIN_BREAK .def("rtrn_lref", &uconsumer::rtrn_lref)
// BAKEIN_BREAK .def("rtrn_cref", &uconsumer::rtrn_cref)
;
.def("rtrn_lref", &uconsumer::rtrn_lref)
.def("rtrn_cref", &uconsumer::rtrn_cref);
// Helpers for testing.
// These require selected functions above to work first, as indicated:
@ -212,7 +211,7 @@ TEST_SUBMODULE(class_sh_basic, m) {
m.def("get_ptr", get_ptr); // pass_cref
m.def("unique_ptr_roundtrip", unique_ptr_roundtrip); // pass_uqmp, rtrn_uqmp
// BAKEIN_BREAK m.def("unique_ptr_cref_roundtrip", unique_ptr_cref_roundtrip);
m.def("unique_ptr_cref_roundtrip", unique_ptr_cref_roundtrip);
py::classh<SharedPtrStash>(m, "SharedPtrStash")
.def(py::init<>())