diff options
Diffstat (limited to 'common/handle_error.cc')
-rw-r--r-- | common/handle_error.cc | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/common/handle_error.cc b/common/handle_error.cc index a091f07e..d5542369 100644 --- a/common/handle_error.cc +++ b/common/handle_error.cc @@ -1,10 +1,10 @@ #ifndef NO_PYTHON #include <Python.h> -#include <boost/python.hpp> +#include <pybind11/pybind11.h> #include "nextpnr.h" -namespace py = boost::python; +namespace py = pybind11; NEXTPNR_NAMESPACE_BEGIN @@ -20,42 +20,36 @@ std::string parse_python_exception() std::string ret("Unfetchable Python error"); // If the fetch got a type pointer, parse the type into the exception string if (type_ptr != NULL) { - py::handle<> h_type(type_ptr); - py::str type_pstr(h_type); - // Extract the string from the boost::python object - py::extract<std::string> e_type_pstr(type_pstr); + py::object obj = py::reinterpret_borrow<py::object>(type_ptr); // If a valid string extraction is available, use it // otherwise use fallback - if (e_type_pstr.check()) - ret = e_type_pstr(); + if (py::isinstance<py::str>(obj)) + ret = obj.cast<std::string>(); else ret = "Unknown exception type"; } // Do the same for the exception value (the stringification of the // exception) if (value_ptr != NULL) { - py::handle<> h_val(value_ptr); - py::str a(h_val); - py::extract<std::string> returned(a); - if (returned.check()) - ret += ": " + returned(); + py::object obj = py::reinterpret_borrow<py::object>(value_ptr); + if (py::isinstance<py::str>(obj)) + ret += ": " + obj.cast<std::string>(); else ret += std::string(": Unparseable Python error: "); } // Parse lines from the traceback using the Python traceback module if (traceback_ptr != NULL) { - py::handle<> h_tb(traceback_ptr); + py::handle h_tb(traceback_ptr); // Load the traceback module and the format_tb function - py::object tb(py::import("traceback")); + py::object tb(py::module::import("traceback")); py::object fmt_tb(tb.attr("format_tb")); // Call format_tb to get a list of traceback strings py::object tb_list(fmt_tb(h_tb)); // Join the traceback strings into a single string - py::object tb_str(py::str("\n").join(tb_list)); + py::object tb_str(py::str("\n") + tb_list); // Extract the string, check the extraction, and fallback in necessary - py::extract<std::string> returned(tb_str); - if (returned.check()) - ret += ": " + returned(); + if (py::isinstance<py::str>(tb_str)) + ret += ": " + tb_str.cast<std::string>(); else ret += std::string(": Unparseable Python traceback"); } |