Part: [skip ci] fix memory leaks
+ add convenience function GeometryExtension::copyPyObject() + make sure to destroy the clone when leaving getGeometry()
This commit is contained in:
@@ -284,9 +284,7 @@ PyObject* GeometryFacadePy::getExtensionOfType(PyObject *args)
|
||||
std::shared_ptr<const Part::GeometryExtension> ext(this->getGeometryFacadePtr()->getExtension(type));
|
||||
|
||||
// we create a copy and transfer this copy's memory management responsibility to Python
|
||||
Py::Tuple tuple;
|
||||
PyObject* cpy = static_cast<Part::GeometryExtensionPy *>(std::const_pointer_cast<Part::GeometryExtension>(ext)->getPyObject())->copy(tuple.ptr());
|
||||
|
||||
PyObject* cpy = ext->copyPyObject();
|
||||
return cpy;
|
||||
}
|
||||
catch(const Base::ValueError& e) {
|
||||
@@ -323,9 +321,7 @@ PyObject* GeometryFacadePy::getExtensionOfName(PyObject *args)
|
||||
std::shared_ptr<const Part::GeometryExtension> ext(this->getGeometryFacadePtr()->getExtension(std::string(o)));
|
||||
|
||||
// we create a copy and transfer this copy's memory management responsibility to Python
|
||||
Py::Tuple tuple;
|
||||
PyObject* cpy = static_cast<Part::GeometryExtensionPy *>(std::const_pointer_cast<Part::GeometryExtension>(ext)->getPyObject())->copy(tuple.ptr());
|
||||
|
||||
PyObject* cpy = ext->copyPyObject();
|
||||
return cpy;
|
||||
}
|
||||
catch(const Base::ValueError& e) {
|
||||
@@ -459,11 +455,8 @@ PyObject* GeometryFacadePy::getExtensions(PyObject *args)
|
||||
|
||||
if(p) {
|
||||
// we create a python copy and add it to the list
|
||||
Py::Tuple tuple;
|
||||
|
||||
try {
|
||||
PyObject* cpy = static_cast<Part::GeometryExtensionPy *>(std::const_pointer_cast<Part::GeometryExtension>(p)->getPyObject())->copy(tuple.ptr());
|
||||
|
||||
PyObject* cpy = p->copyPyObject();
|
||||
PyList_Append( list, cpy);
|
||||
Py_DECREF(cpy);
|
||||
}
|
||||
@@ -501,7 +494,8 @@ Py::String GeometryFacadePy::getTag(void) const
|
||||
Py::Object GeometryFacadePy::getGeometry(void) const
|
||||
{
|
||||
// We return a clone
|
||||
return Py::Object(getGeometryFacadePtr()->getGeometry()->clone()->getPyObject(),true);
|
||||
std::unique_ptr<Part::Geometry> geo(getGeometryFacadePtr()->getGeometry()->clone());
|
||||
return Py::Object(geo->getPyObject(), true);
|
||||
}
|
||||
|
||||
void GeometryFacadePy::setGeometry(Py::Object arg)
|
||||
|
||||
Reference in New Issue
Block a user