X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2FTypeConversions.cxx;h=2d52ea4c26aafd651e6f12e8753f4b82f35a4f5e;hb=b0898fabd07c0b33ed8fd229e779264a67d9110a;hp=895508f8f4c3f625151ed076f00e7c245ad9237a;hpb=0716fd562e4f709b42f40ce827a9ca02ac70634f;p=modules%2Fyacs.git diff --git a/src/runtime/TypeConversions.cxx b/src/runtime/TypeConversions.cxx index 895508f8f..2d52ea4c2 100644 --- a/src/runtime/TypeConversions.cxx +++ b/src/runtime/TypeConversions.cxx @@ -2301,8 +2301,14 @@ namespace YACS { PyObject *s; PyGILState_STATE gstate = PyGILState_Ensure(); - //s=PyObject_Repr(ob); - s=PyObject_ASCII(ob); + // TODO: separate treatment for string (maybe with bad encoding?) and other types of PyObject ? + // Do we need str() or repr() and what are the possible causes of failure of str() ? + // not clear, needs more analysis. + s=PyObject_Str(ob); + if (s == NULL) // for instance string with bad encoding, non utf-8 + { + s=PyObject_ASCII(ob); // escape non ASCII characters and like repr(), which is not the same as str()... + } Py_ssize_t size; char* characters=PyUnicode_AsUTF8AndSize(s, &size); std::string ss( characters, size);