diff options
| author | Mattias Andrée <m@maandree.se> | 2025-12-22 19:00:13 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-12-22 19:00:13 +0100 |
| commit | a4f399cbf699e53a30ef723031bc17a24a4c5d13 (patch) | |
| tree | 226aa6657d88e1ce620e6695640344416513335d | |
| parent | Add TODOs (diff) | |
| download | libsimple-a4f399cbf699e53a30ef723031bc17a24a4c5d13.tar.gz libsimple-a4f399cbf699e53a30ef723031bc17a24a4c5d13.tar.bz2 libsimple-a4f399cbf699e53a30ef723031bc17a24a4c5d13.tar.xz | |
Signed-off-by: Mattias Andrée <m@maandree.se>
| -rw-r--r-- | libsimple.h | 34 | ||||
| -rw-r--r-- | libsimple/definitions.h | 18 |
2 files changed, 52 insertions, 0 deletions
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" diff --git a/libsimple/definitions.h b/libsimple/definitions.h index b0f816b..e5dca61 100644 --- a/libsimple/definitions.h +++ b/libsimple/definitions.h @@ -381,6 +381,24 @@ #endif +/* TODO man, doc, since 1.8 */ +#define LIBSIMPLE_0_TO_7 "01234567" +#define LIBSIMPLE_0_TO_9 "0123456789" +#define LIBSIMPLE_a_TO_f "abcdef" +#define LIBSIMPLE_A_TO_F "ABCDEF" +#define LIBSIMPLE_a_TO_z "abcdefghijklmnopqrstuvwxyz" +#define LIBSIMPLE_A_TO_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define LIBSIMPLE_0_TO_f LIBSIMPLE_0_TO_9 LIBSIMPLE_a_TO_f +#define LIBSIMPLE_0_TO_F LIBSIMPLE_0_TO_9 LIBSIMPLE_A_TO_F + + +/* TODO man, doc, since 1.8 */ +#define LIBSIMPLE_SIZEOF_MEMBER(STRUCT, MEMBER) (sizeof(((STRUCT *)NULL)->MEMBER)) +#ifndef sizeof_member +#define sizeof_member(STRUCT, MEMBER) LIBSIMPLE_SIZEOF_MEMBER(STRUCT, MEMBER) +#endif + + /* --- Maximum values (since 1.0) --- */ #ifndef BLKCNT64_MAX |
