Commit ba173262 authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: Add proper support for bool arguments in python wrappers.

If a method takes a bool argument, then any value that can
be evaluated as true or false can be passed.  Previously,
only numeric values would be allowed.
parent f5ed6d8c
......@@ -1350,6 +1350,10 @@ int PyVTKCheckArg(
case 'l':
penalty = VTK_PYTHON_GOOD_MATCH;
case 'i':
if (PyBool_Check(arg))
{
penalty = VTK_PYTHON_GOOD_MATCH;
}
if (!PyInt_Check(arg))
{
if (level == 0)
......@@ -1465,8 +1469,25 @@ int PyVTKCheckArg(
name[i] = '\0';
classname = name;
// booleans
if (name[0] == 'b' && strcmp(classname, "bool") == 0)
{
#if PY_VERSION_HEX >= 0x02030000
if (!PyBool_Check(arg))
#endif
{
penalty = VTK_PYTHON_NEEDS_CONVERSION;
int tmpi = PyObject_IsTrue(arg);
if (tmpi == -1 || PyErr_Occurred())
{
PyErr_Clear();
penalty = VTK_PYTHON_INCOMPATIBLE;
}
}
}
// callback functions
if (name[0] == 'f' && strcmp(classname, "func") == 0)
else if (name[0] == 'f' && strcmp(classname, "func") == 0)
{
if (!PyCallable_Check(arg))
{
......
......@@ -303,6 +303,14 @@ static void vtkWrapPython_MakeTempVariable(
" PyObject *tempH%d = 0;\n",
i);
}
/* ditto for bool */
if ((i != MAX_ARGS) && (aType == VTK_PARSE_BOOL))
{
fprintf(fp,
" PyObject *tempB%d = 0;\n",
i);
}
}
......@@ -728,8 +736,7 @@ static char *vtkWrapPython_FormatString(FunctionInfo *currentFunction)
result[currPos++] = 'b';
break;
case VTK_PARSE_BOOL:
/* assume that sizeof(bool) == 1 */
result[currPos++] = 'b';
result[currPos++] = 'O';
break;
}
}
......@@ -772,6 +779,12 @@ static char *vtkWrapPython_ArgCheckString(
{
argtype = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE);
if (argtype == VTK_PARSE_BOOL)
{
strcpy(&result[currPos], " bool");
currPos += 5;
}
if (argtype == VTK_PARSE_VTK_OBJECT_REF ||
argtype == VTK_PARSE_VTK_OBJECT_PTR ||
argtype == VTK_PARSE_VTK_OBJECT)
......@@ -1401,6 +1414,10 @@ static void vtkWrapPython_GenerateMethods(
{
fprintf(fp,", &tempH%d",i);
}
else if (argType == VTK_PARSE_BOOL)
{
fprintf(fp,", &tempB%d",i);
}
else if (argType == VTK_PARSE_VOID_PTR)
{
fprintf(fp,", &temp%d, &size%d",i,i);
......@@ -1470,8 +1487,17 @@ static void vtkWrapPython_GenerateMethods(
potential_error = 1;
}
else if (argType == VTK_PARSE_BOOL)
{
fprintf(fp,
" temp%d = PyObject_IsTrue(tempB%d);\n"
" if (PyErr_Occurred())\n"
" {\n"
" %s;\n"
" }\n",
i, i, on_error);
}
}
/* make sure passed method is callable for VAR functions */
if (theSignature->NumberOfArguments == 1 &&
theSignature->ArgTypes[0] == VTK_PARSE_FUNCTION)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment