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/local_bindings.h | |
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/local_bindings.h')
-rw-r--r-- | 3rdparty/pybind11/tests/local_bindings.h | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/3rdparty/pybind11/tests/local_bindings.h b/3rdparty/pybind11/tests/local_bindings.h index 22537b13..01d27853 100644 --- a/3rdparty/pybind11/tests/local_bindings.h +++ b/3rdparty/pybind11/tests/local_bindings.h @@ -1,10 +1,13 @@ #pragma once #include "pybind11_tests.h" +#include <utility> + /// Simple class used to test py::local: -template <int> class LocalBase { +template <int> +class LocalBase { public: - LocalBase(int i) : i(i) { } + explicit LocalBase(int i) : i(i) {} int i = -1; }; @@ -33,32 +36,57 @@ using NonLocalVec2 = std::vector<NonLocal2>; using NonLocalMap = std::unordered_map<std::string, NonLocalType>; using NonLocalMap2 = std::unordered_map<std::string, uint8_t>; +// Exception that will be caught via the module local translator. +class LocalException : public std::exception { +public: + explicit LocalException(const char *m) : message{m} {} + const char *what() const noexcept override { return message.c_str(); } + +private: + std::string message = ""; +}; + +// Exception that will be registered with register_local_exception_translator +class LocalSimpleException : public std::exception { +public: + explicit LocalSimpleException(const char *m) : message{m} {} + const char *what() const noexcept override { return message.c_str(); } + +private: + std::string message = ""; +}; + PYBIND11_MAKE_OPAQUE(LocalVec); PYBIND11_MAKE_OPAQUE(LocalVec2); PYBIND11_MAKE_OPAQUE(LocalMap); PYBIND11_MAKE_OPAQUE(NonLocalVec); -//PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2 +// PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2 PYBIND11_MAKE_OPAQUE(NonLocalMap); PYBIND11_MAKE_OPAQUE(NonLocalMap2); - // Simple bindings (used with the above): template <typename T, int Adjust = 0, typename... Args> -py::class_<T> bind_local(Args && ...args) { - return py::class_<T>(std::forward<Args>(args)...) - .def(py::init<int>()) - .def("get", [](T &i) { return i.i + Adjust; }); +py::class_<T> bind_local(Args &&...args) { + return py::class_<T>(std::forward<Args>(args)...).def(py::init<int>()).def("get", [](T &i) { + return i.i + Adjust; + }); }; // Simulate a foreign library base class (to match the example in the docs): namespace pets { class Pet { public: - Pet(std::string name) : name_(name) {} + explicit Pet(std::string name) : name_(std::move(name)) {} std::string name_; - const std::string &name() { return name_; } + const std::string &name() const { return name_; } }; } // namespace pets -struct MixGL { int i; MixGL(int i) : i{i} {} }; -struct MixGL2 { int i; MixGL2(int i) : i{i} {} }; +struct MixGL { + int i; + explicit MixGL(int i) : i{i} {} +}; +struct MixGL2 { + int i; + explicit MixGL2(int i) : i{i} {} +}; |