# HG changeset patch # User Mike Becker # Date 1734904433 -3600 # Node ID 415bf2ce6bab97e7430f5a3e6022f1d3d4af7d9d # Parent 12f38affefd573b5ac3acb44ed634198b48271f5 fix cx_hash_key_cxstr() being a macro issue #536 diff -r 12f38affefd5 -r 415bf2ce6bab CHANGELOG --- a/CHANGELOG Sun Dec 22 22:14:57 2024 +0100 +++ b/CHANGELOG Sun Dec 22 22:53:53 2024 +0100 @@ -30,6 +30,7 @@ * removes CMake * removes GTest dependency * removes flags to disable SBO in tests + * fixes cx_hash_key_cxstr() being a macro, evaluating the argument twice * fixes wrong link from UCX 2 documentation to UCX 3 documentation * fixes critical bug that produced wrong results when comparing lists of different type but same size diff -r 12f38affefd5 -r 415bf2ce6bab src/cx/hash_key.h --- a/src/cx/hash_key.h Sun Dec 22 22:14:57 2024 +0100 +++ b/src/cx/hash_key.h Sun Dec 22 22:53:53 2024 +0100 @@ -38,6 +38,7 @@ #define UCX_HASH_KEY_H #include "common.h" +#include "string.h" #ifdef __cplusplus extern "C" { @@ -112,22 +113,51 @@ */ cx_attr_nodiscard cx_attr_access_r(1, 2) -__attribute__((__warn_unused_result__)) CxHashKey cx_hash_key( const void *obj, size_t len ); +#ifdef __cplusplus +} // extern "C" + +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxstr(cxstring str) { + return cx_hash_key(str.ptr, str.length); +} + +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxstr(cxmutstr str) { + return cx_hash_key(str.ptr, str.length); +} + +#else /** * Computes a hash key from a UCX string. * * @param str the string * @return the hash key */ -#define cx_hash_key_cxstr(str) cx_hash_key((void*)(str).ptr, (str).length) +#define cx_hash_key_cxstr(str) _Generic((str), \ + cxstring: cx_hash_key_cxstring, \ + cxmutstr: cx_hash_key_cxmutstr) \ + (str) -#ifdef __cplusplus -} // extern "C" +/** + * @copydoc cx_hash_key_cxstr() + */ +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxstring(cxstring str) { + return cx_hash_key(str.ptr, str.length); +} + +/** + * @copydoc cx_hash_key_cxstr() + */ +cx_attr_nodiscard +static inline CxHashKey cx_hash_key_cxmutstr(cxmutstr str) { + return cx_hash_key(str.ptr, str.length); +} #endif #endif // UCX_HASH_KEY_H