From 52aef7348faf2e9b7e109a7a8e97b90cd8314d83 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 7 Sep 2016 12:18:57 +0200 Subject: [PATCH] support of unicode for doc string, fix memory leak --- src/App/FeaturePythonPyImp.inl | 5 ++++- src/Gui/ViewProviderPythonFeaturePyImp.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/App/FeaturePythonPyImp.inl b/src/App/FeaturePythonPyImp.inl index 4fe56f046..e280a13ba 100644 --- a/src/App/FeaturePythonPyImp.inl +++ b/src/App/FeaturePythonPyImp.inl @@ -335,8 +335,11 @@ PyObject* FeaturePythonPyT::addProperty(PyObject *args) &PyBool_Type, &ro, &PyBool_Type, &hd)) // convert args: Python->C return NULL; // NULL triggers exception + std::string sDocStr = std::string(sDoc); + PyMem_Free(sDoc); + Property* prop=0; - prop = FeaturePyT::getDocumentObjectPtr()->addDynamicProperty(sType,sName,sGroup,sDoc,attr, + prop = FeaturePyT::getDocumentObjectPtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr, PyObject_IsTrue(ro) ? true : false, PyObject_IsTrue(hd) ? true : false); if (!prop) { diff --git a/src/Gui/ViewProviderPythonFeaturePyImp.cpp b/src/Gui/ViewProviderPythonFeaturePyImp.cpp index 05acd7e1b..d8697ae29 100644 --- a/src/Gui/ViewProviderPythonFeaturePyImp.cpp +++ b/src/Gui/ViewProviderPythonFeaturePyImp.cpp @@ -68,12 +68,15 @@ PyObject* ViewProviderPythonFeaturePy::addProperty(PyObject *args) char *sType,*sName=0,*sGroup=0,*sDoc=0; short attr=0; PyObject *ro = Py_False, *hd = Py_False; - if (!PyArg_ParseTuple(args, "s|ssshO!O!", &sType,&sName,&sGroup,&sDoc,&attr, + if (!PyArg_ParseTuple(args, "s|ssethO!O!", &sType,&sName,&sGroup,"utf-8",&sDoc,&attr, &PyBool_Type, &ro, &PyBool_Type, &hd)) // convert args: Python->C return NULL; // NULL triggers exception + std::string sDocStr = std::string(sDoc); + PyMem_Free(sDoc); + App::Property* prop=0; - prop = getViewProviderPythonFeaturePtr()->addDynamicProperty(sType,sName,sGroup,sDoc,attr, + prop = getViewProviderPythonFeaturePtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr, PyObject_IsTrue(ro) ? true : false, PyObject_IsTrue(hd) ? true : false); if (!prop) {