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

ENH: support bool arrays in python wrappers

parent 74b437e4
......@@ -720,6 +720,7 @@ PyObject *vtkPythonUtil::CallOverloadedMethod(
{
PyObject *sarg = PySequence_GetItem(arg, j);
helper->penalty(vtkPythonUtil::CheckArg(sarg, format, classname));
Py_DECREF(sarg);
}
}
}
......@@ -1502,6 +1503,40 @@ int vtkPythonCheckLongArray(PyObject *args, int i, T *a, int n)
}
#endif
int vtkPythonUtil::CheckArray(PyObject *args, int i, bool *a, int n)
{
int changed = 0;
PyObject *seq = PyTuple_GET_ITEM(args, i);
for (i = 0; i < n; i++)
{
PyObject *oldobj = PySequence_GetItem(seq, i);
bool oldval = PyObject_IsTrue(oldobj);
Py_DECREF(oldobj);
changed |= (a[i] != oldval);
}
if (changed)
{
for (i = 0; i < n; i++)
{
#if PY_VERSION_HEX >= 0x02030000
PyObject *newobj = PyBool_FromLong(a[i]);
#else
PyObject *newobj = PyInt_FromLong(a[i]);
#endif
int rval = PySequence_SetItem(seq, i, newobj);
Py_DECREF(newobj);
if (rval == -1)
{
return -1;
}
}
}
return 0;
}
int vtkPythonUtil::CheckArray(PyObject *args, int i, char *a, int n)
{
return vtkPythonCheckIntArray(args, i, a, n);
......
......@@ -151,6 +151,7 @@ public:
// check array arguments sent through the wrappers to see if the
// underlying C++ method changed the values, and attempt to modify
// the original python sequence (list or tuple) if so.
static int CheckArray(PyObject *args, int i, bool *a, int n);
static int CheckArray(PyObject *args, int i, char *a, int n);
static int CheckArray(PyObject *args, int i, signed char *a, int n);
static int CheckArray(PyObject *args, int i, unsigned char *a, int n);
......
......@@ -689,6 +689,7 @@ static char *vtkWrapPython_FormatString(FunctionInfo *currentFunction)
}
result[currPos++] = ')';
break;
case VTK_PARSE_BOOL_PTR: /* there is no char for "bool" */
case VTK_PARSE_INT_PTR:
result[currPos++] = '(';
for (j = 0; j < currentFunction->ArgCounts[i]; j++)
......@@ -2208,7 +2209,7 @@ static int vtkWrapPython_MethodCheck(
if (argType == VTK_PARSE_STRING_PTR) args_ok = 0;
if (argType == VTK_PARSE_UNICODE_STRING_PTR) args_ok = 0;
#ifndef Py_UNICODE_SIZE
#ifndef Py_USING_UNICODE
if ((argType & VTK_PARSE_BASE_TYPE) ==
VTK_PARSE_UNICODE_STRING) args_ok = 0;
#endif
......@@ -2258,7 +2259,7 @@ static int vtkWrapPython_MethodCheck(
if (returnType == VTK_PARSE_STRING_PTR) args_ok = 0;
if (returnType == VTK_PARSE_UNICODE_STRING_PTR) args_ok = 0;
#ifndef Py_UNICODE_SIZE
#ifndef Py_USING_UNICODE
if ((returnType & VTK_PARSE_BASE_TYPE) ==
VTK_PARSE_UNICODE_STRING) args_ok = 0;
#endif
......
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