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

STYLE: constness

parent 2a6f9691
...@@ -317,10 +317,9 @@ int PyVTKClass_Check(PyObject *obj) ...@@ -317,10 +317,9 @@ int PyVTKClass_Check(PyObject *obj)
return (obj->ob_type == &PyVTKClassType); return (obj->ob_type == &PyVTKClassType);
} }
PyObject *PyVTKClass_New(vtknewfunc constructor, PyObject *PyVTKClass_New(vtknewfunc constructor, PyMethodDef *methods,
PyMethodDef *methods, const char *classname, const char *modulename,
char *classname, char *modulename, char *docstring[], const char *docstring[], PyObject *base)
PyObject *base)
{ {
static PyObject *modulestr[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static PyObject *modulestr[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static int nmodulestr = 10; static int nmodulestr = 10;
...@@ -352,7 +351,7 @@ PyObject *PyVTKClass_New(vtknewfunc constructor, ...@@ -352,7 +351,7 @@ PyObject *PyVTKClass_New(vtknewfunc constructor,
class_self->vtk_bases = PyTuple_New(0); class_self->vtk_bases = PyTuple_New(0);
} }
class_self->vtk_dict = NULL; class_self->vtk_dict = NULL;
class_self->vtk_name = PyString_FromString(classname); class_self->vtk_name = PyString_FromString((char *)classname);
class_self->vtk_getattr = NULL; class_self->vtk_getattr = NULL;
class_self->vtk_setattr = NULL; class_self->vtk_setattr = NULL;
...@@ -367,12 +366,12 @@ PyObject *PyVTKClass_New(vtknewfunc constructor, ...@@ -367,12 +366,12 @@ PyObject *PyVTKClass_New(vtknewfunc constructor,
{ {
if (modulestr[i] == 0) if (modulestr[i] == 0)
{ {
modulestr[i] = PyString_InternFromString(modulename); modulestr[i] = PyString_InternFromString((char *)modulename);
moduleobj = modulestr[i]; moduleobj = modulestr[i];
Py_INCREF(moduleobj); Py_INCREF(moduleobj);
break; break;
} }
else if (strcmp(modulename,PyString_AsString(modulestr[i])) == 0) else if (strcmp(modulename, PyString_AsString(modulestr[i])) == 0)
{ {
moduleobj = modulestr[i]; moduleobj = modulestr[i];
Py_INCREF(moduleobj); Py_INCREF(moduleobj);
...@@ -381,12 +380,12 @@ PyObject *PyVTKClass_New(vtknewfunc constructor, ...@@ -381,12 +380,12 @@ PyObject *PyVTKClass_New(vtknewfunc constructor,
} }
if (i == nmodulestr) if (i == nmodulestr)
{ {
moduleobj = PyString_FromString(modulename); moduleobj = PyString_FromString((char *)modulename);
} }
class_self->vtk_module = moduleobj; class_self->vtk_module = moduleobj;
vtkPythonUtil::AddClassToMap(self,classname); vtkPythonUtil::AddClassToMap(self, classname);
} }
return (PyObject *)self; return (PyObject *)self;
......
...@@ -51,8 +51,8 @@ int PyVTKClass_Check(PyObject *obj); ...@@ -51,8 +51,8 @@ int PyVTKClass_Check(PyObject *obj);
VTK_PYTHON_EXPORT VTK_PYTHON_EXPORT
PyObject *PyVTKClass_New(vtknewfunc constructor, PyMethodDef *methods, PyObject *PyVTKClass_New(vtknewfunc constructor, PyMethodDef *methods,
char *classname, char *modulename, char *docstring[], const char *classname, const char *modulename,
PyObject *base); const char *docstring[], PyObject *base);
} }
#endif #endif
...@@ -37,12 +37,21 @@ ...@@ -37,12 +37,21 @@
#include <vtksys/ios/sstream> #include <vtksys/ios/sstream>
// Silence warning like
// "dereferencing type-punned pointer will break strict-aliasing rules"
// it happens because this kind of expression: (long *)&ptr
// pragma GCC diagnostic is available since gcc>=4.2
#if defined(__GNUG__) && (__GNUC__>4) || (__GNUC__==4 && __GNUC_MINOR__>=2)
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
//-------------------------------------------------------------------- //--------------------------------------------------------------------
PyVTKSpecialType::PyVTKSpecialType( PyVTKSpecialType::PyVTKSpecialType(
char *cname, char *cdocs[], PyMethodDef *cmethods, PyMethodDef *ccons, const char *cname, const char *cdocs[],
PyMethodDef *cmethods, PyMethodDef *ccons,
PyVTKSpecialMethods *smethods) PyVTKSpecialMethods *smethods)
{ {
this->classname = PyString_FromString(cname); this->classname = PyString_FromString((char *)cname);
this->docstring = vtkPythonUtil::BuildDocString(cdocs); this->docstring = vtkPythonUtil::BuildDocString(cdocs);
this->methods = cmethods; this->methods = cmethods;
this->constructors = ccons; this->constructors = ccons;
...@@ -320,7 +329,8 @@ PyObject *PyVTKSpecialObject_CopyNew(const char *classname, const void *ptr) ...@@ -320,7 +329,8 @@ PyObject *PyVTKSpecialObject_CopyNew(const char *classname, const void *ptr)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
PyObject *PyVTKSpecialType_New( PyObject *PyVTKSpecialType_New(
PyMethodDef *newmethod, PyMethodDef *methods, PyMethodDef *constructors, PyMethodDef *newmethod, PyMethodDef *methods, PyMethodDef *constructors,
char *classname, char *docstring[], PyVTKSpecialMethods *smethods) const char *classname, const char *docstring[],
PyVTKSpecialMethods *smethods)
{ {
// Add this type to the special type map // Add this type to the special type map
PyVTKSpecialType *info = PyVTKSpecialType *info =
......
...@@ -63,7 +63,8 @@ public: ...@@ -63,7 +63,8 @@ public:
copy_func(0), delete_func(0), print_func(0) {}; copy_func(0), delete_func(0), print_func(0) {};
PyVTKSpecialType( PyVTKSpecialType(
char *cname, char *cdocs[], PyMethodDef *cmethods, PyMethodDef *ccons, const char *cname, const char *cdocs[],
PyMethodDef *cmethods, PyMethodDef *ccons,
PyVTKSpecialMethods *smethods); PyVTKSpecialMethods *smethods);
// general information // general information
...@@ -93,7 +94,8 @@ extern "C" ...@@ -93,7 +94,8 @@ extern "C"
VTK_PYTHON_EXPORT VTK_PYTHON_EXPORT
PyObject *PyVTKSpecialType_New( PyObject *PyVTKSpecialType_New(
PyMethodDef *newmethod, PyMethodDef *methods, PyMethodDef *constructors, PyMethodDef *newmethod, PyMethodDef *methods, PyMethodDef *constructors,
char *classname, char *docstring[], PyVTKSpecialMethods *smethods); const char *classname, const char *docstring[],
PyVTKSpecialMethods *smethods);
VTK_PYTHON_EXPORT VTK_PYTHON_EXPORT
int PyVTKSpecialObject_Check(PyObject *obj); int PyVTKSpecialObject_Check(PyObject *obj);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <vtkstd/string> #include <vtkstd/string>
#include <vtkstd/utility> #include <vtkstd/utility>
// Silent warning like // Silence warning like
// "dereferencing type-punned pointer will break strict-aliasing rules" // "dereferencing type-punned pointer will break strict-aliasing rules"
// it happens because this kind of expression: (long *)&ptr // it happens because this kind of expression: (long *)&ptr
// pragma GCC diagnostic is available since gcc>=4.2 // pragma GCC diagnostic is available since gcc>=4.2
...@@ -91,32 +91,32 @@ vtkPythonUtil::~vtkPythonUtil() ...@@ -91,32 +91,32 @@ vtkPythonUtil::~vtkPythonUtil()
// Concatenate an array of strings into a single string. The resulting // Concatenate an array of strings into a single string. The resulting
// string is allocated via new. The array of strings must be null-terminated, // string is allocated via new. The array of strings must be null-terminated,
// e.g. static char *strings[] = {"string1", "string2", NULL}; // e.g. static char *strings[] = {"string1", "string2", NULL};
PyObject *vtkPythonUtil::BuildDocString(char *docstring[]) PyObject *vtkPythonUtil::BuildDocString(const char *docstring[])
{ {
PyObject *result; PyObject *result;
char *data; char *data;
int i, j, n; size_t i, j, n;
int *m; size_t *m;
int total = 0; size_t total = 0;
for (n = 0; docstring[n] != NULL; n++) for (n = 0; docstring[n] != NULL; n++)
{ {
; ;
} }
m = new int[n]; m = new size_t[n];
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
m[i] = static_cast<int>(strlen(docstring[i])); m[i] = strlen(docstring[i]);
total += m[i]; total += m[i];
} }
result = PyString_FromStringAndSize(docstring[0], m[0]); result = PyString_FromStringAndSize((char *)docstring[0], (Py_ssize_t)m[0]);
if (n > 1) if (n > 1)
{ {
_PyString_Resize(&result, total); _PyString_Resize(&result, (Py_ssize_t)total);
} }
data = PyString_AsString(result); data = PyString_AsString(result);
...@@ -826,7 +826,7 @@ PyMethodDef *vtkPythonUtil::FindConversionMethod( ...@@ -826,7 +826,7 @@ PyMethodDef *vtkPythonUtil::FindConversionMethod(
//-------------------------------------------------------------------- //--------------------------------------------------------------------
vtkObjectBase *vtkPythonUtil::VTKParseTuple( vtkObjectBase *vtkPythonUtil::VTKParseTuple(
PyObject *pself, PyObject *args, char *format, ...) PyObject *pself, PyObject *args, const char *format, ...)
{ {
PyVTKObject *self = (PyVTKObject *)pself; PyVTKObject *self = (PyVTKObject *)pself;
vtkObjectBase *obj = NULL; vtkObjectBase *obj = NULL;
...@@ -851,7 +851,7 @@ vtkObjectBase *vtkPythonUtil::VTKParseTuple( ...@@ -851,7 +851,7 @@ vtkObjectBase *vtkPythonUtil::VTKParseTuple(
} }
// re-slice the args to remove 'self' // re-slice the args to remove 'self'
args = PyTuple_GetSlice(args,1,n); args = PyTuple_GetSlice(args,1,n);
if (PyArg_VaParse(args,format,va)) if (PyArg_VaParse(args, (char *)format, va))
{ {
obj = self->vtk_ptr; obj = self->vtk_ptr;
} }
...@@ -860,7 +860,7 @@ vtkObjectBase *vtkPythonUtil::VTKParseTuple( ...@@ -860,7 +860,7 @@ vtkObjectBase *vtkPythonUtil::VTKParseTuple(
/* it was called as a bound method */ /* it was called as a bound method */
else else
{ {
if (PyArg_VaParse(args,format,va)) if (PyArg_VaParse(args, (char *)format, va))
{ {
obj = self->vtk_ptr; obj = self->vtk_ptr;
} }
...@@ -870,7 +870,7 @@ vtkObjectBase *vtkPythonUtil::VTKParseTuple( ...@@ -870,7 +870,7 @@ vtkObjectBase *vtkPythonUtil::VTKParseTuple(
//-------------------------------------------------------------------- //--------------------------------------------------------------------
PyVTKSpecialType *vtkPythonUtil::AddSpecialTypeToMap( PyVTKSpecialType *vtkPythonUtil::AddSpecialTypeToMap(
char *classname, char *docstring[], PyMethodDef *methods, const char *classname, const char *docstring[], PyMethodDef *methods,
PyMethodDef *constructors, PyVTKSpecialMethods *smethods) PyMethodDef *constructors, PyVTKSpecialMethods *smethods)
{ {
if (vtkPythonMap == NULL) if (vtkPythonMap == NULL)
...@@ -1327,7 +1327,7 @@ void *vtkPythonUtil::GetPointerFromSpecialObject( ...@@ -1327,7 +1327,7 @@ void *vtkPythonUtil::GetPointerFromSpecialObject(
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// mangle a void pointer into a SWIG-style string // mangle a void pointer into a SWIG-style string
char *vtkPythonUtil::ManglePointer(void *ptr, const char *type) char *vtkPythonUtil::ManglePointer(const void *ptr, const char *type)
{ {
static char ptrText[128]; static char ptrText[128];
sprintf(ptrText,"_%*.*lx_%s",2*(int)sizeof(void *),2*(int)sizeof(void *), sprintf(ptrText,"_%*.*lx_%s",2*(int)sizeof(void *),2*(int)sizeof(void *),
...@@ -1618,7 +1618,7 @@ int vtkPythonUtil::CheckArray(PyObject *args, int i, unsigned __int64 *a, int n) ...@@ -1618,7 +1618,7 @@ int vtkPythonUtil::CheckArray(PyObject *args, int i, unsigned __int64 *a, int n)
#endif #endif
//-------------------------------------------------------------------- //--------------------------------------------------------------------
long vtkPythonUtil::VariantHash(vtkVariant *v) long vtkPythonUtil::VariantHash(const vtkVariant *v)
{ {
long h = -1; long h = -1;
......
...@@ -35,7 +35,7 @@ public: ...@@ -35,7 +35,7 @@ public:
// and unbound method calls for VTK objects, depending on whether // and unbound method calls for VTK objects, depending on whether
// "self" is a PyVTKObject or a PyVTKClass. // "self" is a PyVTKObject or a PyVTKClass.
static vtkObjectBase *VTKParseTuple(PyObject *self, PyObject *args, static vtkObjectBase *VTKParseTuple(PyObject *self, PyObject *args,
char *format, ...); const char *format, ...);
// Description: // Description:
// Check python object against a format character and return a number // Check python object against a format character and return a number
...@@ -109,7 +109,7 @@ public: ...@@ -109,7 +109,7 @@ public:
// Add a special VTK type to the type lookup table, this allows us to // Add a special VTK type to the type lookup table, this allows us to
// later create object given only the class name. // later create object given only the class name.
static PyVTKSpecialType *AddSpecialTypeToMap( static PyVTKSpecialType *AddSpecialTypeToMap(
char *classname, char *docstring[], PyMethodDef *methods, const char *classname, const char *docstring[], PyMethodDef *methods,
PyMethodDef *constructors, PyVTKSpecialMethods *smethods); PyMethodDef *constructors, PyVTKSpecialMethods *smethods);
// Description: // Description:
...@@ -137,11 +137,11 @@ public: ...@@ -137,11 +137,11 @@ public:
// Description: // Description:
// Utility function to build a docstring by concatenating a series // Utility function to build a docstring by concatenating a series
// of strings until a null string is found. // of strings until a null string is found.
static PyObject *BuildDocString(char *docstring[]); static PyObject *BuildDocString(const char *docstring[]);
// Description: // Description:
// Utility function for creating SWIG-style mangled pointer string. // Utility function for creating SWIG-style mangled pointer string.
static char *ManglePointer(void *ptr, const char *type); static char *ManglePointer(const void *ptr, const char *type);
// Description: // Description:
// Utility function decoding a SWIG-style mangled pointer string. // Utility function decoding a SWIG-style mangled pointer string.
...@@ -174,7 +174,7 @@ public: ...@@ -174,7 +174,7 @@ public:
// Description: // Description:
// Compute a hash for a vtkVariant. // Compute a hash for a vtkVariant.
static long VariantHash(vtkVariant *variant); static long VariantHash(const vtkVariant *variant);
private: private:
vtkPythonUtil(); vtkPythonUtil();
......
...@@ -2571,9 +2571,9 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2571,9 +2571,9 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp, fprintf(fp,
"\n" "\n"
"#if defined(WIN32)\n" "#if defined(WIN32)\n"
"extern \"C\" { __declspec( dllexport ) PyObject *PyVTKClass_%sNew(char *); }\n" "extern \"C\" { __declspec( dllexport ) PyObject *PyVTKClass_%sNew(const char *); }\n"
"#else\n" "#else\n"
"extern \"C\" { PyObject *PyVTKClass_%sNew(char *); }\n" "extern \"C\" { PyObject *PyVTKClass_%sNew(const char *); }\n"
"#endif\n" "#endif\n"
"\n", "\n",
data->ClassName, data->ClassName); data->ClassName, data->ClassName);
...@@ -2582,7 +2582,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2582,7 +2582,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
for (i = 0; i < data->NumberOfSuperClasses; i++) for (i = 0; i < data->NumberOfSuperClasses; i++)
{ {
fprintf(fp, fprintf(fp,
"extern \"C\" { PyObject *PyVTKClass_%sNew(char *); }\n", "extern \"C\" { PyObject *PyVTKClass_%sNew(const char *); }\n",
data->SuperClasses[i]); data->SuperClasses[i]);
} }
...@@ -2727,7 +2727,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2727,7 +2727,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
} }
fprintf(fp, fprintf(fp,
"PyObject *PyVTKClass_%sNew(char *modulename)\n" "PyObject *PyVTKClass_%sNew(const char *modulename)\n"
"{\n", "{\n",
data->ClassName); data->ClassName);
...@@ -2745,8 +2745,8 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2745,8 +2745,8 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp, fprintf(fp,
" Py%sMethods,\n" " Py%sMethods,\n"
" (char*)\"%s\",modulename,\n" " \"%s\",modulename,\n"
" (char**)%sDoc(),0);\n" " %sDoc(),0);\n"
"}\n" "}\n"
"\n", "\n",
data->ClassName, data->ClassName, data->ClassName); data->ClassName, data->ClassName, data->ClassName);
...@@ -2767,7 +2767,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2767,7 +2767,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
} }
fprintf(fp, fprintf(fp,
"PyObject *PyVTKClass_%sNew(char *modulename)\n" "PyObject *PyVTKClass_%sNew(const char *modulename)\n"
"{\n", "{\n",
data->ClassName); data->ClassName);
...@@ -2785,8 +2785,8 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2785,8 +2785,8 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp, fprintf(fp,
" Py%sMethods,\n" " Py%sMethods,\n"
" (char*)\"%s\",modulename,\n" " \"%s\",modulename,\n"
" (char**)%sDoc(),\n" " %sDoc(),\n"
" PyVTKClass_%sNew(modulename));\n" " PyVTKClass_%sNew(modulename));\n"
"}\n" "}\n"
"\n", "\n",
...@@ -2899,7 +2899,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2899,7 +2899,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp, fprintf(fp,
"static long vtkSpecial_%sHash(const void *self, int *immutable)\n" "static long vtkSpecial_%sHash(const void *self, int *immutable)\n"
"{\n" "{\n"
" unsigned long mtime = *((const vtkTimeStamp *)self);\n" " unsigned long mtime = *(static_cast<const vtkTimeStamp *>(self));\n"
" long h = (long)mtime;\n" " long h = (long)mtime;\n"
" *immutable = 0;\n" " *immutable = 0;\n"
" if (h != -1) { return h; };\n" " if (h != -1) { return h; };\n"
...@@ -2917,7 +2917,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2917,7 +2917,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp, fprintf(fp,
"static long vtkSpecial_%sHash(const void *self, int *immutable)\n" "static long vtkSpecial_%sHash(const void *self, int *immutable)\n"
"{\n" "{\n"
" long h = vtkPythonUtil::VariantHash((vtkVariant *)self);\n" " long h = vtkPythonUtil::VariantHash(static_cast<const vtkVariant *>(self));\n"
" *immutable = 1;\n" " *immutable = 1;\n"
" return h;\n" " return h;\n"
"}\n" "}\n"
...@@ -2969,7 +2969,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -2969,7 +2969,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
"{\n" "{\n"
" return PyVTKSpecialType_New(\n" " return PyVTKSpecialType_New(\n"
" &Py%sNewMethod, Py%sMethods, Py%s_%sMethods," " &Py%sNewMethod, Py%sMethods, Py%s_%sMethods,"
" (char *)\"%s\", (char**)%sDoc(),\n" " \"%s\", %sDoc(),\n"
" &vtkSpecial_%sSpecialMethods);\n" " &vtkSpecial_%sSpecialMethods);\n"
"}\n" "}\n"
"\n", "\n",
......
...@@ -33,7 +33,7 @@ static void CreateInitFile(const char *libName, ...@@ -33,7 +33,7 @@ static void CreateInitFile(const char *libName,
for (i = 0; i < numConcrete; i++) for (i = 0; i < numConcrete; i++)
{ {
fprintf(fout,"extern \"C\" {%sPyObject *PyVTKClass_%sNew(char *); }\n", dllexp, concrete[i]); fprintf(fout,"extern \"C\" {%sPyObject *PyVTKClass_%sNew(const char *); }\n", dllexp, concrete[i]);
} }
fprintf(fout,"\nstatic PyMethodDef Py%s_ClassMethods[] = {\n", libName); fprintf(fout,"\nstatic PyMethodDef Py%s_ClassMethods[] = {\n", libName);
...@@ -54,7 +54,7 @@ for (i = 0; i < numConcrete; i++) ...@@ -54,7 +54,7 @@ for (i = 0; i < numConcrete; i++)
for (i = 0; i < numConcrete; i++) for (i = 0; i < numConcrete; i++)
{ {
fprintf(fout," c = PyVTKClass_%sNew((char*)modulename);\n", fprintf(fout," c = PyVTKClass_%sNew(modulename);\n",
concrete[i]); concrete[i]);
fprintf(fout," if (c && -1 == PyDict_SetItemString(d, (char*)\"%s\", c))\n", fprintf(fout," if (c && -1 == PyDict_SetItemString(d, (char*)\"%s\", c))\n",
concrete[i]); concrete[i]);
......
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