diff options
author | gatecat <gatecat@ds0.me> | 2022-09-14 09:28:47 +0200 |
---|---|---|
committer | gatecat <gatecat@ds0.me> | 2022-09-14 09:28:47 +0200 |
commit | a72f898ff4c4237424c468044a6db9d6953b541e (patch) | |
tree | 1c4a543f661dd1b281aecf4660388491702fa8d8 /3rdparty/pybind11/tests/test_call_policies.cpp | |
parent | f1349e114f3a16ccd002e8513339e18f5be4d31b (diff) | |
download | nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.tar.gz nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.tar.bz2 nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.zip |
3rdparty: Bump vendored pybind11 version for py3.11 support
Signed-off-by: gatecat <gatecat@ds0.me>
Diffstat (limited to '3rdparty/pybind11/tests/test_call_policies.cpp')
-rw-r--r-- | 3rdparty/pybind11/tests/test_call_policies.cpp | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/3rdparty/pybind11/tests/test_call_policies.cpp b/3rdparty/pybind11/tests/test_call_policies.cpp index 26c83f81..d177008c 100644 --- a/3rdparty/pybind11/tests/test_call_policies.cpp +++ b/3rdparty/pybind11/tests/test_call_policies.cpp @@ -40,17 +40,17 @@ TEST_SUBMODULE(call_policies, m) { Child(Child &&) = default; ~Child() { py::print("Releasing child."); } }; - py::class_<Child>(m, "Child") - .def(py::init<>()); + py::class_<Child>(m, "Child").def(py::init<>()); class Parent { public: Parent() { py::print("Allocating parent."); } - Parent(const Parent& parent) = default; + Parent(const Parent &parent) = default; ~Parent() { py::print("Releasing parent."); } - void addChild(Child *) { } + void addChild(Child *) {} Child *returnChild() { return new Child(); } Child *returnNullChild() { return nullptr; } + static Child *staticFunction(Parent *) { return new Child(); } }; py::class_<Parent>(m, "Parent") .def(py::init<>()) @@ -60,7 +60,13 @@ TEST_SUBMODULE(call_policies, m) { .def("returnChild", &Parent::returnChild) .def("returnChildKeepAlive", &Parent::returnChild, py::keep_alive<1, 0>()) .def("returnNullChildKeepAliveChild", &Parent::returnNullChild, py::keep_alive<1, 0>()) - .def("returnNullChildKeepAliveParent", &Parent::returnNullChild, py::keep_alive<0, 1>()); + .def("returnNullChildKeepAliveParent", &Parent::returnNullChild, py::keep_alive<0, 1>()) + .def_static("staticFunction", &Parent::staticFunction, py::keep_alive<1, 0>()); + + m.def( + "free_function", [](Parent *, Child *) {}, py::keep_alive<1, 2>()); + m.def( + "invalid_arg_index", [] {}, py::keep_alive<0, 1>()); #if !defined(PYPY_VERSION) // test_alive_gc @@ -68,29 +74,37 @@ TEST_SUBMODULE(call_policies, m) { public: using Parent::Parent; }; - py::class_<ParentGC, Parent>(m, "ParentGC", py::dynamic_attr()) - .def(py::init<>()); + py::class_<ParentGC, Parent>(m, "ParentGC", py::dynamic_attr()).def(py::init<>()); #endif // test_call_guard m.def("unguarded_call", &CustomGuard::report_status); m.def("guarded_call", &CustomGuard::report_status, py::call_guard<CustomGuard>()); - m.def("multiple_guards_correct_order", []() { - return CustomGuard::report_status() + std::string(" & ") + DependentGuard::report_status(); - }, py::call_guard<CustomGuard, DependentGuard>()); - - m.def("multiple_guards_wrong_order", []() { - return DependentGuard::report_status() + std::string(" & ") + CustomGuard::report_status(); - }, py::call_guard<DependentGuard, CustomGuard>()); + m.def( + "multiple_guards_correct_order", + []() { + return CustomGuard::report_status() + std::string(" & ") + + DependentGuard::report_status(); + }, + py::call_guard<CustomGuard, DependentGuard>()); + + m.def( + "multiple_guards_wrong_order", + []() { + return DependentGuard::report_status() + std::string(" & ") + + CustomGuard::report_status(); + }, + py::call_guard<DependentGuard, CustomGuard>()); #if defined(WITH_THREAD) && !defined(PYPY_VERSION) // `py::call_guard<py::gil_scoped_release>()` should work in PyPy as well, // but it's unclear how to test it without `PyGILState_GetThisThreadState`. auto report_gil_status = []() { auto is_gil_held = false; - if (auto tstate = py::detail::get_thread_state_unchecked()) + if (auto *tstate = py::detail::get_thread_state_unchecked()) { is_gil_held = (tstate == PyGILState_GetThisThreadState()); + } return is_gil_held ? "GIL held" : "GIL released"; }; |