Py3 fix: correctly convert a Python str to const char*

This commit is contained in:
wmayer
2019-04-14 13:00:13 +02:00
parent 5d211d8704
commit 88f637d8fd

View File

@@ -1062,6 +1062,7 @@ boost::any ObjectIdentifier::getValue() const
destructor d1(pyvalue);
Base::PyGILStateLocker locker;
if (!pyvalue)
throw Base::RuntimeError("Failed to get property value.");
#if PY_MAJOR_VERSION < 3
@@ -1078,12 +1079,12 @@ boost::any ObjectIdentifier::getValue() const
return boost::any(PyString_AsString(pyvalue));
#endif
else if (PyUnicode_Check(pyvalue)) {
#if PY_MAJOR_VERSION >= 3
return boost::any(PyUnicode_AsUTF8(pyvalue));
#else
PyObject * s = PyUnicode_AsUTF8String(pyvalue);
destructor d2(s);
#if PY_MAJOR_VERSION >= 3
return boost::any(PyUnicode_AsUTF8(s));
#else
return boost::any(PyString_AsString(s));
#endif
}