From c4c3d9a06fb3d213e4e4158a4e11a6b30e2b3f21 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 22 Jul 2024 01:37:20 -0700 Subject: [PATCH] Import non-functional test changes made on smart_holder branch under PR #5258. --- ...t_class_sh_trampoline_self_life_support.cpp | 8 ++++++-- tests/test_class_sh_trampoline_unique_ptr.cpp | 18 ++++++++++++------ tests/test_class_sh_virtual_py_cpp_mix.cpp | 10 +++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/test_class_sh_trampoline_self_life_support.cpp b/tests/test_class_sh_trampoline_self_life_support.cpp index 9b67323f3a..859b9f8fbc 100644 --- a/tests/test_class_sh_trampoline_self_life_support.cpp +++ b/tests/test_class_sh_trampoline_self_life_support.cpp @@ -10,7 +10,8 @@ #include #include -namespace { +namespace pybind11_tests { +namespace class_sh_trampoline_self_life_support { struct Big5 { // Also known as "rule of five". std::string history; @@ -43,7 +44,10 @@ struct Big5Trampoline : Big5, py::trampoline_self_life_support { }; #endif -} // namespace +} // namespace class_sh_trampoline_self_life_support +} // namespace pybind11_tests + +using namespace pybind11_tests::class_sh_trampoline_self_life_support; PYBIND11_SMART_HOLDER_TYPE_CASTERS(Big5) diff --git a/tests/test_class_sh_trampoline_unique_ptr.cpp b/tests/test_class_sh_trampoline_unique_ptr.cpp index af0fb16efc..13dc27b049 100644 --- a/tests/test_class_sh_trampoline_unique_ptr.cpp +++ b/tests/test_class_sh_trampoline_unique_ptr.cpp @@ -9,7 +9,7 @@ #include namespace pybind11_tests { -namespace class_sh_trampoline_basic { +namespace class_sh_trampoline_unique_ptr { class Class { public: @@ -31,6 +31,14 @@ class Class { std::uint64_t val_ = 0; }; +} // namespace class_sh_trampoline_unique_ptr +} // namespace pybind11_tests + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_unique_ptr::Class) + +namespace pybind11_tests { +namespace class_sh_trampoline_unique_ptr { + #ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT class PyClass : public Class, public py::trampoline_self_life_support { public: @@ -42,13 +50,9 @@ class PyClass : public Class, public py::trampoline_self_life_support { }; #endif -} // namespace class_sh_trampoline_basic +} // namespace class_sh_trampoline_unique_ptr } // namespace pybind11_tests -using namespace pybind11_tests::class_sh_trampoline_basic; - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Class) - TEST_SUBMODULE(class_sh_trampoline_unique_ptr, m) { m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = #ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT @@ -56,6 +60,8 @@ TEST_SUBMODULE(class_sh_trampoline_unique_ptr, m) { #else true; + using namespace pybind11_tests::class_sh_trampoline_unique_ptr; + py::classh(m, "Class") .def(py::init<>()) .def("set_val", &Class::setVal) diff --git a/tests/test_class_sh_virtual_py_cpp_mix.cpp b/tests/test_class_sh_virtual_py_cpp_mix.cpp index f85c87b27b..a68cb76aa3 100644 --- a/tests/test_class_sh_virtual_py_cpp_mix.cpp +++ b/tests/test_class_sh_virtual_py_cpp_mix.cpp @@ -50,9 +50,11 @@ struct CppDerivedVirtualOverrider : CppDerived, py::trampoline_self_life_support } // namespace class_sh_virtual_py_cpp_mix } // namespace pybind11_tests -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::Base) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::CppDerivedPlain) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::CppDerived) +using namespace pybind11_tests::class_sh_virtual_py_cpp_mix; + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(Base) +PYBIND11_SMART_HOLDER_TYPE_CASTERS(CppDerivedPlain) +PYBIND11_SMART_HOLDER_TYPE_CASTERS(CppDerived) TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) { m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = @@ -61,8 +63,6 @@ TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) { #else true; - using namespace pybind11_tests::class_sh_virtual_py_cpp_mix; - py::classh(m, "Base").def(py::init<>()).def("get", &Base::get); py::classh(m, "CppDerivedPlain").def(py::init<>());