diff options
author | myrtle <gatecat@ds0.me> | 2022-09-15 09:06:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-15 09:06:35 +0200 |
commit | 3983d4fe53e2c609a5c76510aff8e998a4c22285 (patch) | |
tree | 1c4a543f661dd1b281aecf4660388491702fa8d8 /3rdparty/pybind11/tests/test_local_bindings.cpp | |
parent | f1349e114f3a16ccd002e8513339e18f5be4d31b (diff) | |
parent | a72f898ff4c4237424c468044a6db9d6953b541e (diff) | |
download | nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.tar.gz nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.tar.bz2 nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.zip |
Merge pull request #1024 from YosysHQ/gatecat/pybind11-bump
3rdparty: Bump vendored pybind11 version for py3.11 support
Diffstat (limited to '3rdparty/pybind11/tests/test_local_bindings.cpp')
-rw-r--r-- | 3rdparty/pybind11/tests/test_local_bindings.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/3rdparty/pybind11/tests/test_local_bindings.cpp b/3rdparty/pybind11/tests/test_local_bindings.cpp index c61e3888..13736774 100644 --- a/3rdparty/pybind11/tests/test_local_bindings.cpp +++ b/3rdparty/pybind11/tests/test_local_bindings.cpp @@ -8,11 +8,14 @@ BSD-style license that can be found in the LICENSE file. */ -#include "pybind11_tests.h" -#include "local_bindings.h" #include <pybind11/stl.h> #include <pybind11/stl_bind.h> + +#include "local_bindings.h" +#include "pybind11_tests.h" + #include <numeric> +#include <utility> TEST_SUBMODULE(local_bindings, m) { // test_load_external @@ -21,9 +24,9 @@ TEST_SUBMODULE(local_bindings, m) { // test_local_bindings // Register a class with py::module_local: - bind_local<LocalType, -1>(m, "LocalType", py::module_local()) - .def("get3", [](LocalType &t) { return t.i + 3; }) - ; + bind_local<LocalType, -1>(m, "LocalType", py::module_local()).def("get3", [](LocalType &t) { + return t.i + 3; + }); m.def("local_value", [](LocalType &l) { return l.i; }); @@ -32,20 +35,21 @@ TEST_SUBMODULE(local_bindings, m) { // one, in pybind11_cross_module_tests.cpp, is designed to fail): bind_local<NonLocalType, 0>(m, "NonLocalType") .def(py::init<int>()) - .def("get", [](LocalType &i) { return i.i; }) - ; + .def("get", [](LocalType &i) { return i.i; }); // test_duplicate_local - // py::module_local declarations should be visible across compilation units that get linked together; - // this tries to register a duplicate local. It depends on a definition in test_class.cpp and - // should raise a runtime error from the duplicate definition attempt. If test_class isn't - // available it *also* throws a runtime error (with "test_class not enabled" as value). + // py::module_local declarations should be visible across compilation units that get linked + // together; this tries to register a duplicate local. It depends on a definition in + // test_class.cpp and should raise a runtime error from the duplicate definition attempt. If + // test_class isn't available it *also* throws a runtime error (with "test_class not enabled" + // as value). m.def("register_local_external", [m]() { auto main = py::module_::import("pybind11_tests"); if (py::hasattr(main, "class_")) { bind_local<LocalExternal, 7>(m, "LocalExternal", py::module_local()); + } else { + throw std::runtime_error("test_class not enabled"); } - else throw std::runtime_error("test_class not enabled"); }); // test_stl_bind_local @@ -75,23 +79,24 @@ TEST_SUBMODULE(local_bindings, m) { m.def("get_mixed_lg", [](int i) { return MixedLocalGlobal(i); }); // test_internal_locals_differ - m.def("local_cpp_types_addr", []() { return (uintptr_t) &py::detail::registered_local_types_cpp(); }); + m.def("local_cpp_types_addr", + []() { return (uintptr_t) &py::detail::get_local_internals().registered_types_cpp; }); // test_stl_caster_vs_stl_bind - m.def("load_vector_via_caster", [](std::vector<int> v) { - return std::accumulate(v.begin(), v.end(), 0); - }); + m.def("load_vector_via_caster", + [](std::vector<int> v) { return std::accumulate(v.begin(), v.end(), 0); }); // test_cross_module_calls m.def("return_self", [](LocalVec *v) { return v; }); m.def("return_copy", [](const LocalVec &v) { return LocalVec(v); }); - class Cat : public pets::Pet { public: Cat(std::string name) : Pet(name) {}; }; - py::class_<pets::Pet>(m, "Pet", py::module_local()) - .def("get_name", &pets::Pet::name); + class Cat : public pets::Pet { + public: + explicit Cat(std::string name) : Pet(std::move(name)) {} + }; + py::class_<pets::Pet>(m, "Pet", py::module_local()).def("get_name", &pets::Pet::name); // Binding for local extending class: - py::class_<Cat, pets::Pet>(m, "Cat") - .def(py::init<std::string>()); + py::class_<Cat, pets::Pet>(m, "Cat").def(py::init<std::string>()); m.def("pet_name", [](pets::Pet &p) { return p.name(); }); py::class_<MixGL>(m, "MixGL").def(py::init<int>()); |