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_constants_and_functions.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_constants_and_functions.cpp')
-rw-r--r-- | 3rdparty/pybind11/tests/test_constants_and_functions.cpp | 116 |
1 files changed, 74 insertions, 42 deletions
diff --git a/3rdparty/pybind11/tests/test_constants_and_functions.cpp b/3rdparty/pybind11/tests/test_constants_and_functions.cpp index f6077955..1918a429 100644 --- a/3rdparty/pybind11/tests/test_constants_and_functions.cpp +++ b/3rdparty/pybind11/tests/test_constants_and_functions.cpp @@ -1,5 +1,6 @@ /* - tests/test_constants_and_functions.cpp -- global constants and functions, enumerations, raw byte strings + tests/test_constants_and_functions.cpp -- global constants and functions, enumerations, raw + byte strings Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> @@ -11,20 +12,14 @@ enum MyEnum { EFirstEntry = 1, ESecondEntry }; -std::string test_function1() { - return "test_function()"; -} +std::string test_function1() { return "test_function()"; } -std::string test_function2(MyEnum k) { - return "test_function(enum=" + std::to_string(k) + ")"; -} +std::string test_function2(MyEnum k) { return "test_function(enum=" + std::to_string(k) + ")"; } -std::string test_function3(int i) { - return "test_function(" + std::to_string(i) + ")"; -} +std::string test_function3(int i) { return "test_function(" + std::to_string(i) + ")"; } -py::str test_function4() { return "test_function()"; } -py::str test_function4(char *) { return "test_function(char *)"; } +py::str test_function4() { return "test_function()"; } +py::str test_function4(char *) { return "test_function(char *)"; } py::str test_function4(int, float) { return "test_function(int, float)"; } py::str test_function4(float, int) { return "test_function(float, int)"; } @@ -33,50 +28,60 @@ py::bytes return_bytes() { return std::string(data, 4); } -std::string print_bytes(py::bytes bytes) { +std::string print_bytes(const py::bytes &bytes) { std::string ret = "bytes["; const auto value = static_cast<std::string>(bytes); - for (size_t i = 0; i < value.length(); ++i) { - ret += std::to_string(static_cast<int>(value[i])) + " "; + for (char c : value) { + ret += std::to_string(static_cast<int>(c)) + ' '; } ret.back() = ']'; return ret; } -// Test that we properly handle C++17 exception specifiers (which are part of the function signature -// in C++17). These should all still work before C++17, but don't affect the function signature. +// Test that we properly handle C++17 exception specifiers (which are part of the function +// signature in C++17). These should all still work before C++17, but don't affect the function +// signature. namespace test_exc_sp { -int f1(int x) noexcept { return x+1; } -int f2(int x) noexcept(true) { return x+2; } -int f3(int x) noexcept(false) { return x+3; } -#if defined(__GNUG__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated" +// [workaround(intel)] Unable to use noexcept instead of noexcept(true) +// Make the f1 test basically the same as the f2 test in C++17 mode for the Intel compiler as +// it fails to compile with a plain noexcept (tested with icc (ICC) 2021.1 Beta 20200827). +#if defined(__INTEL_COMPILER) && defined(PYBIND11_CPP17) +int f1(int x) noexcept(true) { return x + 1; } +#else +int f1(int x) noexcept { return x + 1; } +#endif +int f2(int x) noexcept(true) { return x + 2; } +int f3(int x) noexcept(false) { return x + 3; } +#if defined(__GNUG__) && !defined(__INTEL_COMPILER) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated" #endif -int f4(int x) throw() { return x+4; } // Deprecated equivalent to noexcept(true) -#if defined(__GNUG__) -# pragma GCC diagnostic pop +// NOLINTNEXTLINE(modernize-use-noexcept) +int f4(int x) throw() { return x + 4; } // Deprecated equivalent to noexcept(true) +#if defined(__GNUG__) && !defined(__INTEL_COMPILER) +# pragma GCC diagnostic pop #endif struct C { - int m1(int x) noexcept { return x-1; } - int m2(int x) const noexcept { return x-2; } - int m3(int x) noexcept(true) { return x-3; } - int m4(int x) const noexcept(true) { return x-4; } - int m5(int x) noexcept(false) { return x-5; } - int m6(int x) const noexcept(false) { return x-6; } -#if defined(__GNUG__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated" + int m1(int x) noexcept { return x - 1; } + int m2(int x) const noexcept { return x - 2; } + int m3(int x) noexcept(true) { return x - 3; } + int m4(int x) const noexcept(true) { return x - 4; } + int m5(int x) noexcept(false) { return x - 5; } + int m6(int x) const noexcept(false) { return x - 6; } +#if defined(__GNUG__) && !defined(__INTEL_COMPILER) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated" #endif - int m7(int x) throw() { return x-7; } - int m8(int x) const throw() { return x-8; } -#if defined(__GNUG__) -# pragma GCC diagnostic pop + // NOLINTNEXTLINE(modernize-use-noexcept) + int m7(int x) throw() { return x - 7; } + // NOLINTNEXTLINE(modernize-use-noexcept) + int m8(int x) const throw() { return x - 8; } +#if defined(__GNUG__) && !defined(__INTEL_COMPILER) +# pragma GCC diagnostic pop #endif }; } // namespace test_exc_sp - TEST_SUBMODULE(constants_and_functions, m) { // test_constants m.attr("some_constant") = py::int_(14); @@ -118,10 +123,37 @@ TEST_SUBMODULE(constants_and_functions, m) { .def("m5", &C::m5) .def("m6", &C::m6) .def("m7", &C::m7) - .def("m8", &C::m8) - ; + .def("m8", &C::m8); m.def("f1", f1); m.def("f2", f2); +#if defined(__INTEL_COMPILER) +# pragma warning push +# pragma warning disable 878 // incompatible exception specifications +#endif m.def("f3", f3); +#if defined(__INTEL_COMPILER) +# pragma warning pop +#endif m.def("f4", f4); + + // test_function_record_leaks + m.def("register_large_capture_with_invalid_arguments", [](py::module_ m) { + // This should always be enough to trigger the alternative branch + // where `sizeof(capture) > sizeof(rec->data)` + uint64_t capture[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; +#if defined(__GNUC__) && __GNUC__ == 4 // CentOS7 + py::detail::silence_unused_warnings(capture); +#endif + m.def( + "should_raise", [capture](int) { return capture[9] + 33; }, py::kw_only(), py::arg()); + }); + m.def("register_with_raising_repr", [](py::module_ m, const py::object &default_value) { + m.def( + "should_raise", + [](int, int, const py::object &) { return 42; }, + "some docstring", + py::arg_v("x", 42), + py::arg_v("y", 42, "<the answer>"), + py::arg_v("z", default_value)); + }); } |