mdbx: rework '_noop' and related macros.

Change-Id: Ic9ff3662a6abeb64aa0816e448007dd524794b1e
This commit is contained in:
Leo Yuriev 2017-10-29 00:57:14 +03:00
parent db4ab61a0c
commit aec2445161
2 changed files with 42 additions and 22 deletions

View File

@ -139,14 +139,51 @@
# endif
#endif /* __deprecated */
#if !defined(__noop) && !defined(_MSC_VER)
# ifdef __cplusplus
static inline void __noop_consume_args() {}
template <typename First, typename... Rest>
static inline void
__noop_consume_args(const First &first, const Rest &... rest) {
(void) first; __noop_consume_args(rest...);
}
# define __noop(...) __noop_consume_args(__VA_ARGS__)
# elif defined(__GNUC__) && (!defined(__STRICT_ANSI__) || !__STRICT_ANSI__)
static __inline void __noop_consume_args(void* anchor, ...) {
(void) anchor;
}
# define __noop(...) __noop_consume_args(0, ##__VA_ARGS__)
# else
# define __noop(...) do {} while(0)
# endif
#endif /* __noop */
#ifndef __fallthrough
# if __GNUC_PREREQ(7, 0) || __has_attribute(fallthrough)
# define __fallthrough __attribute__((fallthrough))
# else
# define __fallthrough do {} while(0)
# endif
# if __GNUC_PREREQ(7, 0) || __has_attribute(fallthrough)
# define __fallthrough __attribute__((fallthrough))
# else
# define __fallthrough __noop()
# endif
#endif /* __fallthrough */
#ifndef __unreachable
# if __GNUC_PREREQ(4,5)
# define __unreachable() __builtin_unreachable()
# elif defined(_MSC_VER)
# define __unreachable() __assume(0)
# else
# define __unreachable() __noop()
# endif
#endif /* __unreachable */
#ifndef __prefetch
# if defined(__GNUC__) || defined(__clang__)
# define __prefetch(ptr) __builtin_prefetch(ptr)
# else
# define __prefetch(ptr) __noop(ptr)
# endif
#endif /* __prefetch */
#ifndef __aligned
# if defined(__GNUC__) || __has_attribute(aligned)
# define __aligned(N) __attribute__((aligned(N)))
@ -283,13 +320,6 @@
# endif
#endif /* unlikely */
#if !defined(__noop) && !defined(_MSC_VER)
static __inline int __do_noop(void* crutch, ...) {
(void) crutch; return 0;
}
# define __noop(...) __do_noop(0, __VA_ARGS__)
#endif /* __noop */
/* Wrapper around __func__, which is a C99 feature */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define mdbx_func_ __func__

View File

@ -51,9 +51,6 @@
#endif
#if __GNUC_PREREQ(4, 4) || defined(__clang__)
#if __GNUC_PREREQ(4, 5) || defined(__clang__)
#define unreachable() __builtin_unreachable()
#endif
#define bswap64(v) __builtin_bswap64(v)
#define bswap32(v) __builtin_bswap32(v)
#if __GNUC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
@ -67,7 +64,6 @@
"It is recommended to use Visual Studio 2015 (MSC 19.0) or newer.")
#endif
#define unreachable() __assume(0)
#define bswap64(v) _byteswap_uint64(v)
#define bswap32(v) _byteswap_ulong(v)
#define bswap16(v) _byteswap_ushort(v)
@ -90,12 +86,6 @@
#endif /* compiler */
#ifndef unreachable
#define unreachable() \
do { \
} while (1)
#endif
#ifndef bswap64
#ifdef __bswap_64
#define bswap64(v) __bswap_64(v)