Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: mojo/public/c/system/macros.h

Issue 295383012: Mojo: Require our public options structs to be aligned like int64_t's. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win 2 Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/c/system/data_pipe.h ('k') | mojo/public/c/system/tests/macros_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/c/system/macros.h
diff --git a/mojo/public/c/system/macros.h b/mojo/public/c/system/macros.h
index 322c3be61f7cb8f7d9cac345770504537964df97..f1e3c7d6831279202e77e00aedfaa7871177e51f 100644
--- a/mojo/public/c/system/macros.h
+++ b/mojo/public/c/system/macros.h
@@ -26,8 +26,10 @@
#define MOJO_WARN_UNUSED_RESULT
#endif
+// Assert things at compile time. (|msg| should be a valid identifier name.)
// This macro is currently C++-only, but we want to use it in the C core.h.
-// Used to assert things at compile time.
+// Use like:
+// MOJO_COMPILE_ASSERT(sizeof(Foo) == 12, Foo_has_invalid_size);
#if __cplusplus >= 201103L
#define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
#elif defined(__cplusplus)
@@ -38,4 +40,33 @@ namespace mojo { template <bool> struct CompileAssert {}; }
#define MOJO_COMPILE_ASSERT(expr, msg)
#endif
+// Like the C++11 |alignof| operator.
+#if __cplusplus >= 201103L
+#define MOJO_ALIGNOF(type) alignof(type)
+#elif defined(__GNUC__)
+#define MOJO_ALIGNOF(type) __alignof__(type)
+#elif defined(_MSC_VER)
+// The use of |sizeof| is to work around a bug in MSVC 2010 (see
+// http://goo.gl/isH0C; supposedly fixed since then).
+#define MOJO_ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
+#else
+#error "Please define MOJO_ALIGNOF() for your compiler."
+#endif
+
+// Specify the alignment of a |struct|, etc.
+// Use like:
+// struct MOJO_ALIGNAS(8) Foo { ... };
+// Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
+// type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
+// non-C++11 MSVS version).
+#if __cplusplus >= 201103L
+#define MOJO_ALIGNAS(alignment) alignas(alignment)
+#elif defined(__GNUC__)
+#define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
+#elif defined(_MSC_VER)
+#define MOJO_ALIGNAS(alignment) __declspec(align(alignment))
+#else
+#error "Please define MOJO_ALIGNAS() for your compiler."
+#endif
+
#endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_
« no previous file with comments | « mojo/public/c/system/data_pipe.h ('k') | mojo/public/c/system/tests/macros_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698