diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0558fc0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: cpp + +sudo: required +# not totally clear why this is required, but travis support recommended it +# to allow gcc-4.8 to be installed as the system gcc +services: +- docker + +# need at least gcc 4.8 for -std=c++11 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 + +script: make + +compiler: +- clang +- gcc diff --git a/Makefile b/Makefile index f5901df..0524129 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,16 @@ GTEST := gtest-1.7.0 LDFLAGS=-O2 -Wall -Werror -fPIC CFLAGS=-O2 -Wall -Werror -fPIC -I. -Wno-unused-function -GTEST_CFLAGS=-I$(GTEST)/include +ifneq (,$(findstring gcc, $(CC))) + # gcc's maybe-unintialized is too imprecise, disable it. + # clang disbles this functionality by default and doesn't recognize the flag. + # (check for CC that contains rather than equals 'gcc', + # to accommodate using specific versions, like gcc-4.9 etc) + CFLAGS += -Wno-maybe-uninitialized +endif + +GTEST_CFLAGS=-I$(GTEST)/include -std=c++11 +GTEST_LDFLAGS=-lpthread all: capn.so capnpc-c test @@ -30,4 +39,4 @@ gtest-all.o: $(GTEST)/src/*.cc $(CXX) -g -Wall -Werror -I. $(GTEST_CFLAGS) -I$(GTEST) -o $@ -c $< capn-test: capn-test.o capn-stream-test.o compiler/test.capnp.o compiler/schema-test.o compiler/schema.capnp.o gtest-all.o - $(CXX) -g -Wall -Werror -I. -o $@ $^ + $(CXX) -g -Wall -Werror -I. $^ $(GTEST_LDFLAGS) -o $@ \ No newline at end of file diff --git a/capn-malloc.c b/capn-malloc.c index eea040a..f4a62a0 100644 --- a/capn-malloc.c +++ b/capn-malloc.c @@ -161,7 +161,7 @@ capn_write_mem(struct capn *c, uint8_t *p, size_t sz, int packed) { struct capn_segment *seg; struct capn_ptr root; - int i; + unsigned i; uint32_t headerlen; size_t datasz; uint32_t *header; diff --git a/capn-stream.c b/capn-stream.c index a8eeced..4bc1355 100644 --- a/capn-stream.c +++ b/capn-stream.c @@ -3,7 +3,7 @@ #include #ifndef min -static int min(int a, int b) { return (a < b) ? a : b; } +static unsigned min(unsigned a, unsigned b) { return (a < b) ? a : b; } #endif int capn_deflate(struct capn_stream* s) { @@ -12,7 +12,7 @@ int capn_deflate(struct capn_stream* s) { } while (s->avail_in) { - int i, sz = 0; + unsigned i, sz = 0; uint8_t hdr = 0; uint8_t *p; @@ -104,7 +104,7 @@ int capn_inflate(struct capn_stream* s) { } while (s->avail_out) { - int i, sz; + unsigned i, sz; uint8_t hdr; if (s->zeros > 0) { @@ -143,7 +143,7 @@ int capn_inflate(struct capn_stream* s) { return CAPN_NEED_MORE; memcpy(s->next_out, s->next_in+1, 8); - s->raw = (int) s->next_in[9] * 8; + s->raw = s->next_in[9] * 8; s->next_in += 10; s->avail_in -= 10; s->next_out += 8; @@ -154,7 +154,7 @@ int capn_inflate(struct capn_stream* s) { /* 0x00 is followed by a single byte indicating * the count of consecutive zero value words * minus 1 */ - s->zeros = (int) (s->next_in[1] + 1) * 8; + s->zeros = (s->next_in[1] + 1) * 8; s->next_in += 2; s->avail_in -= 2; continue; diff --git a/capn-test.cpp b/capn-test.cpp index 84e3e4b..cf76bc0 100644 --- a/capn-test.cpp +++ b/capn-test.cpp @@ -1,4 +1,5 @@ #include +#include static int g_AddTag = 1; #define ADD_TAG g_AddTag @@ -273,11 +274,11 @@ static void getSegments(struct capn *c, struct capn_segment **s, size_t num) { ASSERT_EQ(num, c->segnum); s[0] = c->seglist; - for (int i = 1; i < num; i++) { + for (unsigned i = 1; i < num; i++) { s[i] = s[i-1]->next; } - for (int i = 0; i < num; i++) { + for (unsigned i = 0; i < num; i++) { EXPECT_EQ(s[i]->id, i); } } @@ -314,7 +315,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) { struct capn ctx2; memset(&ctx2, 0, sizeof(ctx2)); - for (int i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) { + for (unsigned i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) { capn_append_segment(&ctx2, segments[i]); } @@ -370,7 +371,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation_NoTag) { struct capn ctx2; memset(&ctx2, 0, sizeof(ctx2)); - for (int i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) { + for (unsigned i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) { capn_append_segment(&ctx2, segments[i]); } @@ -420,7 +421,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) { struct capn ctx2; memset(&ctx2, 0, sizeof(ctx2)); - for (int i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) { + for (unsigned i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) { capn_append_segment(&ctx2, segments[i]); } diff --git a/capn.h b/capn.h index e24aca2..7fd6c73 100644 --- a/capn.h +++ b/capn.h @@ -94,7 +94,7 @@ struct capn_segment { uint32_t id; /* user settable */ char *data; - int len, cap; + unsigned len, cap; void *user; }; @@ -261,10 +261,10 @@ void capn_reset_copy(struct capn *c); */ struct capn_stream { const uint8_t *next_in; - int avail_in; + unsigned avail_in; uint8_t *next_out; - int avail_out; - int zeros, raw; + unsigned avail_out; + unsigned zeros, raw; }; #define CAPN_MISALIGNED -1 diff --git a/compiler/capnpc-c.c b/compiler/capnpc-c.c index e14b3a7..145977c 100644 --- a/compiler/capnpc-c.c +++ b/compiler/capnpc-c.c @@ -905,7 +905,7 @@ static void define_struct(struct node *n) { } #if 0 -Commenting out interfaces until the RPC protocol has been spec'd +Commenting out interfaces until the RPC protocol has been specified static int find_offset(struct str *v, int inc, uint64_t mask) { int i, j; union {uint64_t u; char c[8];} umask; diff --git a/compiler/schema-test.cpp b/compiler/schema-test.cpp index b192016..802039b 100644 --- a/compiler/schema-test.cpp +++ b/compiler/schema-test.cpp @@ -189,7 +189,7 @@ TEST(Schema, ReadSimple) { struct CodeGeneratorRequest req; read_CodeGeneratorRequest(&req, root); - for (size_t i = 0; i < req.nodes.p.len; i++) { + for (int i = 0; i < req.nodes.p.len; i++) { } }