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.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/pybind11_tests.cpp')
-rw-r--r-- | 3rdparty/pybind11/tests/pybind11_tests.cpp | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/3rdparty/pybind11/tests/pybind11_tests.cpp b/3rdparty/pybind11/tests/pybind11_tests.cpp index 439cd401..aa309559 100644 --- a/3rdparty/pybind11/tests/pybind11_tests.cpp +++ b/3rdparty/pybind11/tests/pybind11_tests.cpp @@ -8,6 +8,7 @@ */ #include "pybind11_tests.h" + #include "constructor_stats.h" #include <functional> @@ -31,9 +32,7 @@ std::list<std::function<void(py::module_ &)>> &initializers() { return inits; } -test_initializer::test_initializer(Initializer init) { - initializers().emplace_back(init); -} +test_initializer::test_initializer(Initializer init) { initializers().emplace_back(init); } test_initializer::test_initializer(const char *submodule_name, Initializer init) { initializers().emplace_back([=](py::module_ &parent) { @@ -51,26 +50,52 @@ void bind_ConstructorStats(py::module_ &m) { .def_readwrite("move_assignments", &ConstructorStats::move_assignments) .def_readwrite("copy_constructions", &ConstructorStats::copy_constructions) .def_readwrite("move_constructions", &ConstructorStats::move_constructions) - .def_static("get", (ConstructorStats &(*)(py::object)) &ConstructorStats::get, py::return_value_policy::reference_internal) + .def_static("get", + (ConstructorStats & (*) (py::object)) & ConstructorStats::get, + py::return_value_policy::reference_internal) - // Not exactly ConstructorStats, but related: expose the internal pybind number of registered instances - // to allow instance cleanup checks (invokes a GC first) + // Not exactly ConstructorStats, but related: expose the internal pybind number of + // registered instances to allow instance cleanup checks (invokes a GC first) .def_static("detail_reg_inst", []() { ConstructorStats::gc(); return py::detail::get_internals().registered_instances.size(); - }) - ; + }); +} + +const char *cpp_std() { + return +#if defined(PYBIND11_CPP20) + "C++20"; +#elif defined(PYBIND11_CPP17) + "C++17"; +#elif defined(PYBIND11_CPP14) + "C++14"; +#else + "C++11"; +#endif } PYBIND11_MODULE(pybind11_tests, m) { m.doc() = "pybind11 test module"; + // Intentionally kept minimal to not create a maintenance chore + // ("just enough" to be conclusive). +#if defined(_MSC_FULL_VER) + m.attr("compiler_info") = "MSVC " PYBIND11_TOSTRING(_MSC_FULL_VER); +#elif defined(__VERSION__) + m.attr("compiler_info") = __VERSION__; +#else + m.attr("compiler_info") = py::none(); +#endif + m.attr("cpp_std") = cpp_std(); + m.attr("PYBIND11_INTERNALS_ID") = PYBIND11_INTERNALS_ID; + bind_ConstructorStats(m); -#if !defined(NDEBUG) - m.attr("debug_enabled") = true; +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) + m.attr("detailed_error_messages_enabled") = true; #else - m.attr("debug_enabled") = false; + m.attr("detailed_error_messages_enabled") = false; #endif py::class_<UserType>(m, "UserType", "A `py::class_` type for testing") @@ -79,13 +104,14 @@ PYBIND11_MODULE(pybind11_tests, m) { .def("get_value", &UserType::value, "Get value using a method") .def("set_value", &UserType::set, "Set value using a method") .def_property("value", &UserType::value, &UserType::set, "Get/set value using a property") - .def("__repr__", [](const UserType& u) { return "UserType({})"_s.format(u.value()); }); + .def("__repr__", [](const UserType &u) { return "UserType({})"_s.format(u.value()); }); py::class_<IncType, UserType>(m, "IncType") .def(py::init<>()) .def(py::init<int>()) - .def("__repr__", [](const IncType& u) { return "IncType({})"_s.format(u.value()); }); + .def("__repr__", [](const IncType &u) { return "IncType({})"_s.format(u.value()); }); - for (const auto &initializer : initializers()) + for (const auto &initializer : initializers()) { initializer(m); + } } |