From: Michael Wallner Date: Wed, 14 Oct 2020 09:00:58 +0000 (+0200) Subject: attempt to fix murmur on big endian X-Git-Tag: 1.1.0-beta1~222 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a7998e86ec86a8e76323597dd024432643ab2067;p=awesomized%2Flibmemcached attempt to fix murmur on big endian --- diff --git a/src/libhashkit/murmur.cc b/src/libhashkit/murmur.cc index 4ff0f7c6..c1451639 100644 --- a/src/libhashkit/murmur.cc +++ b/src/libhashkit/murmur.cc @@ -56,6 +56,10 @@ #ifdef HAVE_MURMUR_HASH +#ifdef BYTESWAP_HEADER +# include BYTESWAP_HEADER +#endif + #include uint32_t hashkit_murmur(const char *key, size_t length, void *context) @@ -82,14 +86,9 @@ uint32_t hashkit_murmur(const char *key, size_t length, void *context) while(length >= 4) { uint32_t k; -#if WORDS_BIGENDIAN - k = (data[0]<<24) - | (data[1]<<16) - | (data[2]<<8) - | (data[3]) - ; -#else memcpy(&k, data, sizeof(k)); +#if WORDS_BIGENDIAN + k = BYTESWAP_32(k); #endif k *= m; @@ -104,21 +103,15 @@ uint32_t hashkit_murmur(const char *key, size_t length, void *context) } // Handle the last few bytes of the input array - - switch(length) - { + if (length) { + uint32_t k = 0; + memcpy(&k, data, length); #if WORDS_BIGENDIAN - case 3: h ^= ((uint32_t)data[2]) << 8; /* fall through */ - case 2: h ^= ((uint32_t)data[1]) << 16; /* fall through */ - case 1: h ^= ((uint32_t)data[0]) << 24; -#else - case 3: h ^= ((uint32_t)data[2]) << 16; /* fall through */ - case 2: h ^= ((uint32_t)data[1]) << 8; /* fall through */ - case 1: h ^= data[0]; + k = BYTESWAP_32(k); #endif - h *= m; - default: break; - }; + h ^= k; + h *= m; + } /* Do a few final mixes of the hash to ensure the last few bytes are diff --git a/src/mem_config.h.in b/src/mem_config.h.in index f761ade0..2048e991 100644 --- a/src/mem_config.h.in +++ b/src/mem_config.h.in @@ -12,6 +12,7 @@ #cmakedefine HAVE_ABI____CXA_DEMANGLE 1 #cmakedefine HAVE_BACKTRACE 1 +#cmakedefine HAVE_BYTESWAP 1 #cmakedefine HAVE_ALLOCA_H 1 #cmakedefine HAVE_ARPA_INET_H 1 #cmakedefine HAVE_DLFCN_H 1 @@ -74,4 +75,9 @@ # define BACKTRACE_HEADER <@Backtrace_HEADER@> #endif +#if HAVE_BYTESWAP +# define BYTESWAP_32 @BYTESWAP_32@ +# cmakedefine BYTESWAP_HEADER <@BYTESWAP_HEADER@> +#endif + #define HAVE_LIBMEMCACHED 1