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

Handle default values for array parameters in python.

Without this change, parameters like ( , int array[3] = 0) are required
parameters when the method is called from python.
parent 000e36f1
Pipeline #6679 passed with stage
......@@ -422,7 +422,6 @@ int vtkWrap_CountRequiredArguments(FunctionInfo *f)
for (i = 0; i < totalArgs; i++)
{
if (f->Parameters[i]->Value == NULL ||
vtkWrap_IsArray(f->Parameters[i]) ||
vtkWrap_IsNArray(f->Parameters[i]))
{
requiredArgs = i+1;
......@@ -1012,7 +1011,8 @@ void vtkWrap_DeclareVariable(
fprintf(fp, "*");
}
/* arrays of unknown size are handled via pointers */
else if (val->CountHint || vtkWrap_IsPODPointer(val))
else if (val->CountHint || vtkWrap_IsPODPointer(val) ||
(vtkWrap_IsArray(val) && val->Value))
{
fprintf(fp, "*");
}
......@@ -1037,7 +1037,8 @@ void vtkWrap_DeclareVariable(
aType != VTK_PARSE_OBJECT_PTR &&
!vtkWrap_IsQtObject(val) &&
val->CountHint == NULL &&
!vtkWrap_IsPODPointer(val))
!vtkWrap_IsPODPointer(val) &&
!(vtkWrap_IsArray(val) && val->Value))
{
if (val->NumberOfDimensions == 1 && val->Count > 0)
{
......@@ -1114,8 +1115,8 @@ void vtkWrap_DeclareVariableSize(
{
fprintf(fp,
" %sint %s%s = %d;\n",
(val->Count == 0 ? "" : "const "), name, idx,
(val->Count == 0 ? 0 : val->Count));
((val->Count == 0 || val->Value != 0) ? "" : "const "),
name, idx, (val->Count == 0 ? 0 : val->Count));
}
else if (val->NumberOfDimensions == 1)
{
......
......@@ -113,7 +113,7 @@ void vtkWrapPython_DeclareVariables(
if (vtkWrap_IsArray(arg) || vtkWrap_IsNArray(arg) ||
vtkWrap_IsPODPointer(arg))
{
storageSize = 4;
storageSize = (arg->Count ? arg->Count : 4);
if (!vtkWrap_IsConst(arg) &&
!vtkWrap_IsSetVectorMethod(theFunc))
{
......@@ -121,7 +121,8 @@ void vtkWrapPython_DeclareVariables(
vtkWrap_DeclareVariable(fp, data, arg, "save", i, VTK_WRAP_ARG);
storageSize *= 2;
}
if (arg->CountHint || vtkWrap_IsPODPointer(arg))
if (arg->CountHint || vtkWrap_IsPODPointer(arg) ||
(vtkWrap_IsArray(arg) && arg->Value))
{
fprintf(fp,
" %s small%d[%d];\n",
......@@ -167,7 +168,8 @@ static void vtkWrapPython_GetSizesForArrays(
{
arg = theFunc->Parameters[i];
if (arg->CountHint || vtkWrap_IsPODPointer(arg))
if (arg->CountHint || vtkWrap_IsPODPointer(arg) ||
(vtkWrap_IsArray(arg) && arg->Value))
{
if (j == 1)
{
......@@ -200,18 +202,29 @@ static void vtkWrapPython_GetSizesForArrays(
fprintf(fp,
"%s if (size%d > 0)\n"
"%s {\n"
"%s temp%d = small%d;\n"
"%s temp%d = small%d;\n",
indentation, i,
indentation,
indentation, i, i);
if (arg->CountHint || vtkWrap_IsPODPointer(arg))
{
fprintf(fp,
"%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,
indentation, i, vtkWrap_GetTypeName(arg), mtwo, i,
indentation);
}
else
{
fprintf(fp,
"%s size%d = %d;\n",
indentation, i, arg->Count);
}
if (*mtwo)
{
......
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