mirror of
https://github.com/openvswitch/ovs
synced 2025-09-03 07:45:30 +00:00
util: Move build assertion macros to compiler.h.
Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -228,4 +228,34 @@
|
|||||||
#define OVS_PREFETCH_WRITE(addr)
|
#define OVS_PREFETCH_WRITE(addr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Build assertions. */
|
||||||
|
#ifdef __CHECKER__
|
||||||
|
#define BUILD_ASSERT(EXPR) ((void) 0)
|
||||||
|
#define BUILD_ASSERT_DECL(EXPR) extern int (*build_assert(void))[1]
|
||||||
|
#elif !defined(__cplusplus)
|
||||||
|
/* Build-time assertion building block. */
|
||||||
|
#define BUILD_ASSERT__(EXPR) \
|
||||||
|
sizeof(struct { unsigned int build_assert_failed : (EXPR) ? 1 : -1; })
|
||||||
|
|
||||||
|
/* Build-time assertion for use in a statement context. */
|
||||||
|
#define BUILD_ASSERT(EXPR) (void) BUILD_ASSERT__(EXPR)
|
||||||
|
|
||||||
|
/* Build-time assertion for use in a declaration context. */
|
||||||
|
#define BUILD_ASSERT_DECL(EXPR) \
|
||||||
|
extern int (*build_assert(void))[BUILD_ASSERT__(EXPR)]
|
||||||
|
#else /* __cplusplus */
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#define BUILD_ASSERT BOOST_STATIC_ASSERT
|
||||||
|
#define BUILD_ASSERT_DECL BOOST_STATIC_ASSERT
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define BUILD_ASSERT_GCCONLY(EXPR) BUILD_ASSERT(EXPR)
|
||||||
|
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) BUILD_ASSERT_DECL(EXPR)
|
||||||
|
#else
|
||||||
|
#define BUILD_ASSERT_GCCONLY(EXPR) ((void) 0)
|
||||||
|
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* compiler.h */
|
#endif /* compiler.h */
|
||||||
|
28
lib/util.h
28
lib/util.h
@@ -39,34 +39,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __CHECKER__
|
|
||||||
#define BUILD_ASSERT(EXPR) ((void) 0)
|
|
||||||
#define BUILD_ASSERT_DECL(EXPR) extern int (*build_assert(void))[1]
|
|
||||||
#elif !defined(__cplusplus)
|
|
||||||
/* Build-time assertion building block. */
|
|
||||||
#define BUILD_ASSERT__(EXPR) \
|
|
||||||
sizeof(struct { unsigned int build_assert_failed : (EXPR) ? 1 : -1; })
|
|
||||||
|
|
||||||
/* Build-time assertion for use in a statement context. */
|
|
||||||
#define BUILD_ASSERT(EXPR) (void) BUILD_ASSERT__(EXPR)
|
|
||||||
|
|
||||||
/* Build-time assertion for use in a declaration context. */
|
|
||||||
#define BUILD_ASSERT_DECL(EXPR) \
|
|
||||||
extern int (*build_assert(void))[BUILD_ASSERT__(EXPR)]
|
|
||||||
#else /* __cplusplus */
|
|
||||||
#include <boost/static_assert.hpp>
|
|
||||||
#define BUILD_ASSERT BOOST_STATIC_ASSERT
|
|
||||||
#define BUILD_ASSERT_DECL BOOST_STATIC_ASSERT
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define BUILD_ASSERT_GCCONLY(EXPR) BUILD_ASSERT(EXPR)
|
|
||||||
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) BUILD_ASSERT_DECL(EXPR)
|
|
||||||
#else
|
|
||||||
#define BUILD_ASSERT_GCCONLY(EXPR) ((void) 0)
|
|
||||||
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern char *program_name;
|
extern char *program_name;
|
||||||
|
|
||||||
#define __ARRAY_SIZE_NOCHECK(ARRAY) (sizeof(ARRAY) / sizeof((ARRAY)[0]))
|
#define __ARRAY_SIZE_NOCHECK(ARRAY) (sizeof(ARRAY) / sizeof((ARRAY)[0]))
|
||||||
|
Reference in New Issue
Block a user