diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2017-05-09 19:22:53 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2017-05-22 17:15:09 +0000 |
commit | 6914a229a038206341ae1fea46393965a555ca9a (patch) | |
tree | 4a11cfaed46dabc827c5ee17cd976f42b5f53d49 /ext/pybind11/tests/test_callbacks.cpp | |
parent | ca1d18d599dcc620bf526fb22042af95b1b60b68 (diff) | |
download | gem5-6914a229a038206341ae1fea46393965a555ca9a.tar.xz |
ext: Upgrade PyBind11 to version 2.1.1
Change-Id: I16870dec402d661295f9d013dc23e362b2b2c169
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/3225
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'ext/pybind11/tests/test_callbacks.cpp')
-rw-r--r-- | ext/pybind11/tests/test_callbacks.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ext/pybind11/tests/test_callbacks.cpp b/ext/pybind11/tests/test_callbacks.cpp index 31d4e39aa..f89cc1c79 100644 --- a/ext/pybind11/tests/test_callbacks.cpp +++ b/ext/pybind11/tests/test_callbacks.cpp @@ -74,6 +74,27 @@ struct Payload { /// Something to trigger a conversion error struct Unregistered {}; +class AbstractBase { +public: + virtual unsigned int func() = 0; +}; + +void func_accepting_func_accepting_base(std::function<double(AbstractBase&)>) { } + +struct MovableObject { + bool valid = true; + + MovableObject() = default; + MovableObject(const MovableObject &) = default; + MovableObject &operator=(const MovableObject &) = default; + MovableObject(MovableObject &&o) : valid(o.valid) { o.valid = false; } + MovableObject &operator=(MovableObject &&o) { + valid = o.valid; + o.valid = false; + return *this; + } +}; + test_initializer callbacks([](py::module &m) { m.def("test_callback1", &test_callback1); m.def("test_callback2", &test_callback2); @@ -136,6 +157,7 @@ test_initializer callbacks([](py::module &m) { return [p]() { /* p should be cleaned up when the returned function is garbage collected */ + (void) p; }; }); @@ -146,4 +168,15 @@ test_initializer callbacks([](py::module &m) { m.def("test_dummy_function", &test_dummy_function); // Export the payload constructor statistics for testing purposes: m.def("payload_cstats", &ConstructorStats::get<Payload>); + + m.def("func_accepting_func_accepting_base", + func_accepting_func_accepting_base); + + py::class_<MovableObject>(m, "MovableObject"); + + m.def("callback_with_movable", [](std::function<void(MovableObject &)> f) { + auto x = MovableObject(); + f(x); // lvalue reference shouldn't move out object + return x.valid; // must still return `true` + }); }); |