From a4f399cbf699e53a30ef723031bc17a24a4c5d13 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 22 Dec 2025 19:00:13 +0100 Subject: Add some macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libsimple.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libsimple.h') diff --git a/libsimple.h b/libsimple.h index 6d1867e..6e5f170 100644 --- a/libsimple.h +++ b/libsimple.h @@ -125,6 +125,40 @@ #endif +/* TODO doc, man, since 1.8, check which are supported by clang */ +#if defined(__GNUC__) && !defined(__clang__) +# define LIBSIMPLE_PURE __attribute__((pure)) +# define LIBSIMPLE_CONST __attribute__((const)) +# define LIBSIMPLE_NONNULL_RETURN __attribute__((returns_nonnull)) +# define LIBSIMPLE_USE_RETURN __attribute__((warn_unused_result)) +# define LIBSIMPLE_NONNULL_ARGS(...) __attribute__((nonnull__(__VA_ARGS__))) +# define LIBSIMPLE_NO_NULL_ARGS __attribute__((nonnull)) +# define LIBSIMPLE_RETURNS_TWICE __attribute__((returns_twice)) +# define LIBSIMPLE_UNREACHABLE __builtin_unreachable() +# define LIBSIMPLE_EXPECT(V, LIKELY) __builtin_expect((V), (LIKELY)) +# define LIBSIMPLE_ALIGNED(P) __builtin_assume_aligned((P), sizeof(*(P))) +# define LIBSIMPLE_ALIGNED_TO(P, A) __builtin_assume_aligned((P), (A)) +# define LIBSIMPLE_MISALIGNED(P, OFF) __builtin_assume_aligned((P), sizeof(*(P)), 0) +# define LIBSIMPLE_MISALIGNED_FROM(P, A, OFF) __builtin_assume_aligned((P), (A), 0) +#else +# define LIBSIMPLE_PURE +# define LIBSIMPLE_CONST +# define LIBSIMPLE_NONNULL_RETURN +# define LIBSIMPLE_USE_RETURN +# define LIBSIMPLE_NONNULL_ARGS(...) +# define LIBSIMPLE_NO_NULL_ARGS +# define LIBSIMPLE_RETURNS_TWICE +# define LIBSIMPLE_UNREACHABLE abort() +# define LIBSIMPLE_EXPECT(V, LIKELY) (V) +# define LIBSIMPLE_ALIGNED(P) (P) +# define LIBSIMPLE_ALIGNED_TO(P, A) (P) +# define LIBSIMPLE_MISALIGNED(P, OFF) (P) +# define LIBSIMPLE_MISALIGNED_FROM(P, A, OFF) (P) +#endif +#define LIBSIMPLE_LIKELY(V) LIBSIMPLE_EXPECT(!!(V), 1) +#define LIBSIMPLE_UNLIKELY(V) LIBSIMPLE_EXPECT(!!(V), 0) + + #include "libsimple/overflow.h" #include "libsimple/printf.h" #include "libsimple/definitions.h" -- cgit v1.2.3-70-g09d2