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

BUG: need separate PyVTKSpecialObject_CopyNew() that takes const pointer

This change converts several "void *" arguments to "const void *".
Without this change, methods that return const special types cannot
be wrapped.
parent c1653557
......@@ -256,8 +256,11 @@ int PyVTKSpecialObject_Check(PyObject *obj)
}
//--------------------------------------------------------------------
PyObject *PyVTKSpecialObject_New(char *classname, void *ptr, int copy)
PyObject *PyVTKSpecialObject_New(const char *classname, void *ptr)
{
// would be nice if "info" could be passed instead if "classname"
PyVTKSpecialType *info = vtkPythonUtil::FindSpecialType(classname);
#if (PY_MAJOR_VERSION >= 2)
PyVTKSpecialObject *self = PyObject_New(PyVTKSpecialObject,
&PyVTKSpecialObjectType);
......@@ -266,6 +269,16 @@ PyObject *PyVTKSpecialObject_New(char *classname, void *ptr, int copy)
&PyVTKSpecialObjectType);
#endif
self->vtk_ptr = ptr;
self->vtk_hash = -1;
self->vtk_info = info;
return (PyObject *)self;
}
//--------------------------------------------------------------------
PyObject *PyVTKSpecialObject_CopyNew(const char *classname, const void *ptr)
{
PyVTKSpecialType *info = vtkPythonUtil::FindSpecialType(classname);
if (info == 0)
......@@ -276,12 +289,15 @@ PyObject *PyVTKSpecialObject_New(char *classname, void *ptr, int copy)
return NULL;
}
if (copy)
{
ptr = info->copy_func(ptr);
}
#if (PY_MAJOR_VERSION >= 2)
PyVTKSpecialObject *self = PyObject_New(PyVTKSpecialObject,
&PyVTKSpecialObjectType);
#else
PyVTKSpecialObject *self = PyObject_NEW(PyVTKSpecialObject,
&PyVTKSpecialObjectType);
#endif
self->vtk_ptr = ptr;
self->vtk_ptr = info->copy_func(ptr);
self->vtk_hash = -1;
self->vtk_info = info;
......@@ -301,5 +317,6 @@ PyObject *PyVTKSpecialType_New(
// Add the built docstring to the method
newmethod->ml_doc = PyString_AsString(info->docstring);
// Returns a function. Returning a type object would be nicer.
return PyCFunction_New(newmethod, Py_None);
}
......@@ -28,18 +28,18 @@
// Prototypes for per-type copy, delete, and print funcs
// copy the object and return the copy
typedef void *(*PyVTKSpecialCopyFunc)(void *);
typedef void *(*PyVTKSpecialCopyFunc)(const void *);
// delete the object
typedef void (*PyVTKSpecialDeleteFunc)(void *);
// print the object to the stream
typedef void (*PyVTKSpecialPrintFunc)(ostream& os, void *);
typedef void (*PyVTKSpecialPrintFunc)(ostream& os, const void *);
// compare objects, final arg is on of the following:
// Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
// return "-1" if the comparison is impossible
typedef int (*PyVTKSpecialCompareFunc)(void *, void *, int);
typedef int (*PyVTKSpecialCompareFunc)(const void *, const void *, int);
// return a hash from the value of the object, or -1 if error,
// set second arg to '1' if the object is immutable
typedef long (*PyVTKSpecialHashFunc)(void *, int *);
typedef long (*PyVTKSpecialHashFunc)(const void *, int *);
// Struct to hold special methods, the first three are mandatory
// and the rest are optional.
......@@ -99,7 +99,10 @@ VTK_PYTHON_EXPORT
int PyVTKSpecialObject_Check(PyObject *obj);
VTK_PYTHON_EXPORT
PyObject *PyVTKSpecialObject_New(char *classname, void *ptr, int copy);
PyObject *PyVTKSpecialObject_New(const char *classname, void *ptr);
VTK_PYTHON_EXPORT
PyObject *PyVTKSpecialObject_CopyNew(const char *classname, const void *ptr);
}
#endif
......@@ -1221,7 +1221,7 @@ PyObject *vtkPythonUtil::GetObjectFromObject(
//--------------------------------------------------------------------
PyObject *vtkPythonUtil::GetSpecialObjectFromPointer(
void *ptr, const char *classname)
const void *ptr, const char *classname)
{
PyObject *obj = NULL;
......@@ -1231,7 +1231,7 @@ PyObject *vtkPythonUtil::GetSpecialObjectFromPointer(
if (ptr)
{
obj = PyVTKSpecialObject_New((char *)(classname), ptr, 1);
obj = PyVTKSpecialObject_CopyNew(classname, ptr);
}
else
{
......
......@@ -131,7 +131,7 @@ public:
// into a PyObject of that type. If the given pointer is NULL, then
// Py_None will be returned with no error. If the given pointer is
// of the wrong type, expect fireworks.
static PyObject *GetSpecialObjectFromPointer(void *ptr,
static PyObject *GetSpecialObjectFromPointer(const void *ptr,
const char *class_type);
// Description:
......
......@@ -220,7 +220,8 @@ static void vtkWrapPython_MakeTempVariable(
}
/* for const * return types, prepend with const */
if ((i == MAX_ARGS) && ((aType & VTK_PARSE_CONST) != 0))
if ((i == MAX_ARGS) && ((aType & VTK_PARSE_CONST) != 0) &&
((aType & VTK_PARSE_INDIRECT) != 0))
{
fprintf(fp," const ");
}
......@@ -1942,7 +1943,7 @@ static void vtkWrapPython_GenerateMethods(
if (do_constructors && !is_vtkobject)
{
fprintf(fp,
" result = PyVTKSpecialObject_New((char*)\"%s\", op, 0);\n",
" result = PyVTKSpecialObject_New(\"%s\", op);\n",
data->ClassName);
}
else
......@@ -2832,11 +2833,11 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
/* the copy constructor */
fprintf(fp,
"static void *vtkSpecial_%sCopy(void *obj)\n"
"static void *vtkSpecial_%sCopy(const void *obj)\n"
"{\n"
" if (obj)\n"
" {\n"
" return new %s(*static_cast<%s*>(obj));\n"
" return new %s(*static_cast<const %s*>(obj));\n"
" }\n"
" return 0;\n"
"}\n"
......@@ -2857,11 +2858,11 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
/* the printer */
fprintf(fp,
"static void vtkSpecial_%sPrint(ostream &os, void *obj)\n"
"static void vtkSpecial_%sPrint(ostream &os, const void *obj)\n"
"{\n"
" if (obj)\n"
" {\n"
" os << *(static_cast<%s*>(obj));\n"
" os << *(static_cast<const %s*>(obj));\n"
" }\n"
"}\n"
"\n",
......@@ -2885,10 +2886,10 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
if (compare_ops != 0)
{
fprintf(fp,
"static int vtkSpecial_%sCompare(void *o1, void *o2, int opid)\n"
"static int vtkSpecial_%sCompare(const void *o1, const void *o2, int opid)\n"
"{\n"
" const %s &so1 = *((%s *)o1);\n"
" const %s &so2 = *((%s *)o2);\n"
" const %s &so1 = *((const %s *)o1);\n"
" const %s &so2 = *((const %s *)o2);\n"
" switch (opid)\n"
" {\n",
data->ClassName, data->ClassName, data->ClassName,
......@@ -2918,9 +2919,9 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
has_hash = 1;
fprintf(fp,
"static long vtkSpecial_%sHash(void *self, int *immutable)\n"
"static long vtkSpecial_%sHash(const void *self, int *immutable)\n"
"{\n"
" unsigned long mtime = *((vtkTimeStamp *)self);\n"
" unsigned long mtime = *((const vtkTimeStamp *)self);\n"
" long h = (long)mtime;\n"
" *immutable = 0;\n"
" if (h != -1) { return h; };\n"
......@@ -2936,7 +2937,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
has_hash = 1;
fprintf(fp,
"static long vtkSpecial_%sHash(void *self, int *immutable)\n"
"static long vtkSpecial_%sHash(const void *self, int *immutable)\n"
"{\n"
" long h = vtkPythonUtil::VariantHash((vtkVariant *)self);\n"
" *immutable = 1;\n"
......
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