From 3186d4753e56cc2a019e78d4321d7bdb993d41a0 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 16 Dec 2019 07:21:14 -0500 Subject: [PATCH] [TD]fix Py2 errors --- src/Mod/TechDraw/App/CenterLinePyImp.cpp | 52 ++++++++++++++++-------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp index 379ad69b04..2b0d866e6b 100644 --- a/src/Mod/TechDraw/App/CenterLinePyImp.cpp +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -333,11 +333,7 @@ void CenterLinePy::setExtension(Py::Float arg) Py::Boolean CenterLinePy::getFlip(void) const { bool flip = getCenterLinePtr()->getFlip(); - if (flip) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } + return Py::Boolean(flip); } void CenterLinePy::setFlip(Py::Boolean arg) @@ -384,10 +380,18 @@ void CenterLinePy::setEdges(Py::Object arg) int tSize = (int) PyList_Size(pList); int i = 0; for ( ; i < tSize; i++) { - PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i); - const char* utf8 = PyUnicode_AsUTF8(item); - std::string ssTemp(utf8); - temp.push_back(ssTemp); + PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i); +#if PY_MAJOR_VERSION >= 3 + if (PyUnicode_Check(item)) { + std::string s = PyUnicode_AsUTF8(item); //py3 only!!! + temp.push_back(s); + } +#else + if (PyString_Check(item)) { + std::string s = PyString_AsString(item); //py2 only!!! + temp.push_back(s); + } +#endif } cl->m_edges = temp; } else { @@ -422,10 +426,18 @@ void CenterLinePy::setFaces(Py::Object arg) int tSize = (int) PyList_Size(pList); int i = 0; for ( ; i < tSize; i++) { - PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i); - const char* utf8 = PyUnicode_AsUTF8(item); - std::string ssTemp(utf8); - temp.push_back(ssTemp); + PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i); +#if PY_MAJOR_VERSION >= 3 + if (PyUnicode_Check(item)) { + std::string s = PyUnicode_AsUTF8(item); //py3 only!!! + temp.push_back(s); + } +#else + if (PyString_Check(item)) { + std::string s = PyString_AsString(item); //py2 only!!! + temp.push_back(s); + } +#endif } cl->m_faces = temp; } else { @@ -462,9 +474,17 @@ void CenterLinePy::setPoints(Py::Object arg) int i = 0; for ( ; i < tSize; i++) { PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i); - const char* utf8 = PyUnicode_AsUTF8(item); - std::string ssTemp(utf8); - temp.push_back(ssTemp); +#if PY_MAJOR_VERSION >= 3 + if (PyUnicode_Check(item)) { + std::string s = PyUnicode_AsUTF8(item); //py3 only!!! + temp.push_back(s); + } +#else + if (PyString_Check(item)) { + std::string s = PyString_AsString(item); //py2 only!!! + temp.push_back(s); + } +#endif } cl->m_verts = temp; } else {