]> git.proxmox.com Git - mirror_ovs.git/commitdiff
packets: Fix C++ compilation issues when include packets.h
authorYi-Hung Wei <yihung.wei@gmail.com>
Wed, 1 Nov 2017 21:40:27 +0000 (14:40 -0700)
committerBen Pfaff <blp@ovn.org>
Thu, 2 Nov 2017 18:23:38 +0000 (11:23 -0700)
This patch fixes three C++ compilation errors when it includes
"lib/packets.h".

1) Fix in "include/openvswitch/util.h" is to avoid duplicated
named_member__ in struct pkt_metadata.

2) Fix in "lib/packets.h" is because designated initializers are not
implemented in GNU C++ [1].

3) Fix in "lib/util.h" is because __builtin_types_compatible_p and
__builtin_choose_expr are only supported in GCC. I use one solution
for C++ that is type-safe and works at compile time from [2].

[1]: https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
[2]: https://goo.gl/xNe48A

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
include/openvswitch/util.h
lib/packets.h
lib/util.h

index 84d7e07ff370ab083e09e17ca3dade43b0af877b..c3e60d56135bcddc38db7ac69ec36a3730e54f88 100644 (file)
@@ -232,12 +232,12 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
         uint8_t PAD_ID[ROUND_UP(sizeof(struct { MEMBERS }), UNIT)]; \
     }
 #else
-#define PADDED_MEMBERS_CACHELINE_MARKER(UNIT, CACHELINE, MEMBERS)   \
-    union {                                                         \
-        OVS_CACHE_LINE_MARKER CACHELINE;                            \
-        struct { MEMBERS };                                         \
-        struct { MEMBERS } named_member__;                          \
-        uint8_t PAD_ID[ROUND_UP(sizeof named_member__, UNIT)];      \
+#define PADDED_MEMBERS_CACHELINE_MARKER(UNIT, CACHELINE, MEMBERS)           \
+    union {                                                                 \
+        OVS_CACHE_LINE_MARKER CACHELINE;                                    \
+        struct { MEMBERS };                                                 \
+        struct { MEMBERS } named_member_##CACHELINE;                        \
+        uint8_t PAD_ID[ROUND_UP(sizeof named_member_##CACHELINE, UNIT)];    \
     }
 #endif
 
index c5915a0f817e966c66c302d35d69ab5aae508f89..461f488a875df0f9d5fb5c4b3f33e6d2f5508814 100644 (file)
@@ -1107,7 +1107,9 @@ static inline bool ipv6_addr_is_multicast(const struct in6_addr *ip) {
 static inline struct in6_addr
 in6_addr_mapped_ipv4(ovs_be32 ip4)
 {
-    struct in6_addr ip6 = { .s6_addr = { [10] = 0xff, [11] = 0xff } };
+    struct in6_addr ip6;
+    memset(&ip6, 0, sizeof(ip6));
+    ip6.s6_addr[10] = 0xff, ip6.s6_addr[11] = 0xff;
     memcpy(&ip6.s6_addr[12], &ip4, 4);
     return ip6;
 }
index 764e0a08a429c20b5a67e9d7642ad31595718482..3c43c2c355e2f229323efc6b95be5c58b7754ced 100644 (file)
@@ -31,7 +31,7 @@
 extern char *program_name;
 
 #define __ARRAY_SIZE_NOCHECK(ARRAY) (sizeof(ARRAY) / sizeof((ARRAY)[0]))
-#ifdef __GNUC__
+#if __GNUC__ && !defined(__cplusplus)
 /* return 0 for array types, 1 otherwise */
 #define __ARRAY_CHECK(ARRAY)                                   \
     !__builtin_types_compatible_p(typeof(ARRAY), typeof(&ARRAY[0]))
@@ -41,6 +41,19 @@ extern char *program_name;
 #define __ARRAY_SIZE(ARRAY)                                    \
     __builtin_choose_expr(__ARRAY_CHECK(ARRAY),                        \
         __ARRAY_SIZE_NOCHECK(ARRAY), __ARRAY_FAIL(ARRAY))
+#elif defined(__cplusplus)
+#define __ARRAY_SIZE(ARRAY) ( \
+   0 * sizeof(reinterpret_cast<const ::Bad_arg_to_ARRAY_SIZE *>(ARRAY)) + \
+   0 * sizeof(::Bad_arg_to_ARRAY_SIZE::check_type((ARRAY), &(ARRAY))) + \
+   sizeof(ARRAY) / sizeof((ARRAY)[0]) )
+
+struct Bad_arg_to_ARRAY_SIZE {
+   class Is_pointer;
+   class Is_array {};
+   template <typename T>
+   static Is_pointer check_type(const T *, const T * const *);
+   static Is_array check_type(const void *, const void *);
+};
 #else
 #define __ARRAY_SIZE(ARRAY) __ARRAY_SIZE_NOCHECK(ARRAY)
 #endif