diff --git a/Makefile b/Makefile index bccf860490..e8f84225ec 100644 --- a/Makefile +++ b/Makefile @@ -216,6 +216,8 @@ tests/test.proto.pb: tests/test.proto SIMPLE_TESTS= \ tests/test_def \ tests/test_varint \ + tests/test_pipeline \ + tests/test_handlers SIMPLE_CXX_TESTS= \ tests/test_cpp \ diff --git a/tests/test_handlers.c b/tests/test_handlers.c index fb0564a783..36881fee7f 100644 --- a/tests/test_handlers.c +++ b/tests/test_handlers.c @@ -11,7 +11,11 @@ #include #include -static bool startmsg(void *c, const void *hd) { return true; } +static bool startmsg(void *c, const void *hd) { + UPB_UNUSED(c); + UPB_UNUSED(hd); + return true; +} static void test_error() { upb_handlers *h = upb_handlers_new(GOOGLE_PROTOBUF_DESCRIPTORPROTO, NULL, &h); @@ -33,6 +37,8 @@ static void test_error() { } int run_tests(int argc, char *argv[]) { + UPB_UNUSED(argc); + UPB_UNUSED(argv); test_error(); return 0; } diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c index d54d15c94a..7214ca58be 100644 --- a/tests/test_pipeline.c +++ b/tests/test_pipeline.c @@ -108,6 +108,8 @@ static void test_realloc() { } int run_tests(int argc, char *argv[]) { + UPB_UNUSED(argc); + UPB_UNUSED(argv); test_empty(); test_only_initial(); test_with_alloc_func(); diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c index e1b0c924e6..43bbdea35f 100644 --- a/upb/descriptor/reader.c +++ b/upb/descriptor/reader.c @@ -296,6 +296,7 @@ static bool enum_startmsg(void *closure, const void *hd) { } static bool enum_endmsg(void *closure, const void *hd, upb_status *status) { + UPB_UNUSED(hd); upb_descreader *r = closure; upb_enumdef *e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); if (upb_def_fullname(upb_descreader_last(r)) == NULL) { diff --git a/upb/google/bridge.cc b/upb/google/bridge.cc index 97a91eac9a..93864273b5 100644 --- a/upb/google/bridge.cc +++ b/upb/google/bridge.cc @@ -131,8 +131,8 @@ FieldDef* AddFieldDef(const goog::Message& m, const goog::FieldDescriptor* f, : upb::FieldDef::ConvertDescriptorType(f->type())); if (weak_prototype) { - const string& name = weak_prototype->GetDescriptor()->full_name(); - upb_f->set_subdef_name(name, &status); + upb_f->set_subdef_name( + weak_prototype->GetDescriptor()->full_name(), &status); } else { switch (upb_f->type()) { case UPB_TYPE_INT32: diff --git a/upb/handlers-inl.h b/upb/handlers-inl.h index 65f21a28f2..6b46b47bc7 100644 --- a/upb/handlers-inl.h +++ b/upb/handlers-inl.h @@ -303,8 +303,8 @@ inline Handlers::StringHandler BindHandler( template <> \ inline bool Handlers::SetValueHandler( \ const FieldDef *f, \ - const typename ValueHandler::Type>::H & \ - handler) { \ + const Handlers::utype ## Handler& handler) { \ + assert(!handler.registered_); \ handler.registered_ = true; \ return upb_handlers_set##ltype(this, f, handler.handler_, handler.data_, \ handler.cleanup_); \ @@ -394,54 +394,63 @@ inline const MessageDef *Handlers::message_def() const { } inline bool Handlers::SetStartMessageHandler( const Handlers::StartMessageHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setstartmsg(this, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetEndMessageHandler( const Handlers::EndMessageHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setendmsg(this, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetStartStringHandler(const FieldDef *f, const StartStringHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setstartstr(this, f, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetEndStringHandler(const FieldDef *f, const EndFieldHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setendstr(this, f, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetStringHandler(const FieldDef *f, const StringHandler& handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setstring(this, f, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetStartSequenceHandler( const FieldDef *f, const StartFieldHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setstartseq(this, f, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetStartSubMessageHandler( const FieldDef *f, const StartFieldHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setstartsubmsg(this, f, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetEndSubMessageHandler(const FieldDef *f, const EndFieldHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setendsubmsg(this, f, handler.handler_, handler.data_, handler.cleanup_); } inline bool Handlers::SetEndSequenceHandler(const FieldDef *f, const EndFieldHandler &handler) { + assert(!handler.registered_); handler.registered_ = true; return upb_handlers_setendseq(this, f, handler.handler_, handler.data_, handler.cleanup_); diff --git a/upb/handlers.h b/upb/handlers.h index a80e401e74..21080463b4 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -116,13 +116,13 @@ class upb::Handlers { typedef Handler H; }; - typedef ValueHandler::H Int32Handler; - typedef ValueHandler::H Int64Handler; - typedef ValueHandler::H UInt32Handler; - typedef ValueHandler::H UInt64Handler; - typedef ValueHandler::H FloatHandler; - typedef ValueHandler::H DoubleHandler; - typedef ValueHandler::H BoolHandler; + typedef ValueHandler::H Int32Handler; + typedef ValueHandler::H Int64Handler; + typedef ValueHandler::H UInt32Handler; + typedef ValueHandler::H UInt64Handler; + typedef ValueHandler::H FloatHandler; + typedef ValueHandler::H DoubleHandler; + typedef ValueHandler::H BoolHandler; // Any function pointer can be converted to this and converted back to its // correct type. @@ -470,8 +470,14 @@ template class Handler { Handler(FuncPtr h, void *d, void (*c)(void *)) : handler_(h), data_(d), cleanup_(c), registered_(false) {} - Handler(const Handler&); void operator=(const Handler&); +#ifdef UPB_CXX11 + // C++98 doesn't support binding a const ref to a temporary, at least + // according to Clang. It is still intended that users NOT create instances + // of this object via this copy constructor, and any attempts to register + // such an object more than once will assert-fail. + Handler(const Handler&); +#endif FuncPtr handler_; void *data_;