Skip to content

Commit

Permalink
added E57_ENABLE_DIAGNOSTIC_OUTPUT (precompiler macro of libe57format…
Browse files Browse the repository at this point in the history
…) to build script parameters to display better C++ exception infos for python
  • Loading branch information
TonnC authored and dancergraham committed Dec 2, 2024
1 parent 1711cc6 commit df9027d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ def build_extensions(self):
opts.append("-DCRCPP_USE_CPP11")
opts.append("-DCRCPP_BRANCHLESS")
opts.append("-Wno-unused-variable")
opts.append("-DE57_ENABLE_DIAGNOSTIC_OUTPUT")
elif ct == "msvc":
opts.append(f'/DVERSION_INFO="{version}"')
opts.append(rf'/DREVISION_ID="\"{revision_id}\""')
opts.append("/DCRCPP_USE_CPP11")
opts.append("/DCRCPP_BRANCHLESS")
opts.append("/DWINDOWS")
opts.append("/DE57_ENABLE_DIAGNOSTIC_OUTPUT")
for ext in self.extensions:
ext.extra_compile_args = opts

Expand Down
15 changes: 10 additions & 5 deletions src/pye57/libe57_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <E57Format.h>
#include <E57Version.h>
#include <ASTMVersion.h>
#include <sstream>
#include <string.h>

namespace py = pybind11;
using namespace pybind11::literals;
Expand Down Expand Up @@ -40,11 +42,14 @@ PYBIND11_MODULE(libe57, m) {

static py::exception<E57Exception> exc(m, "E57Exception");
py::register_exception_translator([](std::exception_ptr p) {
try {
if (p) std::rethrow_exception(p);
} catch (const E57Exception &e) {
exc(Utilities::errorCodeToString(e.errorCode()).c_str());
}
try {
if (p) std::rethrow_exception(p);
} catch (const E57Exception &e) {
std::stringstream ss;
e.report(__FILE__, __LINE__, __FUNCTION__, ss);
std::string output = e.errorStr() + std::string("\n\n") + ss.str();
exc(output.c_str());
}
});

m.attr("E57_FORMAT_MAJOR") = E57_FORMAT_MAJOR;
Expand Down

0 comments on commit df9027d

Please sign in to comment.