Align capn_segment to 64-bit boundaries on MSVC

Unless capn_segment is defined with __declspec(align(64)),
check_segment_alignment fails to compile in x86 mode, as (sizeof(struct
capn_segment)&7) -> (44 & 7) evaluates to 4
Always compiles in x64 mode, as (sizeof(struct capn_segment)&7) -> (80 &
7) evaluates to 0
This commit is contained in:
Nathanael Jones 2016-05-11 10:30:41 -07:00
parent 8f37e0f618
commit 27df3d6064
2 changed files with 8 additions and 0 deletions

View file

@ -14,6 +14,11 @@
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
/* Visual Studio notes:
* Unless capn_segment is defined with __declspec(align(64)), check_segment_alignment
* Fails to compile in x86 mode, as (sizeof(struct capn_segment)&7) -> (44 & 7) evaluates to 4
* Compiles in x64 mode, as (sizeof(struct capn_segment)&7) -> (80 & 7) evaluates to 0
*/
struct check_segment_alignment { struct check_segment_alignment {
unsigned int foo : (sizeof(struct capn_segment)&7) ? -1 : 1; unsigned int foo : (sizeof(struct capn_segment)&7) ? -1 : 1;
}; };

View file

@ -100,6 +100,9 @@ struct capn_tree *capn_tree_insert(struct capn_tree *root, struct capn_tree *n);
* data, len, cap, and user should all set by the user. Other values * data, len, cap, and user should all set by the user. Other values
* should be zero initialized. * should be zero initialized.
*/ */
#ifdef _MSC_VER
__declspec(align(64))
#endif
struct capn_segment { struct capn_segment {
struct capn_tree hdr; struct capn_tree hdr;
struct capn_segment *next; struct capn_segment *next;