[ovs-dev] [PATCH 1/1] lib: Adapt headers for use in C++.
Casey Barker
crbarker at google.com
Thu Aug 4 23:14:40 UTC 2011
This commit makes several library headers suitable for inclusion in C++.
It adds [extern "C"] guards and makes minor changes to fix casting and
keyword issues.
---
I know gmail will screw up the formatting, so I've also attached the pure
patch as a text file.
classifier.h | 8 ++++++++
hash.h | 12 ++++++++++--
hmap.h | 2 +-
ofp-util.h | 3 ++-
sset.h | 8 ++++++++
vconn.h | 8 ++++++++
6 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/lib/classifier.h b/lib/classifier.h
index b1162ae..2e6d8b9 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -32,6 +32,10 @@
#include "openflow/nicira-ext.h"
#include "openflow/openflow.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* A flow classifier. */
struct classifier {
int n_rules; /* Total number of rules. */
@@ -164,4 +168,8 @@ struct cls_rule *cls_cursor_next(struct cls_cursor *,
struct cls_rule *);
: 0); \
(RULE) = (NEXT))
+#ifdef __cplusplus
+}
+#endif
+
#endif /* classifier.h */
diff --git a/lib/hash.h b/lib/hash.h
index 109612f..026eeda 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -22,6 +22,10 @@
#include <string.h>
#include "util.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* This is the public domain lookup3 hash by Bob Jenkins from
* http://burtleburtle.net/bob/c/lookup3.c, modified for style. */
@@ -81,8 +85,8 @@ static inline uint32_t hash_int(uint32_t x, uint32_t
basis)
* quality. */
static inline uint32_t hash_boolean(bool x, uint32_t basis)
{
- enum { P0 = 0xc2b73583 }; /* This is hash_int(1, 0). */
- enum { P1 = 0xe90f1258 }; /* This is hash_int(2, 0). */
+ const uint32_t P0 = 0xc2b73583; /* This is hash_int(1, 0). */
+ const uint32_t P1 = 0xe90f1258; /* This is hash_int(2, 0). */
return (x ? P0 : P1) ^ HASH_ROT(basis, 1);
}
@@ -108,4 +112,8 @@ static inline uint32_t hash_pointer(const void *p,
uint32_t basis)
return hash_int((uint32_t) (uintptr_t) p, basis);
}
+#ifdef __cplusplus
+}
+#endif
+
#endif /* hash.h */
diff --git a/lib/hmap.h b/lib/hmap.h
index a987fa4..ed2d78d 100644
--- a/lib/hmap.h
+++ b/lib/hmap.h
@@ -89,7 +89,7 @@ static inline void hmap_remove(struct hmap *, struct
hmap_node *);
void hmap_node_moved(struct hmap *, struct hmap_node *, struct hmap_node
*);
static inline void hmap_replace(struct hmap *, const struct hmap_node *old,
- struct hmap_node *new);
+ struct hmap_node *new_node);
struct hmap_node *hmap_random_node(const struct hmap *);
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 7ee3e69..dfd47be 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -315,7 +315,8 @@ enum ofputil_action_code ofputil_decode_action_unsafe(
static inline union ofp_action *
ofputil_action_next(const union ofp_action *a)
{
- return (void *) ((uint8_t *) a + ntohs(a->header.len));
+ return ((union ofp_action *) (void *)
+ ((uint8_t *) a + ntohs(a->header.len)));
}
static inline bool
diff --git a/lib/sset.h b/lib/sset.h
index 8810067..a739fce 100644
--- a/lib/sset.h
+++ b/lib/sset.h
@@ -19,6 +19,10 @@
#include "hmap.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct sset_node {
struct hmap_node hmap_node;
char name[1];
@@ -85,4 +89,8 @@ bool sset_equals(const struct sset *, const struct sset
*);
SSET_NAME_FROM_HMAP_NODE( \
hmap_next(&(SSET)->map, &SSET_NODE_FROM_NAME(NAME)->hmap_node))
+#ifdef __cplusplus
+}
+#endif
+
#endif /* sset.h */
diff --git a/lib/vconn.h b/lib/vconn.h
index 3f8bc47..3c1ffe9 100644
--- a/lib/vconn.h
+++ b/lib/vconn.h
@@ -24,6 +24,10 @@
#include "flow.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct list;
struct ofpbuf;
struct ofp_action_header;
@@ -78,4 +82,8 @@ void pvconn_close(struct pvconn *);
int pvconn_accept(struct pvconn *, int min_version, struct vconn **);
void pvconn_wait(struct pvconn *);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* vconn.h */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20110804/51710485/attachment-0003.html>
-------------- next part --------------
diff --git a/lib/classifier.h b/lib/classifier.h
index b1162ae..2e6d8b9 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -32,6 +32,10 @@
#include "openflow/nicira-ext.h"
#include "openflow/openflow.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* A flow classifier. */
struct classifier {
int n_rules; /* Total number of rules. */
@@ -164,4 +168,8 @@ struct cls_rule *cls_cursor_next(struct cls_cursor *, struct cls_rule *);
: 0); \
(RULE) = (NEXT))
+#ifdef __cplusplus
+}
+#endif
+
#endif /* classifier.h */
diff --git a/lib/hash.h b/lib/hash.h
index 109612f..026eeda 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -22,6 +22,10 @@
#include <string.h>
#include "util.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* This is the public domain lookup3 hash by Bob Jenkins from
* http://burtleburtle.net/bob/c/lookup3.c, modified for style. */
@@ -81,8 +85,8 @@ static inline uint32_t hash_int(uint32_t x, uint32_t basis)
* quality. */
static inline uint32_t hash_boolean(bool x, uint32_t basis)
{
- enum { P0 = 0xc2b73583 }; /* This is hash_int(1, 0). */
- enum { P1 = 0xe90f1258 }; /* This is hash_int(2, 0). */
+ const uint32_t P0 = 0xc2b73583; /* This is hash_int(1, 0). */
+ const uint32_t P1 = 0xe90f1258; /* This is hash_int(2, 0). */
return (x ? P0 : P1) ^ HASH_ROT(basis, 1);
}
@@ -108,4 +112,8 @@ static inline uint32_t hash_pointer(const void *p, uint32_t basis)
return hash_int((uint32_t) (uintptr_t) p, basis);
}
+#ifdef __cplusplus
+}
+#endif
+
#endif /* hash.h */
diff --git a/lib/hmap.h b/lib/hmap.h
index a987fa4..ed2d78d 100644
--- a/lib/hmap.h
+++ b/lib/hmap.h
@@ -89,7 +89,7 @@ static inline void hmap_remove(struct hmap *, struct hmap_node *);
void hmap_node_moved(struct hmap *, struct hmap_node *, struct hmap_node *);
static inline void hmap_replace(struct hmap *, const struct hmap_node *old,
- struct hmap_node *new);
+ struct hmap_node *new_node);
struct hmap_node *hmap_random_node(const struct hmap *);
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 7ee3e69..dfd47be 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -315,7 +315,8 @@ enum ofputil_action_code ofputil_decode_action_unsafe(
static inline union ofp_action *
ofputil_action_next(const union ofp_action *a)
{
- return (void *) ((uint8_t *) a + ntohs(a->header.len));
+ return ((union ofp_action *) (void *)
+ ((uint8_t *) a + ntohs(a->header.len)));
}
static inline bool
diff --git a/lib/sset.h b/lib/sset.h
index 8810067..a739fce 100644
--- a/lib/sset.h
+++ b/lib/sset.h
@@ -19,6 +19,10 @@
#include "hmap.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct sset_node {
struct hmap_node hmap_node;
char name[1];
@@ -85,4 +89,8 @@ bool sset_equals(const struct sset *, const struct sset *);
SSET_NAME_FROM_HMAP_NODE( \
hmap_next(&(SSET)->map, &SSET_NODE_FROM_NAME(NAME)->hmap_node))
+#ifdef __cplusplus
+}
+#endif
+
#endif /* sset.h */
diff --git a/lib/vconn.h b/lib/vconn.h
index 3f8bc47..3c1ffe9 100644
--- a/lib/vconn.h
+++ b/lib/vconn.h
@@ -24,6 +24,10 @@
#include "flow.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct list;
struct ofpbuf;
struct ofp_action_header;
@@ -78,4 +82,8 @@ void pvconn_close(struct pvconn *);
int pvconn_accept(struct pvconn *, int min_version, struct vconn **);
void pvconn_wait(struct pvconn *);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* vconn.h */
More information about the dev
mailing list