Commit b1841bfb authored by Ben Boeckel's avatar Ben Boeckel Committed by Code Review
Browse files

Merge topic 'vector-parameter-wrapping-support' into master

77914947 Hide SetArray method on vtk*Array classes from wrapping
cce489ec Wrap methods with POD pointer arguments in Python
4cf2386a Add support for declaring PODPointer variables
parents f13ab5c6 77914947
......@@ -186,7 +186,9 @@ public:
// The class uses the actual array provided; it does not copy the data
// from the supplied array. If save 0, the array must have been allocated
// with new[] not malloc.
#ifndef __WRAP__
void SetArray(unsigned char* array, vtkIdType size, int save);
#endif
void SetVoidArray(void *array, vtkIdType size, int save)
{
this->SetArray(static_cast<unsigned char *>(array), size, save);
......
......@@ -382,9 +382,17 @@ private:
T *GetValueRange(); \
void GetValueRange(T range[2]); \
T* WritePointer(vtkIdType id, vtkIdType number); \
T* GetPointer(vtkIdType id); \
T* GetPointer(vtkIdType id)/*; \
* These methods are not wrapped to avoid wrappers exposing these
* easy-to-get-wrong methods because passing in the wrong value for 'save' is
* guaranteed to cause a memory issue down the line. Either the wrappers
* didn't use malloc to allocate the memory or the memory isn't actually
* persisted because a temporary array is used that doesn't persist like this
* method expects.
void SetArray(T* array, vtkIdType size, int save); \
void SetArray(T* array, vtkIdType size, int save, int deleteMethod)
void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
#endif // !defined(__vtkDataArrayTemplate_h)
......
......@@ -576,7 +576,8 @@ bool vtkPythonGetArray(PyObject *o, T *a, int n)
return vtkPythonSequenceError(o, n, m);
}
return true;
// NULL is allowed if we're expecting a size of 0.
return (n == 0);
}
//--------------------------------------------------------------------
......
......@@ -65,6 +65,11 @@ int vtkWrap_IsCharPointer(ValueInfo *val)
return (t == VTK_PARSE_CHAR && vtkWrap_IsPointer(val));
}
int vtkWrap_IsPODPointer(ValueInfo *val)
{
return (vtkWrap_IsNumeric(val) && vtkWrap_IsPointer(val));
}
int vtkWrap_IsVTKObject(ValueInfo *val)
{
unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
......@@ -921,7 +926,7 @@ void vtkWrap_DeclareVariable(
fprintf(fp, "*");
}
/* arrays of unknown size are handled via pointers */
else if (val->CountHint)
else if (val->CountHint || vtkWrap_IsPODPointer(val))
{
fprintf(fp, "*");
}
......@@ -945,7 +950,8 @@ void vtkWrap_DeclareVariable(
aType != VTK_PARSE_VOID_PTR &&
aType != VTK_PARSE_OBJECT_PTR &&
!vtkWrap_IsQtObject(val) &&
val->CountHint == NULL)
val->CountHint == NULL &&
!vtkWrap_IsPODPointer(val))
{
if (val->NumberOfDimensions == 1 && val->Count > 0)
{
......@@ -974,7 +980,7 @@ void vtkWrap_DeclareVariable(
{
fprintf(fp, " = NULL");
}
else if (val->CountHint)
else if (val->CountHint || vtkWrap_IsPODPointer(val))
{
fprintf(fp, " = NULL");
}
......
......@@ -38,12 +38,14 @@ extern "C" {
/**
* Check for common types.
* IsPODPointer is for unsized arrays of POD types.
*/
/*@{*/
int vtkWrap_IsVoid(ValueInfo *val);
int vtkWrap_IsVoidFunction(ValueInfo *val);
int vtkWrap_IsVoidPointer(ValueInfo *val);
int vtkWrap_IsCharPointer(ValueInfo *val);
int vtkWrap_IsPODPointer(ValueInfo *val);
int vtkWrap_IsVTKObject(ValueInfo *val);
int vtkWrap_IsSpecialObject(ValueInfo *val);
int vtkWrap_IsQtObject(ValueInfo *val);
......
......@@ -676,6 +676,27 @@ static void vtkWrapPython_DeclareVariables(
/* write an int array containing the dimensions */
vtkWrap_DeclareVariableSize(fp, arg, "size", i);
}
/* temps for unsized arrays (but char* is a string, so don't wrap it this way) */
else if (vtkWrap_IsPODPointer(arg) &&
!vtkWrap_IsChar(arg))
{
fprintf(fp,
" const Py_ssize_t size%d = %d + %d < PyTuple_GET_SIZE(args)\n"
" ? PySequence_Size(PyTuple_GET_ITEM(args, %d + %d))\n"
" : (Py_ssize_t)-1;\n"
" std::vector<%s> vec%d;\n"
" if (size%d != (Py_ssize_t)-1)\n"
" {\n"
" vec%d.resize(size%d);\n"
" temp%d = &vec%d.front();\n"
" }\n",
i, i, !theFunc->IsStatic,
i, !theFunc->IsStatic,
vtkWrap_GetTypeName(arg), i,
i,
i, i,
i, i);
}
}
if (theFunc->ReturnValue)
......@@ -853,6 +874,11 @@ static void vtkWrapPython_GetSingleArgument(
fprintf(fp, "%sGetArray(%stemp%d, size%d)",
prefix, argname, i, i);
}
else if (vtkWrap_IsPODPointer(arg))
{
fprintf(fp, "%sGetArray(%stemp%d, size%d)",
prefix, argname, i, i);
}
}
/* -------------------------------------------------------------------- */
......@@ -2820,7 +2846,10 @@ static int vtkWrapPython_IsValueWrappable(
else if (vtkWrap_IsPointer(val))
{
if (vtkWrap_IsCharPointer(val) ||
vtkWrap_IsVoidPointer(val))
vtkWrap_IsVoidPointer(val) ||
(vtkWrap_IsPODPointer(val) &&
/* Boolean values aren't wrappable since vector<bool> is different. */
!vtkWrap_IsBool(val)))
{
return 1;
}
......@@ -4967,7 +4996,8 @@ int main(int argc, char *argv[])
fprintf(fp,
"#include \"vtkPythonArgs.h\"\n"
"#include \"vtkPythonOverload.h\"\n"
"#include <vtksys/ios/sstream>\n");
"#include <vtksys/ios/sstream>\n"
"#include <vector>\n");
/* vtkPythonCommand is needed to wrap vtkObject.h */
if (strcmp("vtkObject", name) == 0)
......
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