From 46882fc6e599e4434bddfb166ae667e2c78a13bb Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 25 Nov 2020 16:56:03 +0100 Subject: [PATCH] Part/Sketcher: [skip ci] fix build failures with gcc 10 on Fedora When using gcc 10 and PyCXX 7.1.4 on Fedora there is an error because the conversion from size_t to Py_ssize_t is ambiguous See https://forum.freecadweb.org/viewtopic.php?f=4&t=52502 The class Py::Tuple is also incorrectly used here and causes a memory leak --- src/Mod/Part/App/GeometryPyImp.cpp | 11 ++++++----- src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp | 11 ++++++----- src/Mod/Sketcher/App/GeometryFacadePyImp.cpp | 11 ++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index c621036f8e..fe5755d2ed 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -248,7 +248,8 @@ PyObject* GeometryPy::getExtensionOfType(PyObject *args) std::shared_ptr ext(this->getGeometryPtr()->getExtension(type)); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(tuple.ptr()); return cpy; } @@ -282,7 +283,8 @@ PyObject* GeometryPy::getExtensionOfName(PyObject *args) std::shared_ptr ext(this->getGeometryPtr()->getExtension(std::string(o))); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(tuple.ptr()); return cpy; } @@ -408,8 +410,6 @@ PyObject* GeometryPy::getExtensions(PyObject *args) PyObject* list = PyList_New(ext.size()); - Py::Tuple tuple(ext.size()); - for (std::size_t i=0; i(p->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(p->getPyObject())->copy(tuple.ptr()); PyList_SetItem( list, i, cpy); } diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp index a8e122194f..306419244f 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp @@ -270,7 +270,8 @@ PyObject* ExternalGeometryFacadePy::getExtensionOfType(PyObject *args) std::shared_ptr ext(this->getExternalGeometryFacadePtr()->getExtension(type)); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(tuple.ptr()); return cpy; } @@ -304,7 +305,8 @@ PyObject* ExternalGeometryFacadePy::getExtensionOfName(PyObject *args) std::shared_ptr ext(this->getExternalGeometryFacadePtr()->getExtension(std::string(o))); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(tuple.ptr()); return cpy; } @@ -430,15 +432,14 @@ PyObject* ExternalGeometryFacadePy::getExtensions(PyObject *args) PyObject* list = PyList_New(ext.size()); - Py::Tuple tuple(ext.size()); - for (std::size_t i=0; i p = ext[i].lock(); if(p) { // we create a python copy and add it to the list - PyObject* cpy = static_cast(std::const_pointer_cast(p)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(p)->getPyObject())->copy(tuple.ptr()); PyList_SetItem( list, i, cpy); } diff --git a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp index d6c3e06ab5..b89460a005 100644 --- a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp @@ -209,7 +209,8 @@ PyObject* GeometryFacadePy::getExtensionOfType(PyObject *args) std::shared_ptr ext(this->getGeometryFacadePtr()->getExtension(type)); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(tuple.ptr()); return cpy; } @@ -243,7 +244,8 @@ PyObject* GeometryFacadePy::getExtensionOfName(PyObject *args) std::shared_ptr ext(this->getGeometryFacadePtr()->getExtension(std::string(o))); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(tuple.ptr()); return cpy; } @@ -369,15 +371,14 @@ PyObject* GeometryFacadePy::getExtensions(PyObject *args) PyObject* list = PyList_New(ext.size()); - Py::Tuple tuple(ext.size()); - for (std::size_t i=0; i p = ext[i].lock(); if(p) { // we create a python copy and add it to the list - PyObject* cpy = static_cast(std::const_pointer_cast(p)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + Py::Tuple tuple; + PyObject* cpy = static_cast(std::const_pointer_cast(p)->getPyObject())->copy(tuple.ptr()); PyList_SetItem( list, i, cpy); }