install a cleanup handler for nontrivial lambda closures

This commit is contained in:
Wenzel Jakob
2015-10-13 17:37:25 +02:00
parent 28f98aa298
commit 19208fe9a4
4 changed files with 42 additions and 1 deletions

View File

@@ -72,4 +72,29 @@ void init_ex5(py::module &m) {
m.def("test_callback2", &test_callback2);
m.def("test_callback3", &test_callback3);
m.def("test_callback4", &test_callback4);
/* Test cleanup of lambda closure */
struct Payload {
Payload() {
std::cout << "Payload constructor" << std::endl;
}
~Payload() {
std::cout << "Payload destructor" << std::endl;
}
Payload(const Payload &) {
std::cout << "Payload copy constructor" << std::endl;
}
Payload(Payload &&) {
std::cout << "Payload move constructor" << std::endl;
}
};
m.def("test_cleanup", []() -> std::function<void(void)> {
Payload p;
return [p]() {
/* p should be cleaned up when the returned function is garbage collected */
};
});
}