* tests: add linking warnings/error Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: check pedantic C++14 * fix: some pedantic warnings Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * feat: add py::mod_gil_used() Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix: use not_supported() Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * style: pre-commit fixes * Update CMakeLists.txt * fix: remove the true/false parameter from mod_gil_not_used Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * style: pre-commit fixes * Update tests/CMakeLists.txt * fix: deprecate mod_gil_not_used(bool) instead of removing it Keep the bool constructor public and mark it deprecated, so existing code that spells mod_gil_not_used(false) still compiles. mod_gil_used() now sets the flag through its friendship, which keeps the deprecated constructor the only bool overload and stops pybind11 warning against itself. Also use the py:: alias in exo_planet_pybind11.cpp to match its sibling home_planet_very_lonely_traveler.cpp. Assisted-by: ClaudeCode:claude-opus-5 * fix: add trailing comma to macros picked up in rebase test_smart_ptr.cpp and standalone_enum_module.cpp came from master after this branch was written, so they still invoked variadic macros with no variadic argument. That is a pedantic error below C++20. Assisted-by: ClaudeCode:claude-opus-5 --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
26 lines
749 B
C++
26 lines
749 B
C++
#include <pybind11/embed.h>
|
|
#include <pybind11/pybind11.h>
|
|
|
|
namespace py = pybind11;
|
|
|
|
PYBIND11_EMBEDDED_MODULE(test_cmake_build, m, py::multiple_interpreters::not_supported()) {
|
|
m.def("add", [](int i, int j) { return i + j; });
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc != 2) {
|
|
throw std::runtime_error("Expected test.py file as the first argument");
|
|
}
|
|
auto *test_py_file = argv[1];
|
|
|
|
py::scoped_interpreter guard{};
|
|
|
|
auto m = py::module_::import("test_cmake_build");
|
|
if (m.attr("add")(1, 2).cast<int>() != 3) {
|
|
throw std::runtime_error("embed.cpp failed");
|
|
}
|
|
|
|
py::module_::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp");
|
|
py::eval_file(test_py_file, py::globals());
|
|
}
|