Fixed build and added Travis CI support.

pull/13171/head
Josh Haberman 10 years ago
parent a25c50361a
commit f447370f80
  1. 4
      .travis.yml
  2. 30
      Makefile
  3. 9
      tests/test_cpp.cc
  4. 51
      upb/handlers-inl.h
  5. 7
      upb/pb/textprinter.c
  6. 2
      upb/table.int.h
  7. 1
      upb/upb.h

@ -0,0 +1,4 @@
install:
- sudo apt-get update -qq
- sudo apt-get install protobuf-compiler libprotobuf-dev
script: make test

@ -26,7 +26,8 @@ all: lib tests benchmarks tools/upbc lua python
testall: test pythontest testall: test pythontest
# User-specified CFLAGS. # User-specified CFLAGS.
USER_CFLAGS=$(strip $(shell test -f perf-cppflags && cat perf-cppflags)) USER_CFLAGS=
USER_CXXFLAGS=
# If the user doesn't specify an -O setting, we default to -O3, except # If the user doesn't specify an -O setting, we default to -O3, except
# for def which gets -Os. # for def which gets -Os.
@ -40,12 +41,12 @@ ifneq (, $(findstring DUPB_USE_JIT_X64, $(USER_CFLAGS)))
endif endif
# Basic compiler/flag setup. # Basic compiler/flag setup.
CC=gcc CC=cc
CXX=g++ CXX=c++
CFLAGS=-std=gnu99 CFLAGS=-std=gnu99
CXXFLAGS= CXXFLAGS=$(USER_CXXFLAGS)
INCLUDE=-Itests -I. INCLUDE=-Itests -I.
CPPFLAGS=$(INCLUDE) -DNDEBUG -Wall -Wextra -Wno-sign-compare $(USER_CFLAGS) CPPFLAGS=$(INCLUDE) -DNDEBUG -Wall -Wextra -Wno-sign-compare -Wno-unused-private-field $(USER_CFLAGS)
LDLIBS=-lpthread upb/libupb.a LDLIBS=-lpthread upb/libupb.a
LUA=lua # 5.1 and 5.2 should both be supported LUA=lua # 5.1 and 5.2 should both be supported
@ -101,8 +102,7 @@ PB= \
upb/pb/compile_decoder.c \ upb/pb/compile_decoder.c \
upb/pb/glue.c \ upb/pb/glue.c \
upb/pb/varint.c \ upb/pb/varint.c \
upb/pb/textprinter.c \
#upb/pb/textprinter.c \
# Rules. ####################################################################### # Rules. #######################################################################
@ -117,8 +117,8 @@ clean_leave_profile:
rm -rf $(TESTS) tests/t.* rm -rf $(TESTS) tests/t.*
rm -rf upb/descriptor.pb rm -rf upb/descriptor.pb
rm -rf tools/upbc deps rm -rf tools/upbc deps
rm -rf bindings/lua/upb.so rm -rf upb/bindings/lua/upb.so
rm -rf bindings/python/build rm -rf upb/bindings/python/build
rm -rf upb/bindings/ruby/Makefile rm -rf upb/bindings/ruby/Makefile
rm -rf upb/bindings/ruby/upb.so rm -rf upb/bindings/ruby/upb.so
@ -126,7 +126,7 @@ clean: clean_leave_profile
rm -rf $(call rwildcard,,*.gcno) $(call rwildcard,,*.gcda) rm -rf $(call rwildcard,,*.gcno) $(call rwildcard,,*.gcda)
# Core library (libupb.a). # Core library (libupb.a).
SRC=$(CORE) $(PB) SRC=$(CORE) $(PB) $(GOOGLEPB)
LIBUPB=upb/libupb.a LIBUPB=upb/libupb.a
LIBUPB_PIC=upb/libupb_pic.a LIBUPB_PIC=upb/libupb_pic.a
lib: $(LIBUPB) lib: $(LIBUPB)
@ -221,16 +221,14 @@ SIMPLE_TESTS= \
SIMPLE_CXX_TESTS= \ SIMPLE_CXX_TESTS= \
tests/pb/test_decoder \ tests/pb/test_decoder \
tests/test_cpp
# tests/test_cpp \
VARIADIC_TESTS= \ VARIADIC_TESTS= \
tests/t.test_vs_proto2.googlemessage1 \ tests/t.test_vs_proto2.googlemessage1 \
tests/t.test_vs_proto2.googlemessage2 \ tests/t.test_vs_proto2.googlemessage2 \
#TESTS=$(SIMPLE_TESTS) $(SIMPLE_CXX_TESTS) $(VARIADIC_TESTS) tests/test_table TESTS=$(SIMPLE_TESTS) $(SIMPLE_CXX_TESTS) $(VARIADIC_TESTS) tests/test_table
TESTS=$(SIMPLE_TESTS) $(SIMPLE_CXX_TESTS) tests/test_table
tests: $(TESTS) $(INTERACTIVE_TESTS) tests: $(TESTS) $(INTERACTIVE_TESTS)
$(TESTS): $(LIBUPB) $(TESTS): $(LIBUPB)
@ -486,9 +484,9 @@ else
LUA_LDFLAGS = LUA_LDFLAGS =
endif endif
LUAEXT=bindings/lua/upb.so LUAEXT=upb/bindings/lua/upb.so
lua: $(LUAEXT) lua: $(LUAEXT)
bindings/lua/upb.so: bindings/lua/upb.c $(LIBUPB_PIC) upb/bindings/lua/upb.so: upb/bindings/lua/upb.c $(LIBUPB_PIC)
$(E) CC bindings/lua/upb.c $(E) CC bindings/lua/upb.c
$(Q) $(CC) $(CFLAGS) $(CPPFLAGS) $(LUA_CPPFLAGS) -fpic -shared -o $@ $< upb/libupb_pic.a $(LUA_LDFLAGS) $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) $(LUA_CPPFLAGS) -fpic -shared -o $@ $< upb/libupb_pic.a $(LUA_LDFLAGS)

