Skip to content
Snippets Groups Projects
Commit 2ac06c6b authored by David Gobbi's avatar David Gobbi
Browse files

Resolve Python ambiguity for sequence objects

VTK has some overloaded methods like the following:
   void SetColor(const vtkColor4d& color);
   void SetColor(const double color[4]);
Since vtkColor4d and similar objects can be indexed as sequences,
they can satisfy both overloads.  This fix penalizes the second
overload, so that the first overload (the one that specifies the
object type) is preferred.  Without this fix, the wrappers report
an overload resolution ambiguity and raise a TypeError.
parent b4ca40a7
No related branches found
No related tags found
No related merge requests found
......@@ -757,17 +757,23 @@ int vtkPythonOverload::CheckArg(PyObject* arg, const char* format, const char* n
PyObject* sarg = arg;
while (PySequence_Check(sarg))
{
Py_ssize_t m = PySequence_Size(sarg);
PyObject* seq = sarg;
Py_ssize_t m = PySequence_Size(seq);
if (m <= 0 || (sizeneeded != 0 && m != sizeneeded))
{
break;
}
PyObject* sargsave = sarg;
sarg = PySequence_GetItem(sarg, 0);
sarg = PySequence_GetItem(seq, 0);
if (*cptr != '[')
{
penalty = vtkPythonOverload::CheckArg(sarg, &classname[1], "");
// increase penalty for sequences, to disambiguate the use
// of an object as a sequence vs. direct use of the object
if (penalty < VTK_PYTHON_NEEDS_CONVERSION)
{
penalty++;
}
Py_DECREF(sarg);
break;
}
......@@ -778,9 +784,9 @@ int vtkPythonOverload::CheckArg(PyObject* arg, const char* format, const char* n
{
cptr++;
}
if (sargsave != arg)
if (seq != arg)
{
Py_DECREF(sargsave);
Py_DECREF(seq);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment