[ovs-dev] [PATCH 5/5] Add 'extern "C"' for all relevant public header files, plus a build check.

Ben Pfaff blp at ovn.org
Mon Jul 31 02:55:00 UTC 2017


Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 include/openvswitch/automake.mk      | 20 ++++++++++++++++++++
 include/openvswitch/dynamic-string.h |  8 ++++++++
 include/openvswitch/flow.h           |  8 ++++++++
 include/openvswitch/geneve.h         |  8 ++++++++
 include/openvswitch/list.h           |  8 ++++++++
 include/openvswitch/match.h          |  8 ++++++++
 include/openvswitch/meta-flow.h      |  9 +++++++++
 include/openvswitch/netdev.h         |  8 ++++++++
 include/openvswitch/ofp-actions.h    |  8 ++++++++
 include/openvswitch/ofp-errors.h     |  8 ++++++++
 include/openvswitch/ofp-msgs.h       |  8 ++++++++
 include/openvswitch/ofp-parse.h      |  8 ++++++++
 include/openvswitch/ofp-prop.h       |  8 ++++++++
 include/openvswitch/ofp-util.h       |  9 +++++++++
 include/openvswitch/packets.h        |  8 ++++++++
 include/openvswitch/thread.h         |  8 ++++++++
 include/openvswitch/token-bucket.h   |  8 ++++++++
 include/openvswitch/tun-metadata.h   |  7 +++++++
 include/openvswitch/type-props.h     |  8 ++++++++
 include/openvswitch/types.h          |  8 ++++++++
 include/openvswitch/uuid.h           |  8 ++++++++
 21 files changed, 181 insertions(+)

diff --git a/include/openvswitch/automake.mk b/include/openvswitch/automake.mk
index 74b31acfa66b..6bace61593ff 100644
--- a/include/openvswitch/automake.mk
+++ b/include/openvswitch/automake.mk
@@ -44,3 +44,23 @@ include/openvswitch/cxxtest.cc: include/openvswitch/automake.mk
 	  echo $$header;						\
 	done | sed 's,^include/\(.*\)$$,#include <\1>,' > $@
 endif
+
+# OVS does not use C++ itself, but it provides public header files
+# that a C++ compiler should accept, so we make sure that every public
+# header file has the proper extern declaration for use with C++.
+#
+# Some header files don't declare any external functions, so they
+# don't really need extern "C".  We only white list a couple of these
+# below, which are the ones that seem unlikely to ever declare
+# external functions.  For the rest, we add extern "C" anyway; it
+# doesn't hurt.
+ALL_LOCAL += cxx-check
+cxx-check: $(openvswitchinclude_HEADERS)
+	@if LC_ALL=C grep -L 'extern "C"' $^ | \
+          $(EGREP) -v 'version.h|compiler.h'; \
+	then \
+	    echo "See above list of public headers lacking 'extern \"C\"'."; \
+	    exit 1; \
+	fi
+	$(AM_V_GEN)touch $@
+CLEANFILES += cxx-check
diff --git a/include/openvswitch/dynamic-string.h b/include/openvswitch/dynamic-string.h
index bf1f64a630fa..ee1821710745 100644
--- a/include/openvswitch/dynamic-string.h
+++ b/include/openvswitch/dynamic-string.h
@@ -24,6 +24,10 @@
 #include <stdio.h>
 #include "openvswitch/compiler.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* A "dynamic string", that is, a buffer that can be used to construct a
  * string across a series of operations that extend or modify it.
  *
@@ -90,4 +94,8 @@ ds_put_char(struct ds *ds, char c)
     }
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* dynamic-string.h */
diff --git a/include/openvswitch/flow.h b/include/openvswitch/flow.h
index 36a2a8577c98..e9782d72c9ad 100644
--- a/include/openvswitch/flow.h
+++ b/include/openvswitch/flow.h
@@ -20,6 +20,10 @@
 #include "openvswitch/packets.h"
 #include "openvswitch/util.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* This sequence number should be incremented whenever anything involving flows
  * or the wildcarding of flows changes.  This will cause build assertion
  * failures in places which likely need to be updated. */
@@ -225,4 +229,8 @@ uint32_t flow_wildcards_hash(const struct flow_wildcards *, uint32_t basis);
 bool flow_wildcards_equal(const struct flow_wildcards *,
                           const struct flow_wildcards *);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* flow.h */
diff --git a/include/openvswitch/geneve.h b/include/openvswitch/geneve.h
index 73119857a1cb..a481cc597960 100644
--- a/include/openvswitch/geneve.h
+++ b/include/openvswitch/geneve.h
@@ -19,6 +19,10 @@
 
 #include "openvswitch/types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define TLV_MAX_OPT_SIZE 124
 #define TLV_TOT_OPT_SIZE 252
 
@@ -60,4 +64,8 @@ struct genevehdr {
     struct geneve_opt options[];
 };
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* geneve.h */
diff --git a/include/openvswitch/list.h b/include/openvswitch/list.h
index 2bc294c5fb07..8ad5eeb32777 100644
--- a/include/openvswitch/list.h
+++ b/include/openvswitch/list.h
@@ -22,6 +22,10 @@
 #include <openvswitch/types.h>
 #include <openvswitch/util.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Doubly linked list head or element. */
 struct ovs_list {
     struct ovs_list *prev;     /* Previous list element. */
@@ -301,4 +305,8 @@ ovs_list_push_back_all(struct ovs_list *dst, struct ovs_list *src)
     ovs_list_splice(dst, src->next, src);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* list.h */
diff --git a/include/openvswitch/match.h b/include/openvswitch/match.h
index aca725265c79..1b43de0d181b 100644
--- a/include/openvswitch/match.h
+++ b/include/openvswitch/match.h
@@ -21,6 +21,10 @@
 #include "openvswitch/packets.h"
 #include "openvswitch/tun-metadata.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct ds;
 struct ofputil_port_map;
 struct mf_field;
@@ -244,4 +248,8 @@ void minimatch_format(const struct minimatch *, const struct tun_table *,
 char *minimatch_to_string(const struct minimatch *,
                           const struct ofputil_port_map *, int priority);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* match.h */
diff --git a/include/openvswitch/meta-flow.h b/include/openvswitch/meta-flow.h
index fc109501d869..7e6d7264e6f5 100644
--- a/include/openvswitch/meta-flow.h
+++ b/include/openvswitch/meta-flow.h
@@ -28,6 +28,10 @@
 #include "openvswitch/packets.h"
 #include "openvswitch/util.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct ds;
 struct match;
 struct ofputil_port_map;
@@ -2136,4 +2140,9 @@ void mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s);
 /* Field Arrays. */
 void field_array_set(enum mf_field_id id, const union mf_value *,
                      struct field_array *);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* meta-flow.h */
diff --git a/include/openvswitch/netdev.h b/include/openvswitch/netdev.h
index 88a25dd2594d..50bafc3a66b1 100644
--- a/include/openvswitch/netdev.h
+++ b/include/openvswitch/netdev.h
@@ -21,6 +21,10 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct netdev;
 
 /* Network device statistics.
@@ -111,4 +115,8 @@ uint64_t netdev_features_to_bps(enum netdev_features features,
 bool netdev_features_is_full_duplex(enum netdev_features features);
 int netdev_set_advertisements(struct netdev *, enum netdev_features advertise);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* netdev.h */
diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h
index 00dde7c89e8d..198107e9cc01 100644
--- a/include/openvswitch/ofp-actions.h
+++ b/include/openvswitch/ofp-actions.h
@@ -26,6 +26,10 @@
 #include "openvswitch/ofp-errors.h"
 #include "openvswitch/types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct vl_mff_map;
 
 /* List of OVS abstracted actions.
@@ -1191,4 +1195,8 @@ ovs_be32 ovsinst_bitmap_to_openflow(uint32_t ovsinst_bitmap, enum ofp_version);
 uint32_t ovsinst_bitmap_from_openflow(ovs_be32 ofpit_bitmap,
                                       enum ofp_version);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ofp-actions.h */
diff --git a/include/openvswitch/ofp-errors.h b/include/openvswitch/ofp-errors.h
index aeb58e012fd3..b551ce67793a 100644
--- a/include/openvswitch/ofp-errors.h
+++ b/include/openvswitch/ofp-errors.h
@@ -21,6 +21,10 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "openflow/openflow.h"
 
 struct ds;
@@ -823,4 +827,8 @@ const char *ofperr_get_description(enum ofperr);
 void ofperr_format(struct ds *, enum ofperr);
 const char *ofperr_to_string(enum ofperr);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ofp-errors.h */
diff --git a/include/openvswitch/ofp-msgs.h b/include/openvswitch/ofp-msgs.h
index 6dc0b60e1816..5f3815c140ef 100644
--- a/include/openvswitch/ofp-msgs.h
+++ b/include/openvswitch/ofp-msgs.h
@@ -41,6 +41,10 @@
 #include "openvswitch/ofp-errors.h"
 #include "openvswitch/types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct ovs_list;
 
 /* Raw identifiers for OpenFlow messages.
@@ -777,4 +781,8 @@ enum ofpraw ofpmp_decode_raw(struct ovs_list *);
 uint16_t ofpmp_flags(const struct ofp_header *);
 bool ofpmp_more(const struct ofp_header *);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ofp-msgs.h */
diff --git a/include/openvswitch/ofp-parse.h b/include/openvswitch/ofp-parse.h
index fc5784e11e36..013a8f3edf70 100644
--- a/include/openvswitch/ofp-parse.h
+++ b/include/openvswitch/ofp-parse.h
@@ -25,6 +25,10 @@
 #include "openvswitch/compiler.h"
 #include "openvswitch/types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct flow;
 struct ofpbuf;
 struct ofputil_flow_mod;
@@ -123,4 +127,8 @@ char *parse_ofp_table_vacancy(struct ofputil_table_mod *,
                               const char *flow_miss_handling)
     OVS_WARN_UNUSED_RESULT;
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ofp-parse.h */
diff --git a/include/openvswitch/ofp-prop.h b/include/openvswitch/ofp-prop.h
index 0ba2d359ce85..e676f8dc0f72 100644
--- a/include/openvswitch/ofp-prop.h
+++ b/include/openvswitch/ofp-prop.h
@@ -52,6 +52,10 @@
 #include "openvswitch/ofp-errors.h"
 #include "openvswitch/types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct ofpbuf;
 struct uuid;
 struct vlog_module;
@@ -135,4 +139,8 @@ enum ofperr ofpprop_unknown(struct vlog_module *, bool loose, const char *msg,
 #define OFPPROP_UNKNOWN(LOOSE, MSG, TYPE) \
     ofpprop_unknown(&this_module, LOOSE, MSG, TYPE)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ofp-prop.h */
diff --git a/include/openvswitch/ofp-util.h b/include/openvswitch/ofp-util.h
index 5d911af89671..a9e57ed5808d 100644
--- a/include/openvswitch/ofp-util.h
+++ b/include/openvswitch/ofp-util.h
@@ -34,6 +34,10 @@
 #include "openvswitch/type-props.h"
 #include "openvswitch/uuid.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct ofpbuf;
 union ofp_action;
 struct ofpact_set_field;
@@ -1498,4 +1502,9 @@ enum ofperr ofputil_decode_table_status(const struct ofp_header *oh,
 struct ofpbuf *
 ofputil_encode_table_status(const struct ofputil_table_status *ts,
                             enum ofputil_protocol protocol);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ofp-util.h */
diff --git a/include/openvswitch/packets.h b/include/openvswitch/packets.h
index f13d634eae3d..e440f666e70f 100644
--- a/include/openvswitch/packets.h
+++ b/include/openvswitch/packets.h
@@ -20,6 +20,10 @@
 #include <netinet/in.h>
 #include "openvswitch/tun-metadata.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Tunnel information used in flow key and metadata. */
 struct flow_tnl {
     ovs_be32 ip_dst;
@@ -69,4 +73,8 @@ union flow_vlan_hdr {
     };
 };
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* packets.h */
diff --git a/include/openvswitch/thread.h b/include/openvswitch/thread.h
index af6f2bbc0c72..5ffc290677f3 100644
--- a/include/openvswitch/thread.h
+++ b/include/openvswitch/thread.h
@@ -23,6 +23,10 @@
 #include <sys/types.h>
 #include "openvswitch/compiler.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Mutex. */
 struct OVS_LOCKABLE ovs_mutex {
     pthread_mutex_t lock;
@@ -134,4 +138,8 @@ ovsthread_once_start(struct ovsthread_once *once)
     return OVS_UNLIKELY(!once->done && ovsthread_once_start__(once));
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* ovs-thread.h */
diff --git a/include/openvswitch/token-bucket.h b/include/openvswitch/token-bucket.h
index 6bb6040f5dce..580747f61d1a 100644
--- a/include/openvswitch/token-bucket.h
+++ b/include/openvswitch/token-bucket.h
@@ -20,6 +20,10 @@
 #include <limits.h>
 #include <stdbool.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct token_bucket {
     /* Configuration settings. */
     unsigned int rate;          /* Tokens added per millisecond. */
@@ -42,4 +46,8 @@ void token_bucket_wait_at(struct token_bucket *, unsigned int n,
 #define token_bucket_wait(bucket, n)                    \
     token_bucket_wait_at(bucket, n, OVS_SOURCE_LOCATOR)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* token-bucket.h */
diff --git a/include/openvswitch/tun-metadata.h b/include/openvswitch/tun-metadata.h
index 1d6b73757711..935c5c495027 100644
--- a/include/openvswitch/tun-metadata.h
+++ b/include/openvswitch/tun-metadata.h
@@ -19,6 +19,10 @@
 
 #include "openvswitch/geneve.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define TUN_METADATA_NUM_OPTS 64
 #define TUN_METADATA_TOT_OPT_SIZE 256
 
@@ -97,5 +101,8 @@ struct tun_metadata_allocation {
     bool valid;                 /* Set to true after any allocation occurs. */
 };
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* tun-metadata.h */
diff --git a/include/openvswitch/type-props.h b/include/openvswitch/type-props.h
index bf879cd82816..8dc74931f69f 100644
--- a/include/openvswitch/type-props.h
+++ b/include/openvswitch/type-props.h
@@ -19,6 +19,10 @@
 
 #include <limits.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* True if TYPE is _Bool, false otherwise. */
 #define TYPE_IS_BOOL(TYPE) ((TYPE) 1 == (TYPE) 2)
 
@@ -52,4 +56,8 @@
  * The value is an overestimate. */
 #define INT_STRLEN(TYPE) (TYPE_IS_SIGNED(TYPE) + TYPE_VALUE_BITS(TYPE) / 3 + 1)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* type-props.h */
diff --git a/include/openvswitch/types.h b/include/openvswitch/types.h
index 111e30bca98b..f7e1c07dd8b0 100644
--- a/include/openvswitch/types.h
+++ b/include/openvswitch/types.h
@@ -21,6 +21,10 @@
 #include <stdint.h>
 #include "openvswitch/compiler.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifdef __CHECKER__
 #define OVS_BITWISE __attribute__((bitwise))
 #define OVS_FORCE __attribute__((force))
@@ -172,4 +176,8 @@ struct eth_addr64 {
     };
 };
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* openvswitch/types.h */
diff --git a/include/openvswitch/uuid.h b/include/openvswitch/uuid.h
index 383a408e5676..988a081d6844 100644
--- a/include/openvswitch/uuid.h
+++ b/include/openvswitch/uuid.h
@@ -18,6 +18,10 @@
 
 #include "openvswitch/util.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define UUID_BIT 128            /* Number of bits in a UUID. */
 #define UUID_OCTET (UUID_BIT / 8) /* Number of bytes in a UUID. */
 
@@ -32,4 +36,8 @@ struct uuid {
 };
 BUILD_ASSERT_DECL(sizeof(struct uuid) == UUID_OCTET);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* uuid.h */
-- 
2.10.2



More information about the dev mailing list