]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
tools: Move ARRAY_SIZE() into xen-tools/libs.h
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 4 Jul 2018 13:32:31 +0000 (14:32 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 4 Jul 2018 16:25:37 +0000 (17:25 +0100)
xen-tools/libs.h currently contains a shared BUILD_BUG_ON() implementation and
is used by some tools.  Extend this to include ARRAY_SIZE and clean up all the
opencoding.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 files changed:
tools/include/xen-tools/libs.h
tools/libxc/xc_private.h
tools/libxl/libxl_internal.h
tools/misc/xen-cpuid.c
tools/misc/xen-diag.c
tools/misc/xen-hptool.c
tools/misc/xen-livepatch.c
tools/misc/xen-mfndump.c
tools/misc/xenpm.c
tools/python/xen/lowlevel/xc/xc.c
tools/tests/vhpet/emul.h
tools/tests/x86_emulator/x86-emulate.h
tools/tests/xen-access/xen-access.c
tools/tests/xenstore/xs-test.c
tools/xenstore/utils.h
tools/xentrace/analyze.h

index e874fb8267c299163df2d47376646483373660bc..63e35071783ec038f8d575698f6c684f1ccdcac6 100644 (file)
@@ -9,4 +9,8 @@
 #endif
 #endif
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
+#endif
+
 #endif /* __XEN_TOOLS_LIBS__ */
index 03bdfca7d49b841baec03455aef20de15f9760c7..a0b203e7e4a19bfa6635c45c606cad6e8a4b436e 100644 (file)
@@ -40,6 +40,8 @@
 
 #include <xen/sys/privcmd.h>
 
+#include <xen-tools/libs.h>
+
 #if defined(HAVE_VALGRIND_MEMCHECK_H) && !defined(NDEBUG) && !defined(__MINIOS__)
 /* Compile in Valgrind client requests? */
 #include <valgrind/memcheck.h>
@@ -73,11 +75,6 @@ struct iovec {
 #define PAGE_SIZE               XC_PAGE_SIZE
 #define PAGE_MASK               XC_PAGE_MASK
 
-#ifndef ARRAY_SIZE /* MiniOS leaks ARRAY_SIZE into our namespace as part of a
-                    * stubdom build.  It shouldn't... */
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-#endif
-
 /*
 ** Define max dirty page cache to permit during save/restore -- need to balance 
 ** keeping cache usage down with CPU impact of invalidating too often.
index c5828945891488bfdfa7ff335f7c36069d762c30..b3c8849de83b6094f75dcf4b81f2cf9d7cafb2f9 100644 (file)
@@ -57,6 +57,8 @@
 #include <xenguest.h>
 #include <xc_dom.h>
 
+#include <xen-tools/libs.h>
+
 #include "xentoollog.h"
 
 #include <xen/io/xenbus.h>
 #define MB(_mb)     (_AC(_mb, ULL) << 20)
 #define GB(_gb)     (_AC(_gb, ULL) << 30)
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
 #define ROUNDUP(_val, _order)                                           \
     (((unsigned long)(_val)+(1UL<<(_order))-1) & ~((1UL<<(_order))-1))
 
index e116339733b8dff20eda070cd3cec610fd03d870..4a4044a62811dc8e81c4a362c3228f4b6f08de06 100644 (file)
@@ -6,7 +6,8 @@
 
 #include <xenctrl.h>
 
-#define ARRAY_SIZE(a) (sizeof a / sizeof *a)
+#include <xen-tools/libs.h>
+
 static uint32_t nr_features;
 
 static const char *str_1d[32] =
index 1da50e14d937f128c0c1a9b8c12b0d5c8baa3a55..47789148206ea370176e48b0b237a0ada0b3f48d 100644 (file)
@@ -15,8 +15,6 @@
 
 static xc_interface *xch;
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 void show_help(void)
 {
     fprintf(stderr,
index ebcc9e8dd6d5b0d8d21aef8bc6574ea7bc52386a..40cd9667685a5f6e96c0ca253bc2fcf2757e77a6 100644 (file)
@@ -5,9 +5,6 @@
 #include <xenstore.h>
 #include <unistd.h>
 
-#undef ARRAY_SIZE /* We shouldn't be including xc_private.h */
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 static xc_interface *xch;
 
 void show_help(void)
index af9fcd60f2c098a0a922ff7fda633d71adba2235..3233472157e57a0a8a32700210a9d0dcf224234c 100644 (file)
@@ -45,8 +45,6 @@ static int help_func(int argc, char *argv[])
     return 0;
 }
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 static const char *state2str(unsigned int state)
 {
 #define STATE(x) [LIVEPATCH_STATE_##x] = #x
index 1b22ad77fb32b2bb46a9d36e69bb1f39df7aaf74..858bd0e26b87548a87fffdd49897e4fd2bfc61a9 100644 (file)
@@ -7,9 +7,6 @@
 
 #include "xg_save_restore.h"
 
-#undef ARRAY_SIZE /* We shouldn't be including xc_private.h */
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 static xc_interface *xch;
 
 int help_func(int argc, char *argv[])
index 0e1968a23d6d32a031110635fc24d7889b9bc672..86c12ea5fb793b2f57e5d43b71c9efd0fbaccd03 100644 (file)
 #include <inttypes.h>
 #include <sys/time.h>
 
+#include <xen-tools/libs.h>
+
 #define MAX_PKG_RESIDENCIES 12
 #define MAX_CORE_RESIDENCIES 8
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 static xc_interface *xc_handle;
 static unsigned int max_cpu_nr;
 
index 694bfa0642723652cda136077803f5b0d658e632..fc19ee07417e8c3740018303c036163e780de6b0 100644 (file)
@@ -22,7 +22,7 @@
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/params.h>
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#include <xen-tools/libs.h>
 
 /* Needed for Python versions earlier than 2.3. */
 #ifndef PyMODINIT_FUNC
index 383acffc3a1076a25e51225f243c9a612de7c824..b022cc0eab0373f8e1896df6d710ad94afb3c62f 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "hpet.h"
 
+#include <xen-tools/libs.h>
+
 #define NR_CPUS 8
 
 typedef int64_t s_time_t;
@@ -61,10 +63,6 @@ struct msi_msg
     u32     dest32;         /* used when Interrupt Remapping with EIM is enabled */
 };
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
-
 #define X86EMUL_OKAY 100
 #define EINVAL 101
 
index c5e85de3a24f3c6eb2820731d22bd73d30823fff..fd1ba5218b93f366615c0dc340fa6094a8f28baa 100644 (file)
 #include <asm/x86-defns.h>
 #include <asm/x86-vendors.h>
 
+#include <xen-tools/libs.h>
+
 #define BUG() abort()
 #define ASSERT assert
 #define ASSERT_UNREACHABLE() assert(!__LINE__)
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
-
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
-#define BUILD_BUG_ON_ZERO(cond) \
-    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
-#else
-#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
-#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
-#endif
-
 #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
 #define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
 
index a081168dea8588552816c31a3425b5853d12fb37..8c32bfbc3f816e1567ea0514dd2e390e1c4c3841 100644 (file)
@@ -42,6 +42,8 @@
 #include <xenevtchn.h>
 #include <xen/vm_event.h>
 
+#include <xen-tools/libs.h>
+
 #if defined(__arm__) || defined(__aarch64__)
 #include <xen/arch-arm.h>
 #define START_PFN (GUEST_RAM0_BASE >> 12)
 /* From xen/include/asm-x86/x86-defns.h */
 #define X86_CR4_PGE        0x00000080 /* enable global pages */
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
-
 typedef struct vm_event {
     domid_t domain_id;
     xenevtchn_handle *xce_handle;
index eb5fe5572287439f40d4ff869c5979d3ee826b22..ec0e47a34556fba0efcb65a039de6104cf62191c 100644 (file)
@@ -30,8 +30,9 @@
 #include <time.h>
 #include <xenstore.h>
 
+#include <xen-tools/libs.h>
+
 #define TEST_PATH "xenstore-test"
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 #define WRITE_BUFFERS_N    10
 #define WRITE_BUFFERS_SIZE 4000
 #define MAX_TA_LOOPS       100
index 2effd17b615f6eb94d3cec9f0be57dba86e03b6f..dc3a0a0f8b4c56e58b4b13ac7e2d22d314bbc428 100644 (file)
@@ -4,6 +4,8 @@
 #include <string.h>
 #include <stdint.h>
 
+#include <xen-tools/libs.h>
+
 /* Is A == B ? */
 #define streq(a,b) (strcmp((a),(b)) == 0)
 
@@ -19,10 +21,6 @@ static inline bool strends(const char *a, const char *b)
        return streq(a + strlen(a) - strlen(b), b);
 }
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
-
 void barf(const char *fmt, ...) __attribute__((noreturn));
 void barf_perror(const char *fmt, ...) __attribute__((noreturn));
 
index 40ee551e1de5d7e5eb3704081e439b5550628274..f9d98d8da489a5358cf74ba76ae09d04def56de7 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <stdint.h>
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#include <xen-tools/libs.h>
 
 #define TRC_GEN_MAIN     0
 #define TRC_SCHED_MAIN   1