Skip to content

Commit

Permalink
Add 'extern "C"' for all relevant public header files, plus a build c…
Browse files Browse the repository at this point in the history
…heck.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
  • Loading branch information
blp committed Jul 31, 2017
1 parent 994bfc2 commit ec30ca5
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/openvswitch/automake.mk
Expand Up @@ -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
8 changes: 8 additions & 0 deletions include/openvswitch/dynamic-string.h
Expand Up @@ -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.
*
Expand Down Expand Up @@ -90,4 +94,8 @@ ds_put_char(struct ds *ds, char c)
}
}

#ifdef __cplusplus
}
#endif

#endif /* dynamic-string.h */
8 changes: 8 additions & 0 deletions include/openvswitch/flow.h
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/geneve.h
Expand Up @@ -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

Expand Down Expand Up @@ -60,4 +64,8 @@ struct genevehdr {
struct geneve_opt options[];
};

#ifdef __cplusplus
}
#endif

#endif /* geneve.h */
8 changes: 8 additions & 0 deletions include/openvswitch/list.h
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/match.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
9 changes: 9 additions & 0 deletions include/openvswitch/meta-flow.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/netdev.h
Expand Up @@ -21,6 +21,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

struct netdev;

/* Network device statistics.
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/ofp-actions.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/ofp-errors.h
Expand Up @@ -21,6 +21,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#include "openflow/openflow.h"

struct ds;
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/ofp-msgs.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/ofp-parse.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/ofp-prop.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
9 changes: 9 additions & 0 deletions include/openvswitch/ofp-util.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/packets.h
Expand Up @@ -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;
Expand Down Expand Up @@ -69,4 +73,8 @@ union flow_vlan_hdr {
};
};

#ifdef __cplusplus
}
#endif

#endif /* packets.h */
8 changes: 8 additions & 0 deletions include/openvswitch/thread.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
8 changes: 8 additions & 0 deletions include/openvswitch/token-bucket.h
Expand Up @@ -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. */
Expand All @@ -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 */
7 changes: 7 additions & 0 deletions include/openvswitch/tun-metadata.h
Expand Up @@ -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

Expand Down Expand Up @@ -97,5 +101,8 @@ struct tun_metadata_allocation {
bool valid; /* Set to true after any allocation occurs. */
};

#ifdef __cplusplus
}
#endif

#endif /* tun-metadata.h */
8 changes: 8 additions & 0 deletions include/openvswitch/type-props.h
Expand Up @@ -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)

Expand Down Expand Up @@ -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 */

0 comments on commit ec30ca5

Please sign in to comment.