From 476b4d5f972a16c22b005df33ed5aed695a0f015 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 14 Apr 2019 13:00:13 +0200 Subject: [PATCH] Py3 fix: correctly convert a Python str to const char* --- src/App/ObjectIdentifier.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index bc5123f8d8c6..18c1ad1ba20a 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -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 }