Merge pull request #78 from haberman/axerefcount

Fixed amalgamated build and added test.
pull/13171/head
Joshua Haberman 8 years ago committed by GitHub
commit 73a48a46f8
  1. 1
      .travis.yml
  2. 4
      Makefile
  3. 12
      travis.sh
  4. 23
      upb/msg.c
  5. 6
      upb/upb.c

@ -21,3 +21,4 @@ env:
- UPB_TRAVIS_BUILD=ndebug - UPB_TRAVIS_BUILD=ndebug
- UPB_TRAVIS_BUILD=coverage - UPB_TRAVIS_BUILD=coverage
- UPB_TRAVIS_BUILD=genfiles - UPB_TRAVIS_BUILD=genfiles
- UPB_TRAVIS_BUILD=amalgamated

@ -534,3 +534,7 @@ amalgamate: upb.c upb.h
upb.c upb.h: $(AMALGAMATE_SRCS) upb.c upb.h: $(AMALGAMATE_SRCS)
$(E) AMALGAMATE $@ $(E) AMALGAMATE $@
$(Q) ./tools/amalgamate.py "" "" $^ $(Q) ./tools/amalgamate.py "" "" $^
amalgamated: upb.c upb.h
$(E) CC upb.c
$(Q) $(CC) -o upb.o -c upb.c $(WARNFLAGS)

@ -107,6 +107,17 @@ ndebug_script() {
make test 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 # A run that executes with coverage support and uploads to coveralls.io
coverage_install() { coverage_install() {
sudo apt-get update -qq sudo apt-get update -qq
@ -145,6 +156,7 @@ if [ "$1" == "local" ]; then
run_config "lua" run_config "lua"
run_config "ndebug" run_config "ndebug"
run_config "genfiles" run_config "genfiles"
run_config "amalgamated"
exit exit
fi fi

@ -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 CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
#define ENCODE_MAX_NESTING 64 #define ENCODE_MAX_NESTING 64
#define CHECK_RETURN(x) if (!(x)) { return false; } #define CHECK_TRUE(x) if (!(x)) { return false; }
/** upb_msgval ****************************************************************/ /** upb_msgval ****************************************************************/
@ -492,7 +492,7 @@ struct upb_visitor {
upb_sink *sink; 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; upb_selector_t ret;
bool ok = upb_handlers_getselector(f, type, &ret); bool ok = upb_handlers_getselector(f, type, &ret);
UPB_ASSERT(ok); UPB_ASSERT(ok);
@ -572,34 +572,31 @@ static bool upb_visitor_visitmsg2(const upb_msg *msg,
} else if (upb_fielddef_isstring(f)) { } else if (upb_fielddef_isstring(f)) {
/* TODO putstr(); */ /* TODO putstr(); */
} else { } 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)); UPB_ASSERT(upb_fielddef_isprimitive(f));
switch (upb_fielddef_type(f)) { switch (upb_fielddef_type(f)) {
case UPB_TYPE_FLOAT: 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; break;
case UPB_TYPE_DOUBLE: case UPB_TYPE_DOUBLE:
CHECK_RETURN( CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
break; break;
case UPB_TYPE_BOOL: 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; break;
case UPB_TYPE_ENUM: case UPB_TYPE_ENUM:
case UPB_TYPE_INT32: 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; break;
case UPB_TYPE_UINT32: case UPB_TYPE_UINT32:
CHECK_RETURN( CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
break; break;
case UPB_TYPE_INT64: 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; break;
case UPB_TYPE_UINT64: case UPB_TYPE_UINT64:
CHECK_RETURN( CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
break; break;
case UPB_TYPE_STRING: case UPB_TYPE_STRING:
case UPB_TYPE_BYTES: case UPB_TYPE_BYTES:

@ -104,7 +104,7 @@ upb_alloc upb_alloc_global = {&upb_global_allocfunc};
/* Be conservative and choose 16 in case anyone is using SSE. */ /* Be conservative and choose 16 in case anyone is using SSE. */
static const size_t maxalign = 16; 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; return ((size + maxalign - 1) / maxalign) * maxalign;
} }
@ -128,7 +128,7 @@ static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size,
block->next = a->block_head; block->next = a->block_head;
block->size = size; block->size = size;
block->used = align_up(sizeof(mem_block)); block->used = align_up_max(sizeof(mem_block));
block->owned = owned; block->owned = owned;
a->block_head = block; a->block_head = block;
@ -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. */ 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? */ /* TODO(haberman): special-case if this is a realloc of the last alloc? */

Loading…
Cancel
Save