ext: Update pybind11 to version 2.6.2.
This should help reduce warning spew when building with newer compilers. The pybind11::module type has been renamed pybind11::module_ to avoid conflicts with c++20 modules, according to the pybind11 changelog, so this CL also updates gem5 source to use the new type. There is supposedly an alias pybind11::module which is for compatibility, but we still get linker errors without changing to pybind11::module_. Change-Id: I0acb36215b33e3a713866baec43f5af630c356ee Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40255 Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
class MyException : public std::exception {
|
||||
public:
|
||||
explicit MyException(const char * m) : message{m} {}
|
||||
virtual const char * what() const noexcept override {return message.c_str();}
|
||||
const char * what() const noexcept override {return message.c_str();}
|
||||
private:
|
||||
std::string message = "";
|
||||
};
|
||||
@@ -22,7 +22,7 @@ private:
|
||||
class MyException2 : public std::exception {
|
||||
public:
|
||||
explicit MyException2(const char * m) : message{m} {}
|
||||
virtual const char * what() const noexcept override {return message.c_str();}
|
||||
const char * what() const noexcept override {return message.c_str();}
|
||||
private:
|
||||
std::string message = "";
|
||||
};
|
||||
@@ -32,6 +32,13 @@ class MyException3 {
|
||||
public:
|
||||
explicit MyException3(const char * m) : message{m} {}
|
||||
virtual const char * what() const noexcept {return message.c_str();}
|
||||
// Rule of 5 BEGIN: to preempt compiler warnings.
|
||||
MyException3(const MyException3&) = default;
|
||||
MyException3(MyException3&&) = default;
|
||||
MyException3& operator=(const MyException3&) = default;
|
||||
MyException3& operator=(MyException3&&) = default;
|
||||
virtual ~MyException3() = default;
|
||||
// Rule of 5 END.
|
||||
private:
|
||||
std::string message = "";
|
||||
};
|
||||
@@ -41,7 +48,7 @@ private:
|
||||
class MyException4 : public std::exception {
|
||||
public:
|
||||
explicit MyException4(const char * m) : message{m} {}
|
||||
virtual const char * what() const noexcept override {return message.c_str();}
|
||||
const char * what() const noexcept override {return message.c_str();}
|
||||
private:
|
||||
std::string message = "";
|
||||
};
|
||||
@@ -65,6 +72,25 @@ struct PythonCallInDestructor {
|
||||
py::dict d;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct PythonAlreadySetInDestructor {
|
||||
PythonAlreadySetInDestructor(const py::str &s) : s(s) {}
|
||||
~PythonAlreadySetInDestructor() {
|
||||
py::dict foo;
|
||||
try {
|
||||
// Assign to a py::object to force read access of nonexistent dict entry
|
||||
py::object o = foo["bar"];
|
||||
}
|
||||
catch (py::error_already_set& ex) {
|
||||
ex.discard_as_unraisable(s);
|
||||
}
|
||||
}
|
||||
|
||||
py::str s;
|
||||
};
|
||||
|
||||
|
||||
TEST_SUBMODULE(exceptions, m) {
|
||||
m.def("throw_std_exception", []() {
|
||||
throw std::runtime_error("This exception was intentionally thrown.");
|
||||
@@ -116,6 +142,7 @@ TEST_SUBMODULE(exceptions, m) {
|
||||
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("throws_overflow_error", []() {throw std::overflow_error(""); });
|
||||
m.def("exception_matches", []() {
|
||||
py::dict foo;
|
||||
try {
|
||||
@@ -143,7 +170,7 @@ TEST_SUBMODULE(exceptions, m) {
|
||||
m.def("modulenotfound_exception_matches_base", []() {
|
||||
try {
|
||||
// On Python >= 3.6, this raises a ModuleNotFoundError, a subclass of ImportError
|
||||
py::module::import("nonexistent");
|
||||
py::module_::import("nonexistent");
|
||||
}
|
||||
catch (py::error_already_set &ex) {
|
||||
if (!ex.matches(PyExc_ImportError)) throw;
|
||||
@@ -182,6 +209,11 @@ TEST_SUBMODULE(exceptions, m) {
|
||||
return false;
|
||||
});
|
||||
|
||||
m.def("python_alreadyset_in_destructor", [](py::str s) {
|
||||
PythonAlreadySetInDestructor alreadyset_in_destructor(s);
|
||||
return true;
|
||||
});
|
||||
|
||||
// test_nested_throws
|
||||
m.def("try_catch", [m](py::object exc_type, py::function f, py::args args) {
|
||||
try { f(*args); }
|
||||
@@ -193,4 +225,7 @@ TEST_SUBMODULE(exceptions, m) {
|
||||
}
|
||||
});
|
||||
|
||||
// Test repr that cannot be displayed
|
||||
m.def("simple_bool_passthrough", [](bool x) {return x;});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user