Skip to content

Commit 6a0bccb

Browse files
Roytakmichalvasko
authored andcommitted
ht BUGFIX 32-bit system compatibility
XXH3_64bits_withSeed may not be available on some 32-bit systems, so use XXH32 instead, since the functions return 32bits anyway
1 parent b71ebc8 commit 6a0bccb

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ if(XXHASH_FOUND)
422422
include_directories(${XXHASH_INCLUDE_DIR})
423423
target_link_libraries(yang ${XXHASH_LIBRARY})
424424
message(STATUS "Hash algorithm: xxhash")
425+
if (HAVE_XXH3_64BITS_WITHSEED)
426+
# for 32-bit system compatibility, this may not be available there, so use XXH32 instead
427+
add_definitions(-DLY_XXH3_64BITS_WITHSEED)
428+
endif()
425429
else()
426430
message(STATUS "Hash algorithm: internal Jenkin's one-at-a-time")
427431
endif()

CMakeModules/FindXXHash.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ find_library(XXHASH_LIBRARY
3434
${CMAKE_INSTALL_PREFIX}/lib
3535
)
3636

37+
# for 32-bit system compatibility
38+
check_symbol_exists(XXH3_64bits_withSeed ${XXHASH_INCLUDE_DIR}/xxhash.h HAVE_XXH3_64BITS_WITHSEED)
39+
3740
include(FindPackageHandleStandardArgs)
3841
find_package_handle_standard_args(XXHash FOUND_VAR XXHASH_FOUND REQUIRED_VARS XXHASH_INCLUDE_DIR XXHASH_LIBRARY)

src/hash_table.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ lyht_hash_multi(uint32_t hash, const char *key_part, size_t len)
3535
{
3636
#ifdef LY_XXHASH_SUPPORT
3737
if (key_part && len) {
38+
# ifdef LY_XXH3_64BITS_WITHSEED
3839
return XXH3_64bits_withSeed(key_part, len, hash);
40+
# else
41+
return XXH32(key_part, len, hash);
42+
# endif
3943
}
40-
44+
# ifdef LY_XXH3_64BITS_WITHSEED
4145
return XXH3_64bits_withSeed(NULL, 0, hash);
46+
# else
47+
return XXH32(NULL, 0, hash);
48+
# endif
4249
#else
4350
uint32_t i;
4451

@@ -62,7 +69,11 @@ LIBYANG_API_DEF uint32_t
6269
lyht_hash(const char *key, size_t len)
6370
{
6471
#ifdef LY_XXHASH_SUPPORT
72+
# ifdef LY_XXH3_64BITS_WITHSEED
6573
return XXH3_64bits(key, len);
74+
# else
75+
return XXH32(key, len, 0);
76+
# endif
6677
#else
6778
uint32_t hash;
6879

0 commit comments

Comments
 (0)