bswap: improve gluing
OpenBSD system compiler (gcc 4.2.1) has problems with concatenation of macro arguments in macro functions: CC aes.o In file included from /src/qemu/include/qemu-common.h:126, from /src/qemu/aes.c:30: /src/qemu/include/qemu/bswap.h: In function 'leul_to_cpu': /src/qemu/include/qemu/bswap.h:461: warning: implicit declaration of function 'bswapHOST_LONG_BITS' /src/qemu/include/qemu/bswap.h:461: warning: nested extern declaration of 'bswapHOST_LONG_BITS' Function leul_to_cpu() is only used in kvm-all.c, so the warnings are not fatal on OpenBSD without -Werror. Fix by applying glue(). Also add do {} while(0) wrapping and fix semicolon use while at it. Signed-off-by: Blue Swirl <blauwirbel@gmail.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
47f4dac3fd
commit
a4cbfe24e4
@ -72,45 +72,45 @@ static inline void bswap64s(uint64_t *s)
|
|||||||
|
|
||||||
#if defined(HOST_WORDS_BIGENDIAN)
|
#if defined(HOST_WORDS_BIGENDIAN)
|
||||||
#define be_bswap(v, size) (v)
|
#define be_bswap(v, size) (v)
|
||||||
#define le_bswap(v, size) bswap ## size(v)
|
#define le_bswap(v, size) glue(bswap, size)(v)
|
||||||
#define be_bswaps(v, size)
|
#define be_bswaps(v, size)
|
||||||
#define le_bswaps(p, size) *p = bswap ## size(*p);
|
#define le_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
|
||||||
#else
|
#else
|
||||||
#define le_bswap(v, size) (v)
|
#define le_bswap(v, size) (v)
|
||||||
#define be_bswap(v, size) bswap ## size(v)
|
#define be_bswap(v, size) glue(bswap, size)(v)
|
||||||
#define le_bswaps(v, size)
|
#define le_bswaps(v, size)
|
||||||
#define be_bswaps(p, size) *p = bswap ## size(*p);
|
#define be_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CPU_CONVERT(endian, size, type)\
|
#define CPU_CONVERT(endian, size, type)\
|
||||||
static inline type endian ## size ## _to_cpu(type v)\
|
static inline type endian ## size ## _to_cpu(type v)\
|
||||||
{\
|
{\
|
||||||
return endian ## _bswap(v, size);\
|
return glue(endian, _bswap)(v, size);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
static inline type cpu_to_ ## endian ## size(type v)\
|
static inline type cpu_to_ ## endian ## size(type v)\
|
||||||
{\
|
{\
|
||||||
return endian ## _bswap(v, size);\
|
return glue(endian, _bswap)(v, size);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
static inline void endian ## size ## _to_cpus(type *p)\
|
static inline void endian ## size ## _to_cpus(type *p)\
|
||||||
{\
|
{\
|
||||||
endian ## _bswaps(p, size)\
|
glue(endian, _bswaps)(p, size);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
static inline void cpu_to_ ## endian ## size ## s(type *p)\
|
static inline void cpu_to_ ## endian ## size ## s(type *p)\
|
||||||
{\
|
{\
|
||||||
endian ## _bswaps(p, size)\
|
glue(endian, _bswaps)(p, size);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
static inline type endian ## size ## _to_cpup(const type *p)\
|
static inline type endian ## size ## _to_cpup(const type *p)\
|
||||||
{\
|
{\
|
||||||
return endian ## size ## _to_cpu(*p);\
|
return glue(glue(endian, size), _to_cpu)(*p);\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
static inline void cpu_to_ ## endian ## size ## w(type *p, type v)\
|
static inline void cpu_to_ ## endian ## size ## w(type *p, type v)\
|
||||||
{\
|
{\
|
||||||
*p = cpu_to_ ## endian ## size(v);\
|
*p = glue(glue(cpu_to_, endian), size)(v);\
|
||||||
}
|
}
|
||||||
|
|
||||||
CPU_CONVERT(be, 16, uint16_t)
|
CPU_CONVERT(be, 16, uint16_t)
|
||||||
|
Loading…
Reference in New Issue
Block a user