mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 08:32:02 +00:00
Import https://github.com/pybind/pybind11/pull/5256 from smart_holder branch back here (same test code as in test_class_sh_property_bakein.cpp,py).
This commit is contained in:
parent
df54a82dab
commit
84f71f1b69
@ -35,6 +35,15 @@ struct Outer {
|
|||||||
|
|
||||||
inline void DisownOuter(std::unique_ptr<Outer>) {}
|
inline void DisownOuter(std::unique_ptr<Outer>) {}
|
||||||
|
|
||||||
|
struct WithCharArrayMember {
|
||||||
|
WithCharArrayMember() { std::memcpy(char6_member, "Char6", 6); }
|
||||||
|
char char6_member[6];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WithConstCharPtrMember {
|
||||||
|
const char *const_char_ptr_member = "ConstChar*";
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace test_class_sh_property
|
} // namespace test_class_sh_property
|
||||||
|
|
||||||
PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicField,
|
PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicField,
|
||||||
@ -45,6 +54,9 @@ PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicOuter,
|
|||||||
PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Field)
|
PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Field)
|
||||||
PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Outer)
|
PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Outer)
|
||||||
|
|
||||||
|
PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::WithCharArrayMember)
|
||||||
|
PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::WithConstCharPtrMember)
|
||||||
|
|
||||||
TEST_SUBMODULE(class_sh_property, m) {
|
TEST_SUBMODULE(class_sh_property, m) {
|
||||||
m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") =
|
m.attr("defined_PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT") =
|
||||||
#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
#ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||||
@ -89,5 +101,13 @@ TEST_SUBMODULE(class_sh_property, m) {
|
|||||||
.def_readwrite("m_shcp_readwrite", &Outer::m_shcp);
|
.def_readwrite("m_shcp_readwrite", &Outer::m_shcp);
|
||||||
|
|
||||||
m.def("DisownOuter", DisownOuter);
|
m.def("DisownOuter", DisownOuter);
|
||||||
|
|
||||||
|
py::classh<WithCharArrayMember>(m, "WithCharArrayMember")
|
||||||
|
.def(py::init<>())
|
||||||
|
.def_readonly("char6_member", &WithCharArrayMember::char6_member);
|
||||||
|
|
||||||
|
py::classh<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
|
#endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
||||||
}
|
}
|
||||||
|
@ -155,3 +155,13 @@ def test_unique_ptr_field_proxy_poc(m_attr):
|
|||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
del field_proxy.num
|
del field_proxy.num
|
||||||
assert field_proxy.num == 82
|
assert field_proxy.num == 82
|
||||||
|
|
||||||
|
|
||||||
|
def test_readonly_char6_member():
|
||||||
|
obj = m.WithCharArrayMember()
|
||||||
|
assert obj.char6_member == "Char6"
|
||||||
|
|
||||||
|
|
||||||
|
def test_readonly_const_char_ptr_member():
|
||||||
|
obj = m.WithConstCharPtrMember()
|
||||||
|
assert obj.const_char_ptr_member == "ConstChar*"
|
||||||
|
Loading…
Reference in New Issue
Block a user