Commit 3ef62a62 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move static asserts to vas.h, and decouple from OS #includes

parent 3e0cdae0
...@@ -112,6 +112,9 @@ ...@@ -112,6 +112,9 @@
-emacro(527, WRONG) // unreachable code -emacro(527, WRONG) // unreachable code
-emacro(774, VALID_OBJ) // boolean always true -emacro(774, VALID_OBJ) // boolean always true
-emacro(506, v_static_assert) // Constant value Boolean
-esym(751, __vassert_*) // local typedef '___' (___) not referenced
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// Places where we use x<<0 for reasons of symmetry // Places where we use x<<0 for reasons of symmetry
......
...@@ -90,4 +90,26 @@ do { \ ...@@ -90,4 +90,26 @@ do { \
"", VAS_INCOMPLETE); \ "", VAS_INCOMPLETE); \
} while (0) } while (0)
/*
* Most of this nightmare is stolen from FreeBSD's <cdefs.h>
*/
#ifndef __has_extension
# define __has_extension(x) 0
#endif
#if __has_extension(c_static_assert)
# define v_static_assert _Static_assert
#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus)
# define v_static_assert _Static_assert
#else
# if defined(__COUNTER__)
# define v_static_assert(x, y) __v_static_assert(x, __COUNTER__)
# else
# define v_static_assert(x, y) __v_static_assert(x, __LINE__)
# endif
# define __v_static_assert(x, y) ___v_static_assert(x, y)
# define ___v_static_assert(x, y) \
typedef char __vassert_## y[(x) ? 1 : -1] v_unused_
#endif
#endif #endif
...@@ -73,9 +73,7 @@ ...@@ -73,9 +73,7 @@
# endif # endif
#endif #endif
#ifdef __printflike #if __GNUC_PREREQ__(2, 95) || defined(__INTEL_COMPILER)
# define v_printflike_(f,a) __printflike(f,a)
#elif __GNUC_PREREQ__(2, 95) || defined(__INTEL_COMPILER)
# define v_printflike_(f,a) __attribute__((format(printf, f, a))) # define v_printflike_(f,a) __attribute__((format(printf, f, a)))
#else #else
# define v_printflike_(f,a) # define v_printflike_(f,a)
...@@ -139,33 +137,6 @@ ...@@ -139,33 +137,6 @@
# define v_unused_ # define v_unused_
#endif #endif
/*
* Most of this nightmare is stolen from FreeBSD's <cdefs.h>
*/
#ifndef __has_extension
# define __has_extension(x) 0
#endif
#if defined(_Static_assert)
/* Nothing, somebody already did this for us */
#elif __has_extension(c_static_assert)
/* Nothing, we should be fine */
#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
__has_extension(cxx_static_assert)
# define _Static_assert(x, y) static_assert(x, y)
#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus)
/* Nothing, gcc 4.6 and higher has _Static_assert built-in */
#else
# if defined(__COUNTER__)
# define _Static_assert(x, y) __Static_assert(x, __COUNTER__)
# else
# define _Static_assert(x, y) __Static_assert(x, __LINE__)
# endif
# define __Static_assert(x, y) ___Static_assert(x, y)
# define ___Static_assert(x, y) \
typedef char __assert_## y[(x) ? 1 : -1] v_unused_
#endif
/* VTIM API overhaul WIP */ /* VTIM API overhaul WIP */
typedef double vtim_mono; typedef double vtim_mono;
typedef double vtim_real; typedef double vtim_real;
......
...@@ -219,7 +219,7 @@ class CounterSet(object): ...@@ -219,7 +219,7 @@ class CounterSet(object):
def emit_c_paranoia(self, fo): def emit_c_paranoia(self, fo):
'''Emit asserts to make sure compiler gets same byte index''' '''Emit asserts to make sure compiler gets same byte index'''
fo.write("#define PARANOIA(a,n)\t\t\t\t\\\n") fo.write("#define PARANOIA(a,n)\t\t\t\t\\\n")
fo.write(" _Static_assert(\t\t\t\t\\\n") fo.write(" v_static_assert(\t\t\t\t\\\n")
fo.write("\toffsetof(" + self.struct + ", a) == n,\t\\\n") fo.write("\toffsetof(" + self.struct + ", a) == n,\t\\\n")
fo.write("\t\"VSC element '\" #a \"' at wrong offset\")\n\n") fo.write("\t\"VSC element '\" #a \"' at wrong offset\")\n\n")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment