ext: Update pybind11 to v2.8.1
Change-Id: Ia1c7081377f53fd470addf35526f8b28a949a7b0 Signed-off-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52523 Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Gabe Black <gabe.black@gmail.com>
This commit is contained in:
committed by
Jason Lowe-Power
parent
ba5f68db3d
commit
1e8aeee698
@@ -15,9 +15,12 @@
|
||||
/* This is an example class that we'll want to be able to extend from Python */
|
||||
class ExampleVirt {
|
||||
public:
|
||||
ExampleVirt(int state) : state(state) { print_created(this, state); }
|
||||
explicit ExampleVirt(int state) : state(state) { print_created(this, state); }
|
||||
ExampleVirt(const ExampleVirt &e) : state(e.state) { print_copy_created(this); }
|
||||
ExampleVirt(ExampleVirt &&e) : state(e.state) { print_move_created(this); e.state = 0; }
|
||||
ExampleVirt(ExampleVirt &&e) noexcept : state(e.state) {
|
||||
print_move_created(this);
|
||||
e.state = 0;
|
||||
}
|
||||
virtual ~ExampleVirt() { print_destroyed(this); }
|
||||
|
||||
virtual int run(int value) {
|
||||
@@ -100,13 +103,18 @@ public:
|
||||
class NonCopyable {
|
||||
public:
|
||||
NonCopyable(int a, int b) : value{new int(a*b)} { print_created(this, a, b); }
|
||||
NonCopyable(NonCopyable &&o) { value = std::move(o.value); print_move_created(this); }
|
||||
NonCopyable(NonCopyable &&o) noexcept {
|
||||
value = std::move(o.value);
|
||||
print_move_created(this);
|
||||
}
|
||||
NonCopyable(const NonCopyable &) = delete;
|
||||
NonCopyable() = delete;
|
||||
void operator=(const NonCopyable &) = delete;
|
||||
void operator=(NonCopyable &&) = delete;
|
||||
std::string get_value() const {
|
||||
if (value) return std::to_string(*value); else return "(null)";
|
||||
if (value)
|
||||
return std::to_string(*value);
|
||||
return "(null)";
|
||||
}
|
||||
~NonCopyable() { print_destroyed(this); }
|
||||
|
||||
@@ -120,7 +128,10 @@ class Movable {
|
||||
public:
|
||||
Movable(int a, int b) : value{a+b} { print_created(this, a, b); }
|
||||
Movable(const Movable &m) { value = m.value; print_copy_created(this); }
|
||||
Movable(Movable &&m) { value = std::move(m.value); print_move_created(this); }
|
||||
Movable(Movable &&m) noexcept {
|
||||
value = m.value;
|
||||
print_move_created(this);
|
||||
}
|
||||
std::string get_value() const { return std::to_string(value); }
|
||||
~Movable() { print_destroyed(this); }
|
||||
private:
|
||||
@@ -163,6 +174,25 @@ struct DispatchIssue : Base {
|
||||
}
|
||||
};
|
||||
|
||||
// An abstract adder class that uses visitor pattern to add two data
|
||||
// objects and send the result to the visitor functor
|
||||
struct AdderBase {
|
||||
struct Data {};
|
||||
using DataVisitor = std::function<void (const Data&)>;
|
||||
|
||||
virtual void operator()(const Data& first, const Data& second, const DataVisitor& visitor) const = 0;
|
||||
virtual ~AdderBase() = default;
|
||||
AdderBase() = default;
|
||||
AdderBase(const AdderBase&) = delete;
|
||||
};
|
||||
|
||||
struct Adder : AdderBase {
|
||||
void operator()(const Data& first, const Data& second, const DataVisitor& visitor) const override {
|
||||
PYBIND11_OVERRIDE_PURE_NAME(void, AdderBase, "__call__", operator(), first, second, visitor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void test_gil() {
|
||||
{
|
||||
py::gil_scoped_acquire lock;
|
||||
@@ -284,6 +314,27 @@ TEST_SUBMODULE(virtual_functions, m) {
|
||||
|
||||
m.def("dispatch_issue_go", [](const Base * b) { return b->dispatch(); });
|
||||
|
||||
// test_recursive_dispatch_issue
|
||||
// #3357: Recursive dispatch fails to find python function override
|
||||
pybind11::class_<AdderBase, Adder>(m, "Adder")
|
||||
.def(pybind11::init<>())
|
||||
.def("__call__", &AdderBase::operator());
|
||||
|
||||
pybind11::class_<AdderBase::Data>(m, "Data")
|
||||
.def(pybind11::init<>());
|
||||
|
||||
m.def("add2", [](const AdderBase::Data& first, const AdderBase::Data& second,
|
||||
const AdderBase& adder, const AdderBase::DataVisitor& visitor) {
|
||||
adder(first, second, visitor);
|
||||
});
|
||||
|
||||
m.def("add3", [](const AdderBase::Data& first, const AdderBase::Data& second, const AdderBase::Data& third,
|
||||
const AdderBase& adder, const AdderBase::DataVisitor& visitor) {
|
||||
adder(first, second, [&] (const AdderBase::Data& first_plus_second) {
|
||||
adder(first_plus_second, third, visitor);
|
||||
});
|
||||
});
|
||||
|
||||
// test_override_ref
|
||||
// #392/397: overriding reference-returning functions
|
||||
class OverrideTest {
|
||||
@@ -443,6 +494,7 @@ template <class Base = B_Tpl>
|
||||
class PyB_Tpl : public PyA_Tpl<Base> {
|
||||
public:
|
||||
using PyA_Tpl<Base>::PyA_Tpl; // Inherit constructors (via PyA_Tpl's inherited constructors)
|
||||
// NOLINTNEXTLINE(bugprone-parent-virtual-call)
|
||||
int unlucky_number() override { PYBIND11_OVERRIDE(int, Base, unlucky_number, ); }
|
||||
double lucky_number() override { PYBIND11_OVERRIDE(double, Base, lucky_number, ); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user