Skip to content

Commit

Permalink
Roundtrip through unique pointer with custom deleter.
Browse files Browse the repository at this point in the history
Currently failing.
  • Loading branch information
iwanders committed Nov 4, 2023
1 parent edfaaed commit 7cc1e1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_class_sh_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ std::unique_ptr<atyp const, sddc> rtrn_udcp() { return std::unique_ptr<atyp cons
std::string pass_udmp(std::unique_ptr<atyp, sddm> obj) { return "pass_udmp:" + obj->mtxt; }
std::string pass_udcp(std::unique_ptr<atyp const, sddc> obj) { return "pass_udcp:" + obj->mtxt; }


struct custom_deleter
{
std::string delete_txt;
void operator()(atyp* p) const
{
std::default_delete<atyp>()(p);
}
};

std::unique_ptr<atyp, custom_deleter> rtrn_udmp_del() { return std::unique_ptr<atyp, custom_deleter>(new atyp{"rtrn_udmp_del"}, custom_deleter{"udmp_deleter"}); }

std::string pass_udmp_del(std::unique_ptr<atyp, custom_deleter> obj) {
const auto d = obj.get_deleter();
return "pass_udmp_del:" + obj->mtxt + "," + d.delete_txt;
}

// clang-format on

// Helpers for testing.
Expand Down Expand Up @@ -130,6 +147,9 @@ TEST_SUBMODULE(class_sh_basic, m) {
m.def("pass_udmp", pass_udmp);
m.def("pass_udcp", pass_udcp);

m.def("rtrn_udmp_del", rtrn_udmp_del);
m.def("pass_udmp_del", pass_udmp_del);

py::classh<uconsumer>(m, "uconsumer")
.def(py::init<>())
.def("valid", &uconsumer::valid)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_class_sh_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def test_load_with_mtxt(pass_f, mtxt, expected):
def test_load_with_rtrn_f(pass_f, rtrn_f, expected):
assert pass_f(rtrn_f()) == expected

def test_deleter_roundtrip():
t = m.rtrn_udmp_del()
r = m.pass_udmp_del(t)
assert r == "pass_udmp_del:rtrn_udmp_del,udmp_deleter"

@pytest.mark.parametrize(
("pass_f", "rtrn_f", "expected"),
Expand Down

0 comments on commit 7cc1e1f

Please sign in to comment.