Commit fcd2ac5a authored by David Gobbi's avatar David Gobbi
Browse files

Fix wrapping pointer parameters with default value 0.

When the python wrappers were wrapping a pointer parameter with a default
value of null, e.g. func(int *x=0), then if no parameter was passed then
the underlying C++ function would receive an uninitialized array rather
a null pointer.

In addition, the SaveArray() and ArrayHasChanged() methods that the python
wrappers use when wrapping non-const pointers and arrays would overflow
when the array size was zero.
parent 3ecb4cd9
Pipeline #5585 passed with stage
......@@ -425,16 +425,17 @@ public:
// Copy an array.
template<class T>
static void SaveArray(const T *a, T *b, int n) {
int i = 0;
do { b[i] = a[i]; } while (++i < n); }
for (int i = 0; i < n; i++) {
b[i] = a[i]; } }
// Description:
// Check if an array has changed.
template<class T>
static bool ArrayHasChanged(const T *a, const T *b, int n) {
int i = 0;
do { if (a[i] != b[i]) break; } while (++i < n);
return (i < n); }
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
return true; } }
return false; }
// Description:
// Get the argument count.
......
......@@ -198,11 +198,15 @@ static void vtkWrapPython_GetSizesForArrays(
}
fprintf(fp,
"%s temp%d = small%d;\n"
"%s if (size%d > 4)\n"
"%s if (size%d > 0)\n"
"%s {\n"
"%s temp%d = new %s[%ssize%d];\n"
"%s }\n",
"%s temp%d = small%d;\n"
"%s if (size%d > 4)\n"
"%s {\n"
"%s temp%d = new %s[%ssize%d];\n"
"%s }\n",
indentation, i,
indentation,
indentation, i, i,
indentation, i,
indentation,
......@@ -212,9 +216,13 @@ static void vtkWrapPython_GetSizesForArrays(
if (*mtwo)
{
fprintf(fp,
"%s save%d = &temp%d[size%d];\n",
"%s save%d = &temp%d[size%d];\n",
indentation, i, i, i);
}
fprintf(fp,
"%s }\n",
indentation);
}
}
if (j > 1)
......
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