Salome HOME
Deal with PyUnicode_AsUTF8 returning NULL.
[tools/py2cpp.git] / src / PyPtr.cxx
index c5624bce28d4c486c249e88064dad6ddcea03d6e..658c3d648b00f45080026ab977aab1f90a26a4b4 100644 (file)
@@ -75,7 +75,11 @@ std::string PyPtr::repr()const
   {
     PyObject* pyResult = PyObject_Repr(thisObj);
     if(pyResult && PyUnicode_Check(pyResult))
-      result = PyUnicode_AsUTF8(pyResult);
+    {
+      const char* charstr = PyUnicode_AsUTF8(pyResult);
+      if(charstr != nullptr)
+        result = charstr;
+    }
     Py_XDECREF(pyResult);
   }
   return result;