From 8d0ccbeeae8921ecb04cddb51f002d15cf8dce49 Mon Sep 17 00:00:00 2001 From: Nathanael Jones Date: Wed, 11 May 2016 09:57:41 -0700 Subject: [PATCH 1/3] Define ssize_t for MSVC ssize_t is not available in visual studio, nor is sys/param.h We typedef intmax_t to ssize_t --- lib/capn.c | 2 ++ lib/capnp_c.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/capn.c b/lib/capn.c index 82df285..c753e2c 100644 --- a/lib/capn.c +++ b/lib/capn.c @@ -11,7 +11,9 @@ #include #include +#ifndef _MSC_VER #include +#endif #define STRUCT_PTR 0 #define LIST_PTR 1 diff --git a/lib/capnp_c.h b/lib/capnp_c.h index 900bfc3..5ccf0f5 100644 --- a/lib/capnp_c.h +++ b/lib/capnp_c.h @@ -14,6 +14,11 @@ #include #include +// ssize_t is not defined in stdint.h in MSVC. +#ifdef _MSC_VER +typedef intmax_t ssize_t; +#endif + #ifdef __cplusplus extern "C" { #endif From 8f37e0f61897d06441a7a9ff7b396d3a8991bc10 Mon Sep 17 00:00:00 2001 From: Nathanael Jones Date: Wed, 11 May 2016 09:58:42 -0700 Subject: [PATCH 2/3] Define default value for char *e Visual studio's execution flow analysis insists that (e) could be undefined. I don't see it, but this permits compilation. --- lib/capn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capn.c b/lib/capn.c index c753e2c..60e139c 100644 --- a/lib/capn.c +++ b/lib/capn.c @@ -318,7 +318,7 @@ static char *struct_ptr(struct capn_segment *s, char *d, int minsz) { static capn_ptr read_ptr(struct capn_segment *s, char *d) { capn_ptr ret = {CAPN_NULL}; uint64_t val; - char *e; + char *e = 0; val = capn_flip64(*(uint64_t*) d); From 27df3d60649a1269ed6922cec0f2a2485a2791cd Mon Sep 17 00:00:00 2001 From: Nathanael Jones Date: Wed, 11 May 2016 10:30:41 -0700 Subject: [PATCH 3/3] 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 --- lib/capn-malloc.c | 5 +++++ lib/capnp_c.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/lib/capn-malloc.c b/lib/capn-malloc.c index 7a2977c..525ae99 100644 --- a/lib/capn-malloc.c +++ b/lib/capn-malloc.c @@ -14,6 +14,11 @@ #include #include +/* 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 { unsigned int foo : (sizeof(struct capn_segment)&7) ? -1 : 1; }; diff --git a/lib/capnp_c.h b/lib/capnp_c.h index 5ccf0f5..40432ba 100644 --- a/lib/capnp_c.h +++ b/lib/capnp_c.h @@ -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 * should be zero initialized. */ +#ifdef _MSC_VER +__declspec(align(64)) +#endif struct capn_segment { struct capn_tree hdr; struct capn_segment *next;