summaryrefslogtreecommitdiff
path: root/python/modules
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2017-03-17 16:48:03 -0700
committerMark Spruiell <mes@zeroc.com>2017-03-17 16:48:03 -0700
commit7109cbfd3cf69163b6501619277f38c1d08cbef0 (patch)
tree2af8f6aed06d37e8bae1a4083ff8f1c67b9a9a33 /python/modules
parentIceGridGUI proguard warning extra fixes (diff)
downloadice-7109cbfd3cf69163b6501619277f38c1d08cbef0.tar.bz2
ice-7109cbfd3cf69163b6501619277f38c1d08cbef0.tar.xz
ice-7109cbfd3cf69163b6501619277f38c1d08cbef0.zip
Add connection hashing in Python
Diffstat (limited to 'python/modules')
-rw-r--r--python/modules/IcePy/Connection.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/python/modules/IcePy/Connection.cpp b/python/modules/IcePy/Connection.cpp
index 69caaaeacb3..34d296307f2 100644
--- a/python/modules/IcePy/Connection.cpp
+++ b/python/modules/IcePy/Connection.cpp
@@ -294,6 +294,28 @@ connectionCompare(ConnectionObject* c1, PyObject* other, int op)
#ifdef WIN32
extern "C"
#endif
+static long
+connectionHash(ConnectionObject* self)
+{
+#if defined(_MSC_VER) && defined(_WIN64)
+ //
+ // Hash a 64-bit pointer into a 32-bit long.
+ //
+ unsigned long long addr = reinterpret_cast<long>((*self->connection).get());
+ unsigned long low = static_cast<unsigned long>(addr);
+ unsigned long hi = static_cast<unsigned long>(addr >> 32);
+ unsigned long hash = 5381;
+ hash = ((hash << 5) + hash) ^ (2654435761u * low);
+ hash = ((hash << 5) + hash) ^ (2654435761u * hi);
+ return static_cast<long>(hash);
+#else
+ return reinterpret_cast<long>((*self->connection).get());
+#endif
+}
+
+#ifdef WIN32
+extern "C"
+#endif
static PyObject*
connectionClose(ConnectionObject* self, PyObject* args)
{
@@ -1160,7 +1182,7 @@ PyTypeObject ConnectionType =
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
- 0, /* tp_hash */
+ reinterpret_cast<hashfunc>(connectionHash), /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */