diff -r 38800d479cd4 -r e86049631677 ucx/cx/common.h --- a/ucx/cx/common.h Tue Dec 30 21:39:38 2025 +0100 +++ b/ucx/cx/common.h Wed Dec 31 16:41:16 2025 +0100 @@ -133,27 +133,27 @@ /** * Inform the compiler that falling through a switch case is intentional. */ -#define cx_attr_fallthrough __attribute__((__fallthrough__)) +#define CX_FALLTHROUGH __attribute__((__fallthrough__)) /** * All pointer arguments must be non-NULL. */ -#define cx_attr_nonnull __attribute__((__nonnull__)) +#define CX_NONNULL __attribute__((__nonnull__)) /** * The specified pointer arguments must be non-NULL. */ -#define cx_attr_nonnull_arg(...) __attribute__((__nonnull__(__VA_ARGS__))) +#define CX_NONNULL_ARG(...) __attribute__((__nonnull__(__VA_ARGS__))) /** * The returned value is guaranteed to be non-NULL. */ -#define cx_attr_returns_nonnull __attribute__((__returns_nonnull__)) +#define CX_RETURNS_NONNULL __attribute__((__returns_nonnull__)) /** * The attributed function always returns freshly allocated memory. */ -#define cx_attr_malloc __attribute__((__malloc__)) +#define CX_MALLOC __attribute__((__malloc__)) #if !defined(__clang__) && __GNUC__ >= 11 /** @@ -163,59 +163,59 @@ * @param freefunc the function that shall be used to free the memory * @param freefunc_arg the index of the pointer argument in @p freefunc */ -#define cx_attr_dealloc(freefunc, freefunc_arg) \ +#define CX_DEALLOC(freefunc, freefunc_arg) \ __attribute__((__malloc__(freefunc, freefunc_arg))) #else /** * Not supported in clang. */ -#define cx_attr_dealloc(...) +#define CX_DEALLOC(...) #endif // __clang__ /** * Shortcut to specify #cxFree() as deallocator. */ -#define cx_attr_dealloc_ucx cx_attr_dealloc(cxFree, 2) +#define CX_DEALLOC_UCX CX_DEALLOC(cxFree, 2) /** * Specifies the parameters from which the allocation size is calculated. */ -#define cx_attr_allocsize(...) __attribute__((__alloc_size__(__VA_ARGS__))) +#define CX_ALLOCSIZE(...) __attribute__((__alloc_size__(__VA_ARGS__))) #ifdef __clang__ /** * No support for @c null_terminated_string_arg in clang or GCC below 14. */ -#define cx_attr_cstr_arg(idx) +#define CX_CSTR_ARG(idx) /** * No support for the access attribute in clang. */ -#define cx_attr_access(mode, ...) +#define CX_ACCESS(mode, ...) #else #if __GNUC__ < 10 /** * No support for access attribute in GCC < 10. */ -#define cx_attr_access(mode, ...) +#define CX_ACCESS(mode, ...) #else /** * Helper macro to define access macros. */ -#define cx_attr_access(mode, ...) __attribute__((__access__(mode, __VA_ARGS__))) +#define CX_ACCESS(mode, ...) __attribute__((__access__(mode, __VA_ARGS__))) #endif // __GNUC__ < 10 #if __GNUC__ < 14 /** * No support for @c null_terminated_string_arg in clang or GCC below 14. */ -#define cx_attr_cstr_arg(idx) +#define CX_CSTR_ARG(idx) #else /** * The specified argument is expected to be a zero-terminated string. * * @param idx the index of the argument */ -#define cx_attr_cstr_arg(idx) \ +#define CX_CSTR_ARG(idx) \ __attribute__((__null_terminated_string_arg__(idx))) #endif // __GNUC__ < 14 #endif // __clang__ @@ -227,7 +227,7 @@ * Takes one or two arguments: the index of the pointer and (optionally) the * index of another argument specifying the maximum number of accessed bytes. */ -#define cx_attr_access_r(...) cx_attr_access(__read_only__, __VA_ARGS__) +#define CX_ACCESS_R(...) CX_ACCESS(__read_only__, __VA_ARGS__) /** * Specifies that the function will read and write through the given pointer. @@ -235,7 +235,7 @@ * Takes one or two arguments: the index of the pointer and (optionally) the * index of another argument specifying the maximum number of accessed bytes. */ -#define cx_attr_access_rw(...) cx_attr_access(__read_write__, __VA_ARGS__) +#define CX_ACCESS_RW(...) CX_ACCESS(__read_write__, __VA_ARGS__) /** * Specifies that the function will only write through the given pointer. @@ -243,27 +243,38 @@ * Takes one or two arguments: the index of the pointer and (optionally) the * index of another argument specifying the maximum number of accessed bytes. */ -#define cx_attr_access_w(...) cx_attr_access(__write_only__, __VA_ARGS__) +#define CX_ACCESS_W(...) CX_ACCESS(__write_only__, __VA_ARGS__) /** * Do not warn about unused variable. */ -#define cx_attr_unused __attribute__((__unused__)) +#define CX_UNUSED __attribute__((__unused__)) /** * Warn about discarded return value. */ -#define cx_attr_nodiscard __attribute__((__warn_unused_result__)) +#define CX_NODISCARD __attribute__((__warn_unused_result__)) // --------------------------------------------------------------------------- -// MSVC specifics +// Support for thread_local // --------------------------------------------------------------------------- +#ifdef __cplusplus +#define cx_thread_local thread_local +#else // ! __cplusplus #ifdef _MSC_VER -// fix missing _Thread_local support -#define _Thread_local __declspec(thread) +#define cx_thread_local __declspec(thread) +#else // ! _MSC_VER +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 202300L +/** Platform independent thread-local macro. */ +#define cx_thread_local _Thread_local +#else // C23 or newer +/** Platform independent thread-local macro. */ +#define cx_thread_local thread_local +#endif // C23 #endif // _MSC_VER +#endif // __cplusplus // --------------------------------------------------------------------------- // Exported and inlined functions @@ -278,6 +289,16 @@ #define CX_EXPORT #endif // CX_WINDLL / CX_WINDLL_EXPORT +#ifdef __cplusplus +#define CX_EXTERN extern "C" CX_EXPORT +#define CX_FPTR extern "C" typedef +#else +/** Declares a function with external linkage. */ +#define CX_EXTERN CX_EXPORT +/** Defines a function pointer. */ +#define CX_FPTR typedef +#endif + #ifdef __GNUC__ /** * Declares a function to be inlined. @@ -355,10 +376,8 @@ * @retval zero success * @retval non-zero the multiplication would overflow */ -#if __cplusplus -extern "C" -#endif -CX_EXPORT int cx_szmul_impl(size_t a, size_t b, size_t *result); +CX_EXTERN +int cx_szmul_impl(size_t a, size_t b, size_t *result); #endif // cx_szmul #endif // UCX_COMMON_H