aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-12-08 16:12:16 +0100
committerMartin Willi <martin@strongswan.org>2009-12-17 13:53:24 +0100
commit1a1ff9d1276a48a8c0bc0732a6ef7364b2e0e01f (patch)
tree1077cdf3c3f59ddbfdfd633f3c89932eedc18c68
parent74eed73a40916ad5160d50209968cf093161db5f (diff)
downloadstrongswan-1a1ff9d1276a48a8c0bc0732a6ef7364b2e0e01f.tar.bz2
strongswan-1a1ff9d1276a48a8c0bc0732a6ef7364b2e0e01f.tar.xz
Added a METHOD() macro to define methods with both public and private signatures
-rw-r--r--src/libstrongswan/utils.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h
index ebc67db00..f07e83582 100644
--- a/src/libstrongswan/utils.h
+++ b/src/libstrongswan/utils.h
@@ -115,6 +115,19 @@
*(this) = (typeof(*this)){ __VA_ARGS__ }; }
/**
+ * Method declaration/definition macro, providing private and public interface.
+ *
+ * Defines a method name with this as first parameter and a return value ret,
+ * and an alias for this method with a _ prefix, having the this argument
+ * safely casted to the public interface iface.
+ * _name is provided a function pointer, but will get optimized out by GCC.
+ */
+#define METHOD(iface, name, ret, this, ...) \
+ static ret name(union {iface *_public; this;} __attribute__((transparent_union)), ##__VA_ARGS__); \
+ const static typeof(name) *_##name = (const typeof(name)*)name; \
+ static ret name(this, ##__VA_ARGS__)
+
+/**
* Macro to allocate a sized type.
*/
#define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))