]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* include/grub/types.h: Declare all byteswaps as inline functions
authorVladimir Serbinenko <phcoder@gmail.com>
Wed, 4 Dec 2013 07:42:35 +0000 (08:42 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Wed, 4 Dec 2013 07:42:35 +0000 (08:42 +0100)
except compile-time ones.

Solves variable shadowing in constructions like
cpu_to_le (le_to_cpu(x) + 1).

ChangeLog
include/grub/types.h

index c1f2b61c7b85efd11cfc66b721c36a18402e8901..38e128462d45f97c758bbc484d4d06ab44600ffe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-12-04  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * 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  <phcoder@gmail.com>
 
        * grub-core/kern/efi/efi.c: Remove variable length arrays.
index 8c737aa6f17ac70e234072577a04963ceacdd5ee..e8c2f68f9d3ce884c5746ec93a3bcb8f40305eb6 100644 (file)
@@ -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