@ -12,7 +12,6 @@
#include <iostream> #include <iostream>
#include <set> #include <set>
#include <type_traits>
#include "upb/def.h" #include "upb/def.h"
#include "upb/descriptor/reader.h" #include "upb/descriptor/reader.h"
@ -1062,11 +1061,15 @@ void TestMismatchedTypes() {
class IntIncrementer { class IntIncrementer {
public: public:
IntIncrementer(int* x) : x_(x) { (*x_)++; } explicit IntIncrementer(int* x) : x_(x) { (*x_)++; }
~IntIncrementer() { (*x_)--; } ~IntIncrementer() { (*x_)--; }
static void Handler(void* closure, const IntIncrementer* incrementer, static void Handler(void* closure, const IntIncrementer* incrementer,
int32_t x) {} int32_t x) {
UPB_UNUSED(closure);
UPB_UNUSED(incrementer);
UPB_UNUSED(x);
}
private: private:
int* x_; int* x_;

@ -695,7 +695,7 @@ struct MaybeWrapReturn<
// ignores the HandlerData parameter if appropriate. // ignores the HandlerData parameter if appropriate.
// //
// Template parameter is the are FuncN function type. // Template parameter is the are FuncN function type.
template <class F> template <class F, class T>
struct ConvertParams; struct ConvertParams;
// Function that discards the handler data parameter. // Function that discards the handler data parameter.
@ -758,59 +758,62 @@ R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3,
} }
// For unbound functions, ignore the handler data. // For unbound functions, ignore the handler data.
template <class R, class P1, R F(P1), class I> template <class R, class P1, R F(P1), class I, class T>
struct ConvertParams<Func1<R, P1, F, I> > { struct ConvertParams<Func1<R, P1, F, I>, T> {
typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func; typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func;
}; };
template <class R, class P1, class P2, R F(P1, P2), class I> template <class R, class P1, class P2, R F(P1, P2), class I,
struct ConvertParams<Func2<R, P1, P2, F, I> > { class R2, class P1_2, class P2_2, class P3_2>
typedef typename CanonicalType<P2>::Type CanonicalP2; struct ConvertParams<Func2<R, P1, P2, F, I>,
typedef Func3<R, void *, const void *, CanonicalP2, R2 (*)(P1_2, P2_2, P3_2)> {
IgnoreHandlerData3<R, P1, CanonicalP2, P2, F>, I> Func; typedef Func3<R, void *, const void *, P3_2,
IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func;
}; };
// For StringBuffer only; this ignores both the handler data and the // For StringBuffer only; this ignores both the handler data and the
// BufferHandle. // BufferHandle.
template <class R, class P1, R F(P1, const char *, size_t), class I> template <class R, class P1, R F(P1, const char *, size_t), class I, class T>
struct ConvertParams<Func3<R, P1, const char *, size_t, F, I> > { struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> {
typedef Func5<R, void *, const void *, const char *, size_t, typedef Func5<R, void *, const void *, const char *, size_t,
const BufferHandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>, const BufferHandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>,
I> Func; I> Func;
}; };
template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4), class I> template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I> > { class I, class T>
struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> {
typedef Func5<R, void *, const void *, P2, P3, P4, typedef Func5<R, void *, const void *, P2, P3, P4,
IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func; IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func;
}; };
// For bound functions, cast the handler data. // For bound functions, cast the handler data.
template <class R, class P1, class P2, R F(P1, P2), class I> template <class R, class P1, class P2, R F(P1, P2), class I, class T>
struct ConvertParams<BoundFunc2<R, P1, P2, F, I> > { struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> {
typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I> typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I>
Func; Func;
}; };
template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I> template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I,
struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I> > { class R2, class P1_2, class P2_2, class P3_2>
typedef typename CanonicalType<P3>::Type CanonicalP3; struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>,
typedef Func3<R, void *, const void *, CanonicalP3, R2 (*)(P1_2, P2_2, P3_2)> {
CastHandlerData3<R, P1, P2, CanonicalP3, P3, F>, I> Func; typedef Func3<R, void *, const void *, P3_2,
CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func;
}; };
// For StringBuffer only; this ignores the BufferHandle. // For StringBuffer only; this ignores the BufferHandle.
template <class R, class P1, class P2, R F(P1, P2, const char *, size_t), template <class R, class P1, class P2, R F(P1, P2, const char *, size_t),
class I> class I, class T>
struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I> > { struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> {
typedef Func5<R, void *, const void *, const char *, size_t, typedef Func5<R, void *, const void *, const char *, size_t,
const BufferHandle *, CastHandlerDataIgnoreHandle<R, P1, P2, F>, const BufferHandle *, CastHandlerDataIgnoreHandle<R, P1, P2, F>,
I> Func; I> Func;
}; };
template <class R, class P1, class P2, class P3, class P4, class P5, template <class R, class P1, class P2, class P3, class P4, class P5,
R F(P1, P2, P3, P4, P5), class I> R F(P1, P2, P3, P4, P5), class I, class T>
struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I> > { struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> {
typedef Func5<R, void *, const void *, P3, P4, P5, typedef Func5<R, void *, const void *, P3, P4, P5,
CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func; CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func;
}; };
@ -906,7 +909,7 @@ inline Handler<T>::Handler(F func)
cleanup_func_(func.GetCleanup()) { cleanup_func_(func.GetCleanup()) {
upb_handlerattr_sethandlerdata(&attr_, func.GetData()); upb_handlerattr_sethandlerdata(&attr_, func.GetData());
typedef typename ReturnOf<T>::Return Return; typedef typename ReturnOf<T>::Return Return;
typedef typename ConvertParams<F>::Func ConvertedParamsFunc; typedef typename ConvertParams<F, T>::Func ConvertedParamsFunc;
typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func
ReturnWrappedFunc; ReturnWrappedFunc;
handler_ = ReturnWrappedFunc().Call; handler_ = ReturnWrappedFunc().Call;

@ -111,6 +111,7 @@ bool putf(upb_textprinter *p, const char *fmt, ...) {
/* handlers *******************************************************************/ /* handlers *******************************************************************/
static bool startmsg(void *c, const void *hd) { static bool startmsg(void *c, const void *hd) {
UPB_UNUSED(hd);
upb_textprinter *p = c; upb_textprinter *p = c;
if (p->indent_depth_ == 0) { if (p->indent_depth_ == 0) {
upb_bytessink_start(p->output_, 0, &p->subc); upb_bytessink_start(p->output_, 0, &p->subc);
@ -119,6 +120,8 @@ static bool startmsg(void *c, const void *hd) {
} }
static bool endmsg(void *c, const void *hd, upb_status *s) { static bool endmsg(void *c, const void *hd, upb_status *s) {
UPB_UNUSED(hd);
UPB_UNUSED(s);
upb_textprinter *p = c; upb_textprinter *p = c;
if (p->indent_depth_ == 0) { if (p->indent_depth_ == 0) {
upb_bytessink_end(p->output_); upb_bytessink_end(p->output_);
@ -237,7 +240,9 @@ void upb_textprinter_init(upb_textprinter *p, const upb_handlers *h) {
upb_sink_reset(&p->input_, h, p); upb_sink_reset(&p->input_, h, p);
} }
void upb_textprinter_uninit(upb_textprinter *p) {} void upb_textprinter_uninit(upb_textprinter *p) {
UPB_UNUSED(p);
}
void upb_textprinter_reset(upb_textprinter *p, bool single_line) { void upb_textprinter_reset(upb_textprinter *p, bool single_line) {
p->single_line_ = single_line; p->single_line_ = single_line;

@ -301,7 +301,7 @@ UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
} }
} else { } else {
const upb_tabent *e; const upb_tabent *e;
if (t->t.entries == NULL) return NULL; if (t->t.entries == NULL) return false;
for (e = upb_inthash(&t->t, upb_intkey(key)); true; e = e->next) { for (e = upb_inthash(&t->t, upb_intkey(key)); true; e = e->next) {
if ((uint32_t)e->key.num == key) { if ((uint32_t)e->key.num == key) {
_upb_value_setval(v, e->val, t->t.ctype); _upb_value_setval(v, e->val, t->t.ctype);

@ -35,6 +35,7 @@
#endif #endif
#ifdef UPB_CXX11 #ifdef UPB_CXX11
#include <type_traits>
#define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \ #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
class_name(const class_name&) = delete; \ class_name(const class_name&) = delete; \
void operator=(const class_name&) = delete; void operator=(const class_name&) = delete;

Loading…
Cancel
Save