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:
@@ -43,6 +43,13 @@ public:
|
||||
friend Vector2 operator-(float f, const Vector2 &v) { return Vector2(f - v.x, f - v.y); }
|
||||
friend Vector2 operator*(float f, const Vector2 &v) { return Vector2(f * v.x, f * v.y); }
|
||||
friend Vector2 operator/(float f, const Vector2 &v) { return Vector2(f / v.x, f / v.y); }
|
||||
|
||||
bool operator==(const Vector2 &v) const {
|
||||
return x == v.x && y == v.y;
|
||||
}
|
||||
bool operator!=(const Vector2 &v) const {
|
||||
return x != v.x || y != v.y;
|
||||
}
|
||||
private:
|
||||
float x, y;
|
||||
};
|
||||
@@ -55,12 +62,22 @@ int operator+(const C2 &, const C2 &) { return 22; }
|
||||
int operator+(const C2 &, const C1 &) { return 21; }
|
||||
int operator+(const C1 &, const C2 &) { return 12; }
|
||||
|
||||
// Note: Specializing explicit within `namespace std { ... }` is done due to a
|
||||
// bug in GCC<7. If you are supporting compilers later than this, consider
|
||||
// specializing `using template<> struct std::hash<...>` in the global
|
||||
// namespace instead, per this recommendation:
|
||||
// https://en.cppreference.com/w/cpp/language/extending_std#Adding_template_specializations
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<Vector2> {
|
||||
// Not a good hash function, but easy to test
|
||||
size_t operator()(const Vector2 &) { return 4; }
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
// Not a good abs function, but easy to test.
|
||||
std::string abs(const Vector2&) {
|
||||
return "abs(Vector2)";
|
||||
}
|
||||
|
||||
// MSVC warns about unknown pragmas, and warnings are errors.
|
||||
@@ -71,11 +88,11 @@ namespace std {
|
||||
// Here, we suppress the warning using `#pragma diagnostic`.
|
||||
// Taken from: https://github.com/RobotLocomotion/drake/commit/aaf84b46
|
||||
// TODO(eric): This could be resolved using a function / functor (e.g. `py::self()`).
|
||||
#if (__APPLE__) && (__clang__)
|
||||
#if (__clang_major__ >= 10) && (__clang_minor__ >= 0) && (__clang_patchlevel__ >= 1)
|
||||
#if defined(__APPLE__) && defined(__clang__)
|
||||
#if (__clang_major__ >= 10)
|
||||
#pragma GCC diagnostic ignored "-Wself-assign-overloaded"
|
||||
#endif
|
||||
#elif (__clang__)
|
||||
#elif defined(__clang__)
|
||||
#if (__clang_major__ >= 7)
|
||||
#pragma GCC diagnostic ignored "-Wself-assign-overloaded"
|
||||
#endif
|
||||
@@ -107,7 +124,13 @@ TEST_SUBMODULE(operators, m) {
|
||||
.def(float() / py::self)
|
||||
.def(-py::self)
|
||||
.def("__str__", &Vector2::toString)
|
||||
.def(hash(py::self))
|
||||
.def("__repr__", &Vector2::toString)
|
||||
.def(py::self == py::self)
|
||||
.def(py::self != py::self)
|
||||
.def(py::hash(py::self))
|
||||
// N.B. See warning about usage of `py::detail::abs(py::self)` in
|
||||
// `operators.h`.
|
||||
.def("__abs__", [](const Vector2& v) { return abs(v); })
|
||||
;
|
||||
|
||||
m.attr("Vector") = m.attr("Vector2");
|
||||
@@ -164,6 +187,38 @@ TEST_SUBMODULE(operators, m) {
|
||||
.def(py::self *= int())
|
||||
.def_readwrite("b", &NestC::b);
|
||||
m.def("get_NestC", [](const NestC &c) { return c.value; });
|
||||
|
||||
|
||||
// test_overriding_eq_reset_hash
|
||||
// #2191 Overriding __eq__ should set __hash__ to None
|
||||
struct Comparable {
|
||||
int value;
|
||||
bool operator==(const Comparable& rhs) const {return value == rhs.value;}
|
||||
};
|
||||
|
||||
struct Hashable : Comparable {
|
||||
explicit Hashable(int value): Comparable{value}{};
|
||||
size_t hash() const { return static_cast<size_t>(value); }
|
||||
};
|
||||
|
||||
struct Hashable2 : Hashable {
|
||||
using Hashable::Hashable;
|
||||
};
|
||||
|
||||
py::class_<Comparable>(m, "Comparable")
|
||||
.def(py::init<int>())
|
||||
.def(py::self == py::self);
|
||||
|
||||
py::class_<Hashable>(m, "Hashable")
|
||||
.def(py::init<int>())
|
||||
.def(py::self == py::self)
|
||||
.def("__hash__", &Hashable::hash);
|
||||
|
||||
// define __hash__ before __eq__
|
||||
py::class_<Hashable2>(m, "Hashable2")
|
||||
.def("__hash__", &Hashable::hash)
|
||||
.def(py::init<int>())
|
||||
.def(py::self == py::self);
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
Reference in New Issue
Block a user