From 4359422d9935ab150d851af411fd31790ac54fda Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 12 Jan 2021 14:24:31 -0800 Subject: [PATCH] static cast handle for rtrn_valu works by simply dropping in code from type_caster_base (marked with comments). rtrn_rref raises a RuntimeError, to be investigated. --- tests/test_classh_wip.cpp | 8 ++++++-- tests/test_classh_wip.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_classh_wip.cpp b/tests/test_classh_wip.cpp index d974452da..5fe14a638 100644 --- a/tests/test_classh_wip.cpp +++ b/tests/test_classh_wip.cpp @@ -74,8 +74,12 @@ struct type_caster : smart_holder_type_caster_load { // static handle cast(mpty, ...) // is redundant (leads to ambiguous overloads). - static handle cast(mpty && /*src*/, return_value_policy /*policy*/, handle /*parent*/) { - return str("cast_rref").release(); + static handle cast(mpty &&src, return_value_policy /*policy*/, handle parent) { + // type_caster_base BEGIN + // clang-format off + return cast(&src, return_value_policy::move, parent); + // clang-format on + // type_caster_base END } static handle cast(mpty const &src, return_value_policy policy, handle parent) { diff --git a/tests/test_classh_wip.py b/tests/test_classh_wip.py index 10a42ae9d..93aaae01d 100644 --- a/tests/test_classh_wip.py +++ b/tests/test_classh_wip.py @@ -14,14 +14,21 @@ def test_mpty_constructors(): def test_cast(): - assert m.rtrn_mpty_valu() == "cast_rref" - assert m.rtrn_mpty_rref() == "cast_rref" + assert m.get_mtxt(m.rtrn_mpty_valu()) == "rtrn_valu" + # rtrn_rref exercised separately. assert m.get_mtxt(m.rtrn_mpty_cref()) == "rtrn_cref" assert m.get_mtxt(m.rtrn_mpty_mref()) == "rtrn_mref" assert m.get_mtxt(m.rtrn_mpty_cptr()) == "rtrn_cptr" assert m.get_mtxt(m.rtrn_mpty_mptr()) == "rtrn_mptr" +def test_cast_rref(): + e = m.rtrn_mpty_rref() + assert e.__class__.__name__ == "mpty" + with pytest.raises(RuntimeError): + m.get_mtxt(e) # E.g. basic_string::_M_construct null not valid + + def test_load(): assert m.pass_mpty_valu(m.mpty("Valu")) == "pass_valu:Valu" assert m.pass_mpty_rref(m.mpty("Rref")) == "pass_rref:Rref"