From be8e8e8e19d7457c689267488b41c4a0108619bc Mon Sep 17 00:00:00 2001 From: Sander van Dijk Date: Thu, 20 Dec 2018 08:47:48 +0000 Subject: [PATCH 1/3] Ensure that context instance id storage is aligned correctly --- rcl/include/rcl/context.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rcl/include/rcl/context.h b/rcl/include/rcl/context.h index 71bae0733..164cf3ea0 100644 --- a/rcl/include/rcl/context.h +++ b/rcl/include/rcl/context.h @@ -29,6 +29,8 @@ extern "C" #include "rcl/types.h" #include "rcl/visibility_control.h" +#include + typedef uint64_t rcl_context_instance_id_t; struct rcl_context_impl_t; @@ -132,7 +134,7 @@ typedef struct rcl_context_t * See this paper for an effort to make this possible in the future: * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0943r1.html */ - uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]; + alignas(uint_least64_t) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]; } rcl_context_t; /// Return a zero initialization context object. From 31fcc920a03e0d252cdcc3c39b206926d9e7ed15 Mon Sep 17 00:00:00 2001 From: Sander van Dijk Date: Thu, 20 Dec 2018 23:28:31 +0000 Subject: [PATCH 2/3] Make alignment compatible with MSVC --- rcl/include/rcl/context.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rcl/include/rcl/context.h b/rcl/include/rcl/context.h index 164cf3ea0..3cfe70b56 100644 --- a/rcl/include/rcl/context.h +++ b/rcl/include/rcl/context.h @@ -29,7 +29,12 @@ extern "C" #include "rcl/types.h" #include "rcl/visibility_control.h" +#ifdef _MSC_VER +#define ALIGNAS_(N) __declspec(align(N)) +#else #include +#define ALIGNAS_(N) alignas(N) +#endif typedef uint64_t rcl_context_instance_id_t; @@ -134,7 +139,7 @@ typedef struct rcl_context_t * See this paper for an effort to make this possible in the future: * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0943r1.html */ - alignas(uint_least64_t) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]; + ALIGNAS_(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]; } rcl_context_t; /// Return a zero initialization context object. From 14819de5ec0ab182c298c2cef830fb4063f47d3f Mon Sep 17 00:00:00 2001 From: Sander van Dijk Date: Fri, 21 Dec 2018 19:13:39 +0000 Subject: [PATCH 3/3] Namespace alignment macro with RCL_ --- rcl/include/rcl/context.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rcl/include/rcl/context.h b/rcl/include/rcl/context.h index 3cfe70b56..64610e0d8 100644 --- a/rcl/include/rcl/context.h +++ b/rcl/include/rcl/context.h @@ -30,10 +30,10 @@ extern "C" #include "rcl/visibility_control.h" #ifdef _MSC_VER -#define ALIGNAS_(N) __declspec(align(N)) +#define RCL_ALIGNAS(N) __declspec(align(N)) #else #include -#define ALIGNAS_(N) alignas(N) +#define RCL_ALIGNAS(N) alignas(N) #endif typedef uint64_t rcl_context_instance_id_t; @@ -139,7 +139,7 @@ typedef struct rcl_context_t * See this paper for an effort to make this possible in the future: * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0943r1.html */ - ALIGNAS_(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]; + RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]; } rcl_context_t; /// Return a zero initialization context object.