Fix invalid Python object error

Example below led to a crash:
import Path
t = Path.Tool(name='t', diameter=1.2)
tt = Path.Tooltable()
tt.setTool(3, t)
attrs = tt.templateAttrs()
del attrs
This commit is contained in:
wmayer
2018-02-11 16:04:17 +01:00
parent 58887d8b84
commit 738b904592

View File

@@ -515,9 +515,13 @@ PyObject* TooltablePy::templateAttrs(PyObject * args)
(void)args;
PyObject *dict = PyDict_New();
for(std::map<int,Path::Tool*>::iterator i = getTooltablePtr()->Tools.begin(); i != getTooltablePtr()->Tools.end(); ++i) {
Path::ToolPy tool(new Path::Tool(*i->second));
PyObject *attrs = tool.templateAttrs(0);
// The 'tool' object must be created on the heap otherwise Python
// will fail to properly track the reference counts and aborts
// in debug mode.
Path::ToolPy* tool = new Path::ToolPy(new Path::Tool(*i->second));
PyObject *attrs = tool->templateAttrs(0);
PyDict_SetItem(dict, PYINT_FROMLONG(i->first), attrs);
Py_DECREF(tool);
}
return dict;
}