From 95e9053f7f5801c1f616acb1e6319a562ba375b7 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 19 Jul 2024 09:37:45 -0700 Subject: [PATCH] Boilerplate changes: Skip all test_class_sh_* if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined. --- tests/class_sh_module_local_0.cpp | 7 +++ tests/class_sh_module_local_1.cpp | 7 +++ tests/class_sh_module_local_2.cpp | 7 +++ tests/test_class_sh_basic.cpp | 7 +++ tests/test_class_sh_basic.py | 3 ++ tests/test_class_sh_disowning.cpp | 7 +++ tests/test_class_sh_disowning.py | 3 ++ tests/test_class_sh_disowning_mi.cpp | 7 +++ tests/test_class_sh_disowning_mi.py | 3 ++ tests/test_class_sh_factory_constructors.cpp | 7 +++ tests/test_class_sh_factory_constructors.py | 3 ++ tests/test_class_sh_inheritance.cpp | 7 +++ tests/test_class_sh_inheritance.py | 5 ++ tests/test_class_sh_mi_thunks.cpp | 7 +++ tests/test_class_sh_mi_thunks.py | 3 ++ tests/test_class_sh_module_local.py | 3 ++ tests/test_class_sh_property.cpp | 7 +++ tests/test_class_sh_property.py | 3 ++ tests/test_class_sh_property_bakein.cpp | 7 +++ tests/test_class_sh_property_bakein.py | 5 ++ tests/test_class_sh_property_non_owning.cpp | 7 +++ tests/test_class_sh_property_non_owning.py | 3 ++ tests/test_class_sh_shared_ptr_copy_move.cpp | 47 +++++++++++-------- tests/test_class_sh_shared_ptr_copy_move.py | 5 ++ tests/test_class_sh_trampoline_basic.cpp | 14 ++++-- tests/test_class_sh_trampoline_basic.py | 3 ++ ..._class_sh_trampoline_self_life_support.cpp | 7 +++ ...t_class_sh_trampoline_self_life_support.py | 3 ++ ...t_class_sh_trampoline_shared_from_this.cpp | 15 +++++- ...st_class_sh_trampoline_shared_from_this.py | 3 ++ ...class_sh_trampoline_shared_ptr_cpp_arg.cpp | 15 +++++- ..._class_sh_trampoline_shared_ptr_cpp_arg.py | 3 ++ tests/test_class_sh_trampoline_unique_ptr.cpp | 25 +++++++--- tests/test_class_sh_trampoline_unique_ptr.py | 5 ++ ...est_class_sh_unique_ptr_custom_deleter.cpp | 7 +++ ...test_class_sh_unique_ptr_custom_deleter.py | 5 ++ tests/test_class_sh_unique_ptr_member.cpp | 7 +++ tests/test_class_sh_unique_ptr_member.py | 3 ++ tests/test_class_sh_virtual_py_cpp_mix.cpp | 7 +++ tests/test_class_sh_virtual_py_cpp_mix.py | 3 ++ 40 files changed, 261 insertions(+), 34 deletions(-) diff --git a/tests/class_sh_module_local_0.cpp b/tests/class_sh_module_local_0.cpp index bb1f46d5c..8a0ac0f63 100644 --- a/tests/class_sh_module_local_0.cpp +++ b/tests/class_sh_module_local_0.cpp @@ -19,9 +19,16 @@ atyp rtrn_valu_atyp() { return atyp(); } PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_module_local::atyp) PYBIND11_MODULE(class_sh_module_local_0, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace pybind11_tests::class_sh_module_local; m.def("get_mtxt", get_mtxt); m.def("rtrn_valu_atyp", rtrn_valu_atyp); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/class_sh_module_local_1.cpp b/tests/class_sh_module_local_1.cpp index 66bc95516..e5a458445 100644 --- a/tests/class_sh_module_local_1.cpp +++ b/tests/class_sh_module_local_1.cpp @@ -18,6 +18,12 @@ std::string get_mtxt(const atyp &obj) { return obj.mtxt; } PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_module_local::atyp) PYBIND11_MODULE(class_sh_module_local_1, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + namespace py = pybind11; using namespace pybind11_tests::class_sh_module_local; @@ -30,4 +36,5 @@ PYBIND11_MODULE(class_sh_module_local_1, m) { .def("tag", [](const atyp &) { return 1; }); m.def("get_mtxt", get_mtxt); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/class_sh_module_local_2.cpp b/tests/class_sh_module_local_2.cpp index bef105aad..5dd4104a6 100644 --- a/tests/class_sh_module_local_2.cpp +++ b/tests/class_sh_module_local_2.cpp @@ -18,6 +18,12 @@ std::string get_mtxt(const atyp &obj) { return obj.mtxt; } PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_module_local::atyp) PYBIND11_MODULE(class_sh_module_local_2, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + namespace py = pybind11; using namespace pybind11_tests::class_sh_module_local; @@ -30,4 +36,5 @@ PYBIND11_MODULE(class_sh_module_local_2, m) { .def("tag", [](const atyp &) { return 2; }); m.def("get_mtxt", get_mtxt); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_basic.cpp b/tests/test_class_sh_basic.cpp index fb9395180..55a0eb783 100644 --- a/tests/test_class_sh_basic.cpp +++ b/tests/test_class_sh_basic.cpp @@ -145,6 +145,12 @@ namespace pybind11_tests { namespace class_sh_basic { TEST_SUBMODULE(class_sh_basic, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + namespace py = pybind11; py::classh(m, "atyp").def(py::init<>()).def(py::init([](const std::string &mtxt) { @@ -238,6 +244,7 @@ TEST_SUBMODULE(class_sh_basic, m) { []() { return CastUnusualOpRefConstRef(LocalUnusualOpRef()); }); m.def("CallCastUnusualOpRefMovable", []() { return CastUnusualOpRefMovable(LocalUnusualOpRef()); }); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } } // namespace class_sh_basic diff --git a/tests/test_class_sh_basic.py b/tests/test_class_sh_basic.py index 56d45d185..717ff6f59 100644 --- a/tests/test_class_sh_basic.py +++ b/tests/test_class_sh_basic.py @@ -7,6 +7,9 @@ import pytest from pybind11_tests import class_sh_basic as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_atyp_constructors(): obj = m.atyp() diff --git a/tests/test_class_sh_disowning.cpp b/tests/test_class_sh_disowning.cpp index f934852f6..aba3dc819 100644 --- a/tests/test_class_sh_disowning.cpp +++ b/tests/test_class_sh_disowning.cpp @@ -32,6 +32,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning::Atype<1>) PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning::Atype<2>) TEST_SUBMODULE(class_sh_disowning, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace pybind11_tests::class_sh_disowning; py::classh>(m, "Atype1").def(py::init()).def("get", &Atype<1>::get); @@ -43,4 +49,5 @@ TEST_SUBMODULE(class_sh_disowning, m) { m.def("overloaded", (int (*)(std::unique_ptr>, int)) & overloaded); m.def("overloaded", (int (*)(std::unique_ptr>, int)) & overloaded); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_disowning.py b/tests/test_class_sh_disowning.py index 52568203e..36e461012 100644 --- a/tests/test_class_sh_disowning.py +++ b/tests/test_class_sh_disowning.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_disowning as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def is_disowned(obj): try: diff --git a/tests/test_class_sh_disowning_mi.cpp b/tests/test_class_sh_disowning_mi.cpp index 86333e864..1bba40154 100644 --- a/tests/test_class_sh_disowning_mi.cpp +++ b/tests/test_class_sh_disowning_mi.cpp @@ -57,6 +57,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::Base1) PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::Base2) TEST_SUBMODULE(class_sh_disowning_mi, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace pybind11_tests::class_sh_disowning_mi; py::classh(m, "B") @@ -92,4 +98,5 @@ TEST_SUBMODULE(class_sh_disowning_mi, m) { py::classh(m, "Base2").def(py::init()).def("bar", &Base2::bar); m.def("disown_base1", disown_base1); m.def("disown_base2", disown_base2); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_disowning_mi.py b/tests/test_class_sh_disowning_mi.py index 4a4beecce..781db8c0e 100644 --- a/tests/test_class_sh_disowning_mi.py +++ b/tests/test_class_sh_disowning_mi.py @@ -5,6 +5,9 @@ import pytest import env # noqa: F401 from pybind11_tests import class_sh_disowning_mi as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_diamond_inheritance(): # Very similar to test_multiple_inheritance.py:test_diamond_inheritance. diff --git a/tests/test_class_sh_factory_constructors.cpp b/tests/test_class_sh_factory_constructors.cpp index 937672cbd..7ee56a8b4 100644 --- a/tests/test_class_sh_factory_constructors.cpp +++ b/tests/test_class_sh_factory_constructors.cpp @@ -87,6 +87,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::with_alias) TEST_SUBMODULE(class_sh_factory_constructors, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace pybind11_tests::class_sh_factory_constructors; py::classh(m, "atyp_valu") @@ -177,4 +183,5 @@ TEST_SUBMODULE(class_sh_factory_constructors, m) { [](int, int, int, int, int) { return std::make_shared(); // Invalid alias factory. })); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_factory_constructors.py b/tests/test_class_sh_factory_constructors.py index 5d45db6fd..38e529e55 100644 --- a/tests/test_class_sh_factory_constructors.py +++ b/tests/test_class_sh_factory_constructors.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_factory_constructors as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_atyp_factories(): assert m.atyp_valu().get_mtxt() == "Valu" diff --git a/tests/test_class_sh_inheritance.cpp b/tests/test_class_sh_inheritance.cpp index d8f7da0e2..af57f03bd 100644 --- a/tests/test_class_sh_inheritance.cpp +++ b/tests/test_class_sh_inheritance.cpp @@ -73,6 +73,12 @@ namespace pybind11_tests { namespace class_sh_inheritance { TEST_SUBMODULE(class_sh_inheritance, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + py::classh(m, "base"); py::classh(m, "drvd"); @@ -99,6 +105,7 @@ TEST_SUBMODULE(class_sh_inheritance, m) { m.def("pass_cptr_base1", pass_cptr_base1); m.def("pass_cptr_base2", pass_cptr_base2); m.def("pass_cptr_drvd2", pass_cptr_drvd2); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } } // namespace class_sh_inheritance diff --git a/tests/test_class_sh_inheritance.py b/tests/test_class_sh_inheritance.py index cd9d6f47e..f03cee36b 100644 --- a/tests/test_class_sh_inheritance.py +++ b/tests/test_class_sh_inheritance.py @@ -1,7 +1,12 @@ from __future__ import annotations +import pytest + from pybind11_tests import class_sh_inheritance as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_rtrn_mptr_drvd_pass_cptr_base(): d = m.rtrn_mptr_drvd() diff --git a/tests/test_class_sh_mi_thunks.cpp b/tests/test_class_sh_mi_thunks.cpp index c4f430e86..0990c34fc 100644 --- a/tests/test_class_sh_mi_thunks.cpp +++ b/tests/test_class_sh_mi_thunks.cpp @@ -40,6 +40,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_mi_thunks::Base1) PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_mi_thunks::Derived) TEST_SUBMODULE(class_sh_mi_thunks, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace test_class_sh_mi_thunks; m.def("ptrdiff_drvd_base0", []() { @@ -97,4 +103,5 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) { } return obj_der->vec.size(); }); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_mi_thunks.py b/tests/test_class_sh_mi_thunks.py index c1c8a3043..4fe34b4ad 100644 --- a/tests/test_class_sh_mi_thunks.py +++ b/tests/test_class_sh_mi_thunks.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_mi_thunks as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_ptrdiff_drvd_base0(): ptrdiff = m.ptrdiff_drvd_base0() diff --git a/tests/test_class_sh_module_local.py b/tests/test_class_sh_module_local.py index e504152a1..79ccb8b42 100644 --- a/tests/test_class_sh_module_local.py +++ b/tests/test_class_sh_module_local.py @@ -5,6 +5,9 @@ import class_sh_module_local_1 as m1 import class_sh_module_local_2 as m2 import pytest +if not m0.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_cross_module_get_mtxt(): obj1 = m1.atyp("A") diff --git a/tests/test_class_sh_property.cpp b/tests/test_class_sh_property.cpp index 35615cec6..a89057a51 100644 --- a/tests/test_class_sh_property.cpp +++ b/tests/test_class_sh_property.cpp @@ -46,6 +46,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Field) PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Outer) TEST_SUBMODULE(class_sh_property, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace test_class_sh_property; py::class_>(m, "ClassicField") @@ -83,4 +89,5 @@ TEST_SUBMODULE(class_sh_property, m) { .def_readwrite("m_shcp_readwrite", &Outer::m_shcp); m.def("DisownOuter", DisownOuter); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_property.py b/tests/test_class_sh_property.py index 9aeef44e0..e0aff75a0 100644 --- a/tests/test_class_sh_property.py +++ b/tests/test_class_sh_property.py @@ -7,6 +7,9 @@ import pytest import env # noqa: F401 from pybind11_tests import class_sh_property as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + @pytest.mark.xfail("env.PYPY", reason="gc after `del field` is apparently deferred") @pytest.mark.parametrize("m_attr", ["m_valu_readonly", "m_valu_readwrite"]) diff --git a/tests/test_class_sh_property_bakein.cpp b/tests/test_class_sh_property_bakein.cpp index 6063aab5a..85ede2547 100644 --- a/tests/test_class_sh_property_bakein.cpp +++ b/tests/test_class_sh_property_bakein.cpp @@ -16,6 +16,12 @@ struct WithConstCharPtrMember { } // namespace test_class_sh_property_bakein TEST_SUBMODULE(class_sh_property_bakein, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace test_class_sh_property_bakein; py::class_(m, "WithCharArrayMember") @@ -25,4 +31,5 @@ TEST_SUBMODULE(class_sh_property_bakein, m) { py::class_(m, "WithConstCharPtrMember") .def(py::init<>()) .def_readonly("const_char_ptr_member", &WithConstCharPtrMember::const_char_ptr_member); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_property_bakein.py b/tests/test_class_sh_property_bakein.py index 746231859..179bf8662 100644 --- a/tests/test_class_sh_property_bakein.py +++ b/tests/test_class_sh_property_bakein.py @@ -1,7 +1,12 @@ from __future__ import annotations +import pytest + from pybind11_tests import class_sh_property_bakein as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_readonly_char6_member(): obj = m.WithCharArrayMember() diff --git a/tests/test_class_sh_property_non_owning.cpp b/tests/test_class_sh_property_non_owning.cpp index cd7fc5c60..65103148f 100644 --- a/tests/test_class_sh_property_non_owning.cpp +++ b/tests/test_class_sh_property_non_owning.cpp @@ -51,6 +51,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(DataField) PYBIND11_SMART_HOLDER_TYPE_CASTERS(DataFieldsHolder) TEST_SUBMODULE(class_sh_property_non_owning, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + py::classh(m, "CoreField").def_readwrite("int_value", &CoreField::int_value); py::classh(m, "DataField") @@ -65,4 +71,5 @@ TEST_SUBMODULE(class_sh_property_non_owning, m) { py::classh(m, "DataFieldsHolder") .def(py::init()) .def("vec_at", &DataFieldsHolder::vec_at, py::return_value_policy::reference_internal); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_property_non_owning.py b/tests/test_class_sh_property_non_owning.py index 33a9d4503..89c7c0cd5 100644 --- a/tests/test_class_sh_property_non_owning.py +++ b/tests/test_class_sh_property_non_owning.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_property_non_owning as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + @pytest.mark.parametrize("persistent_holder", [True, False]) @pytest.mark.parametrize( diff --git a/tests/test_class_sh_shared_ptr_copy_move.cpp b/tests/test_class_sh_shared_ptr_copy_move.cpp index 1d4ec3cdf..3e9eb9ac9 100644 --- a/tests/test_class_sh_shared_ptr_copy_move.cpp +++ b/tests/test_class_sh_shared_ptr_copy_move.cpp @@ -50,6 +50,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::FooSmHld) namespace pybind11_tests { TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + namespace py = pybind11; py::class_>(m, "FooShPtr") @@ -57,30 +63,30 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) { py::classh(m, "FooSmHld").def("get_history", &FooSmHld::get_history); auto outer = py::class_(m, "Outer").def(py::init()); -#define MAKE_PROP(PropTyp) \ - MAKE_PROP_FOO(ShPtr, PropTyp) \ - MAKE_PROP_FOO(SmHld, PropTyp) +# define MAKE_PROP(PropTyp) \ + MAKE_PROP_FOO(ShPtr, PropTyp) \ + MAKE_PROP_FOO(SmHld, PropTyp) -#define MAKE_PROP_FOO(FooTyp, PropTyp) \ - .def_##PropTyp(#FooTyp "_" #PropTyp "_default", &Outer::FooTyp) \ - .def_##PropTyp( \ - #FooTyp "_" #PropTyp "_copy", &Outer::FooTyp, py::return_value_policy::copy) \ - .def_##PropTyp( \ - #FooTyp "_" #PropTyp "_move", &Outer::FooTyp, py::return_value_policy::move) +# define MAKE_PROP_FOO(FooTyp, PropTyp) \ + .def_##PropTyp(#FooTyp "_" #PropTyp "_default", &Outer::FooTyp) \ + .def_##PropTyp( \ + #FooTyp "_" #PropTyp "_copy", &Outer::FooTyp, py::return_value_policy::copy) \ + .def_##PropTyp( \ + #FooTyp "_" #PropTyp "_move", &Outer::FooTyp, py::return_value_policy::move) outer MAKE_PROP(readonly) MAKE_PROP(readwrite); -#undef MAKE_PROP_FOO +# undef MAKE_PROP_FOO -#define MAKE_PROP_FOO(FooTyp, PropTyp) \ - .def_##PropTyp(#FooTyp "_property_" #PropTyp "_default", &Outer::FooTyp) \ - .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_copy", \ - &Outer::get##FooTyp, \ - py::return_value_policy::copy) \ - .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_move", \ - &Outer::get##FooTyp, \ - py::return_value_policy::move) +# define MAKE_PROP_FOO(FooTyp, PropTyp) \ + .def_##PropTyp(#FooTyp "_property_" #PropTyp "_default", &Outer::FooTyp) \ + .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_copy", \ + &Outer::get##FooTyp, \ + py::return_value_policy::copy) \ + .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_move", \ + &Outer::get##FooTyp, \ + py::return_value_policy::move) outer MAKE_PROP(readonly); -#undef MAKE_PROP_FOO -#undef MAKE_PROP +# undef MAKE_PROP_FOO +# undef MAKE_PROP m.def("test_ShPtr_copy", []() { auto o = std::make_shared("copy"); @@ -107,6 +113,7 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) { l.append(std::move(o)); return l; }); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } } // namespace pybind11_tests diff --git a/tests/test_class_sh_shared_ptr_copy_move.py b/tests/test_class_sh_shared_ptr_copy_move.py index 067bb47d2..092aa1f3f 100644 --- a/tests/test_class_sh_shared_ptr_copy_move.py +++ b/tests/test_class_sh_shared_ptr_copy_move.py @@ -1,7 +1,12 @@ from __future__ import annotations +import pytest + from pybind11_tests import class_sh_shared_ptr_copy_move as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_shptr_copy(): txt = m.test_ShPtr_copy()[0].get_history() diff --git a/tests/test_class_sh_trampoline_basic.cpp b/tests/test_class_sh_trampoline_basic.cpp index e31bcf719..8627a8d6d 100644 --- a/tests/test_class_sh_trampoline_basic.cpp +++ b/tests/test_class_sh_trampoline_basic.cpp @@ -76,11 +76,19 @@ void wrap(py::module_ m, const char *py_class_name) { } // namespace class_sh_trampoline_basic } // namespace pybind11_tests -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_basic::Abase<0>) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_basic::Abase<1>) +using namespace pybind11_tests::class_sh_trampoline_basic; + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(Abase<0>) +PYBIND11_SMART_HOLDER_TYPE_CASTERS(Abase<1>) TEST_SUBMODULE(class_sh_trampoline_basic, m) { - using namespace pybind11_tests::class_sh_trampoline_basic; + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + wrap<0>(m, "Abase0"); wrap<1>(m, "Abase1"); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_trampoline_basic.py b/tests/test_class_sh_trampoline_basic.py index eab82121f..7b6e1a0fc 100644 --- a/tests/test_class_sh_trampoline_basic.py +++ b/tests/test_class_sh_trampoline_basic.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_trampoline_basic as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + class PyDrvd0(m.Abase0): def __init__(self, val): diff --git a/tests/test_class_sh_trampoline_self_life_support.cpp b/tests/test_class_sh_trampoline_self_life_support.cpp index c1eb03543..3b202deb3 100644 --- a/tests/test_class_sh_trampoline_self_life_support.cpp +++ b/tests/test_class_sh_trampoline_self_life_support.cpp @@ -46,6 +46,12 @@ struct Big5Trampoline : Big5, py::trampoline_self_life_support { PYBIND11_SMART_HOLDER_TYPE_CASTERS(Big5) TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + py::classh(m, "Big5") .def(py::init()) .def_readonly("history", &Big5::history); @@ -82,4 +88,5 @@ TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) { py::object o1 = py::cast(std::move(obj)); return py::make_tuple(o1, o2); }); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_trampoline_self_life_support.py b/tests/test_class_sh_trampoline_self_life_support.py index d4af2ab99..d366b48c6 100644 --- a/tests/test_class_sh_trampoline_self_life_support.py +++ b/tests/test_class_sh_trampoline_self_life_support.py @@ -4,6 +4,9 @@ import pytest import pybind11_tests.class_sh_trampoline_self_life_support as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + class PyBig5(m.Big5): pass diff --git a/tests/test_class_sh_trampoline_shared_from_this.cpp b/tests/test_class_sh_trampoline_shared_from_this.cpp index ae9f27465..38b36e1b0 100644 --- a/tests/test_class_sh_trampoline_shared_from_this.cpp +++ b/tests/test_class_sh_trampoline_shared_from_this.cpp @@ -8,7 +8,8 @@ #include #include -namespace { +namespace pybind11_tests { +namespace class_sh_trampoline_shared_from_this { struct Sft : std::enable_shared_from_this { std::string history; @@ -98,12 +99,21 @@ std::shared_ptr make_pure_cpp_sft_shd_ptr(const std::string &history_seed) std::shared_ptr pass_through_shd_ptr(const std::shared_ptr &obj) { return obj; } -} // namespace +} // namespace class_sh_trampoline_shared_from_this +} // namespace pybind11_tests + +using namespace pybind11_tests::class_sh_trampoline_shared_from_this; PYBIND11_SMART_HOLDER_TYPE_CASTERS(Sft) PYBIND11_SMART_HOLDER_TYPE_CASTERS(SftSharedPtrStash) TEST_SUBMODULE(class_sh_trampoline_shared_from_this, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + py::classh(m, "Sft") .def(py::init()) .def(py::init([](const std::string &history, int) { @@ -128,4 +138,5 @@ TEST_SUBMODULE(class_sh_trampoline_shared_from_this, m) { m.def("make_pure_cpp_sft_unq_ptr", make_pure_cpp_sft_unq_ptr); m.def("make_pure_cpp_sft_shd_ptr", make_pure_cpp_sft_shd_ptr); m.def("pass_through_shd_ptr", pass_through_shd_ptr); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_trampoline_shared_from_this.py b/tests/test_class_sh_trampoline_shared_from_this.py index 85fe7858f..4332fc9fd 100644 --- a/tests/test_class_sh_trampoline_shared_from_this.py +++ b/tests/test_class_sh_trampoline_shared_from_this.py @@ -8,6 +8,9 @@ import pytest import env import pybind11_tests.class_sh_trampoline_shared_from_this as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + class PySft(m.Sft): pass diff --git a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp index 9e44927a8..2b94310b5 100644 --- a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp +++ b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp @@ -7,7 +7,8 @@ #include -namespace { +namespace pybind11_tests { +namespace class_sh_trampoline_shared_ptr_cpp_arg { // For testing whether a python subclass of a C++ object dies when the // last python reference is lost @@ -51,7 +52,10 @@ struct SpGoAwayTester { std::shared_ptr m_obj; }; -} // namespace +} // namespace class_sh_trampoline_shared_ptr_cpp_arg +} // namespace pybind11_tests + +using namespace pybind11_tests::class_sh_trampoline_shared_ptr_cpp_arg; PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpBase) PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpBaseTester) @@ -59,6 +63,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpGoAway) PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpGoAwayTester) TEST_SUBMODULE(class_sh_trampoline_shared_ptr_cpp_arg, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + // For testing whether a python subclass of a C++ object dies when the // last python reference is lost @@ -91,4 +101,5 @@ TEST_SUBMODULE(class_sh_trampoline_shared_ptr_cpp_arg, m) { py::classh(m, "SpGoAwayTester") .def(py::init<>()) .def_readwrite("obj", &SpGoAwayTester::m_obj); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py index 431edb719..54575ddcc 100644 --- a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py +++ b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py @@ -4,6 +4,9 @@ import pytest import pybind11_tests.class_sh_trampoline_shared_ptr_cpp_arg as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_shared_ptr_cpp_arg(): import weakref diff --git a/tests/test_class_sh_trampoline_unique_ptr.cpp b/tests/test_class_sh_trampoline_unique_ptr.cpp index 141a6e8b5..26ddf7750 100644 --- a/tests/test_class_sh_trampoline_unique_ptr.cpp +++ b/tests/test_class_sh_trampoline_unique_ptr.cpp @@ -8,7 +8,8 @@ #include -namespace { +namespace pybind11_tests { +namespace class_sh_trampoline_basic { class Class { public: @@ -30,11 +31,7 @@ private: std::uint64_t val_ = 0; }; -} // namespace - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Class) - -namespace { +#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT class PyClass : public Class, public py::trampoline_self_life_support { public: @@ -45,9 +42,22 @@ public: int foo() const override { PYBIND11_OVERRIDE_PURE(int, Class, foo); } }; -} // namespace +#endif + +} // namespace class_sh_trampoline_basic +} // 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 + false; +#else + true; + py::classh(m, "Class") .def(py::init<>()) .def("set_val", &Class::setVal) @@ -57,4 +67,5 @@ TEST_SUBMODULE(class_sh_trampoline_unique_ptr, m) { m.def("clone", [](const Class &obj) { return obj.clone(); }); m.def("clone_and_foo", [](const Class &obj) { return obj.clone()->foo(); }); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_trampoline_unique_ptr.py b/tests/test_class_sh_trampoline_unique_ptr.py index 7799df6d6..22505dc6e 100644 --- a/tests/test_class_sh_trampoline_unique_ptr.py +++ b/tests/test_class_sh_trampoline_unique_ptr.py @@ -1,7 +1,12 @@ from __future__ import annotations +import pytest + import pybind11_tests.class_sh_trampoline_unique_ptr as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + class MyClass(m.Class): def foo(self): diff --git a/tests/test_class_sh_unique_ptr_custom_deleter.cpp b/tests/test_class_sh_unique_ptr_custom_deleter.cpp index 070a10e0f..973bf4908 100644 --- a/tests/test_class_sh_unique_ptr_custom_deleter.cpp +++ b/tests/test_class_sh_unique_ptr_custom_deleter.cpp @@ -31,9 +31,16 @@ namespace pybind11_tests { namespace class_sh_unique_ptr_custom_deleter { TEST_SUBMODULE(class_sh_unique_ptr_custom_deleter, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + py::classh(m, "Pet").def_readwrite("name", &Pet::name); m.def("create", &Pet::New); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } } // namespace class_sh_unique_ptr_custom_deleter diff --git a/tests/test_class_sh_unique_ptr_custom_deleter.py b/tests/test_class_sh_unique_ptr_custom_deleter.py index 34aa52068..f246e2d7e 100644 --- a/tests/test_class_sh_unique_ptr_custom_deleter.py +++ b/tests/test_class_sh_unique_ptr_custom_deleter.py @@ -1,7 +1,12 @@ from __future__ import annotations +import pytest + from pybind11_tests import class_sh_unique_ptr_custom_deleter as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_create(): pet = m.create("abc") diff --git a/tests/test_class_sh_unique_ptr_member.cpp b/tests/test_class_sh_unique_ptr_member.cpp index 3de12fe62..1341f140e 100644 --- a/tests/test_class_sh_unique_ptr_member.cpp +++ b/tests/test_class_sh_unique_ptr_member.cpp @@ -45,6 +45,12 @@ namespace pybind11_tests { namespace class_sh_unique_ptr_member { TEST_SUBMODULE(class_sh_unique_ptr_member, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + py::classh(m, "pointee").def(py::init<>()).def("get_int", &pointee::get_int); m.def("make_unique_pointee", make_unique_pointee); @@ -54,6 +60,7 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) { .def("is_owner", &ptr_owner::is_owner) .def("give_up_ownership_via_unique_ptr", &ptr_owner::give_up_ownership_via_unique_ptr) .def("give_up_ownership_via_shared_ptr", &ptr_owner::give_up_ownership_via_shared_ptr); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } } // namespace class_sh_unique_ptr_member diff --git a/tests/test_class_sh_unique_ptr_member.py b/tests/test_class_sh_unique_ptr_member.py index a5d2ccd23..dc1d5482f 100644 --- a/tests/test_class_sh_unique_ptr_member.py +++ b/tests/test_class_sh_unique_ptr_member.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_unique_ptr_member as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + def test_make_unique_pointee(): obj = m.make_unique_pointee() diff --git a/tests/test_class_sh_virtual_py_cpp_mix.cpp b/tests/test_class_sh_virtual_py_cpp_mix.cpp index 2fa9990a2..c8477d483 100644 --- a/tests/test_class_sh_virtual_py_cpp_mix.cpp +++ b/tests/test_class_sh_virtual_py_cpp_mix.cpp @@ -51,6 +51,12 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix:: PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::CppDerived) TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) { + m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") = +#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + false; +#else + true; + using namespace pybind11_tests::class_sh_virtual_py_cpp_mix; py::classh(m, "Base").def(py::init<>()).def("get", &Base::get); @@ -61,4 +67,5 @@ TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) { m.def("get_from_cpp_plainc_ptr", get_from_cpp_plainc_ptr, py::arg("b")); m.def("get_from_cpp_unique_ptr", get_from_cpp_unique_ptr, py::arg("b")); +#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT } diff --git a/tests/test_class_sh_virtual_py_cpp_mix.py b/tests/test_class_sh_virtual_py_cpp_mix.py index 33133eb88..3361713c7 100644 --- a/tests/test_class_sh_virtual_py_cpp_mix.py +++ b/tests/test_class_sh_virtual_py_cpp_mix.py @@ -4,6 +4,9 @@ import pytest from pybind11_tests import class_sh_virtual_py_cpp_mix as m +if not m.defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT: + pytest.skip("smart_holder not available.", allow_module_level=True) + class PyBase(m.Base): # Avoiding name PyDerived, for more systematic naming. def __init__(self):