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