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.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-12 14:24:31 -08:00
parent 6dea65fe64
commit 4359422d99
2 changed files with 15 additions and 4 deletions

View File

@ -74,8 +74,12 @@ struct type_caster<mpty> : smart_holder_type_caster_load<mpty> {
// 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) {

View File

@ -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"