diff options
author | Mark Spruiell <mes@zeroc.com> | 2017-03-17 16:48:03 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2017-03-17 16:48:03 -0700 |
commit | 7109cbfd3cf69163b6501619277f38c1d08cbef0 (patch) | |
tree | 2af8f6aed06d37e8bae1a4083ff8f1c67b9a9a33 /python/modules | |
parent | IceGridGUI proguard warning extra fixes (diff) | |
download | ice-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.cpp | 24 |
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 */ |