mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 00:22:00 +00:00
Boilerplate changes: Skip all test_class_sh_* if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined.
This commit is contained in:
parent
6fb8b5157d
commit
95e9053f7f
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<atyp>(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
|
||||
|
@ -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()
|
||||
|
@ -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<Atype<1>>(m, "Atype1").def(py::init<int>()).def("get", &Atype<1>::get);
|
||||
@ -43,4 +49,5 @@ TEST_SUBMODULE(class_sh_disowning, m) {
|
||||
|
||||
m.def("overloaded", (int (*)(std::unique_ptr<Atype<1>>, int)) & overloaded);
|
||||
m.def("overloaded", (int (*)(std::unique_ptr<Atype<2>>, int)) & overloaded);
|
||||
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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<B>(m, "B")
|
||||
@ -92,4 +98,5 @@ TEST_SUBMODULE(class_sh_disowning_mi, m) {
|
||||
py::classh<Base2>(m, "Base2").def(py::init<int>()).def("bar", &Base2::bar);
|
||||
m.def("disown_base1", disown_base1);
|
||||
m.def("disown_base2", disown_base2);
|
||||
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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<atyp_valu>(m, "atyp_valu")
|
||||
@ -177,4 +183,5 @@ TEST_SUBMODULE(class_sh_factory_constructors, m) {
|
||||
[](int, int, int, int, int) {
|
||||
return std::make_shared<with_alias>(); // Invalid alias factory.
|
||||
}));
|
||||
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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<base>(m, "base");
|
||||
py::classh<drvd, base>(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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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")
|
||||
|
@ -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_<ClassicField, std::unique_ptr<ClassicField>>(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
|
||||
}
|
||||
|
@ -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"])
|
||||
|
@ -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_<WithCharArrayMember>(m, "WithCharArrayMember")
|
||||
@ -25,4 +31,5 @@ TEST_SUBMODULE(class_sh_property_bakein, m) {
|
||||
py::class_<WithConstCharPtrMember>(m, "WithConstCharPtrMember")
|
||||
.def(py::init<>())
|
||||
.def_readonly("const_char_ptr_member", &WithConstCharPtrMember::const_char_ptr_member);
|
||||
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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<CoreField>(m, "CoreField").def_readwrite("int_value", &CoreField::int_value);
|
||||
|
||||
py::classh<DataField>(m, "DataField")
|
||||
@ -65,4 +71,5 @@ TEST_SUBMODULE(class_sh_property_non_owning, m) {
|
||||
py::classh<DataFieldsHolder>(m, "DataFieldsHolder")
|
||||
.def(py::init<std::size_t>())
|
||||
.def("vec_at", &DataFieldsHolder::vec_at, py::return_value_policy::reference_internal);
|
||||
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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_<FooShPtr, std::shared_ptr<FooShPtr>>(m, "FooShPtr")
|
||||
@ -57,30 +63,30 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
|
||||
py::classh<FooSmHld>(m, "FooSmHld").def("get_history", &FooSmHld::get_history);
|
||||
|
||||
auto outer = py::class_<Outer>(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<FooShPtr>("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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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):
|
||||
|
@ -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<Big5, Big5Trampoline>(m, "Big5")
|
||||
.def(py::init<std::string>())
|
||||
.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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
namespace pybind11_tests {
|
||||
namespace class_sh_trampoline_shared_from_this {
|
||||
|
||||
struct Sft : std::enable_shared_from_this<Sft> {
|
||||
std::string history;
|
||||
@ -98,12 +99,21 @@ std::shared_ptr<Sft> make_pure_cpp_sft_shd_ptr(const std::string &history_seed)
|
||||
|
||||
std::shared_ptr<Sft> pass_through_shd_ptr(const std::shared_ptr<Sft> &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<Sft, SftTrampoline>(m, "Sft")
|
||||
.def(py::init<const std::string &>())
|
||||
.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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -7,7 +7,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
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<SpGoAway> 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<SpGoAwayTester>(m, "SpGoAwayTester")
|
||||
.def(py::init<>())
|
||||
.def_readwrite("obj", &SpGoAwayTester::m_obj);
|
||||
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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<Class, PyClass>(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
|
||||
}
|
||||
|
@ -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):
|
||||
|
@ -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<Pet>(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
|
||||
|
@ -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")
|
||||
|
@ -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<pointee>(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
|
||||
|
@ -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()
|
||||
|
@ -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<Base, BaseVirtualOverrider>(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
|
||||
}
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user