From 42b1fbaebaa58aeb9d0f37b6bb5315b4c219ee67 Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Tue, 11 Jul 2017 15:29:09 -0400 Subject: [PATCH 1/2] fix murmur3 on big-endian systems --- CHANGELOG.rst | 1 + cassandra/murmur3.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 56c9c585..e28afe80 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ Bug Fixes * Installation doesn't always fall back to no cython in Windows (PYTHON-763) * Avoid to replace a connection that is supposed to shutdown (PYTHON-772) * request_ids may not be returned to the pool (PYTHON-739) +* Fix murmur3 on big-endian systems (PYTHON-653) Other ----- diff --git a/cassandra/murmur3.py b/cassandra/murmur3.py index 61180c01..c1d5ab32 100644 --- a/cassandra/murmur3.py +++ b/cassandra/murmur3.py @@ -7,7 +7,7 @@ def body_and_tail(data): nblocks = l // 16 tail = l % 16 if nblocks: - return struct.unpack_from('qq' * nblocks, data), struct.unpack_from('b' * tail, data, -tail), l + return struct.unpack_from('<' + ('qq' * nblocks), data), struct.unpack_from('b' * tail, data, -tail), l else: return tuple(), struct.unpack_from('b' * tail, data, -tail), l From b349ecbf699e8f6a5e8aacf893383a7e6679ac0a Mon Sep 17 00:00:00 2001 From: Jim Witschey Date: Wed, 12 Jul 2017 10:24:03 -0400 Subject: [PATCH 2/2] explain use of byte-order sigil --- cassandra/murmur3.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cassandra/murmur3.py b/cassandra/murmur3.py index c1d5ab32..7c8d641b 100644 --- a/cassandra/murmur3.py +++ b/cassandra/murmur3.py @@ -7,6 +7,8 @@ def body_and_tail(data): nblocks = l // 16 tail = l % 16 if nblocks: + # we use '<', specifying little-endian byte order for data bigger than + # a byte so behavior is the same on little- and big-endian platforms return struct.unpack_from('<' + ('qq' * nblocks), data), struct.unpack_from('b' * tail, data, -tail), l else: return tuple(), struct.unpack_from('b' * tail, data, -tail), l