From 093e0f4514277b520dd90ea53524744c3a9f4672 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 4 Feb 2021 22:32:27 -0800 Subject: [PATCH] Adding PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS in test_class.cpp (with this all but one test succeed with PYBIND11_USE_SMART_HOLDER_AS_DEFAULT). --- tests/test_class.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 02aa52a29..e6e7e5d62 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -32,6 +32,20 @@ struct NoBraceInitialization { std::vector vec; }; +struct MismatchBase1 { }; +struct MismatchDerived1 : MismatchBase1 { }; + +struct MismatchBase2 { }; +struct MismatchDerived2 : MismatchBase2 { }; + +struct SamePointer {}; + +PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(MismatchBase1, std::shared_ptr) +PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(MismatchDerived1, std::unique_ptr) +PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(MismatchBase2, std::unique_ptr) +PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(MismatchDerived2, std::shared_ptr) +PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(SamePointer, std::unique_ptr) + TEST_SUBMODULE(class_, m) { // test_instance struct NoConstructor { @@ -168,20 +182,15 @@ TEST_SUBMODULE(class_, m) { }); // test_mismatched_holder - struct MismatchBase1 { }; - struct MismatchDerived1 : MismatchBase1 { }; - - struct MismatchBase2 { }; - struct MismatchDerived2 : MismatchBase2 { }; - m.def("mismatched_holder_1", []() { auto mod = py::module_::import("__main__"); py::class_>(mod, "MismatchBase1"); - py::class_(mod, "MismatchDerived1"); + py::class_, + MismatchBase1>(mod, "MismatchDerived1"); }); m.def("mismatched_holder_2", []() { auto mod = py::module_::import("__main__"); - py::class_(mod, "MismatchBase2"); + py::class_>(mod, "MismatchBase2"); py::class_, MismatchBase2>(mod, "MismatchDerived2"); }); @@ -431,7 +440,6 @@ TEST_SUBMODULE(class_, m) { .def("throw_something", &PyPrintDestructor::throw_something); // test_multiple_instances_with_same_pointer - struct SamePointer {}; static SamePointer samePointer; py::class_>(m, "SamePointer") .def(py::init([]() { return &samePointer; }));