summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-10-14 15:24:13 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-10-14 15:24:13 -0300
commit4ec9ca59a505eecdc7c1a7cd844b2340a5caf534 (patch)
treeb1291384ce0f84961429f6d57a0eabec2ae5adb4 /libshiboken
parent60807a3d1e3d8e6ba722ec59a0e5f7b0b0c753a5 (diff)
downloadshiboken-4ec9ca59a505eecdc7c1a7cd844b2340a5caf534.tar.gz
shiboken-4ec9ca59a505eecdc7c1a7cd844b2340a5caf534.tar.xz
shiboken-4ec9ca59a505eecdc7c1a7cd844b2340a5caf534.zip
Fixed regression that made enums not hashable.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/sbkenum.cpp6
-rw-r--r--libshiboken/sbkpython.h2
2 files changed, 7 insertions, 1 deletions
diff --git a/libshiboken/sbkenum.cpp b/libshiboken/sbkenum.cpp
index 0304a1a9..e6da02d7 100644
--- a/libshiboken/sbkenum.cpp
+++ b/libshiboken/sbkenum.cpp
@@ -230,7 +230,10 @@ enum_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_FALSE;
}
-
+static Py_hash_t enum_hash(PyObject* pyObj)
+{
+ return PyObject_Hash(reinterpret_cast<SbkEnumObject*>(pyObj)->ob_name);
+}
static PyGetSetDef SbkEnumGetSetList[] = {
{const_cast<char*>("name"), &SbkEnumObject_name},
@@ -507,6 +510,7 @@ PyTypeObject* newTypeWithName(const char* name, const char* cppName)
type->tp_new = SbkEnum_tp_new;
type->tp_as_number = &enum_as_number;
type->tp_richcompare = &enum_richcompare;
+ type->tp_hash = &enum_hash;
DeclaredEnumTypes::instance().addEnumType(type, cppName);
return type;
diff --git a/libshiboken/sbkpython.h b/libshiboken/sbkpython.h
index d269c7e9..850f122f 100644
--- a/libshiboken/sbkpython.h
+++ b/libshiboken/sbkpython.h
@@ -49,6 +49,8 @@
#define SBK_NB_BOOL(x) (x).nb_nonzero
#define SBK_STR_NAME "str"
#define SBK_PyMethod_New(X, Y) PyMethod_New(X, Y, (PyObject*)Py_TYPE(Y))
+
+ #define Py_hash_t long
#endif
#endif