| 81 | } // namespace test_exc_sp |
| 82 | |
| 83 | TEST_SUBMODULE(constants_and_functions, m) { |
| 84 | // test_constants |
| 85 | m.attr("some_constant") = py::int_(14); |
| 86 | |
| 87 | // test_function_overloading |
| 88 | m.def("test_function", &test_function1); |
| 89 | m.def("test_function", &test_function2); |
| 90 | m.def("test_function", &test_function3); |
| 91 | |
| 92 | #if defined(PYBIND11_OVERLOAD_CAST) |
| 93 | m.def("test_function", py::overload_cast<>(&test_function4)); |
| 94 | m.def("test_function", py::overload_cast<char *>(&test_function4)); |
| 95 | m.def("test_function", py::overload_cast<int, float>(&test_function4)); |
| 96 | m.def("test_function", py::overload_cast<float, int>(&test_function4)); |
| 97 | #else |
| 98 | m.def("test_function", static_cast<py::str (*)()>(&test_function4)); |
| 99 | m.def("test_function", static_cast<py::str (*)(char *)>(&test_function4)); |
| 100 | m.def("test_function", static_cast<py::str (*)(int, float)>(&test_function4)); |
| 101 | m.def("test_function", static_cast<py::str (*)(float, int)>(&test_function4)); |
| 102 | #endif |
| 103 | |
| 104 | py::enum_<MyEnum>(m, "MyEnum") |
| 105 | .value("EFirstEntry", EFirstEntry) |
| 106 | .value("ESecondEntry", ESecondEntry) |
| 107 | .export_values(); |
| 108 | |
| 109 | // test_bytes |
| 110 | m.def("return_bytes", &return_bytes); |
| 111 | m.def("print_bytes", &print_bytes); |
| 112 | |
| 113 | // test_exception_specifiers |
| 114 | using namespace test_exc_sp; |
| 115 | py::class_<C>(m, "C") |
| 116 | .def(py::init<>()) |
| 117 | .def("m1", &C::m1) |
| 118 | .def("m2", &C::m2) |
| 119 | .def("m3", &C::m3) |
| 120 | .def("m4", &C::m4) |
| 121 | .def("m5", &C::m5) |
| 122 | .def("m6", &C::m6) |
| 123 | .def("m7", &C::m7) |
| 124 | .def("m8", &C::m8); |
| 125 | m.def("f1", f1); |
| 126 | m.def("f2", f2); |
| 127 | |
| 128 | PYBIND11_WARNING_PUSH |
| 129 | PYBIND11_WARNING_DISABLE_INTEL(878) // incompatible exception specifications |
| 130 | m.def("f3", f3); |
| 131 | PYBIND11_WARNING_POP |
| 132 | |
| 133 | m.def("f4", f4); |
| 134 | |
| 135 | // test_function_record_leaks |
| 136 | m.def("register_large_capture_with_invalid_arguments", [](py::module_ m) { |
| 137 | // This should always be enough to trigger the alternative branch |
| 138 | // where `sizeof(capture) > sizeof(rec->data)` |
| 139 | uint64_t capture[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 140 | #if defined(__GNUC__) && __GNUC__ == 4 // CentOS7 |