aboutsummaryrefslogtreecommitdiffstats
path: root/libsimple.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-06-11 16:37:09 +0200
committerMattias Andrée <maandree@kth.se>2022-06-11 16:37:09 +0200
commitfcfe59c1f2219408ac2a9cd84b386816ff252221 (patch)
tree0f46c009babfba2d0200ece3ecce067c548a66b6 /libsimple.h
parentRemove `static` from some `static inline` (diff)
downloadlibsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.gz
libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.bz2
libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.xz
Fix warnings, replace some static inline with inline + extern inline, and fix glibc support
Diffstat (limited to 'libsimple.h')
-rw-r--r--libsimple.h93
1 files changed, 49 insertions, 44 deletions
diff --git a/libsimple.h b/libsimple.h
index 2dda0c2..8af98e8 100644
--- a/libsimple.h
+++ b/libsimple.h
@@ -43,51 +43,56 @@
#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__)
-# 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 __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))))
#include "libsimple/overflow.h"
@@ -141,16 +146,16 @@
* @return Return value of close(3) (0 on success,
* -1 on error), 0 if `*fdp < 0`
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__)))
inline int
-libsimple_close(int *__fdp)
+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__;
}
@@ -179,45 +184,45 @@ libsimple_close(int *__fdp)
* @param n Pointer to the number of items in the list, will be updated
* @param width The width, in bytes, of each item in the list
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__)))
inline void
-libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width)
+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 */
+#define LIBSIMPLE_REMOVE_CONST__(X, TYPE, ...) (*(TYPE *)(void *)&(X))
+#define LIBSIMPLE_REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST__(__VA_ARGS__, void *) /* TODO test, doc, man */
#ifndef REMOVE_CONST
# define REMOVE_CONST(...) LIBSIMPLE_REMOVE_CONST(__VA_ARGS__)
#endif
#define LIBSIMPLE_PREFETCH_RDONLY(ADDRESS, LOCALITY) /* void */ /* TODO test, doc, man */\
- _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 */\
- _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))
+#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 */\
- _LIBSIMPLE_GCC_ONLY(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\
- _LIBSIMPLE_C11_ONLY(_Alignof(PTR))\
+ LIBSIMPLE_GCC_ONLY__(__builtin_assume_aligned(PTR, ##__VA_ARGS__,\
+ LIBSIMPLE_C11_ONLY__(_Alignof(PTR))\
_LIBSIMPLE_PREC11_ONLY(__alignof(PTR))))
#endif
#ifndef ASSUME_ALIGNED
@@ -232,13 +237,13 @@ 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 */
+#define LIBSIMPLE_UNROLLED(N) LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC unroll "#N))) /* TODO test, doc, man */
#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 */
+#define LIBSIMPLE_SIMDLOOP LIBSIMPLE_GCC_ONLY__(LIBSIMPLE_C11_ONLY__(_Pragma("GCC ivdep"))) /* TODO test, doc, man */
#ifndef SIMDLOOP
# define SIMDLOOP LIBSIMPLE_SIMDLOOP
#endif