diff options
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | Makefile | 33 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | tests/json/test_json.cc | 2 | ||||
-rwxr-xr-x | travis.sh | 31 | ||||
-rw-r--r-- | upb/handlers.c | 2 | ||||
-rw-r--r-- | upb/json/parser.c | 17 | ||||
-rw-r--r-- | upb/json/parser.rl | 9 | ||||
-rw-r--r-- | upb/json/printer.c | 2 | ||||
-rw-r--r-- | upb/pb/compile_decoder_x64.c | 3 | ||||
-rw-r--r-- | upb/pb/decoder.c | 6 | ||||
-rw-r--r-- | upb/pb/encoder.c | 4 | ||||
-rw-r--r-- | upb/table.c | 2 |
13 files changed, 87 insertions, 30 deletions
diff --git a/.travis.yml b/.travis.yml index a65f56a..917aa91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,13 @@ +language: cpp +compiler: gcc install: ./travis.sh install script: ./travis.sh script +after_success: ./travis.sh after_success env: - UPB_TRAVIS_BUILD=bare - UPB_TRAVIS_BUILD=barejit - UPB_TRAVIS_BUILD=core32 - UPB_TRAVIS_BUILD=withprotobuf - UPB_TRAVIS_BUILD=lua + - UPB_TRAVIS_BUILD=coverage + - UPB_TRAVIS_BUILD=warnings @@ -38,6 +38,10 @@ USER_CPPFLAGS= # Build with "make WITH_JIT=yes" (or anything besides "no") to enable the JIT. WITH_JIT=no +# Build with "make WITH_MAX_WARNINGS=yes" (or anything besides "no") to enable +# with strict warnings and treat warnings as errors. +WITH_MAX_WARNINGS=no + # Basic compiler/flag setup. CC=cc CXX=c++ @@ -53,6 +57,10 @@ ifneq ($(WITH_JIT), no) CPPFLAGS += -DUPB_USE_JIT_X64 endif +ifneq ($(WITH_MAX_WARNINGS), no) + WARNFLAGS=-Wall -Wextra -Wpointer-arith -Werror +endif + # Build with "make Q=" to see all commands that are being executed. Q=@ @@ -85,7 +93,7 @@ dep: clean_leave_profile: @rm -rf obj lib - @rm -f tests/*.pb* tests/google_message?.h + @rm -f tests/google_message?.h @rm -f $(TESTS) tests/testmain.o tests/t.* @rm -f upb/descriptor.pb @rm -rf tools/upbc deps @@ -115,8 +123,8 @@ clean: clean_leave_profile .SECONDEXPANSION: to_srcs = $(subst .,_,$(1)_SRCS) pc = % -make_objs = $$(patsubst upb/$$(pc).c,obj/$$(pc).$(1),$$($$(call to_srcs,$$*))) -make_objs_cc = $$(patsubst upb/$$(pc).cc,obj/$$(pc).$(1),$$($$(call to_srcs,$$*))) +make_objs = $$(patsubst upb/$$(pc).c,obj/upb/$$(pc).$(1),$$($$(call to_srcs,$$*))) +make_objs_cc = $$(patsubst upb/$$(pc).cc,obj/upb/$$(pc).$(1),$$($$(call to_srcs,$$*))) # Core libraries (ie. not bindings). ############################################################### @@ -146,8 +154,7 @@ upb_pb_SRCS = \ # If Lua is present we can use DynASM to regenerate the .h file. ifdef USE_JIT upb_pb_SRCS += upb/pb/compile_decoder_x64.c -obj/pb/compile_decoder_x64.o obj/pb/compile_decoder_x64.lo: upb/pb/compile_decoder_x64.h -obj/pb/compile_decoder_x64.o: CFLAGS=-std=gnu99 +obj/upb/pb/compile_decoder_x64.o obj/upb/pb/compile_decoder_x64.lo: upb/pb/compile_decoder_x64.h upb/pb/compile_decoder_x64.h: upb/pb/compile_decoder_x64.dasc $(E) DYNASM $< @@ -168,11 +175,11 @@ ifeq (, $(findstring -O, $(USER_CPPFLAGS))) OPT = -O3 lib/libupb.a : OPT = -Os lib/libupb.descriptor.a : OPT = -Os -obj/pb/compile_decoder.o : OPT = -Os -obj/pb/compile_decoder_64.o : OPT = -Os +obj/upb/pb/compile_decoder.o : OPT = -Os +obj/upb/pb/compile_decoder_64.o : OPT = -Os ifdef USE_JIT -obj/pb/compile_decoder_x64.o: OPT=-Os +obj/upb/pb/compile_decoder_x64.o: OPT=-Os endif endif @@ -186,19 +193,19 @@ $(UPB_LIBS): lib/lib%.a: $(call make_objs,o) $(Q) mkdir -p lib && ar rcs $@ $^ -obj/%.o: upb/%.c | $$(@D)/. +obj/upb/%.o: upb/%.c | $$(@D)/. $(E) CC $< $(Q) $(CC) $(OPT) $(WARNFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -obj/%.o: upb/%.cc | $$(@D)/. +obj/upb/%.o: upb/%.cc | $$(@D)/. $(E) CXX $< $(Q) $(CXX) $(OPT) $(WARNFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< -obj/%.lo: upb/%.c | $$(@D)/. +obj/upb/%.lo: upb/%.c | $$(@D)/. $(E) 'CC -fPIC' $< $(Q) $(CC) $(OPT) $(WARNFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -fPIC -obj/%.lo: upb/%.cc | $$(@D)/. +obj/upb/%.lo: upb/%.cc | $$(@D)/. $(E) CXX $< $(Q) $(CXX) $(OPT) $(WARNFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< -fPIC @@ -315,7 +322,7 @@ clean_googlepb: googlepb: default $(GOOGLEPB_LIB) googlepbtests: googlepb $(GOOGLEPB_TESTS) -lib/libupb.bindings.googlepb.a: $(upb_bindings_googlepb_SRCS:upb/%.cc=obj/%.o) +lib/libupb.bindings.googlepb.a: $(upb_bindings_googlepb_SRCS:upb/%.cc=obj/upb/%.o) $(E) AR $@ $(Q) mkdir -p lib && ar rcs $@ $^ @@ -2,6 +2,7 @@ # Unleaded - small, fast parsers for the 21st century [![Build Status](https://travis-ci.org/haberman/upb.svg?branch=master)](https://travis-ci.org/haberman/upb) +[![Coverage Status](https://img.shields.io/coveralls/haberman/upb.svg)](https://coveralls.io/r/haberman/upb?branch=master) Unleaded is a library of fast parsers and serializers. These parsers/serializers are written in C and use every available diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc index f2e26b8..cb60bad 100644 --- a/tests/json/test_json.cc +++ b/tests/json/test_json.cc @@ -347,7 +347,7 @@ void test_json_roundtrip() { test_case->input : test_case->expected; - for (int i = 0; i < strlen(test_case->input); i++) { + for (size_t i = 0; i < strlen(test_case->input); i++) { test_json_roundtrip_message(test_case->input, expected, serialize_handlers.get(), i); } @@ -28,6 +28,16 @@ withprotobuf_script() { make test } +# Build with strict warnings. +warnings_install() { + : +} +warnings_script() { + make -j12 default WITH_MAX_WARNINGS=yes + make -j12 tests WITH_MAX_WARNINGS=yes + make test +} + # A 32-bit build. Can only test the core because any dependencies # need to be available as 32-bit libs also, which gets hairy fast. # Can't enable the JIT because it only supports x64. @@ -49,7 +59,26 @@ lua_script() { make -j12 testlua USER_CPPFLAGS=`pkg-config lua5.2 --cflags` } +# A run that executes with coverage support and uploads to coveralls.io +coverage_install() { + sudo apt-get update -qq + sudo apt-get install protobuf-compiler libprotobuf-dev lua5.2 liblua5.2-dev + sudo pip install cpp-coveralls +} +coverage_script() { + make -j12 tests googlepbtests testlua WITH_JIT=yes \ + USER_CPPFLAGS="--coverage -O0 `pkg-config lua5.2 --cflags`" + make test +} +coverage_after_success() { + coveralls --exclude dynasm --exclude tests --exclude upb/bindings/linux --gcov-options '\-lp' +} + +if [ "$1" == "after_success" ] && [ "$UPB_TRAVIS_BUILD" != "coverage" ]; then + # after_success is only used for coverage. + exit +fi + set -e set -x eval ${UPB_TRAVIS_BUILD}_${1} - diff --git a/upb/handlers.c b/upb/handlers.c index 93f22a1..5a253f1 100644 --- a/upb/handlers.c +++ b/upb/handlers.c @@ -581,7 +581,7 @@ bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, *s = f->selector_base; break; } - assert(*s < upb_fielddef_containingtype(f)->selector_count); + assert((size_t)*s < upb_fielddef_containingtype(f)->selector_count); return true; } diff --git a/upb/json/parser.c b/upb/json/parser.c index 4f4a96e..f4f5628 100644 --- a/upb/json/parser.c +++ b/upb/json/parser.c @@ -1201,8 +1201,6 @@ static const char _json_trans_actions[] = { }; static const int json_start = 1; -static const int json_first_final = 56; -static const int json_error = 0; static const int json_en_number_machine = 10; static const int json_en_string_machine = 19; @@ -1230,7 +1228,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 1234 "upb/json/parser.c" +#line 1232 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -1416,7 +1414,7 @@ _match: #line 1148 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -#line 1420 "upb/json/parser.c" +#line 1418 "upb/json/parser.c" } } @@ -1448,6 +1446,13 @@ error: bool end(void *closure, const void *hd) { UPB_UNUSED(closure); UPB_UNUSED(hd); + + // Prevent compile warning on unused static constants. + UPB_UNUSED(json_start); + UPB_UNUSED(json_en_number_machine); + UPB_UNUSED(json_en_string_machine); + UPB_UNUSED(json_en_value_machine); + UPB_UNUSED(json_en_main); return true; } @@ -1461,13 +1466,13 @@ static void json_parser_reset(upb_json_parser *p) { int top; // Emit Ragel initialization of the parser. -#line 1465 "upb/json/parser.c" +#line 1470 "upb/json/parser.c" { cs = json_start; top = 0; } -#line 1204 "upb/json/parser.rl" +#line 1211 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 3a400ea..81d1514 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -1150,7 +1150,7 @@ static void end_object(upb_json_parser *p) { main := ws object ws; }%% -%% write data; +%% write data noerror nofinal; size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -1188,6 +1188,13 @@ error: bool end(void *closure, const void *hd) { UPB_UNUSED(closure); UPB_UNUSED(hd); + + // Prevent compile warning on unused static constants. + UPB_UNUSED(json_start); + UPB_UNUSED(json_en_number_machine); + UPB_UNUSED(json_en_string_machine); + UPB_UNUSED(json_en_value_machine); + UPB_UNUSED(json_en_main); return true; } diff --git a/upb/json/printer.c b/upb/json/printer.c index 132736c..539f83a 100644 --- a/upb/json/printer.c +++ b/upb/json/printer.c @@ -183,7 +183,7 @@ static bool putkey(void *closure, const void *handler_data) { return true; } -#define CHKFMT(val) if ((val) == -1) return false; +#define CHKFMT(val) if ((val) == (size_t)-1) return false; #define CHK(val) if (!(val)) return false; #define TYPE_HANDLERS(type, fmt_func) \ diff --git a/upb/pb/compile_decoder_x64.c b/upb/pb/compile_decoder_x64.c index b4086c7..a0cb3c9 100644 --- a/upb/pb/compile_decoder_x64.c +++ b/upb/pb/compile_decoder_x64.c @@ -7,6 +7,9 @@ * Driver code for the x64 JIT compiler. */ +// Needed to ensure we get defines like MAP_ANON. +#define _GNU_SOURCE + #include <dlfcn.h> #include <stdio.h> #include <sys/mman.h> diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index f371bce..f23645d 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -120,7 +120,7 @@ static bool in_residual_buf(const upb_pbdecoder *d, const char *p) { // and the parsing stack, so must be called whenever either is updated. static void set_delim_end(upb_pbdecoder *d) { size_t delim_ofs = d->top->end_ofs - d->bufstart_ofs; - if (delim_ofs <= (d->end - d->buf)) { + if (delim_ofs <= (size_t)(d->end - d->buf)) { d->delim_end = d->buf + delim_ofs; d->data_end = d->delim_end; } else { @@ -265,7 +265,7 @@ UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, advancetobuf(d, d->buf_param, d->size_param); } if (curbufleft(d) >= bytes) { - consumebytes(d, buf + avail, bytes); + consumebytes(d, (char *)buf + avail, bytes); return DECODE_OK; } else if (d->data_end == d->delim_end) { seterr(d, "Submessage ended in the middle of a value or group"); @@ -294,7 +294,7 @@ UPB_NOINLINE static size_t peekbytes_slow(upb_pbdecoder *d, void *buf, memcpy(buf, d->ptr, ret); if (in_residual_buf(d, d->ptr)) { size_t copy = UPB_MIN(bytes - ret, d->size_param); - memcpy(buf + ret, d->buf_param, copy); + memcpy((char *)buf + ret, d->buf_param, copy); ret += copy; } return ret; diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index 7a50996..ca5ebc1 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -141,7 +141,7 @@ static upb_pb_encoder_segment *top(upb_pb_encoder *e) { // Call to ensure that at least "bytes" bytes are available for writing at // e->ptr. Returns false if the bytes could not be allocated. static bool reserve(upb_pb_encoder *e, size_t bytes) { - if ((e->limit - e->ptr) < bytes) { + if ((size_t)(e->limit - e->ptr) < bytes) { // Grow buffer. size_t needed = bytes + (e->ptr - e->buf); size_t old_size = e->limit - e->buf; @@ -170,7 +170,7 @@ static bool reserve(upb_pb_encoder *e, size_t bytes) { // Call when "bytes" bytes have been writte at e->ptr. The caller *must* have // previously called reserve() with at least this many bytes. static void encoder_advance(upb_pb_encoder *e, size_t bytes) { - assert((e->limit - e->ptr) >= bytes); + assert((size_t)(e->limit - e->ptr) >= bytes); e->ptr += bytes; } diff --git a/upb/table.c b/upb/table.c index fc69125..9914a03 100644 --- a/upb/table.c +++ b/upb/table.c @@ -542,7 +542,7 @@ void upb_inttable_compact(upb_inttable *t) { counts[log2ceil(key)]++; } - int arr_size; + size_t arr_size = 1; int arr_count = upb_inttable_count(t); if (upb_inttable_count(t) >= max_key * MIN_DENSITY) { |