From: Ovidiu Mircescu Date: Tue, 26 Feb 2019 09:23:11 +0000 (+0100) Subject: Deal with PyUnicode_AsUTF8 returning NULL. X-Git-Tag: v1.0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=65c17b8dea0c45bbcf3daf4463d2855d4d50ac5e;p=tools%2Fpy2cpp.git Deal with PyUnicode_AsUTF8 returning NULL. According to https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8 PyUnicode_AsUTF8String may return NULL in case of error. --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fbd6d76..08bfb17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,8 +50,8 @@ TARGET_INCLUDE_DIRECTORIES(py2cpp PUBLIC $ $) -INSTALL(TARGETS py2cpp EXPORT FindPy2cpp LIBRARY DESTINATION lib) +INSTALL(TARGETS py2cpp EXPORT Py2cppCfg LIBRARY DESTINATION lib) INSTALL(FILES ${_py2cpp_headers} DESTINATION include/py2cpp) -INSTALL(EXPORT FindPy2cpp DESTINATION lib/cmake/py2cpp) +INSTALL(EXPORT Py2cppCfg DESTINATION lib/cmake/py2cpp FILE Py2cppConfig.cmake) ADD_SUBDIRECTORY(Test) diff --git a/src/Errors.cxx b/src/Errors.cxx index eb80814..f0984fc 100644 --- a/src/Errors.cxx +++ b/src/Errors.cxx @@ -31,7 +31,9 @@ std::string getLastPyError() PyErr_Fetch(&ptype, &pvalue, &ptraceback); PyErr_NormalizeException(&ptype, &pvalue, &ptraceback); pystr = PyObject_Str(pvalue); - result = std::string(PyUnicode_AsUTF8(pystr)); + const char* charstr = PyUnicode_AsUTF8(pystr); + if(charstr != nullptr) + result = std::string(charstr); result += "\n"; Py_DECREF(pystr); @@ -54,7 +56,9 @@ std::string getLastPyError() for(int i=0; i