diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index b425b5663c..b4642fb89b 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -544,15 +544,8 @@ void InterpreterSingleton::addType(PyTypeObject* Type,PyObject* Module, const ch void InterpreterSingleton::addPythonPath(const char* Path) { PyGILStateLocker locker; - PyObject *list = PySys_GetObject("path"); -#if PY_MAJOR_VERSION >= 3 - PyObject *path = PyUnicode_FromString(Path); -#else - PyObject *path = PyString_FromString(Path); -#endif - PyList_Append(list, path); - Py_DECREF(path); - PySys_SetObject("path", list); + Py::List list(PySys_GetObject("path")); + list.append(Py::String(Path)); } const char* InterpreterSingleton::init(int argc,char *argv[]) diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp index a86bce0e22..13095bec3c 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp @@ -469,7 +469,7 @@ PyObject* ExternalGeometryFacadePy::getExtensions(PyObject *args) try { const std::vector> ext = this->getExternalGeometryFacadePtr()->getExtensions(); - PyObject* list = PyList_New(0); + Py::List list; for (std::size_t i=0; icopyPyObject(); - PyList_Append( list, cpy); - Py_DECREF(cpy); + list.append(Py::asObject(p->copyPyObject())); } catch(Base::NotImplementedError) { // silently ignoring extensions not having a Python object @@ -488,7 +486,7 @@ PyObject* ExternalGeometryFacadePy::getExtensions(PyObject *args) } } - return list; + return Py::new_reference_to(list); } catch(const Base::ValueError& e) { PyErr_SetString(Part::PartExceptionOCCError, e.what()); diff --git a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp index 5ddf5885a4..ab00cba9b6 100644 --- a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp @@ -447,7 +447,7 @@ PyObject* GeometryFacadePy::getExtensions(PyObject *args) try { const std::vector> ext = this->getGeometryFacadePtr()->getExtensions(); - PyObject* list = PyList_New(0); + Py::List list; for (std::size_t i=0; icopyPyObject(); - PyList_Append( list, cpy); - Py_DECREF(cpy); + list.append(Py::asObject(p->copyPyObject())); } catch(Base::NotImplementedError) { // silently ignoring extensions not having a Python object @@ -466,7 +464,7 @@ PyObject* GeometryFacadePy::getExtensions(PyObject *args) } } - return list; + return Py::new_reference_to(list); } catch(const Base::ValueError& e) { PyErr_SetString(Part::PartExceptionOCCError, e.what());