diff --git a/ChangeLog b/ChangeLog index c1f2b61c7..38e128462 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2013-12-04 Vladimir Serbinenko + + * include/grub/types.h: Declare all byteswaps as inline functions + except compile-time ones. + + Solves variable shadowing in constructions like + cpu_to_le (le_to_cpu(x) + 1). + 2013-12-04 Vladimir Serbinenko * grub-core/kern/efi/efi.c: Remove variable length arrays. diff --git a/include/grub/types.h b/include/grub/types.h index 8c737aa6f..e8c2f68f9 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -153,11 +153,10 @@ typedef grub_uint64_t grub_off_t; typedef grub_uint64_t grub_disk_addr_t; /* Byte-orders. */ -#define grub_swap_bytes16(x) \ -({ \ - grub_uint16_t _x = (x); \ - (grub_uint16_t) ((_x << 8) | (_x >> 8)); \ -}) +static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x) +{ + return (grub_uint16_t) ((_x << 8) | (_x >> 8)); +} #define grub_swap_bytes16_compile_time(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8)) #define grub_swap_bytes32_compile_time(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24)) @@ -185,27 +184,25 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x) return __builtin_bswap64(x); } #else /* not gcc 4.3 or newer */ -#define grub_swap_bytes32(x) \ -({ \ - grub_uint32_t _x = (x); \ - (grub_uint32_t) ((_x << 24) \ - | ((_x & (grub_uint32_t) 0xFF00UL) << 8) \ - | ((_x & (grub_uint32_t) 0xFF0000UL) >> 8) \ - | (_x >> 24)); \ -}) +static inline grub_uint32_t grub_swap_bytes32(grub_uint32_t _x) +{ + return ((_x << 24) + | ((_x & (grub_uint32_t) 0xFF00UL) << 8) + | ((_x & (grub_uint32_t) 0xFF0000UL) >> 8) + | (_x >> 24)); +} -#define grub_swap_bytes64(x) \ -({ \ - grub_uint64_t _x = (x); \ - (grub_uint64_t) ((_x << 56) \ - | ((_x & (grub_uint64_t) 0xFF00ULL) << 40) \ - | ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) \ - | ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) \ - | ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) \ - | ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \ - | ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \ - | (_x >> 56)); \ -}) +static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t _x) +{ + return ((_x << 56) + | ((_x & (grub_uint64_t) 0xFF00ULL) << 40) + | ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) + | ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) + | ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) + | ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) + | ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) + | (_x >> 56)); +} #endif /* not gcc 4.3 or newer */ #ifdef GRUB_CPU_WORDS_BIGENDIAN