aboutsummaryrefslogtreecommitdiffstats
path: root/libsimple.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-18 09:58:23 +0200
committerMattias Andrée <maandree@kth.se>2024-08-18 09:58:23 +0200
commita69f0f613687edf6c1f1ee83b462f77e8ea3c9a9 (patch)
treed976683461a0f427d2f1ef79a8732a048dd0c67b /libsimple.h
parentMerge tag '1.3' into since (diff)
parentUpdate VERSION_MINOR (diff)
downloadlibsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.gz
libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.bz2
libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.xz
Merge tag '1.4' into since
Version 1.4
Diffstat (limited to 'libsimple.h')
-rw-r--r--libsimple.h145
1 files changed, 95 insertions, 50 deletions
diff --git a/libsimple.h b/libsimple.h
index 3ee1e90..430dbe0 100644
--- a/libsimple.h
+++ b/libsimple.h
@@ -3,6 +3,14 @@
#define LIBSIMPLE_H
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdocumentation"
+# pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
+# pragma clang diagnostic ignored "-Wreserved-identifier"
+# pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
+#endif
+
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
@@ -43,51 +51,78 @@
#include <wctype.h>
+#if defined(__GLIBC__) && (__GLIBC_PREREQ(2, 29) ? defined(_DEFAULT_SOURCE) : (__GLIBC_PREREQ(2, 26) && defined(_GNU_SOURCE)))
+# define reallocarray reallocarray
+#endif
+
+
+
+#if defined(__GNUC__) && !defined(__clang__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Winline"
+#endif
+
+
#if defined(__GNUC__) && !defined(__clang__)
-# define _LIBSIMPLE_GCC_ONLY(x) x
-# define _LIBSIMPLE_NON_GCC_ONLY(x)
+# define LIBSIMPLE_GCC_ONLY__(x) x
+# define LIBSIMPLE_NON_GCC_ONLY__(x)
#else
-# define _LIBSIMPLE_GCC_ONLY(x)
-# define _LIBSIMPLE_NON_GCC_ONLY(x) x
+# define LIBSIMPLE_GCC_ONLY__(x)
+# define LIBSIMPLE_NON_GCC_ONLY__(x) x
+#endif
+
+#if defined(__GNUC__)
+# define LIBSIMPLE_EXTENSION__ __extension__
+#else
+# define LIBSIMPLE_EXTENSION__
#endif
#if __STDC_VERSION__ >= 199409L
-# define _LIBSIMPLE_C95_ONLY(x) x
-# define _LIBSIMPLE_PRE_C95_ONLY(x)
+# define LIBSIMPLE_C95_ONLY__(x) x
+# define LIBSIMPLE_PRE_C95_ONLY__(x)
#else
-# define _LIBSIMPLE_C95_ONLY(x)
-# define _LIBSIMPLE_PRE_C95_ONLY(x) x
+# define LIBSIMPLE_C95_ONLY__(x)
+# define LIBSIMPLE_PRE_C95_ONLY__(x) x
#endif
#if __STDC_VERSION__ >= 199901L
-# define _LIBSIMPLE_C99_ONLY(x) x
-# define _LIBSIMPLE_PRE_C99_ONLY(x)
+# define LIBSIMPLE_C99_ONLY__(x) x
+# define LIBSIMPLE_PRE_C99_ONLY__(x)
#else
-# define _LIBSIMPLE_C99_ONLY(x)
-# define _LIBSIMPLE_PRE_C99_ONLY(x) x
+# define LIBSIMPLE_C99_ONLY__(x)
+# define LIBSIMPLE_PRE_C99_ONLY__(x) x
#endif
#if __STDC_VERSION__ >= 201112L
-# define _LIBSIMPLE_C11_ONLY(x) x
-# define _LIBSIMPLE_PRE_C11_ONLY(x)
+# define LIBSIMPLE_C11_ONLY__(x) x
+# define LIBSIMPLE_PRE_C11_ONLY__(x)
#else
-# define _LIBSIMPLE_C11_ONLY(x)
-# define _LIBSIMPLE_PRE_C11_ONLY(x) x
+# define LIBSIMPLE_C11_ONLY__(x)
+# define LIBSIMPLE_PRE_C11_ONLY__(x) x
#endif
#if __STDC_VERSION__ >= 201710L
-# define _LIBSIMPLE_C17_ONLY(x) x
-# define _LIBSIMPLE_PRE_C17_ONLY(x)
+# define LIBSIMPLE_C17_ONLY__(x) x
+# define LIBSIMPLE_PRE_C17_ONLY__(x)
#else
-# define _LIBSIMPLE_C17_ONLY(x)
-# define _LIBSIMPLE_PRE_C17_ONLY(x) x
+# define LIBSIMPLE_C17_ONLY__(x)
+# define LIBSIMPLE_PRE_C17_ONLY__(x) x
#endif
-#define _libsimple_assume_aligned_as(TYPE)\
- _LIBSIMPLE_C11_ONLY(__assume_aligned__(_Alignof(TYPE)))\
- _LIBSIMPLE_PRE_C11_ONLY(_LIBSIMPLE_GCC_ONLY__assume_aligned__(__alignof(TYPE)))
+#define libsimple_assume_aligned_as__(TYPE)\
+ LIBSIMPLE_C11_ONLY__(__assume_aligned__(_Alignof(TYPE)))\
+ LIBSIMPLE_PRE_C11_ONLY__(LIBSIMPLE_GCC_ONLY__(__assume_aligned__(__alignof(TYPE))))
+
+
+#if __STDC_VERSION__ >= 201112L
+# define LIBSIMPLE_NORETURN _Noreturn /* TODO doc, man */
+#elif defined(__GNUC__) || defined(__clang__)
+# define LIBSIMPLE_NORETURN __attribute__((noreturn))
+#else
+# define LIBSIMPLE_NORETURN
+#endif
#include "libsimple/overflow.h"
@@ -128,6 +163,8 @@
#include "libsimple/array.h"
#include "libsimple/str.h"
#include "libsimple/strn.h"
+#include "libsimple/strtoint.h"
+#include "libsimple/search.h"
/**
@@ -142,16 +179,16 @@
*
* @since 1.0
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
-static inline int
-libsimple_close(int *__fdp)
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__)))
+inline int
+libsimple_close(int *fdp__)
{
- int __ret;
- if (*__fdp < 0)
+ int ret__;
+ if (*fdp__ < 0)
return 0;
- __ret = close(*__fdp);
- *__fdp = -1;
- return __ret;
+ ret__ = close(*fdp__);
+ *fdp__ = -1;
+ return ret__;
}
@@ -184,47 +221,45 @@ libsimple_close(int *__fdp)
*
* @since 1.0
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
-static inline void
-libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width)
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__)))
+inline void
+libsimple_unlist(void *list__, size_t i__, size_t *np__, size_t width__)
{
- char *__lst = __list;
- memmove(&__lst[__i * __width], &__lst[(__i + 1) * __width], (--*__np - __i) * __width);
+ char *lst__ = list__;
+ memmove(&lst__[i__ * width__], &lst__[(i__ + 1) * width__], (--*np__ - i__) * width__);
}
#ifndef unlist
# define unlist libsimple_unlist
#endif
-#define _LIBSIMPLE_REMOVE_CONST(X, TYPE, ...) (*(TYPE *)(void *)&(X))
-#define LIBSIMPLE_REMOVE_CONST(...) _LIBSIMPLE_REMOVE_CONST(__VA_ARGS__, void *) /* TODO test, doc, man (since 1.2) */
+#define LIBSIMPLE_REMOVE_CONST__(X, TYPE, ...) (*(TYPE *)(void *)&(X))
+#define LIBSIMPLE_REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST__(__VA_ARGS__, void *) /* TODO test, doc, man (since 1.2) */
#ifndef REMOVE_CONST
# define REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST(__VA_ARGS__)
#endif
#define LIBSIMPLE_PREFETCH_RDONLY(ADDRESS, LOCALITY) /* void */ /* TODO test, doc, man (since 1.2) */\
- _LIBSIMPLE_GCC_ONLY(__builtin_prefetch(ADDRESS, 0, LOCALITY))
+ LIBSIMPLE_GCC_ONLY__(__builtin_prefetch(ADDRESS, 0, LOCALITY))
#ifndef PREFETCH_RDONLY
# define PREFETCH_RDONLY(...) LIBSIMPLE_PREFETCH_RDONLY(__VA_ARGS__)
#endif
#define LIBSIMPLE_PREFETCH_RDWR(ADDRESS, LOCALITY) /* void */ /* TODO test, doc, man (since 1.2) */\
- _LIBSIMPLE_GCC_ONLY(__builtin_prefetch(ADDRESS, 1, LOCALITY))
+ LIBSIMPLE_GCC_ONLY__(__builtin_prefetch(ADDRESS, 1, LOCALITY))
#ifndef PREFETCH_RDWR
# define PREFETCH_RDWR(...) LIBSIMPLE_PREFETCH_RDWR(__VA_ARGS__)
#endif
-#define _LIBSIMPLE_ASSUME_ALIGNED(PTR, ALIGNMENT, ...)\
- _LIBSIMPLE_GCC_ONLY(__builtin_assume_aligned(PTR, ALIGNMENT))
-#if defined(__GNUC__) && !defined(__clang__)
-# define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man (since 1.2) */\
- _LIBSIMPLE_GCC_ONLY(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\
- _LIBSIMPLE_C11_ONLY(_Alignof(PTR))\
- _LIBSIMPLE_PREC11_ONLY(__alignof(PTR))))
-#endif
+#define LIBSIMPLE_ASSUME_ALIGNED__(PTR, ALIGNMENT, ...)\
+ LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ALIGNMENT))\
+ LIBSIMPLE_NON_GCC_ONLY__(PTR)
+#define LIBSIMPLE_ASSUME_ALIGNED(PTR, ...) /* returns PTR */ /* TODO test, doc, man (since 1.2) */\
+ LIBSIMPLE_ASSUME_ALIGNED__(PTR, ##__VA_ARGS__, LIBSIMPLE_C11_ONLY__(_Alignof(*PTR)) /* no , */\
+ LIBSIMPLE_PRE_C11_ONLY__(__alignof(*PTR)))
#ifndef ASSUME_ALIGNED
# define ASSUME_ALIGNED(...) LIBSIMPLE_ASSUME_ALIGNED(__VA_ARGS__)
#endif
@@ -237,17 +272,27 @@ libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width)
#endif
-#define LIBSIMPLE_UNROLLED(N) _LIBSIMPLE_GCC_ONLY(_LIBSIMPLE_C11_ONLY(_Pragma("GCC unroll "#N))) /* TODO test, doc, man (since 1.2) */
+#define LIBSIMPLE_UNROLLED(N) LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC unroll "#N))) /* TODO test, doc, man (since 1.2) */
#ifndef UNROLLED
# define UNROLLED(N) LIBSIMPLE_UNROLLED(N)
#endif
-#define LIBSIMPLE_SIMDLOOP _LIBSIMPLE_GCC_ONLY(_LIBSIMPLE_C11_ONLY(_Pragma("GCC ivdep"))) /* TODO test, doc, man (since 1.2) */
+#define LIBSIMPLE_SIMDLOOP LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC ivdep"))) /* TODO test, doc, man (since 1.2) */
#ifndef SIMDLOOP
# define SIMDLOOP LIBSIMPLE_SIMDLOOP
#endif
+
+#if defined(__GNUC__) && !defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+
#endif