Merge branch 'master' into sh_merge_master

Includes follow-on to pybind/pybind11#5189: Backport the smart_holder-specific changes from google/pybind11k#30093 and google/pybind11k#30098.
This commit is contained in:
Ralf W. Grosse-Kunstleve
2024-06-24 09:01:55 -07:00
7 changed files with 52 additions and 4 deletions

View File

@@ -129,12 +129,17 @@ struct SharedPtrStash {
void Add(const std::shared_ptr<const atyp> &obj) { stash.push_back(obj); }
};
class LocalUnusualOpRef : UnusualOpRef {}; // To avoid clashing with `py::class_<UnusualOpRef>`.
py::object CastUnusualOpRefConstRef(const LocalUnusualOpRef &cref) { return py::cast(cref); }
py::object CastUnusualOpRefMovable(LocalUnusualOpRef &&mvbl) { return py::cast(std::move(mvbl)); }
} // namespace class_sh_basic
} // namespace pybind11_tests
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::atyp)
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::uconsumer)
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::SharedPtrStash)
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::LocalUnusualOpRef)
namespace pybind11_tests {
namespace class_sh_basic {
@@ -227,6 +232,12 @@ TEST_SUBMODULE(class_sh_basic, m) {
"rtrn_uq_automatic_reference",
[]() { return std::unique_ptr<atyp>(new atyp("rtrn_uq_automatic_reference")); },
pybind11::return_value_policy::automatic_reference);
py::classh<LocalUnusualOpRef>(m, "LocalUnusualOpRef");
m.def("CallCastUnusualOpRefConstRef",
[]() { return CastUnusualOpRefConstRef(LocalUnusualOpRef()); });
m.def("CallCastUnusualOpRefMovable",
[]() { return CastUnusualOpRefMovable(LocalUnusualOpRef()); });
}
} // namespace class_sh_basic