Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Py3 fix: correctly convert a Python str to const char*
  • Loading branch information
wwmayer committed Apr 21, 2019
1 parent 3450cf9 commit 476b4d5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/App/ObjectIdentifier.cpp
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 476b4d5

Please sign in to comment.