From 4cf2fa381f966e4a3b6994fd9b7c8a8cbb132a59 Mon Sep 17 00:00:00 2001 From: David Gobbi <david.gobbi@gmail.com> Date: Fri, 10 Jul 2015 23:16:17 -0600 Subject: [PATCH] Change wrappers to require python 2.5 or later. This allows a lot of obsolete code to be removed. --- Wrapping/PythonCore/PyVTKClass.cxx | 44 ------ Wrapping/PythonCore/PyVTKMutableObject.cxx | 155 +-------------------- Wrapping/PythonCore/PyVTKObject.cxx | 46 ------ Wrapping/PythonCore/PyVTKObject.h | 2 - Wrapping/PythonCore/PyVTKSpecialObject.cxx | 89 +----------- Wrapping/PythonCore/PyVTKSpecialObject.h | 5 - Wrapping/PythonCore/PyVTKTemplate.cxx | 33 +---- Wrapping/PythonCore/vtkPythonArgs.cxx | 84 +++-------- Wrapping/PythonCore/vtkPythonArgs.h | 4 - Wrapping/PythonCore/vtkPythonCommand.cxx | 6 - Wrapping/PythonCore/vtkPythonOverload.cxx | 15 +- Wrapping/PythonCore/vtkPythonUtil.cxx | 18 --- Wrapping/PythonCore/vtkPythonUtil.h | 16 --- Wrapping/Tools/vtkWrapPythonConstant.c | 8 +- Wrapping/Tools/vtkWrapPythonType.c | 40 +----- 15 files changed, 27 insertions(+), 538 deletions(-) diff --git a/Wrapping/PythonCore/PyVTKClass.cxx b/Wrapping/PythonCore/PyVTKClass.cxx index 39c18cc147c..5a4e7ca3146 100644 --- a/Wrapping/PythonCore/PyVTKClass.cxx +++ b/Wrapping/PythonCore/PyVTKClass.cxx @@ -195,7 +195,6 @@ static PyObject *PyVTKClass_GetAttr(PyObject *op, PyObject *attr) } //-------------------------------------------------------------------- -#if PY_VERSION_HEX >= 0x02020000 static PyObject *PyVTKClass_Dir(PyObject *op, PyObject *arg) { /* depending on where it is bound */ @@ -251,10 +250,8 @@ static PyObject *PyVTKClass_Dir(PyObject *op, PyObject *arg) static PyMethodDef PyVTKClass_Dir_Method = { (char *)"__dir__", PyVTKClass_Dir, METH_O, (char *)"class directory" }; -#endif //-------------------------------------------------------------------- -#if PY_MAJOR_VERSION >= 2 static int PyVTKClass_Traverse(PyObject *o, visitproc visit, void *arg) { PyVTKClass *self = (PyVTKClass *)o; @@ -281,16 +278,13 @@ static int PyVTKClass_Traverse(PyObject *o, visitproc visit, void *arg) return err; } -#endif //-------------------------------------------------------------------- static void PyVTKClass_Delete(PyObject *op) { PyVTKClass *self = (PyVTKClass *)op; -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_UnTrack(op); -#endif Py_XDECREF(self->vtk_bases); Py_XDECREF(self->vtk_dict); Py_XDECREF(self->vtk_name); @@ -302,13 +296,7 @@ static void PyVTKClass_Delete(PyObject *op) Py_XDECREF(self->vtk_module); Py_XDECREF(self->vtk_doc); -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Del(op); -#elif PY_MAJOR_VERSION >= 2 - PyObject_Del(op); -#else - PyMem_DEL(op); -#endif } //-------------------------------------------------------------------- @@ -335,12 +323,10 @@ static PyObject *PyVTKClassMetaType_GetAttr(PyObject *op, PyObject *attr) { return Py_BuildValue((char*)"[ss]", "__doc__", "__name__"); } -#if PY_VERSION_HEX >= 0x02020000 if (strcmp(name,"__dir__") == 0) { return PyCFunction_New(&PyVTKClass_Dir_Method, op); } -#endif PyErr_SetString(PyExc_AttributeError, name); return NULL; @@ -382,14 +368,10 @@ static PyTypeObject PyVTKClassMetaType = { 0, // tp_as_buffer 0, // tp_flags (char*)"PyVTKClassMetaType, part of the subclassing mechanism for VTK classes.", -#if PY_MAJOR_VERSION >= 2 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset -#else - 0, 0, 0, 0, // reserved -#endif VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED }; @@ -415,21 +397,12 @@ PyTypeObject PyVTKClass_Type = { PyVTKClass_GetAttr, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer -#if PY_VERSION_HEX >= 0x02020000 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags -#else - 0, // tp_flags -#endif (char*)"A generator for VTK objects. Special attributes are: __bases__ (a tuple of base classes), __dict__ (methods and attributes), __doc__ (the docstring for the class), __name__ (the name of class), and __module__ (module that the class is defined in).", // tp_doc -#if PY_MAJOR_VERSION >= 2 PyVTKClass_Traverse, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset -#else - 0, 0, 0, 0, // reserved -#endif -#if PY_VERSION_HEX >= 0x02020000 0, // tp_iter 0, // tp_iternext 0, // tp_methods @@ -450,7 +423,6 @@ PyTypeObject PyVTKClass_Type = { 0, // tp_cache 0, // tp_subclasses 0, // tp_weaklist -#endif VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED }; @@ -541,13 +513,7 @@ PyObject *PyVTKClass_New(vtknewfunc constructor, PyMethodDef *methods, doc = vtkPythonUtil::BuildDocString(docstring); -#if PY_VERSION_HEX >= 0x02020000 PyVTKClass *class_self = PyObject_GC_New(PyVTKClass, &PyVTKClass_Type); -#elif PY_MAJOR_VERSION >= 2 - PyVTKClass *class_self = PyObject_New(PyVTKClass, &PyVTKClass_Type); -#else - PyVTKClass *class_self = PyObject_NEW(PyVTKClass, &PyVTKClass_Type); -#endif self = (PyObject *)class_self; class_self->vtk_bases = bases; @@ -565,9 +531,7 @@ PyObject *PyVTKClass_New(vtknewfunc constructor, PyMethodDef *methods, class_self->vtk_cppname = classname; class_self->vtk_mangle = (manglename ? manglename : classname); -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Track(self); -#endif vtkPythonUtil::AddClassToMap(self, classname); } @@ -623,13 +587,7 @@ static PyObject *PyVTKClass_NewSubclass(PyObject *, PyObject *args, return NULL; } -#if PY_VERSION_HEX >= 0x02020000 newclass = PyObject_GC_New(PyVTKClass, &PyVTKClass_Type); -#elif PY_MAJOR_VERSION >= 2 - newclass = PyObject_New(PyVTKClass, &PyVTKClass_Type); -#else - newclass = PyObject_NEW(PyVTKClass, &PyVTKClass_Type); -#endif Py_INCREF(bases); Py_INCREF(attributes); @@ -690,9 +648,7 @@ static PyObject *PyVTKClass_NewSubclass(PyObject *, PyObject *args, newclass->vtk_doc = PyString_FromString(""); } -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Track((PyObject *)newclass); -#endif return (PyObject *)newclass; } diff --git a/Wrapping/PythonCore/PyVTKMutableObject.cxx b/Wrapping/PythonCore/PyVTKMutableObject.cxx index ac61dfdecd6..6dcc22a3915 100644 --- a/Wrapping/PythonCore/PyVTKMutableObject.cxx +++ b/Wrapping/PythonCore/PyVTKMutableObject.cxx @@ -65,7 +65,6 @@ static PyObject *PyVTKMutableObject_CompatibleObject(PyObject *opn) opn = ((PyVTKMutableObject *)opn)->value; Py_INCREF(opn); } -#if PY_VERSION_HEX >= 0x02050000 else if (nb && nb->nb_index) { opn = nb->nb_index(opn); @@ -76,7 +75,6 @@ static PyObject *PyVTKMutableObject_CompatibleObject(PyObject *opn) return NULL; } } -#endif else if (nb && nb->nb_float) { opn = nb->nb_float(opn); @@ -439,7 +437,6 @@ REFOBJECT_UNARYFUNC(Number,Float) // Hex // Oct -#if PY_VERSION_HEX >= 0x02000000 REFOBJECT_INPLACEFUNC(Number,Add) REFOBJECT_INPLACEFUNC(Number,Subtract) REFOBJECT_INPLACEFUNC(Number,Multiply) @@ -451,18 +448,13 @@ REFOBJECT_INPLACEFUNC(Number,Rshift) REFOBJECT_INPLACEFUNC(Number,And) REFOBJECT_INPLACEFUNC(Number,Or) REFOBJECT_INPLACEFUNC(Number,Xor) -#endif -#if PY_VERSION_HEX >= 0x02020000 REFOBJECT_BINARYFUNC(Number,FloorDivide) REFOBJECT_BINARYFUNC(Number,TrueDivide) REFOBJECT_INPLACEFUNC(Number,FloorDivide) REFOBJECT_INPLACEFUNC(Number,TrueDivide) -#endif -#if PY_VERSION_HEX >= 0x02050000 REFOBJECT_UNARYFUNC(Number,Index) -#endif //-------------------------------------------------------------------- static PyNumberMethods PyVTKMutableObject_AsNumber = { @@ -489,7 +481,6 @@ static PyNumberMethods PyVTKMutableObject_AsNumber = { PyVTKMutableObject_Float, // nb_float PyVTKMutableObject_Oct, // nb_oct PyVTKMutableObject_Hex, // nb_hex -#if PY_VERSION_HEX >= 0x02000000 PyVTKMutableObject_InPlaceAdd, // nb_inplace_add PyVTKMutableObject_InPlaceSubtract, // nb_inplace_subtract PyVTKMutableObject_InPlaceMultiply, // nb_inplace_multiply @@ -501,16 +492,11 @@ static PyNumberMethods PyVTKMutableObject_AsNumber = { PyVTKMutableObject_InPlaceAnd, // nb_inplace_and PyVTKMutableObject_InPlaceXor, // nb_inplace_xor PyVTKMutableObject_InPlaceOr, // nb_inplace_or -#endif -#if PY_VERSION_HEX >= 0x02020000 PyVTKMutableObject_FloorDivide, // nb_floor_divide PyVTKMutableObject_TrueDivide, // nb_true_divide PyVTKMutableObject_InPlaceFloorDivide, // nb_inplace_floor_divide PyVTKMutableObject_InPlaceTrueDivide, // nb_inplace_true_divide -#endif -#if PY_VERSION_HEX >= 0x02050000 PyVTKMutableObject_Index, // nb_index -#endif }; @@ -519,11 +505,7 @@ static PyNumberMethods PyVTKMutableObject_AsNumber = { //-------------------------------------------------------------------- // Sequence protocol -#if PY_MAJOR_VERSION >= 2 REFOBJECT_SIZEFUNC(Sequence,Size) -#else -REFOBJECT_SIZEFUNC(Sequence,Length) -#endif REFOBJECT_BINARYFUNC(Sequence,Concat) REFOBJECT_INDEXFUNC(Sequence,Repeat) REFOBJECT_INDEXFUNC(Sequence,GetItem) @@ -531,29 +513,21 @@ REFOBJECT_SLICEFUNC(Sequence,GetSlice) REFOBJECT_INDEXSETFUNC(Sequence,SetItem) REFOBJECT_SLICESETFUNC(Sequence,SetSlice) -#if PY_VERSION_HEX >= 0x02000000 REFOBJECT_INPLACEFUNC(Sequence,Concat) REFOBJECT_INPLACEIFUNC(Sequence,Repeat) -#endif //-------------------------------------------------------------------- static PySequenceMethods PyVTKMutableObject_AsSequence = { -#if PY_MAJOR_VERSION >= 2 PyVTKMutableObject_Size, // sq_length -#else - PyVTKMutableObject_Length, // sq_length -#endif PyVTKMutableObject_Concat, // sq_concat PyVTKMutableObject_Repeat, // sq_repeat PyVTKMutableObject_GetItem, // sq_item PyVTKMutableObject_GetSlice, // sq_slice PyVTKMutableObject_SetItem, // sq_ass_item PyVTKMutableObject_SetSlice, // sq_ass_slice -#if PY_VERSION_HEX >= 0x02000000 0, // sq_contains PyVTKMutableObject_InPlaceConcat, // sq_inplace_concat PyVTKMutableObject_InPlaceRepeat, // sq_inplace_repeat -#endif }; //-------------------------------------------------------------------- @@ -575,11 +549,7 @@ PyVTKMutableObject_SetMapItem(PyObject *ob, PyObject *key, PyObject *o) //-------------------------------------------------------------------- static PyMappingMethods PyVTKMutableObject_AsMapping = { -#if PY_MAJOR_VERSION >= 2 PyVTKMutableObject_Size, // mp_length -#else - PyVTKMutableObject_Length, // mp_length -#endif PyVTKMutableObject_GetMapItem, // mp_subscript PyVTKMutableObject_SetMapItem, // mp_ass_subscript }; @@ -650,13 +620,8 @@ PyVTKMutableObject_GetSegCount(PyObject *op, Py_ssize_t *lenp) return -1; } -#if PY_VERSION_HEX >= 0x02050000 static Py_ssize_t PyVTKMutableObject_GetCharBuf( PyObject *op, Py_ssize_t segment, char **ptrptr) -#else -static Py_ssize_t PyVTKMutableObject_GetCharBuf( - PyObject *op, Py_ssize_t segment, const char **ptrptr) -#endif { char text[80]; PyBufferProcs *pb; @@ -693,11 +658,7 @@ static PyBufferProcs PyVTKMutableObject_AsBuffer = { static void PyVTKMutableObject_Delete(PyObject *ob) { Py_DECREF(((PyVTKMutableObject *)ob)->value); -#if PY_MAJOR_VERSION >= 2 PyObject_Del(ob); -#else - PyMem_DEL(ob); -#endif } static PyObject *PyVTKMutableObject_Repr(PyObject *ob) @@ -725,7 +686,6 @@ static PyObject *PyVTKMutableObject_Str(PyObject *ob) return PyObject_Str(((PyVTKMutableObject *)ob)->value); } -#if PY_VERSION_HEX >= 0x02010000 static PyObject *PyVTKMutableObject_RichCompare( PyObject *ob1, PyObject *ob2, int opid) { @@ -739,91 +699,18 @@ static PyObject *PyVTKMutableObject_RichCompare( } return PyObject_RichCompare(ob1, ob2, opid); } -#else -static int PyVTKMutableObject_Compare(PyObject *ob1, PyObject *ob2) -{ - if (PyVTKMutableObject_Check(ob1)) - { - ob1 = ((PyVTKMutableObject *)ob1)->value; - } - if (PyVTKMutableObject_Check(ob2)) - { - ob2 = ((PyVTKMutableObject *)ob2)->value; - } - return PyObject_Compare(ob1, ob2); -} -#endif static PyObject *PyVTKMutableObject_GetAttr(PyObject *self, PyObject *attr) { char text[128]; char *name = PyString_AsString(attr); PyObject *a; -#if PY_VERSION_HEX < 0x02020000 - PyMethodDef *meth; - - if (name[0] == '_') - { - if (strcmp(name, "__name__") == 0) - { - return PyString_FromString(self->ob_type->tp_name); - } - if (strcmp(name, "__doc__") == 0) - { - return PyString_FromString(self->ob_type->tp_doc); - } - if (strcmp(name,"__methods__") == 0) - { - meth = PyVTKMutableObject_Methods; - PyObject *lst; - int i, n; - - for (n = 0; meth && meth[n].ml_name; n++) - { - ; - } - - if ((lst = PyList_New(n)) != NULL) - { - meth = PyVTKMutableObject_Methods; - for (i = 0; i < n; i++) - { - PyList_SetItem(lst, i, PyString_FromString(meth[i].ml_name)); - } - PyList_Sort(lst); - } - return lst; - } - - if (strcmp(name, "__members__") == 0) - { - PyObject *lst; - if ((lst = PyList_New(4)) != NULL) - { - PyList_SetItem(lst, 0, PyString_FromString("__doc__")); - PyList_SetItem(lst, 1, PyString_FromString("__members__")); - PyList_SetItem(lst, 2, PyString_FromString("__methods__")); - PyList_SetItem(lst, 3, PyString_FromString("__name__")); - } - return lst; - } - } - - for (meth = PyVTKMutableObject_Methods; meth && meth->ml_name; meth++) - { - if (strcmp(name, meth->ml_name) == 0) - { - return PyCFunction_New(meth, self); - } - } -#else a = PyObject_GenericGetAttr(self, attr); if (a || !PyErr_ExceptionMatches(PyExc_AttributeError)) { return a; } PyErr_Clear(); -#endif if (name[0] != '_') { @@ -860,11 +747,7 @@ static PyObject *PyVTKMutableObject_New( if (o) { -#if PY_MAJOR_VERSION >= 2 PyVTKMutableObject *self = PyObject_New(PyVTKMutableObject, &PyVTKMutableObject_Type); -#else - PyVTKMutableObject *self = PyObject_NEW(PyVTKMutableObject, &PyVTKMutableObject_Type); -#endif self->value = o; return (PyObject *)self; } @@ -884,11 +767,7 @@ PyTypeObject PyVTKMutableObject_Type = { 0, // tp_print 0, // tp_getattr 0, // tp_setattr -#if PY_VERSION_HEX >= 0x02010000 0, // tp_compare -#else - PyVTKMutableObject_Compare, // tp_compare -#endif PyVTKMutableObject_Repr, // tp_repr &PyVTKMutableObject_AsNumber, // tp_as_number 0, // tp_as_sequence @@ -903,20 +782,12 @@ PyTypeObject PyVTKMutableObject_Type = { PyVTKMutableObject_GetAttr, // tp_getattro 0, // tp_setattro &PyVTKMutableObject_AsBuffer, // tp_as_buffer -#if PY_VERSION_HEX >= 0x02020000 - Py_TPFLAGS_CHECKTYPES | -#endif - Py_TPFLAGS_DEFAULT, // tp_flags + Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_DEFAULT, // tp_flags (char*)PyVTKMutableObject_Doc, // tp_doc 0, // tp_traverse 0, // tp_clear -#if PY_VERSION_HEX >= 0x02010000 PyVTKMutableObject_RichCompare, // tp_richcompare -#else - 0, // tp_richcompare -#endif 0, // tp_weaklistoffset -#if PY_VERSION_HEX >= 0x02020000 0, // tp_iter 0, // tp_iternext PyVTKMutableObject_Methods, // tp_methods @@ -930,46 +801,22 @@ PyTypeObject PyVTKMutableObject_Type = { 0, // tp_init 0, // tp_alloc PyVTKMutableObject_New, // tp_new -#if PY_VERSION_HEX >= 0x02030000 PyObject_Del, // tp_free -#else - _PyObject_Del, // tp_free -#endif 0, // tp_is_gc 0, // tp_bases 0, // tp_mro 0, // tp_cache 0, // tp_subclasses 0, // tp_weaklist -#endif VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED }; -//-------------------------------------------------------------------- -// Classic new method - -#if PY_VERSION_HEX < 0x02020000 -static PyObject *PyVTKMutableObject_ClassicNew(PyObject *, PyObject *args) -{ - return PyVTKMutableObject_New(PyVTKMutableObject_Type, args, 0); -} - -static PyMethodDef PyVTKMutableObject_NewMethod = - {(char*)"mutable", PyVTKMutableObject_ClassicNew, 1, - (char*)PyVTKMutableObject_Doc } -}; -#endif - //-------------------------------------------------------------------- // Exported method for adding this type to a module's dict void PyVTKAddFile_mutable( PyObject *dict, const char *) { -#if PY_VERSION_HEX < 0x2020000 - PyObject *o = PyCFunction_New(&PyVTKMutableObject_NewMethod, Py_None); -#else PyObject *o = (PyObject *)&PyVTKMutableObject_Type; -#endif if (o && PyDict_SetItemString(dict, (char *)"mutable", o) != 0) { diff --git a/Wrapping/PythonCore/PyVTKObject.cxx b/Wrapping/PythonCore/PyVTKObject.cxx index 426d4bf4e9c..a4fa6b3f78c 100644 --- a/Wrapping/PythonCore/PyVTKObject.cxx +++ b/Wrapping/PythonCore/PyVTKObject.cxx @@ -240,7 +240,6 @@ static PyObject *PyVTKObject_GetAttr(PyObject *op, PyObject *attr) } //-------------------------------------------------------------------- -#if PY_MAJOR_VERSION >= 2 static int PyVTKObject_Traverse(PyObject *o, visitproc visit, void *arg) { PyVTKObject *self = (PyVTKObject *)o; @@ -286,23 +285,18 @@ static int PyVTKObject_Traverse(PyObject *o, visitproc visit, void *arg) return err; } -#endif //-------------------------------------------------------------------- static void PyVTKObject_Delete(PyObject *op) { PyVTKObject *self = (PyVTKObject *)op; -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_UnTrack(op); -#endif -#if PY_VERSION_HEX >= 0x02010000 if (self->vtk_weakreflist != NULL) { PyObject_ClearWeakRefs(op); } -#endif // A python object owning a VTK object reference is getting // destroyed. Remove the python object's VTK object reference. @@ -312,13 +306,7 @@ static void PyVTKObject_Delete(PyObject *op) Py_DECREF(self->vtk_dict); delete [] self->vtk_observers; -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Del(op); -#elif PY_MAJOR_VERSION >= 2 - PyObject_Del(op); -#else - PyMem_DEL(op); -#endif } //-------------------------------------------------------------------- @@ -385,7 +373,6 @@ PyVTKObject_AsBuffer_GetWriteBuf( //-------------------------------------------------------------------- static PyBufferProcs PyVTKObject_AsBuffer = { -#if PY_VERSION_HEX >= 0x02050000 PyVTKObject_AsBuffer_GetReadBuf, // bf_getreadbuffer PyVTKObject_AsBuffer_GetWriteBuf, // bf_getwritebuffer PyVTKObject_AsBuffer_GetSegCount, // bf_getsegcount @@ -394,12 +381,6 @@ static PyBufferProcs PyVTKObject_AsBuffer = { 0, // bf_getbuffer 0 // bf_releasebuffer #endif -#else - PyVTKObject_AsBuffer_GetReadBuf, // bf_getreadbuffer - PyVTKObject_AsBuffer_GetWriteBuf, // bf_getwritebuffer - PyVTKObject_AsBuffer_GetSegCount, // bf_getsegcount - 0, // bf_getcharbuffer -#endif }; //-------------------------------------------------------------------- @@ -424,27 +405,12 @@ PyTypeObject PyVTKObject_Type = { PyVTKObject_GetAttr, // tp_getattro PyVTKObject_SetAttr, // tp_setattro &PyVTKObject_AsBuffer, // tp_as_buffer -#if PY_VERSION_HEX >= 0x02020000 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags -#elif PY_VERSION_HEX >= 0x02010000 - Py_TPFLAGS_HAVE_WEAKREFS, // tp_flags -#else - 0, // tp_flags -#endif (char*)"Use help(x.__class__) to get full documentation.", // tp_doc -#if PY_MAJOR_VERSION >= 2 PyVTKObject_Traverse, // tp_traverse 0, // tp_clear 0, // tp_richcompare -#if PY_VERSION_HEX >= 0x02010000 offsetof(PyVTKObject, vtk_weakreflist),// tp_weaklistoffset -#else - 0, // tp_weaklistoffset -#endif -#else - 0, 0, 0, 0, // reserved -#endif -#if PY_VERSION_HEX >= 0x02020000 0, // tp_iter 0, // tp_iternext 0, // tp_methods @@ -465,7 +431,6 @@ PyTypeObject PyVTKObject_Type = { 0, // tp_cache 0, // tp_subclasses 0, // tp_weaklist -#endif VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED }; @@ -534,27 +499,16 @@ PyObject *PyVTKObject_New( dict = PyDict_New(); } -#if PY_VERSION_HEX >= 0x02020000 PyVTKObject *self = PyObject_GC_New(PyVTKObject, &PyVTKObject_Type); -#elif PY_MAJOR_VERSION >= 2 - PyVTKObject *self = PyObject_New(PyVTKObject, &PyVTKObject_Type); -#else - PyVTKObject *self = PyObject_NEW(PyVTKObject, &PyVTKObject_Type); -#endif self->vtk_ptr = ptr; self->vtk_flags = 0; self->vtk_class = (PyVTKClass *)cls; self->vtk_dict = dict; self->vtk_observers = 0; - -#if PY_VERSION_HEX >= 0x02010000 self->vtk_weakreflist = NULL; -#endif -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Track((PyObject *)self); -#endif // A python object owning a VTK object reference is getting // created. Add the python object's VTK object reference. diff --git a/Wrapping/PythonCore/PyVTKObject.h b/Wrapping/PythonCore/PyVTKObject.h index be0200359ea..bf5f623b2e5 100644 --- a/Wrapping/PythonCore/PyVTKObject.h +++ b/Wrapping/PythonCore/PyVTKObject.h @@ -37,9 +37,7 @@ struct PyVTKObject { vtkObjectBase *vtk_ptr; unsigned long *vtk_observers; unsigned int vtk_flags; -#if PY_VERSION_HEX >= 0x02010000 PyObject *vtk_weakreflist; -#endif }; extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKObject_Type; diff --git a/Wrapping/PythonCore/PyVTKSpecialObject.cxx b/Wrapping/PythonCore/PyVTKSpecialObject.cxx index b6fdff43446..c94a3e1f850 100644 --- a/Wrapping/PythonCore/PyVTKSpecialObject.cxx +++ b/Wrapping/PythonCore/PyVTKSpecialObject.cxx @@ -65,7 +65,6 @@ PyObject *PyVTKSpecialObject_Repr(PyObject *self) PyString_ConcatAndDel(&s, PyString_FromString((char *)name)); PyString_ConcatAndDel(&s, PyString_FromString((char *)")")); -#if PY_VERSION_HEX >= 0x02020000 while (type->tp_base && !type->tp_str) { type = type->tp_base; @@ -86,9 +85,7 @@ PyObject *PyVTKSpecialObject_Repr(PyObject *self) } } // otherwise just print address of object - else -#endif - if (obj->vtk_ptr) + else if (obj->vtk_ptr) { char buf[256]; sprintf(buf, "%p", obj->vtk_ptr); @@ -168,75 +165,6 @@ PyObject *PyVTKSpecialObject_SequenceString(PyObject *self) return s; } -//-------------------------------------------------------------------- -#if PY_VERSION_HEX < 0x02020000 -PyObject *PyVTKSpecialObject_GetAttr(PyObject *self, PyObject *attr) -{ - PyVTKSpecialObject *obj = (PyVTKSpecialObject *)self; - char *name = PyString_AsString(attr); - PyMethodDef *meth; - - if (name[0] == '_') - { - if (strcmp(name, "__name__") == 0) - { - return PyString_FromString(self->ob_type->tp_name); - } - if (strcmp(name, "__doc__") == 0) - { - Py_INCREF(obj->vtk_info->docstring); - return obj->vtk_info->docstring; - } - if (strcmp(name,"__methods__") == 0) - { - meth = obj->vtk_info->methods; - PyObject *lst; - int i, n; - - for (n = 0; meth && meth[n].ml_name; n++) - { - ; - } - - if ((lst = PyList_New(n)) != NULL) - { - meth = obj->vtk_info->methods; - for (i = 0; i < n; i++) - { - PyList_SetItem(lst, i, PyString_FromString(meth[i].ml_name)); - } - PyList_Sort(lst); - } - return lst; - } - - if (strcmp(name, "__members__") == 0) - { - PyObject *lst; - if ((lst = PyList_New(4)) != NULL) - { - PyList_SetItem(lst, 0, PyString_FromString("__doc__")); - PyList_SetItem(lst, 1, PyString_FromString("__members__")); - PyList_SetItem(lst, 2, PyString_FromString("__methods__")); - PyList_SetItem(lst, 3, PyString_FromString("__name__")); - } - return lst; - } - } - - for (meth = obj->vtk_info->methods; meth && meth->ml_name; meth++) - { - if (strcmp(name, meth->ml_name) == 0) - { - return PyCFunction_New(meth, self); - } - } - - PyErr_SetString(PyExc_AttributeError, name); - return NULL; -} -#endif - //-------------------------------------------------------------------- PyObject *PyVTKSpecialObject_New(const char *classname, void *ptr) { @@ -244,11 +172,7 @@ PyObject *PyVTKSpecialObject_New(const char *classname, void *ptr) // but this way of doing things is more dynamic if less efficient PyVTKSpecialType *info = vtkPythonUtil::FindSpecialType(classname); -#if PY_MAJOR_VERSION >= 2 PyVTKSpecialObject *self = PyObject_New(PyVTKSpecialObject, info->py_type); -#else - PyVTKSpecialObject *self = PyObject_NEW(PyVTKSpecialObject, info->py_type); -#endif self->vtk_info = info; self->vtk_ptr = ptr; @@ -270,11 +194,7 @@ PyObject *PyVTKSpecialObject_CopyNew(const char *classname, const void *ptr) return NULL; } -#if PY_MAJOR_VERSION >= 2 PyVTKSpecialObject *self = PyObject_New(PyVTKSpecialObject, info->py_type); -#else - PyVTKSpecialObject *self = PyObject_NEW(PyVTKSpecialObject, info->py_type); -#endif self->vtk_info = info; self->vtk_ptr = info->copy_func(ptr); @@ -300,12 +220,7 @@ PyObject *PyVTKSpecialType_New(PyTypeObject *pytype, newmethod->ml_doc = PyString_AsString(info->docstring); } - // Return a generator function for python < 2.2, - // return the type object itself for python >= 2.2 -#if PY_VERSION_HEX < 0x2020000 - return PyCFunction_New(newmethod, Py_None); -#else + // Return the type object PyType_Ready(pytype); return (PyObject *)pytype; -#endif } diff --git a/Wrapping/PythonCore/PyVTKSpecialObject.h b/Wrapping/PythonCore/PyVTKSpecialObject.h index bb6a4deb5d2..85bd507da32 100644 --- a/Wrapping/PythonCore/PyVTKSpecialObject.h +++ b/Wrapping/PythonCore/PyVTKSpecialObject.h @@ -83,11 +83,6 @@ PyObject *PyVTKSpecialObject_Repr(PyObject *self); VTKWRAPPINGPYTHONCORE_EXPORT PyObject *PyVTKSpecialObject_SequenceString(PyObject *self); - -#if PY_VERSION_HEX < 0x02020000 -VTKWRAPPINGPYTHONCORE_EXPORT -PyObject *PyVTKSpecialObject_GetAttr(PyObject *self, PyObject *attr); -#endif } #endif diff --git a/Wrapping/PythonCore/PyVTKTemplate.cxx b/Wrapping/PythonCore/PyVTKTemplate.cxx index d06ba6f409b..3eaed112cd5 100644 --- a/Wrapping/PythonCore/PyVTKTemplate.cxx +++ b/Wrapping/PythonCore/PyVTKTemplate.cxx @@ -129,11 +129,7 @@ static Py_ssize_t PyVTKTemplate_Size(PyObject *ob) { ob = ((PyVTKTemplate *)ob)->dict; -#if PY_MAJOR_VERSION >= 2 return PyObject_Size(ob); -#else - return PyObject_Length(ob); -#endif } static PyObject * @@ -239,7 +235,6 @@ static PyMappingMethods PyVTKTemplate_AsMapping = { }; //-------------------------------------------------------------------- -#if PY_MAJOR_VERSION >= 2 static int PyVTKTemplate_Traverse(PyObject *o, visitproc visit, void *arg) { PyVTKTemplate *self = (PyVTKTemplate *)o; @@ -260,25 +255,16 @@ static int PyVTKTemplate_Traverse(PyObject *o, visitproc visit, void *arg) return err; } -#endif //-------------------------------------------------------------------- static void PyVTKTemplate_Delete(PyObject *op) { -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_UnTrack(op); -#endif Py_DECREF(((PyVTKTemplate *)op)->dict); Py_DECREF(((PyVTKTemplate *)op)->doc); -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Del(op); -#elif PY_MAJOR_VERSION >= 2 - PyObject_Del(op); -#else - PyMem_DEL(op); -#endif } //-------------------------------------------------------------------- @@ -367,16 +353,12 @@ PyTypeObject PyVTKTemplate_Type = { PyVTKTemplate_GetAttr, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer -#if PY_VERSION_HEX >= 0x02020000 - Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_HAVE_GC | -#endif - Py_TPFLAGS_DEFAULT, // tp_flags + Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_DEFAULT, // tp_flags (char*)PyVTKTemplate_Doc, // tp_doc PyVTKTemplate_Traverse, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset -#if PY_VERSION_HEX >= 0x02020000 0, // tp_iter 0, // tp_iternext PyVTKTemplate_Methods, // tp_methods @@ -390,18 +372,13 @@ PyTypeObject PyVTKTemplate_Type = { 0, // tp_init 0, // tp_alloc 0, // tp_new -#if PY_VERSION_HEX >= 0x02030000 PyObject_Del, // tp_free -#else - _PyObject_Del, // tp_free -#endif 0, // tp_is_gc 0, // tp_bases 0, // tp_mro 0, // tp_cache 0, // tp_subclasses 0, // tp_weaklist -#endif VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED }; @@ -412,13 +389,7 @@ PyObject *PyVTKTemplate_New(const char *name, const char *modulename, PyObject *doc = vtkPythonUtil::BuildDocString(docstring); PyObject *dict = PyDict_New(); -#if PY_VERSION_HEX >= 0x02020000 PyVTKTemplate *op = PyObject_GC_New(PyVTKTemplate, &PyVTKTemplate_Type); -#elif PY_MAJOR_VERSION >= 2 - PyVTKTemplate *op = PyObject_New(PyVTKTemplate, &PyVTKTemplate_Type); -#else - PyVTKTemplate *op = PyObject_NEW(PyVTKTemplate, &PyVTKTemplate_Type); -#endif PyObject *self = (PyObject *)op; op->dict = dict; @@ -426,9 +397,7 @@ PyObject *PyVTKTemplate_New(const char *name, const char *modulename, op->name = name; op->module = modulename; -#if PY_VERSION_HEX >= 0x02020000 PyObject_GC_Track(self); -#endif return self; } diff --git a/Wrapping/PythonCore/vtkPythonArgs.cxx b/Wrapping/PythonCore/vtkPythonArgs.cxx index 6203ab886da..96ab769b317 100644 --- a/Wrapping/PythonCore/vtkPythonArgs.cxx +++ b/Wrapping/PythonCore/vtkPythonArgs.cxx @@ -32,7 +32,6 @@ resulting in wrapper code that is faster and more compact. // on unsigned values. // Macro to mimic a check done in PyArg_ParseTuple -#if PY_VERSION_HEX >= 0x02030000 #define VTK_PYTHON_FLOAT_CHECK()\ if (PyFloat_Check(o)) \ { \ @@ -40,9 +39,6 @@ resulting in wrapper code that is faster and more compact. (char *)"integer argument expected, got float"); \ return false; \ } -#else -#define VTK_PYTHON_FLOAT_CHECK() -#endif inline bool vtkPythonGetValue(PyObject *o, long &a) @@ -58,31 +54,15 @@ bool vtkPythonGetValue(PyObject *o, unsigned long &a) { VTK_PYTHON_FLOAT_CHECK(); -#if PY_VERSION_HEX >= 0x02020000 && PY_VERSION_HEX < 0x2040000 - if (PyInt_Check(o)) - { -#endif -#if PY_VERSION_HEX < 0x2040000 - long l = PyInt_AsLong(o); - if (l < 0) - { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned integer"); - return false; - } - a = static_cast<unsigned long>(l); -#endif -#if PY_VERSION_HEX >= 0x02020000 && PY_VERSION_HEX < 0x2040000 - } - else + long l = PyInt_AsLong(o); + if (l < 0) { -#endif -#if PY_VERSION_HEX >= 0x2020000 - a = PyLong_AsUnsignedLong(o); -#endif -#if PY_VERSION_HEX >= 0x02020000 && PY_VERSION_HEX < 0x2040000 + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned integer"); + return false; } -#endif + a = static_cast<unsigned long>(l); + a = PyLong_AsUnsignedLong(o); return (static_cast<long>(a) != -1 || !PyErr_Occurred()); } @@ -110,36 +90,22 @@ bool vtkPythonGetUnsignedLongLongValue(PyObject *o, T &a) #else unsigned long i; #endif -#if PY_VERSION_HEX >= 0x02020000 - if (PyInt_Check(o)) + long l = PyInt_AsLong(o); + if (l < 0) { -#endif - long l = PyInt_AsLong(o); - if (l < 0) - { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return false; - } + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return false; + } #ifdef PY_LONG_LONG - i = static_cast<unsigned PY_LONG_LONG>(l); + i = static_cast<unsigned PY_LONG_LONG>(l); #else - i = static_cast<unsigned long>(l); + i = static_cast<unsigned long>(l); #endif -#if PY_VERSION_HEX >= 0x02020000 - } - else - { -#endif -#if PY_VERSION_HEX >= 0x2020000 #ifdef PY_LONG_LONG - i = PyLong_AsUnsignedLongLong(o); + i = PyLong_AsUnsignedLongLong(o); #else - i = PyLong_AsUnsignedLong(o); -#endif -#endif -#if PY_VERSION_HEX >= 0x02020000 - } + i = PyLong_AsUnsignedLong(o); #endif a = static_cast<T>(i); return (static_cast<int>(i) != -1 || !PyErr_Occurred()); @@ -553,11 +519,7 @@ bool vtkPythonGetArray(PyObject *o, T *a, int n) } else if (PySequence_Check(o)) { -#if PY_MAJOR_VERSION >= 2 m = PySequence_Size(o); -#else - m = PySequence_Length(o); -#endif if (m == n) { bool r = true; @@ -626,11 +588,7 @@ bool vtkPythonGetNArray(PyObject *o, T *a, int ndim, const int *dims) } else if (PySequence_Check(o)) { -#if PY_MAJOR_VERSION >= 2 m = PySequence_Size(o); -#else - m = PySequence_Length(o); -#endif if (m == n) { bool r = true; @@ -694,11 +652,7 @@ bool vtkPythonSetArray(PyObject *o, const T *a, int n) } else if (PySequence_Check(o)) { -#if PY_MAJOR_VERSION >= 2 m = PySequence_Size(o); -#else - m = PySequence_Length(o); -#endif if (m == n) { bool r = true; @@ -774,11 +728,7 @@ bool vtkPythonSetNArray( } else if (PySequence_Check(o)) { -#if PY_MAJOR_VERSION >= 2 m = PySequence_Size(o); -#else - m = PySequence_Length(o); -#endif if (m == n) { bool r = true; diff --git a/Wrapping/PythonCore/vtkPythonArgs.h b/Wrapping/PythonCore/vtkPythonArgs.h index 1d47a74660a..be0bf4e5390 100644 --- a/Wrapping/PythonCore/vtkPythonArgs.h +++ b/Wrapping/PythonCore/vtkPythonArgs.h @@ -736,11 +736,7 @@ PyObject *vtkPythonArgs::BuildValue(double a) inline PyObject *vtkPythonArgs::BuildValue(bool a) { -#if PY_VERSION_HEX >= 0x02030000 return PyBool_FromLong((long)a); -#else - return PyInt_FromLong((long)a); -#endif } inline diff --git a/Wrapping/PythonCore/vtkPythonCommand.cxx b/Wrapping/PythonCore/vtkPythonCommand.cxx index 33ee9f4bd2f..c43f561ecc0 100644 --- a/Wrapping/PythonCore/vtkPythonCommand.cxx +++ b/Wrapping/PythonCore/vtkPythonCommand.cxx @@ -83,10 +83,7 @@ void vtkPythonCommand::Execute(vtkObject *ptr, unsigned long eventtype, } #ifndef VTK_NO_PYTHON_THREADS -#if (PY_MAJOR_VERSION > 2) || \ -((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION >= 3)) PyGILState_STATE state = PyGILState_Ensure(); -#endif #endif // If a threadstate has been set using vtkPythonCommand::SetThreadState, @@ -243,9 +240,6 @@ void vtkPythonCommand::Execute(vtkObject *ptr, unsigned long eventtype, } #ifndef VTK_NO_PYTHON_THREADS -#if (PY_MAJOR_VERSION > 2) || \ -((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION >= 3)) PyGILState_Release(state); #endif -#endif } diff --git a/Wrapping/PythonCore/vtkPythonOverload.cxx b/Wrapping/PythonCore/vtkPythonOverload.cxx index e5c61dacdcb..e1be509ba5d 100644 --- a/Wrapping/PythonCore/vtkPythonOverload.cxx +++ b/Wrapping/PythonCore/vtkPythonOverload.cxx @@ -223,7 +223,6 @@ int vtkPythonOverload::CheckArg( case 'k': case 'i': case 'I': -#if PY_VERSION_HEX >= 0x02030000 if (PyBool_Check(arg)) { penalty = VTK_PYTHON_GOOD_MATCH; @@ -232,9 +231,7 @@ int vtkPythonOverload::CheckArg( penalty++; } } - else -#endif - if (PyInt_Check(arg)) + else if (PyInt_Check(arg)) { #if VTK_SIZEOF_LONG == VTK_SIZEOF_INT if (*format != 'i') @@ -405,9 +402,7 @@ int vtkPythonOverload::CheckArg( // booleans if (name[0] == 'b' && strcmp(classname, "bool") == 0) { -#if PY_VERSION_HEX >= 0x02030000 if (!PyBool_Check(arg)) -#endif { penalty = VTK_PYTHON_NEEDS_CONVERSION; int tmpi = PyObject_IsTrue(arg); @@ -502,7 +497,6 @@ int vtkPythonOverload::CheckArg( // Check for an exact match if (strncmp(arg->ob_type->tp_name, classname, 127) != 0) { -#if PY_VERSION_HEX >= 0x02020000 // Check superclasses PyTypeObject *basetype = arg->ob_type->tp_base; penalty = VTK_PYTHON_GOOD_MATCH; @@ -513,7 +507,6 @@ int vtkPythonOverload::CheckArg( basetype = basetype->tp_base; } if (!basetype) -#endif { // If it didn't match, then maybe conversion is possible penalty = VTK_PYTHON_NEEDS_CONVERSION; @@ -548,7 +541,6 @@ int vtkPythonOverload::CheckArg( // Check for an exact match if (strncmp(arg->ob_type->tp_name, classname, 127) != 0) { -#if PY_VERSION_HEX >= 0x02020000 // Check superclasses PyTypeObject *basetype = arg->ob_type->tp_base; penalty = VTK_PYTHON_GOOD_MATCH; @@ -559,7 +551,6 @@ int vtkPythonOverload::CheckArg( basetype = basetype->tp_base; } if (!basetype) -#endif { penalty = VTK_PYTHON_INCOMPATIBLE; } @@ -661,11 +652,7 @@ int vtkPythonOverload::CheckArg( PyObject *sarg = arg; while (PySequence_Check(sarg)) { -#if PY_MAJOR_VERSION >= 2 Py_ssize_t m = PySequence_Size(sarg); -#else - Py_ssize_t m = PySequence_Length(sarg); -#endif if (m <= 0 || (sizeneeded != 0 && m != sizeneeded)) { break; diff --git a/Wrapping/PythonCore/vtkPythonUtil.cxx b/Wrapping/PythonCore/vtkPythonUtil.cxx index bd79c093644..680dfc69716 100644 --- a/Wrapping/PythonCore/vtkPythonUtil.cxx +++ b/Wrapping/PythonCore/vtkPythonUtil.cxx @@ -769,7 +769,6 @@ void *vtkPythonUtil::GetPointerFromSpecialObject( return ((PyVTKSpecialObject *)obj)->vtk_ptr; } -#if PY_VERSION_HEX >= 0x02020000 // check superclasses for (PyTypeObject *basetype = obj->ob_type->tp_base; basetype != NULL; @@ -780,7 +779,6 @@ void *vtkPythonUtil::GetPointerFromSpecialObject( return ((PyVTKSpecialObject *)obj)->vtk_ptr; } } -#endif if (PyVTKObject_Check(obj)) { @@ -1011,11 +1009,7 @@ long vtkPythonUtil::VariantHash(const vtkVariant *v) { case VTK_OBJECT: { -#if PY_MAJOR_VERSION >= 2 h = _Py_HashPointer(v->ToVTKObject()); -#else - h = (long)(v->ToVTKObject()); -#endif break; } @@ -1064,10 +1058,7 @@ void vtkPythonVoidFunc(void *arg) } #ifndef VTK_NO_PYTHON_THREADS -#if (PY_MAJOR_VERSION > 2) || \ -((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION >= 3)) PyGILState_STATE state = PyGILState_Ensure(); -#endif #endif arglist = Py_BuildValue((char*)"()"); @@ -1090,11 +1081,8 @@ void vtkPythonVoidFunc(void *arg) } #ifndef VTK_NO_PYTHON_THREADS -#if (PY_MAJOR_VERSION > 2) || \ -((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION >= 3)) PyGILState_Release(state); #endif -#endif } //-------------------------------------------------------------------- @@ -1111,10 +1099,7 @@ void vtkPythonVoidFuncArgDelete(void *arg) } #ifndef VTK_NO_PYTHON_THREADS -#if (PY_MAJOR_VERSION > 2) || \ -((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION >= 3)) PyGILState_STATE state = PyGILState_Ensure(); -#endif #endif if (func) @@ -1123,11 +1108,8 @@ void vtkPythonVoidFuncArgDelete(void *arg) } #ifndef VTK_NO_PYTHON_THREADS -#if (PY_MAJOR_VERSION > 2) || \ -((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION >= 3)) PyGILState_Release(state); #endif -#endif } diff --git a/Wrapping/PythonCore/vtkPythonUtil.h b/Wrapping/PythonCore/vtkPythonUtil.h index ba0a396e474..928ca386f72 100644 --- a/Wrapping/PythonCore/vtkPythonUtil.h +++ b/Wrapping/PythonCore/vtkPythonUtil.h @@ -197,22 +197,6 @@ extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *); 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 0, #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \ 0, 0, -#elif PY_VERSION_HEX >= 0x02030000 -#define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ - 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, -#define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \ - 0, -#elif PY_VERSION_HEX >= 0x02020000 -#define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ - 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, -#define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED -#else -#define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED -#define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED -#endif - -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; #endif #endif diff --git a/Wrapping/Tools/vtkWrapPythonConstant.c b/Wrapping/Tools/vtkWrapPythonConstant.c index 399ca832365..461ae594fdb 100644 --- a/Wrapping/Tools/vtkWrapPythonConstant.c +++ b/Wrapping/Tools/vtkWrapPythonConstant.c @@ -186,12 +186,8 @@ void vtkWrapPython_AddConstantHelper( case VTK_PARSE_BOOL: fprintf(fp, - "#if PY_VERSION_HEX >= 0x02030000\n" - "%s%s = PyBool_FromLong((long)(%s));\n" - "#else\n" - "%s%s = PyInt_FromLong((long)(%s));\n" - "#endif\n", - indent, objvar, valstring, indent, objvar, valstring); + "%s%s = PyBool_FromLong((long)(%s));\n", + indent, objvar, valstring); objcreated = 1; break; } diff --git a/Wrapping/Tools/vtkWrapPythonType.c b/Wrapping/Tools/vtkWrapPythonType.c index 62d80d032da..d9369f3dba8 100644 --- a/Wrapping/Tools/vtkWrapPythonType.c +++ b/Wrapping/Tools/vtkWrapPythonType.c @@ -69,9 +69,8 @@ static void vtkWrapPython_NewDeleteProtocol( } } - /* the new method for python versions >= 2.2 */ + /* the "new" method */ fprintf(fp, - "#if PY_VERSION_HEX >= 0x02020000\n" "static PyObject *\n" "Py%s_New(PyTypeObject *, PyObject *args, PyObject *kwds)\n" "{\n" @@ -84,7 +83,6 @@ static void vtkWrapPython_NewDeleteProtocol( "\n" " return Py%s_%*.*s(NULL, args);\n" "}\n" - "#endif\n" "\n", classname, classname, (int)n, (int)n, constructor); @@ -94,11 +92,7 @@ static void vtkWrapPython_NewDeleteProtocol( "{\n" " PyVTKSpecialObject *obj = (PyVTKSpecialObject *)self;\n" " delete static_cast<%s *>(obj->vtk_ptr);\n" - "#if PY_MAJOR_VERSION >= 2\n" " PyObject_Del(self);\n" - "#else\n" - " PyMem_DEL(self);\n" - "#endif\n" "}\n" "\n", classname, data->Name); @@ -237,7 +231,6 @@ static void vtkWrapPython_RichCompareProtocol( info->has_compare = 1; fprintf(fp, - "#if PY_VERSION_HEX >= 0x02010000\n" "static PyObject *Py%s_RichCompare(\n" " PyObject *o1, PyObject *o2, int opid)\n" "{\n" @@ -324,20 +317,9 @@ static void vtkWrapPython_RichCompareProtocol( " return NULL;\n" " }\n" "\n" - "#if PY_VERSION_HEX >= 0x02030000\n" " // avoids aliasing issues with Py_INCREF(Py_False)\n" " return PyBool_FromLong((long)result);\n" - "#else\n" - " if (result == 0)\n" - " {\n" - " Py_INCREF(Py_False);\n" - " return Py_False;\n" - " }\n" - " Py_INCREF(Py_True);\n" - " return Py_True;\n" - "#endif\n" "}\n" - "#endif\n" "\n"); } } @@ -503,10 +485,8 @@ static void vtkWrapPython_SequenceProtocol( fprintf(fp, " 0, // sq_ass_slice\n" " 0, // sq_contains\n" - "#if PY_VERSION_HEX >= 0x2000000\n" " 0, // sq_inplace_concat\n" " 0, // sq_inplace_repeat\n" - "#endif\n" "};\n\n"); } } @@ -754,11 +734,7 @@ void vtkWrapPython_GenerateSpecialType( } fprintf(fp, - "#if PY_VERSION_HEX >= 0x02020000\n" " PyObject_GenericGetAttr, // tp_getattro\n" - "#else\n" - " PyVTKSpecialObject_GetAttr, // tp_getattro\n" - "#endif\n" " 0, // tp_setattro\n" " 0, // tp_as_buffer\n" " Py_TPFLAGS_DEFAULT, // tp_flags\n" @@ -769,11 +745,7 @@ void vtkWrapPython_GenerateSpecialType( if (info.has_compare) { fprintf(fp, - "#if PY_VERSION_HEX >= 0x02010000\n" - " Py%s_RichCompare, // tp_richcompare\n" - "#else\n" - " 0, // tp_richcompare\n" - "#endif\n", + " Py%s_RichCompare, // tp_richcompare\n", classname); } else @@ -784,7 +756,6 @@ void vtkWrapPython_GenerateSpecialType( fprintf(fp, " 0, // tp_weaklistoffset\n" - "#if PY_VERSION_HEX >= 0x02020000\n" " 0, // tp_iter\n" " 0, // tp_iternext\n"); @@ -815,11 +786,7 @@ void vtkWrapPython_GenerateSpecialType( " 0, // tp_init\n" " 0, // tp_alloc\n" " Py%s_New, // tp_new\n" - "#if PY_VERSION_HEX >= 0x02030000\n" " PyObject_Del, // tp_free\n" - "#else\n" - " _PyObject_Del, // tp_free\n" - "#endif\n" " 0, // tp_is_gc\n", classname); @@ -829,8 +796,7 @@ void vtkWrapPython_GenerateSpecialType( " 0, // tp_mro\n" " 0, // tp_cache\n" " 0, // tp_subclasses\n" - " 0, // tp_weaklist\n" - "#endif\n"); + " 0, // tp_weaklist\n"); /* internal struct members */ fprintf(fp, -- GitLab