[master] 3ef62a623 Move static asserts to vas.h, and decouple from OS #includes
Poul-Henning Kamp
phk at FreeBSD.org
Tue Nov 6 08:41:19 UTC 2018
commit 3ef62a623a1e8ebfd4eb1dfd53410445fb468c2a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 6 08:39:59 2018 +0000
Move static asserts to vas.h, and decouple from OS #includes
diff --git a/flint.lnt b/flint.lnt
index 7c7736d3d..a20d04af2 100644
--- a/flint.lnt
+++ b/flint.lnt
@@ -112,6 +112,9 @@
-emacro(527, WRONG) // unreachable code
-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
diff --git a/include/vas.h b/include/vas.h
index 841bd309a..bd51d9211 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -90,4 +90,26 @@ do { \
"", VAS_INCOMPLETE); \
} 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
diff --git a/include/vdef.h b/include/vdef.h
index 3a5e40329..df63b245f 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -73,9 +73,7 @@
# endif
#endif
-#ifdef __printflike
-# define v_printflike_(f,a) __printflike(f,a)
-#elif __GNUC_PREREQ__(2, 95) || defined(__INTEL_COMPILER)
+#if __GNUC_PREREQ__(2, 95) || defined(__INTEL_COMPILER)
# define v_printflike_(f,a) __attribute__((format(printf, f, a)))
#else
# define v_printflike_(f,a)
@@ -139,33 +137,6 @@
# define v_unused_
#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 */
typedef double vtim_mono;
typedef double vtim_real;
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index f1e0d02ab..d93871b73 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -219,7 +219,7 @@ class CounterSet(object):
def emit_c_paranoia(self, fo):
'''Emit asserts to make sure compiler gets same byte index'''
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("\t\"VSC element '\" #a \"' at wrong offset\")\n\n")
More information about the varnish-commit
mailing list