From aea226869423e51d4748b3c11f393cd4c7f4fdfc Mon Sep 17 00:00:00 2001 From: David Gobbi <david.gobbi@gmail.com> Date: Tue, 30 Apr 2013 13:06:53 -0600 Subject: [PATCH] BUG 14037: Add hash function to PyVTKClass type. In Python 2.7, python was calling PyType_Ready() on the PyVTKClass type in order to get its superclasses whenever hash() was called. This raised an exception because this type predates the type/class refinements that occurred in python 2.2. A simple fix is to add tp_hash to the type. Change-Id: I9f2ec46839bd8409bbc3bfadd3a7ac8791d36ca3 --- Wrapping/PythonCore/PyVTKClass.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Wrapping/PythonCore/PyVTKClass.cxx b/Wrapping/PythonCore/PyVTKClass.cxx index c15aa840872..39c18cc147c 100644 --- a/Wrapping/PythonCore/PyVTKClass.cxx +++ b/Wrapping/PythonCore/PyVTKClass.cxx @@ -55,6 +55,17 @@ static PyObject *PyVTKClass_Repr(PyObject *op) return PyString_FromString(buf); } +//-------------------------------------------------------------------- +static long PyVTKClass_Hash(PyObject *op) +{ + size_t y = reinterpret_cast<size_t>(op); + y = (y >> 4) | (y << (8 * sizeof(op) - 4)); + long x = static_cast<long>(y); + if (x == -1) { x = -2; } + + return x; +} + //-------------------------------------------------------------------- static PyObject *PyVTKClass_Call(PyObject *op, PyObject *arg, PyObject *kw) { @@ -398,7 +409,7 @@ PyTypeObject PyVTKClass_Type = { 0, // tp_as_number 0, // tp_as_sequence 0, // tp_as_mapping - 0, // tp_hash + PyVTKClass_Hash, // tp_hash PyVTKClass_Call, // tp_call PyVTKClass_String, // tp_string PyVTKClass_GetAttr, // tp_getattro -- GitLab