summaryrefslogtreecommitdiff
path: root/ext/pybind11/tests/test_stl.cpp
diff options
context:
space:
mode:
authorBobby R. Bruce <bbruce@ucdavis.edu>2019-09-23 13:52:58 -0700
committerBobby R. Bruce <bbruce@ucdavis.edu>2019-09-24 21:40:15 +0000
commitf97cf54db7a6f7642cc9fd122f23c4396c39bcf0 (patch)
tree17d2ed22a1114cb138500d46afddb3bafcc2b418 /ext/pybind11/tests/test_stl.cpp
parent9235ae56c282d5a02ada3ed9b4e0fe2ee5738bde (diff)
downloadgem5-f97cf54db7a6f7642cc9fd122f23c4396c39bcf0.tar.xz
ext: Updated Pybind11 to version 2.4.1.
This updates Pybind11 from version 2.2.1 to version 2.4.1. This fixes warning/error received when "<experiment/optional>" is used when compiling using c++14 with clang. It should be noted that "ext/pybind11/include/pybind11/std.h" has been changed to include a fix added by commit ba42457254cc362eddc099f22b60d469cc6369e0. This is necessary to avoid build errors. Built: Linux (gcc, c++11) and MacOS (clang, c++14). Tested: Ran quick tests for X86, ARM, and RISC-V. Deprecates: https://gem5-review.googlesource.com/c/public/gem5/+/21019 Change-Id: Ie9783511cb6be50136076a55330e645f4f36d075 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21119 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Jason Lowe-Power <jason@lowepower.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'ext/pybind11/tests/test_stl.cpp')
-rw-r--r--ext/pybind11/tests/test_stl.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/pybind11/tests/test_stl.cpp b/ext/pybind11/tests/test_stl.cpp
index 7d53e9c18..207c9fb2b 100644
--- a/ext/pybind11/tests/test_stl.cpp
+++ b/ext/pybind11/tests/test_stl.cpp
@@ -8,8 +8,12 @@
*/
#include "pybind11_tests.h"
+#include "constructor_stats.h"
#include <pybind11/stl.h>
+#include <vector>
+#include <string>
+
// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
#if PYBIND11_HAS_VARIANT
using std::variant;
@@ -32,6 +36,8 @@ struct visit_helper<boost::variant> {
}} // namespace pybind11::detail
#endif
+PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
+
/// Issue #528: templated constructor
struct TplCtorClass {
template <typename T> TplCtorClass(const T &) { }
@@ -57,6 +63,10 @@ TEST_SUBMODULE(stl, m) {
static std::vector<RValueCaster> lvv{2};
m.def("cast_ptr_vector", []() { return &lvv; });
+ // test_deque
+ m.def("cast_deque", []() { return std::deque<int>{1}; });
+ m.def("load_deque", [](const std::deque<int> &v) { return v.at(0) == 1 && v.at(1) == 2; });
+
// test_array
m.def("cast_array", []() { return std::array<int, 2> {{1 , 2}}; });
m.def("load_array", [](const std::array<int, 2> &a) { return a[0] == 1 && a[1] == 2; });
@@ -235,4 +245,40 @@ TEST_SUBMODULE(stl, m) {
// test_stl_pass_by_pointer
m.def("stl_pass_by_pointer", [](std::vector<int>* v) { return *v; }, "v"_a=nullptr);
+
+ // #1258: pybind11/stl.h converts string to vector<string>
+ m.def("func_with_string_or_vector_string_arg_overload", [](std::vector<std::string>) { return 1; });
+ m.def("func_with_string_or_vector_string_arg_overload", [](std::list<std::string>) { return 2; });
+ m.def("func_with_string_or_vector_string_arg_overload", [](std::string) { return 3; });
+
+ class Placeholder {
+ public:
+ Placeholder() { print_created(this); }
+ Placeholder(const Placeholder &) = delete;
+ ~Placeholder() { print_destroyed(this); }
+ };
+ py::class_<Placeholder>(m, "Placeholder");
+
+ /// test_stl_vector_ownership
+ m.def("test_stl_ownership",
+ []() {
+ std::vector<Placeholder *> result;
+ result.push_back(new Placeholder());
+ return result;
+ },
+ py::return_value_policy::take_ownership);
+
+ m.def("array_cast_sequence", [](std::array<int, 3> x) { return x; });
+
+ /// test_issue_1561
+ struct Issue1561Inner { std::string data; };
+ struct Issue1561Outer { std::vector<Issue1561Inner> list; };
+
+ py::class_<Issue1561Inner>(m, "Issue1561Inner")
+ .def(py::init<std::string>())
+ .def_readwrite("data", &Issue1561Inner::data);
+
+ py::class_<Issue1561Outer>(m, "Issue1561Outer")
+ .def(py::init<>())
+ .def_readwrite("list", &Issue1561Outer::list);
}