ext: Upgrade PyBind11 to version 2.2.1
This upgrade is necessary for pybind to build with GCC 7.2. We still need to add the patch for stl.h. MSC_FULL_VER change is no longer needed. See https://gem5-review.googlesource.com/c/public/gem5/+/2230 Change-Id: I806729217d022070583994c2dfcaa74476aef30f Signed-off-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-on: https://gem5-review.googlesource.com/5801 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
#include "pybind11_tests.h"
|
||||
#include "constructor_stats.h"
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
|
||||
/*
|
||||
For testing purposes, we define a static global variable here in a function that each individual
|
||||
test .cpp calls with its initialization lambda. It's convenient here because we can just not
|
||||
@@ -28,8 +31,15 @@ std::list<std::function<void(py::module &)>> &initializers() {
|
||||
return inits;
|
||||
}
|
||||
|
||||
test_initializer::test_initializer(std::function<void(py::module &)> initializer) {
|
||||
initializers().push_back(std::move(initializer));
|
||||
test_initializer::test_initializer(Initializer init) {
|
||||
initializers().push_back(init);
|
||||
}
|
||||
|
||||
test_initializer::test_initializer(const char *submodule_name, Initializer init) {
|
||||
initializers().push_back([=](py::module &parent) {
|
||||
auto m = parent.def_submodule(submodule_name);
|
||||
init(m);
|
||||
});
|
||||
}
|
||||
|
||||
void bind_ConstructorStats(py::module &m) {
|
||||
@@ -41,18 +51,43 @@ void bind_ConstructorStats(py::module &m) {
|
||||
.def_readwrite("move_assignments", &ConstructorStats::move_assignments)
|
||||
.def_readwrite("copy_constructions", &ConstructorStats::copy_constructions)
|
||||
.def_readwrite("move_constructions", &ConstructorStats::move_constructions)
|
||||
.def_static("get", (ConstructorStats &(*)(py::object)) &ConstructorStats::get, py::return_value_policy::reference_internal);
|
||||
.def_static("get", (ConstructorStats &(*)(py::object)) &ConstructorStats::get, py::return_value_policy::reference_internal)
|
||||
|
||||
// Not exactly ConstructorStats, but related: expose the internal pybind number of registered instances
|
||||
// to allow instance cleanup checks (invokes a GC first)
|
||||
.def_static("detail_reg_inst", []() {
|
||||
ConstructorStats::gc();
|
||||
return py::detail::get_internals().registered_instances.size();
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
PYBIND11_PLUGIN(pybind11_tests) {
|
||||
py::module m("pybind11_tests", "pybind testing plugin");
|
||||
PYBIND11_MODULE(pybind11_tests, m) {
|
||||
m.doc() = "pybind11 test module";
|
||||
|
||||
bind_ConstructorStats(m);
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
m.attr("debug_enabled") = true;
|
||||
#else
|
||||
m.attr("debug_enabled") = false;
|
||||
#endif
|
||||
|
||||
py::class_<UserType>(m, "UserType", "A `py::class_` type for testing")
|
||||
.def(py::init<>())
|
||||
.def(py::init<int>())
|
||||
.def("get_value", &UserType::value, "Get value using a method")
|
||||
.def("set_value", &UserType::set, "Set value using a method")
|
||||
.def_property("value", &UserType::value, &UserType::set, "Get/set value using a property")
|
||||
.def("__repr__", [](const UserType& u) { return "UserType({})"_s.format(u.value()); });
|
||||
|
||||
py::class_<IncType, UserType>(m, "IncType")
|
||||
.def(py::init<>())
|
||||
.def(py::init<int>())
|
||||
.def("__repr__", [](const IncType& u) { return "IncType({})"_s.format(u.value()); });
|
||||
|
||||
for (const auto &initializer : initializers())
|
||||
initializer(m);
|
||||
|
||||
if (!py::hasattr(m, "have_eigen")) m.attr("have_eigen") = false;
|
||||
|
||||
return m.ptr();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user