Sketch: Fix SketchObjectPy::addExternal
Use PyArg_ParseTuple's support of optional arguments than doing it with several calls of PyArg_ParseTuple with different arguments. This is error-prone, leads to convoluted code logic and may even fail because once the error indicator is set PyArg_ParseTuple may unexpectedly fail.
This commit is contained in:
@@ -555,39 +555,24 @@ PyObject* SketchObjectPy::carbonCopy(PyObject* args)
|
||||
|
||||
PyObject* SketchObjectPy::addExternal(PyObject* args)
|
||||
{
|
||||
char* ObjectName;
|
||||
char* SubName;
|
||||
PyObject* defining; // this is an optional argument default false
|
||||
PyObject* intersection; // this is an optional argument default false
|
||||
bool isDefining;
|
||||
bool isIntersection;
|
||||
char* ObjectName = nullptr;
|
||||
char* SubName = nullptr;
|
||||
PyObject* defining = Py_False;
|
||||
PyObject* intersection = Py_False;
|
||||
if (!PyArg_ParseTuple(args,
|
||||
"ssO!O!",
|
||||
"ss|O!O!",
|
||||
&ObjectName,
|
||||
&SubName,
|
||||
&PyBool_Type,
|
||||
&defining,
|
||||
&PyBool_Type,
|
||||
&intersection)) {
|
||||
if (!PyArg_ParseTuple(args, "ssO!", &ObjectName, &SubName, &PyBool_Type, &defining)) {
|
||||
PyErr_Clear();
|
||||
if (!PyArg_ParseTuple(args, "ss", &ObjectName, &SubName)) {
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
isDefining = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
isDefining = Base::asBoolean(defining);
|
||||
}
|
||||
isIntersection = false;
|
||||
}
|
||||
else {
|
||||
isDefining = Base::asBoolean(defining);
|
||||
isIntersection = Base::asBoolean(intersection);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool isDefining = Base::asBoolean(defining);
|
||||
bool isIntersection = Base::asBoolean(intersection);
|
||||
|
||||
// get the target object for the external link
|
||||
Sketcher::SketchObject* skObj = this->getSketchObjectPtr();
|
||||
App::DocumentObject* Obj = skObj->getDocument()->getObject(ObjectName);
|
||||
|
||||
Reference in New Issue
Block a user