tools: Move ARRAY_SIZE() into xen-tools/libs.h
PATCH 1/1 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.
---
CC: Jan Beulich <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
--- tools/include/xen-tools/libs.h | 4 ++++ tools/libxc/xc_private.h | 7 ++----- tools/libxl/libxl_internal.h | 4 ++-- tools/misc/xen-cpuid.c | 3 ++- tools/misc/xen-diag.c | 2 -- tools/misc/xen-hptool.c | 3 --- tools/misc/xen-livepatch.c | 2 -- tools/misc/xen-mfndump.c | 3 --- tools/misc/xenpm.c | 4 ++-- tools/python/xen/lowlevel/xc/xc.c | 2 +- tools/tests/vhpet/emul.h | 6 ++---- tools/tests/x86_emulator/x86-emulate.h | 14 ++------------ tools/tests/xen-access/xen-access.c | 6 ++---- tools/tests/xenstore/xs-test.c | 3 ++- tools/xenstore/utils.h | 6 ++---- tools/xentrace/analyze.h | 2 +- 16 files changed, 24 insertions(+), 47 deletions(-)
tools/include/xen-tools/libs.h +4 -0
@@ -9,4 +9,8 @@#endif #endif +#ifndef ARRAY_SIZE +#define ARRAY_SIZE (a) (sizeof(a) / sizeof(*a)) +#endif +#endif /* __XEN_TOOLS_LIBS__ */
tools/libxc/xc_private.h +2 -5
@@ -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.
tools/libxl/libxl_internal.h +2 -2
@@ -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))
tools/misc/xen-cpuid.c +2 -1
@@ -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] =
tools/misc/xen-diag.c +0 -2
@@ -15,8 +15,6 @@static xc_interface *xch; -#define ARRAY_SIZE (a) (sizeof (a) / sizeof ((a)[0])) -void show_help (void ) { fprintf(stderr,
tools/misc/xen-hptool.c +0 -3
@@ -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 )
tools/misc/xen-livepatch.c +0 -2
@@ -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
tools/misc/xen-mfndump.c +0 -3
@@ -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[])
tools/misc/xenpm.c +2 -2
@@ -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;
tools/python/xen/lowlevel/xc/xc.c +1 -1
@@ -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
tools/tests/vhpet/emul.h +2 -4
@@ -24,6 +24,8 @@#include "hpet.h" +#include <xen-tools/libs.h> +#define NR_CPUS 8typedef int64_t s_time_t ;
@@ -61,10 +63,6 @@ struct msi_msgu32 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
tools/tests/x86_emulator/x86-emulate.h +2 -12
@@ -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))
tools/tests/xen-access/xen-access.c +2 -4
@@ -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;
tools/tests/xenstore/xs-test.c +2 -1
@@ -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
tools/xenstore/utils.h +2 -4
@@ -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));
tools/xentrace/analyze.h +1 -1
@@ -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
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Andrew Cooper writes ("[PATCH] tools: Move ARRAY_SIZE() into xen-tools/libs.h"):
Quoted 3 lines
xen-tools/libs.hcurrently contains a sharedBUILD_BUG_ON()implementation and is used by some tools. Extend this to includeARRAY_SIZEand clean up all the opencoding.
Wow. Thank you.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 04.07.18 at 16:44, <[email protected]> wrote:
xen-tools/libs.hcurrently contains a sharedBUILD_BUG_ON()implementation and is used by some tools. Extend this to includeARRAY_SIZEand clean up all the opencoding.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel