2018-03-07 12:09:43 +03:00
|
|
|
/*
|
2019-02-03 12:28:01 +03:00
|
|
|
* Copyright 2015-2019 Leonid Yuriev <leo@yuriev.ru>
|
2017-03-16 18:09:27 +03:00
|
|
|
* and other libmdbx authors: please see AUTHORS file.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
/* clang-format off */
|
|
|
|
|
|
|
|
#ifndef __GNUC_PREREQ
|
2017-05-24 13:37:06 +03:00
|
|
|
# if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
|
|
|
# define __GNUC_PREREQ(maj, min) \
|
|
|
|
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
|
|
|
# else
|
|
|
|
# define __GNUC_PREREQ(maj, min) (0)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __GNUC_PREREQ */
|
|
|
|
|
|
|
|
#ifndef __CLANG_PREREQ
|
2017-05-24 13:37:06 +03:00
|
|
|
# ifdef __clang__
|
|
|
|
# define __CLANG_PREREQ(maj,min) \
|
|
|
|
((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
|
|
|
|
# else
|
|
|
|
# define __CLANG_PREREQ(maj,min) (0)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __CLANG_PREREQ */
|
|
|
|
|
|
|
|
#ifndef __GLIBC_PREREQ
|
2017-05-24 13:37:06 +03:00
|
|
|
# if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
|
|
|
|
# define __GLIBC_PREREQ(maj, min) \
|
|
|
|
((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
|
|
|
|
# else
|
|
|
|
# define __GLIBC_PREREQ(maj, min) (0)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __GLIBC_PREREQ */
|
|
|
|
|
|
|
|
#ifndef __has_attribute
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __has_attribute(x) (0)
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __has_feature
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __has_feature(x) (0)
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __has_extension
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __has_extension(x) (0)
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __has_builtin
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __has_builtin(x) (0)
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
2018-03-07 13:07:17 +03:00
|
|
|
#ifndef __has_warning
|
|
|
|
# define __has_warning(x) (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __has_include
|
|
|
|
# define __has_include(x) (0)
|
|
|
|
#endif
|
|
|
|
|
2017-03-16 18:09:27 +03:00
|
|
|
#if __has_feature(thread_sanitizer)
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __SANITIZE_THREAD__ 1
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __has_feature(address_sanitizer)
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __SANITIZE_ADDRESS__ 1
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifndef __extern_C
|
2017-05-24 13:37:06 +03:00
|
|
|
# ifdef __cplusplus
|
|
|
|
# define __extern_C extern "C"
|
|
|
|
# else
|
|
|
|
# define __extern_C
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __extern_C */
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
2017-05-24 13:37:06 +03:00
|
|
|
# ifndef bool
|
|
|
|
# define bool _Bool
|
|
|
|
# endif
|
|
|
|
# ifndef true
|
|
|
|
# define true (1)
|
|
|
|
# endif
|
|
|
|
# ifndef false
|
|
|
|
# define false (0)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(nullptr) && !defined(__cplusplus) || (__cplusplus < 201103L && !defined(_MSC_VER))
|
2017-05-24 13:37:06 +03:00
|
|
|
# define nullptr NULL
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2018-11-01 21:00:25 +03:00
|
|
|
#ifndef __always_inline
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__always_inline__)
|
|
|
|
# define __always_inline __inline __attribute__((__always_inline__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# elif defined(_MSC_VER)
|
2018-11-01 21:00:25 +03:00
|
|
|
# define __always_inline __forceinline
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
2018-11-01 21:00:25 +03:00
|
|
|
# define __always_inline
|
2017-05-24 13:37:06 +03:00
|
|
|
# endif
|
2018-11-01 21:00:25 +03:00
|
|
|
#endif /* __always_inline */
|
2017-03-16 18:09:27 +03:00
|
|
|
|
|
|
|
#ifndef __noinline
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__noinline__)
|
|
|
|
# define __noinline __attribute__((__noinline__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# elif defined(_MSC_VER)
|
|
|
|
# define __noinline __declspec(noinline)
|
|
|
|
# elif defined(__SUNPRO_C) || defined(__sun) || defined(sun)
|
|
|
|
# define __noinline inline
|
|
|
|
# elif !defined(__INTEL_COMPILER)
|
|
|
|
# define __noinline /* FIXME ? */
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __noinline */
|
|
|
|
|
|
|
|
#ifndef __must_check_result
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__warn_unused_result__)
|
|
|
|
# define __must_check_result __attribute__((__warn_unused_result__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __must_check_result
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __must_check_result */
|
|
|
|
|
2019-08-31 17:10:04 +03:00
|
|
|
#ifndef __maybe_unused
|
|
|
|
# if defined(__GNUC__) || __has_attribute(__unused__)
|
|
|
|
# define __maybe_unused __attribute__((__unused__))
|
|
|
|
# else
|
|
|
|
# define __maybe_unused
|
|
|
|
# endif
|
|
|
|
#endif /* __maybe_unused */
|
|
|
|
|
2017-03-16 18:09:27 +03:00
|
|
|
#ifndef __deprecated
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__deprecated__)
|
|
|
|
# define __deprecated __attribute__((__deprecated__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# elif defined(_MSC_VER)
|
|
|
|
# define __deprecated __declspec(deprecated)
|
|
|
|
# else
|
|
|
|
# define __deprecated
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __deprecated */
|
|
|
|
|
2017-10-29 00:57:14 +03:00
|
|
|
#if !defined(__noop) && !defined(_MSC_VER)
|
|
|
|
# ifdef __cplusplus
|
2019-09-19 13:23:47 +03:00
|
|
|
static __maybe_unused inline void __noop_consume_args() {}
|
2017-10-29 00:57:14 +03:00
|
|
|
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__)
|
2019-09-19 13:23:47 +03:00
|
|
|
static __maybe_unused __inline void __noop_consume_args(void* anchor, ...) {
|
2017-10-29 00:57:14 +03:00
|
|
|
(void) anchor;
|
|
|
|
}
|
|
|
|
# define __noop(...) __noop_consume_args(0, ##__VA_ARGS__)
|
|
|
|
# else
|
|
|
|
# define __noop(...) do {} while(0)
|
|
|
|
# endif
|
|
|
|
#endif /* __noop */
|
|
|
|
|
2017-10-28 10:35:01 +03:00
|
|
|
#ifndef __fallthrough
|
2019-08-25 03:05:58 +03:00
|
|
|
# if __GNUC_PREREQ(7, 0) || __has_attribute(__fallthrough__)
|
|
|
|
# define __fallthrough __attribute__((__fallthrough__))
|
2017-10-29 00:57:14 +03:00
|
|
|
# else
|
|
|
|
# define __fallthrough __noop()
|
|
|
|
# endif
|
2017-10-28 10:35:01 +03:00
|
|
|
#endif /* __fallthrough */
|
|
|
|
|
2017-10-29 00:57:14 +03:00
|
|
|
#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 */
|
|
|
|
|
2017-03-16 18:09:27 +03:00
|
|
|
#ifndef __noreturn
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__noreturn__)
|
|
|
|
# define __noreturn __attribute__((__noreturn__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# elif defined(_MSC_VER)
|
|
|
|
# define __noreturn __declspec(noreturn)
|
|
|
|
# else
|
|
|
|
# define __noreturn
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __noreturn */
|
|
|
|
|
|
|
|
#ifndef __nothrow
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__cplusplus)
|
|
|
|
# if __cplusplus < 201703L
|
|
|
|
# define __nothrow throw()
|
|
|
|
# else
|
|
|
|
# define __nothrow noexcept(true)
|
|
|
|
# endif /* __cplusplus */
|
|
|
|
# elif defined(__GNUC__) || __has_attribute(__nothrow__)
|
|
|
|
# define __nothrow __attribute__((__nothrow__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# elif defined(_MSC_VER) && defined(__cplusplus)
|
|
|
|
# define __nothrow __declspec(nothrow)
|
|
|
|
# else
|
|
|
|
# define __nothrow
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __nothrow */
|
|
|
|
|
|
|
|
#ifndef __pure_function
|
2017-05-24 13:37:06 +03:00
|
|
|
/* Many functions have no effects except the return value and their
|
|
|
|
* return value depends only on the parameters and/or global variables.
|
|
|
|
* Such a function can be subject to common subexpression elimination
|
|
|
|
* and loop optimization just as an arithmetic operator would be.
|
|
|
|
* These functions should be declared with the attribute pure. */
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__pure__)
|
|
|
|
# define __pure_function __attribute__((__pure__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __pure_function
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __pure_function */
|
|
|
|
|
|
|
|
#ifndef __const_function
|
2017-05-24 13:37:06 +03:00
|
|
|
/* Many functions do not examine any values except their arguments,
|
|
|
|
* and have no effects except the return value. Basically this is just
|
|
|
|
* slightly more strict class than the PURE attribute, since function
|
|
|
|
* is not allowed to read global memory.
|
|
|
|
*
|
|
|
|
* Note that a function that has pointer arguments and examines the
|
|
|
|
* data pointed to must not be declared const. Likewise, a function
|
|
|
|
* that calls a non-const function usually must not be const.
|
|
|
|
* It does not make sense for a const function to return void. */
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__GNUC__) || __has_attribute(__const__)
|
|
|
|
# define __const_function __attribute__((__const__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __const_function
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __const_function */
|
|
|
|
|
2019-08-25 03:05:58 +03:00
|
|
|
#ifndef __hidden
|
|
|
|
# if defined(__GNUC__) || __has_attribute(__visibility__)
|
|
|
|
# define __hidden __attribute__((__visibility__("hidden")))
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
2019-08-25 03:05:58 +03:00
|
|
|
# define __hidden
|
2017-05-24 13:37:06 +03:00
|
|
|
# endif
|
2019-08-25 03:05:58 +03:00
|
|
|
#endif /* __hidden */
|
2017-03-16 18:09:27 +03:00
|
|
|
|
|
|
|
#ifndef __optimize
|
2017-05-24 13:37:06 +03:00
|
|
|
# if defined(__OPTIMIZE__)
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__clang__) && !__has_attribute(__optimize__)
|
2017-05-24 13:37:06 +03:00
|
|
|
# define __optimize(ops)
|
2019-08-25 03:05:58 +03:00
|
|
|
# elif defined(__GNUC__) || __has_attribute(__optimize__)
|
|
|
|
# define __optimize(ops) __attribute__((__optimize__(ops)))
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __optimize(ops)
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
# define __optimize(ops)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __optimize */
|
|
|
|
|
|
|
|
#ifndef __hot
|
2017-05-24 13:37:06 +03:00
|
|
|
# if defined(__OPTIMIZE__)
|
2018-03-07 12:23:41 +03:00
|
|
|
# if defined(__e2k__)
|
2019-08-25 03:05:58 +03:00
|
|
|
# define __hot __attribute__((__hot__)) __optimize(3)
|
|
|
|
# elif defined(__clang__) && !__has_attribute(__hot_) \
|
|
|
|
&& __has_attribute(__section__) && (defined(__linux__) || defined(__gnu_linux__))
|
2017-05-24 13:37:06 +03:00
|
|
|
/* just put frequently used functions in separate section */
|
2019-08-25 03:05:58 +03:00
|
|
|
# define __hot __attribute__((__section__("text.hot"))) __optimize("O3")
|
|
|
|
# elif defined(__GNUC__) || __has_attribute(__hot__)
|
|
|
|
# define __hot __attribute__((__hot__)) __optimize("O3")
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __hot __optimize("O3")
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
# define __hot
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __hot */
|
|
|
|
|
|
|
|
#ifndef __cold
|
2017-05-24 13:37:06 +03:00
|
|
|
# if defined(__OPTIMIZE__)
|
2018-03-07 12:23:41 +03:00
|
|
|
# if defined(__e2k__)
|
2019-08-25 03:05:58 +03:00
|
|
|
# define __cold __attribute__((__cold__)) __optimize(1)
|
|
|
|
# elif defined(__clang__) && !__has_attribute(cold) \
|
|
|
|
&& __has_attribute(__section__) && (defined(__linux__) || defined(__gnu_linux__))
|
2017-05-24 13:37:06 +03:00
|
|
|
/* just put infrequently used functions in separate section */
|
2019-08-25 03:05:58 +03:00
|
|
|
# define __cold __attribute__((__section__("text.unlikely"))) __optimize("Os")
|
2017-05-24 13:37:06 +03:00
|
|
|
# elif defined(__GNUC__) || __has_attribute(cold)
|
2019-08-25 03:05:58 +03:00
|
|
|
# define __cold __attribute__((__cold__)) __optimize("Os")
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __cold __optimize("Os")
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
# define __cold
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __cold */
|
|
|
|
|
|
|
|
#ifndef __flatten
|
2019-08-25 03:05:58 +03:00
|
|
|
# if defined(__OPTIMIZE__) && (defined(__GNUC__) || __has_attribute(__flatten__))
|
|
|
|
# define __flatten __attribute__((__flatten__))
|
2017-05-24 13:37:06 +03:00
|
|
|
# else
|
|
|
|
# define __flatten
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* __flatten */
|
|
|
|
|
|
|
|
#ifndef likely
|
2019-05-28 21:19:54 +03:00
|
|
|
# if (defined(__GNUC__) || defined(__clang__)) && !defined(__COVERITY__)
|
2017-05-24 13:37:06 +03:00
|
|
|
# define likely(cond) __builtin_expect(!!(cond), 1)
|
|
|
|
# else
|
|
|
|
# define likely(x) (x)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* likely */
|
|
|
|
|
|
|
|
#ifndef unlikely
|
2019-05-28 21:19:54 +03:00
|
|
|
# if (defined(__GNUC__) || defined(__clang__)) && !defined(__COVERITY__)
|
2017-05-24 13:37:06 +03:00
|
|
|
# define unlikely(cond) __builtin_expect(!!(cond), 0)
|
|
|
|
# else
|
|
|
|
# define unlikely(x) (x)
|
|
|
|
# endif
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif /* unlikely */
|
|
|
|
|
2019-05-28 21:19:54 +03:00
|
|
|
/* Workaround for Coverity Scan */
|
|
|
|
#if defined(__COVERITY__) && __GNUC_PREREQ(7, 0) && !defined(__cplusplus)
|
|
|
|
typedef float _Float32;
|
|
|
|
typedef double _Float32x;
|
|
|
|
typedef double _Float64;
|
|
|
|
typedef long double _Float64x;
|
|
|
|
typedef float _Float128 __attribute__((__mode__(__TF__)));
|
|
|
|
typedef __complex__ float __cfloat128 __attribute__ ((__mode__ (__TC__)));
|
|
|
|
typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
|
|
|
|
#endif /* Workaround for Coverity Scan */
|
|
|
|
|
2017-03-16 18:09:27 +03:00
|
|
|
/* Wrapper around __func__, which is a C99 feature */
|
|
|
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
2017-05-24 13:37:06 +03:00
|
|
|
# define mdbx_func_ __func__
|
2017-03-16 18:09:27 +03:00
|
|
|
#elif (defined(__GNUC__) && __GNUC__ >= 2) || defined(__clang__) || defined(_MSC_VER)
|
2017-05-24 13:37:06 +03:00
|
|
|
# define mdbx_func_ __FUNCTION__
|
2017-03-16 18:09:27 +03:00
|
|
|
#else
|
2017-05-24 13:37:06 +03:00
|
|
|
# define mdbx_func_ "<mdbx_unknown>"
|
2017-03-16 18:09:27 +03:00
|
|
|
#endif
|
|
|
|
|
2019-08-25 03:05:58 +03:00
|
|
|
#if defined(__GNUC__) || __has_attribute(__format__)
|
2018-07-28 17:57:54 +03:00
|
|
|
#define __printf_args(format_index, first_arg) \
|
2019-08-25 03:05:58 +03:00
|
|
|
__attribute__((__format__(printf, format_index, first_arg)))
|
2018-07-28 17:57:54 +03:00
|
|
|
#else
|
|
|
|
#define __printf_args(format_index, first_arg)
|
|
|
|
#endif
|
|
|
|
|
2017-05-24 13:59:50 +03:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#if defined(USE_VALGRIND)
|
|
|
|
# include <valgrind/memcheck.h>
|
|
|
|
# ifndef VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE
|
|
|
|
/* LY: available since Valgrind 3.10 */
|
|
|
|
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
|
|
|
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
|
|
|
# endif
|
2018-02-02 19:04:33 +03:00
|
|
|
#elif !defined(RUNNING_ON_VALGRIND)
|
2017-05-24 13:59:50 +03:00
|
|
|
# define VALGRIND_CREATE_MEMPOOL(h,r,z)
|
|
|
|
# define VALGRIND_DESTROY_MEMPOOL(h)
|
|
|
|
# define VALGRIND_MEMPOOL_TRIM(h,a,s)
|
|
|
|
# define VALGRIND_MEMPOOL_ALLOC(h,a,s)
|
|
|
|
# define VALGRIND_MEMPOOL_FREE(h,a)
|
|
|
|
# define VALGRIND_MEMPOOL_CHANGE(h,a,b,s)
|
|
|
|
# define VALGRIND_MAKE_MEM_NOACCESS(a,s)
|
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(a,s)
|
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(a,s)
|
|
|
|
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
|
|
|
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
|
|
|
# define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,s) (0)
|
|
|
|
# define VALGRIND_CHECK_MEM_IS_DEFINED(a,s) (0)
|
2017-05-29 19:27:17 +03:00
|
|
|
# define RUNNING_ON_VALGRIND (0)
|
2017-05-24 13:59:50 +03:00
|
|
|
#endif /* USE_VALGRIND */
|
|
|
|
|
|
|
|
#ifdef __SANITIZE_ADDRESS__
|
|
|
|
# include <sanitizer/asan_interface.h>
|
2018-02-02 19:04:33 +03:00
|
|
|
#elif !defined(ASAN_POISON_MEMORY_REGION)
|
2017-05-24 13:59:50 +03:00
|
|
|
# define ASAN_POISON_MEMORY_REGION(addr, size) \
|
|
|
|
((void)(addr), (void)(size))
|
|
|
|
# define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
|
|
|
((void)(addr), (void)(size))
|
|
|
|
#endif /* __SANITIZE_ADDRESS__ */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifndef ARRAY_LENGTH
|
|
|
|
# ifdef __cplusplus
|
|
|
|
template <typename T, size_t N>
|
|
|
|
char (&__ArraySizeHelper(T (&array)[N]))[N];
|
|
|
|
# define ARRAY_LENGTH(array) (sizeof(::__ArraySizeHelper(array)))
|
|
|
|
# else
|
|
|
|
# define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
|
|
|
|
# endif
|
|
|
|
#endif /* ARRAY_LENGTH */
|
|
|
|
|
|
|
|
#ifndef ARRAY_END
|
|
|
|
# define ARRAY_END(array) (&array[ARRAY_LENGTH(array)])
|
|
|
|
#endif /* ARRAY_END */
|
|
|
|
|
|
|
|
#ifndef STRINGIFY
|
|
|
|
# define STRINGIFY_HELPER(x) #x
|
|
|
|
# define STRINGIFY(x) STRINGIFY_HELPER(x)
|
|
|
|
#endif /* STRINGIFY */
|
|
|
|
|
2019-09-05 11:57:52 +03:00
|
|
|
#define CONCAT(a,b) a##b
|
|
|
|
#define XCONCAT(a,b) CONCAT(a,b)
|
|
|
|
|
2017-05-24 13:59:50 +03:00
|
|
|
#ifndef offsetof
|
|
|
|
# define offsetof(type, member) __builtin_offsetof(type, member)
|
|
|
|
#endif /* offsetof */
|
|
|
|
|
|
|
|
#ifndef container_of
|
|
|
|
# define container_of(ptr, type, member) \
|
|
|
|
((type *)((char *)(ptr) - offsetof(type, member)))
|
|
|
|
#endif /* container_of */
|
2017-03-16 18:09:27 +03:00
|
|
|
|
|
|
|
#define MDBX_TETRAD(a, b, c, d) \
|
2017-05-24 13:37:06 +03:00
|
|
|
((uint32_t)(a) << 24 | (uint32_t)(b) << 16 | (uint32_t)(c) << 8 | (d))
|
2017-05-24 13:59:50 +03:00
|
|
|
|
2017-06-30 00:20:33 +03:00
|
|
|
#define MDBX_STRING_TETRAD(str) MDBX_TETRAD(str[0], str[1], str[2], str[3])
|
|
|
|
|
2017-05-24 13:59:50 +03:00
|
|
|
#define FIXME "FIXME: " __FILE__ ", " STRINGIFY(__LINE__)
|
|
|
|
|
2017-05-26 17:11:48 +03:00
|
|
|
#ifndef STATIC_ASSERT_MSG
|
|
|
|
# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
|
|
|
|
|| __has_feature(c_static_assert)
|
|
|
|
# define STATIC_ASSERT_MSG(expr, msg) _Static_assert(expr, msg)
|
2017-05-24 18:42:13 +03:00
|
|
|
# elif defined(static_assert)
|
2017-05-26 17:11:48 +03:00
|
|
|
# define STATIC_ASSERT_MSG(expr, msg) static_assert(expr, msg)
|
2017-05-31 17:09:43 +03:00
|
|
|
# elif defined(_MSC_VER)
|
|
|
|
# include <crtdbg.h>
|
|
|
|
# define STATIC_ASSERT_MSG(expr, msg) _STATIC_ASSERT(expr)
|
2017-05-24 18:42:13 +03:00
|
|
|
# else
|
2017-05-26 17:11:48 +03:00
|
|
|
# define STATIC_ASSERT_MSG(expr, msg) switch (0) {case 0:case (expr):;}
|
2017-05-24 18:42:13 +03:00
|
|
|
# endif
|
|
|
|
#endif /* STATIC_ASSERT */
|
|
|
|
|
2017-05-26 17:11:48 +03:00
|
|
|
#ifndef STATIC_ASSERT
|
|
|
|
# define STATIC_ASSERT(expr) STATIC_ASSERT_MSG(expr, #expr)
|
|
|
|
#endif
|
|
|
|
|
2017-05-24 13:59:50 +03:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
/* clang-format on */
|