mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 16:13:53 +00:00
Minimal test covering classh_type_casters load_impl Case 2b.
This commit is contained in:
parent
82f619bdb2
commit
c362b91a80
@ -167,7 +167,6 @@ public:
|
||||
// we can find an exact match (or, for a simple C++ type, an inherited match); if so, we
|
||||
// can safely reinterpret_cast to the relevant pointer.
|
||||
else if (bases.size() > 1) {
|
||||
pybind11_fail("classh_type_casters: Case 2b UNTESTED.");
|
||||
for (auto base : bases) {
|
||||
if (no_cpp_mi ? PyType_IsSubtype(base->type, typeinfo->type) : base->type == typeinfo->type) {
|
||||
this_.load_value_and_holder(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(base));
|
||||
|
@ -67,8 +67,8 @@ TEST_SUBMODULE(classh_inheritance, m) {
|
||||
m.def("pass_base", pass_base);
|
||||
m.def("pass_drvd", pass_drvd);
|
||||
|
||||
py::classh<base1>(m, "base1");
|
||||
py::classh<base2>(m, "base2");
|
||||
py::classh<base1>(m, "base1").def(py::init<>()); // __init__ needed for Python inheritance.
|
||||
py::classh<base2>(m, "base2").def(py::init<>());
|
||||
py::classh<drvd2, base1, base2>(m, "drvd2");
|
||||
|
||||
m.def("make_drvd2", make_drvd2, py::return_value_policy::take_ownership);
|
||||
|
@ -34,3 +34,16 @@ def test_make_drvd2_up_casts_pass_drvd2():
|
||||
assert b2.__class__.__name__ == "drvd2"
|
||||
i2 = m.pass_drvd2(b2)
|
||||
assert i2 == 3 * 110 + 4 * 120 + 23
|
||||
|
||||
|
||||
def test_python_drvd2():
|
||||
class Drvd2(m.base1, m.base2):
|
||||
def __init__(self):
|
||||
m.base1.__init__(self)
|
||||
m.base2.__init__(self)
|
||||
|
||||
d = Drvd2()
|
||||
i1 = m.pass_base1(d) # load_impl Case 2b
|
||||
assert i1 == 110 + 21
|
||||
i2 = m.pass_base2(d)
|
||||
assert i2 == 120 + 22
|
||||
|
Loading…
Reference in New Issue
Block a user