Skip to content

Commit

Permalink
Fixed amalgamated build and added test.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed Jan 24, 2017
1 parent 5aa01b4 commit 3b7dc27
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ env:
- UPB_TRAVIS_BUILD=ndebug
- UPB_TRAVIS_BUILD=coverage
- UPB_TRAVIS_BUILD=genfiles
- UPB_TRAVIS_BUILD=amalgamated
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,7 @@ amalgamate: upb.c upb.h
upb.c upb.h: $(AMALGAMATE_SRCS)
$(E) AMALGAMATE $@
$(Q) ./tools/amalgamate.py "" "" $^

amalgamated: upb.c upb.h
$(E) CC upb.c
$(Q) $(CC) -o upb.o -c upb.c $(WARNFLAGS)
12 changes: 12 additions & 0 deletions travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ ndebug_script() {
make test
}

# Tests the amalgamated build (this ensures that the different .c files
# don't have symbols or macros that conflict with each other.
amalgamated_install() {
:
}
amalgamated_script() {
# Override of USER_CPPFLAGS removes -UNDEBUG.
export USER_CPPFLAGS="-UNDEBUG"
make amalgamated
}

# A run that executes with coverage support and uploads to coveralls.io
coverage_install() {
sudo apt-get update -qq
Expand Down Expand Up @@ -145,6 +156,7 @@ if [ "$1" == "local" ]; then
run_config "lua"
run_config "ndebug"
run_config "genfiles"
run_config "amalgamated"
exit
fi

Expand Down
23 changes: 10 additions & 13 deletions upb/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size);

#define CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
#define ENCODE_MAX_NESTING 64
#define CHECK_RETURN(x) if (!(x)) { return false; }
#define CHECK_TRUE(x) if (!(x)) { return false; }

/** upb_msgval ****************************************************************/

Expand Down Expand Up @@ -492,7 +492,7 @@ struct upb_visitor {
upb_sink *sink;
};

static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) {
static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) {
upb_selector_t ret;
bool ok = upb_handlers_getselector(f, type, &ret);
UPB_ASSERT(ok);
Expand Down Expand Up @@ -572,34 +572,31 @@ static bool upb_visitor_visitmsg2(const upb_msg *msg,
} else if (upb_fielddef_isstring(f)) {
/* TODO putstr(); */
} else {
upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f));
UPB_ASSERT(upb_fielddef_isprimitive(f));

switch (upb_fielddef_type(f)) {
case UPB_TYPE_FLOAT:
CHECK_RETURN(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val)));
CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val)));
break;
case UPB_TYPE_DOUBLE:
CHECK_RETURN(
upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
break;
case UPB_TYPE_BOOL:
CHECK_RETURN(upb_sink_putbool(sink, sel, upb_msgval_getbool(val)));
CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val)));
break;
case UPB_TYPE_ENUM:
case UPB_TYPE_INT32:
CHECK_RETURN(upb_sink_putint32(sink, sel, upb_msgval_getint32(val)));
CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val)));
break;
case UPB_TYPE_UINT32:
CHECK_RETURN(
upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
break;
case UPB_TYPE_INT64:
CHECK_RETURN(upb_sink_putint64(sink, sel, upb_msgval_getint64(val)));
CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val)));
break;
case UPB_TYPE_UINT64:
CHECK_RETURN(
upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
break;
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
Expand Down
6 changes: 3 additions & 3 deletions upb/upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ upb_alloc upb_alloc_global = {&upb_global_allocfunc};
/* Be conservative and choose 16 in case anyone is using SSE. */
static const size_t maxalign = 16;

static size_t align_up(size_t size) {
static size_t align_up_max(size_t size) {
return ((size + maxalign - 1) / maxalign) * maxalign;
}

Expand All @@ -128,7 +128,7 @@ static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size,

block->next = a->block_head;
block->size = size;
block->used = align_up(sizeof(mem_block));
block->used = align_up_max(sizeof(mem_block));
block->owned = owned;

a->block_head = block;
Expand Down Expand Up @@ -161,7 +161,7 @@ static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
return NULL; /* We are an arena, don't need individual frees. */
}

size = align_up(size);
size = align_up_max(size);

/* TODO(haberman): special-case if this is a realloc of the last alloc? */

Expand Down

0 comments on commit 3b7dc27

Please sign in to comment.