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:
Jason Lowe-Power
2017-11-17 17:02:05 -08:00
parent 3f64b374c4
commit f07d5069d8
160 changed files with 15668 additions and 7238 deletions

View File

@@ -58,34 +58,6 @@ class MyException5_1 : public MyException5 {
using MyException5::MyException5;
};
void throws1() {
throw MyException("this error should go to a custom type");
}
void throws2() {
throw MyException2("this error should go to a standard Python exception");
}
void throws3() {
throw MyException3("this error cannot be translated");
}
void throws4() {
throw MyException4("this error is rethrown");
}
void throws5() {
throw MyException5("this is a helper-defined translated exception");
}
void throws5_1() {
throw MyException5_1("MyException5 subclass");
}
void throws_logic_error() {
throw std::logic_error("this error should fall through to the standard handler");
}
struct PythonCallInDestructor {
PythonCallInDestructor(const py::dict &d) : d(d) {}
~PythonCallInDestructor() { d["good"] = true; }
@@ -93,7 +65,11 @@ struct PythonCallInDestructor {
py::dict d;
};
test_initializer custom_exceptions([](py::module &m) {
TEST_SUBMODULE(exceptions, m) {
m.def("throw_std_exception", []() {
throw std::runtime_error("This exception was intentionally thrown.");
});
// make a new custom exception and use it as a translation target
static py::exception<MyException> ex(m, "MyException");
py::register_exception_translator([](std::exception_ptr p) {
@@ -133,13 +109,20 @@ test_initializer custom_exceptions([](py::module &m) {
// A slightly more complicated one that declares MyException5_1 as a subclass of MyException5
py::register_exception<MyException5_1>(m, "MyException5_1", ex5.ptr());
m.def("throws1", &throws1);
m.def("throws2", &throws2);
m.def("throws3", &throws3);
m.def("throws4", &throws4);
m.def("throws5", &throws5);
m.def("throws5_1", &throws5_1);
m.def("throws_logic_error", &throws_logic_error);
m.def("throws1", []() { throw MyException("this error should go to a custom type"); });
m.def("throws2", []() { throw MyException2("this error should go to a standard Python exception"); });
m.def("throws3", []() { throw MyException3("this error cannot be translated"); });
m.def("throws4", []() { throw MyException4("this error is rethrown"); });
m.def("throws5", []() { throw MyException5("this is a helper-defined translated exception"); });
m.def("throws5_1", []() { throw MyException5_1("MyException5 subclass"); });
m.def("throws_logic_error", []() { throw std::logic_error("this error should fall through to the standard handler"); });
m.def("exception_matches", []() {
py::dict foo;
try { foo["bar"]; }
catch (py::error_already_set& ex) {
if (!ex.matches(PyExc_KeyError)) throw;
}
});
m.def("throw_already_set", [](bool err) {
if (err)
@@ -170,4 +153,16 @@ test_initializer custom_exceptions([](py::module &m) {
}
return false;
});
});
// test_nested_throws
m.def("try_catch", [m](py::object exc_type, py::function f, py::args args) {
try { f(*args); }
catch (py::error_already_set &ex) {
if (ex.matches(exc_type))
py::print(ex.what());
else
throw;
}
});
}