From a16bdcaba6a6341ee2697ff2b19e6a2e591c1834 Mon Sep 17 00:00:00 2001 From: J-Dunn Date: Mon, 4 Jan 2021 08:58:55 +0000 Subject: [PATCH] add comment about clearing Py::Dict when changing C++ data --- src/Mod/Path/App/CommandPyImp.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/App/CommandPyImp.cpp b/src/Mod/Path/App/CommandPyImp.cpp index b6344ba4c4..88bd30fce5 100644 --- a/src/Mod/Path/App/CommandPyImp.cpp +++ b/src/Mod/Path/App/CommandPyImp.cpp @@ -56,6 +56,11 @@ std::string CommandPy::representation(void) const return str.str(); } +// +// Py::Dict parameters_copy_dict is now a class member to avoid delete/create/copy on every read access from python code +// Now the pre-filled Py::Dict is returned which is more consistent with normal python behaviour. +// It should be cleared whenever the c++ Parameters object is changed eg setParameters() or other objects invalidate its content, eg setPlacement() +// https://forum.freecadweb.org/viewtopic.php?f=15&t=50583 PyObject *CommandPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper { @@ -158,7 +163,7 @@ void CommandPy::setName(Py::String arg) Py::Dict CommandPy::getParameters(void) const { - // dict now a class member , https://forum.freecadweb.org/viewtopic.php?f=15&t=50583& + // dict now a class member , https://forum.freecadweb.org/viewtopic.php?f=15&t=50583 if (parameters_copy_dict.length()==0) { for(std::map::iterator i = getCommandPtr()->Parameters.begin(); i != getCommandPtr()->Parameters.end(); ++i) { parameters_copy_dict.setItem(i->first, Py::Float(i->second));