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/pybind11_tests.h | |
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/pybind11_tests.h')
-rw-r--r-- | 3rdparty/pybind11/tests/pybind11_tests.h | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/3rdparty/pybind11/tests/pybind11_tests.h b/3rdparty/pybind11/tests/pybind11_tests.h index 4ff56c07..a7c00c2f 100644 --- a/3rdparty/pybind11/tests/pybind11_tests.h +++ b/3rdparty/pybind11/tests/pybind11_tests.h @@ -1,10 +1,7 @@ #pragma once -#include <pybind11/pybind11.h> -#if defined(_MSC_VER) && _MSC_VER < 1910 -// We get some really long type names here which causes MSVC 2015 to emit warnings -# pragma warning(disable: 4503) // warning C4503: decorated name length exceeded, name was truncated -#endif +#include <pybind11/eval.h> +#include <pybind11/pybind11.h> namespace py = pybind11; using namespace pybind11::literals; @@ -13,24 +10,23 @@ class test_initializer { using Initializer = void (*)(py::module_ &); public: - test_initializer(Initializer init); + explicit test_initializer(Initializer init); test_initializer(const char *submodule_name, Initializer init); }; -#define TEST_SUBMODULE(name, variable) \ - void test_submodule_##name(py::module_ &); \ - test_initializer name(#name, test_submodule_##name); \ - void test_submodule_##name(py::module_ &variable) - +#define TEST_SUBMODULE(name, variable) \ + void test_submodule_##name(py::module_ &); \ + test_initializer name(#name, test_submodule_##name); \ + void test_submodule_##name(py::module_ &(variable)) /// Dummy type which is not exported anywhere -- something to trigger a conversion error -struct UnregisteredType { }; +struct UnregisteredType {}; /// A user-defined type which is exported and can be used by any test class UserType { public: UserType() = default; - UserType(int i) : i(i) { } + explicit UserType(int i) : i(i) {} int value() const { return i; } void set(int set) { i = set; } @@ -44,7 +40,7 @@ class IncType : public UserType { public: using UserType::UserType; IncType() = default; - IncType(const IncType &other) : IncType(other.value() + 1) { } + IncType(const IncType &other) : IncType(other.value() + 1) {} IncType(IncType &&) = delete; IncType &operator=(const IncType &) = delete; IncType &operator=(IncType &&) = delete; @@ -56,16 +52,34 @@ union IntFloat { float f; }; -/// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast context. -/// Used to test recursive casters (e.g. std::tuple, stl containers). +/// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast +/// context. Used to test recursive casters (e.g. std::tuple, stl containers). struct RValueCaster {}; PYBIND11_NAMESPACE_BEGIN(pybind11) PYBIND11_NAMESPACE_BEGIN(detail) -template<> class type_caster<RValueCaster> { +template <> +class type_caster<RValueCaster> { public: - PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster")); - static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); } - static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); } + PYBIND11_TYPE_CASTER(RValueCaster, const_name("RValueCaster")); + static handle cast(RValueCaster &&, return_value_policy, handle) { + return py::str("rvalue").release(); + } + static handle cast(const RValueCaster &, return_value_policy, handle) { + return py::str("lvalue").release(); + } }; PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(pybind11) + +template <typename F> +void ignoreOldStyleInitWarnings(F &&body) { + py::exec(R"( + message = "pybind11-bound class '.+' is using an old-style placement-new '(?:__init__|__setstate__)' which has been deprecated" + + import warnings + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", message=message, category=FutureWarning) + body() + )", + py::dict(py::arg("body") = py::cpp_function(body))); +} |