From: Matteo Croce Date: Thu, 3 Apr 2025 01:09:47 +0000 (+0200) Subject: move XXH_FALLTHROUGH into a generic include file X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a3cbd3c0f7c84f977b624a6240d02ce741fc747;p=thirdparty%2Futil-linux.git move XXH_FALLTHROUGH into a generic include file Move XXH_FALLTHROUGH in c.h, and rename it to FALLTHROUGH --- diff --git a/include/c.h b/include/c.h index dcb2d683c..e0148e019 100644 --- a/include/c.h +++ b/include/c.h @@ -82,6 +82,39 @@ # endif #endif +#ifdef __has_attribute +# define UL_HAS_ATTRIBUTE(x) __has_attribute(x) +#else +# define UL_HAS_ATTRIBUTE(x) 0 +#endif + +/* C-language Attributes are added in C23. */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute) +# define UL_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) +#else +# define UL_HAS_C_ATTRIBUTE(x) 0 +#endif + +#if defined(__cplusplus) && defined(__has_cpp_attribute) +# define UL_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#else +# define UL_HAS_CPP_ATTRIBUTE(x) 0 +#endif + +/* +Define FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute +introduced in CPP17 and C23. +CPP17 : https://en.cppreference.com/w/cpp/language/attributes/fallthrough +C23 : https://en.cppreference.com/w/c/language/attributes/fallthrough +*/ +#if UL_HAS_C_ATTRIBUTE(fallthrough) || UL_HAS_CPP_ATTRIBUTE(fallthrough) +# define FALLTHROUGH [[fallthrough]] +#elif UL_HAS_ATTRIBUTE(__fallthrough__) +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +#else +# define FALLTHROUGH /* fallthrough */ +#endif + /* * It evaluates to 1 if the attribute/feature is supported by the current diff --git a/include/xxhash.h b/include/xxhash.h index c17521f99..5a581b888 100644 --- a/include/xxhash.h +++ b/include/xxhash.h @@ -605,39 +605,10 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t */ XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); +/* Reuse FALLTHROUGH macro from c.h */ +#include "c.h" -#ifdef __has_attribute -# define XXH_HAS_ATTRIBUTE(x) __has_attribute(x) -#else -# define XXH_HAS_ATTRIBUTE(x) 0 -#endif - -/* C-language Attributes are added in C23. */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute) -# define XXH_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) -#else -# define XXH_HAS_C_ATTRIBUTE(x) 0 -#endif - -#if defined(__cplusplus) && defined(__has_cpp_attribute) -# define XXH_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -# define XXH_HAS_CPP_ATTRIBUTE(x) 0 -#endif - -/* -Define XXH_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute -introduced in CPP17 and C23. -CPP17 : https://en.cppreference.com/w/cpp/language/attributes/fallthrough -C23 : https://en.cppreference.com/w/c/language/attributes/fallthrough -*/ -#if XXH_HAS_C_ATTRIBUTE(fallthrough) || XXH_HAS_CPP_ATTRIBUTE(fallthrough) -# define XXH_FALLTHROUGH [[fallthrough]] -#elif XXH_HAS_ATTRIBUTE(__fallthrough__) -# define XXH_FALLTHROUGH __attribute__ ((__fallthrough__)) -#else -# define XXH_FALLTHROUGH /* fallthrough */ -#endif +#define XXH_FALLTHROUGH FALLTHROUGH /*! * @}