tools: Move ARRAY_SIZE() into xen-tools/libs.h

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>
This commit is contained in:
Andrew Cooper committed 2018-07-04 17:25:37 +01:00
1 parent 8674b02374
commit e1b7eb92d3
16 files changed
+24 -47

No files matched your search

+4
View File
@@ -9,4 +9,8 @@
#endif
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
#endif
#endif /* __XEN_TOOLS_LIBS__ */
+2 -5
View 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.
+2 -2
View 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>
@@ -127,8 +129,6 @@
#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))
+2 -1
View 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] =
-2
View File
@@ -15,8 +15,6 @@
static xc_interface *xch;
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
void show_help(void)
{
fprintf(stderr,
-3
View 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)
-2
View 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
-3
View 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[])
+2 -2
View File
@@ -28,11 +28,11 @@
#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;
+1 -1
View 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
+2 -4
View 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
+2 -12
View File
@@ -15,22 +15,12 @@
#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))
+2 -4
View 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)
@@ -60,10 +62,6 @@
/* 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;
+2 -1
View 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
+2 -4
View 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));
+1 -1
View 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
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.