summaryrefslogtreecommitdiff
path: root/upb/bindings/googlepb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-05-12 11:54:34 -0700
committerJoshua Haberman <jhaberman@gmail.com>2016-05-12 11:54:34 -0700
commitfa338b70a602d9f5657528d0322535959a92d4b0 (patch)
treea7ec8b8d61a1ff3657aff99316ec51a8b81726ad /upb/bindings/googlepb
parente16ed470be7d0d459e85e1d7b43893358a625d34 (diff)
Added UPB_ASSERT() that helps avoid unused var warnings.
* Added UPB_ASSERT() that helps avoid unused var warnings. * Addressed PR comments. * Fixed assert in the JIT.
Diffstat (limited to 'upb/bindings/googlepb')
-rw-r--r--upb/bindings/googlepb/bridge.cc16
-rw-r--r--upb/bindings/googlepb/bridge.h4
-rw-r--r--upb/bindings/googlepb/proto1.cc22
-rw-r--r--upb/bindings/googlepb/proto2.cc38
4 files changed, 40 insertions, 40 deletions
diff --git a/upb/bindings/googlepb/bridge.cc b/upb/bindings/googlepb/bridge.cc
index c196140..adba3e7 100644
--- a/upb/bindings/googlepb/bridge.cc
+++ b/upb/bindings/googlepb/bridge.cc
@@ -18,7 +18,7 @@
#define ASSERT_STATUS(status) do { \
if (!upb_ok(status)) { \
fprintf(stderr, "upb status failure: %s\n", upb_status_errmsg(status)); \
- assert(upb_ok(status)); \
+ UPB_ASSERT(upb_ok(status)); \
} \
} while (0)
@@ -49,7 +49,7 @@ const goog::Message* TryGetFieldPrototype(const goog::Message& m,
const goog::Message* GetFieldPrototype(const goog::Message& m,
const goog::FieldDescriptor* f) {
const goog::Message* ret = TryGetFieldPrototype(m, f);
- assert(ret);
+ UPB_ASSERT(ret);
return ret;
}
@@ -66,7 +66,7 @@ const EnumDef* DefBuilder::GetEnumDef(const goog::EnumDescriptor* ed) {
for (int i = 0; i < ed->value_count(); i++) {
const goog::EnumValueDescriptor* val = ed->value(i);
bool success = e->AddValue(val->name(), val->number(), &status);
- UPB_ASSERT_VAR(success, success);
+ UPB_ASSERT(success);
}
e->Freeze(&status);
@@ -96,7 +96,7 @@ const MessageDef* DefBuilder::GetMaybeUnfrozenMessageDef(
for (size_t i = 0; i < fields.size(); i++) {
const goog::FieldDescriptor* proto2_f = fields[i];
- assert(proto2_f);
+ UPB_ASSERT(proto2_f);
md->AddField(NewFieldDef(proto2_f, m), &status);
}
ASSERT_STATUS(&status);
@@ -128,7 +128,7 @@ reffed_ptr<FieldDef> DefBuilder::NewFieldDef(const goog::FieldDescriptor* f,
subm = TryGetFieldPrototype(*m, f);
if (upb_f->type() == UPB_TYPE_MESSAGE) {
- assert(subm);
+ UPB_ASSERT(subm);
} else if (subm) {
// Weak field: subm will be weak prototype even though the proto2
// descriptor does not indicate a submessage field.
@@ -250,14 +250,14 @@ const Handlers* CodeCache::GetMaybeUnfrozenWriteHandlers(
if (!proto2_f) {
proto2_f = d->file()->pool()->FindExtensionByNumber(d, upb_f->number());
}
- assert(proto2_f);
+ UPB_ASSERT(proto2_f);
bool ok = WriteHandlers::AddFieldHandler(m, proto2_f, h);
- UPB_ASSERT_VAR(ok, ok);
+ UPB_ASSERT(ok);
if (upb_f->type() == UPB_TYPE_MESSAGE) {
const goog::Message* prototype = GetFieldPrototype(m, proto2_f);
- assert(prototype);
+ UPB_ASSERT(prototype);
const upb::Handlers* sub_handlers =
GetMaybeUnfrozenWriteHandlers(upb_f->message_subdef(), *prototype);
h->SetSubHandlers(upb_f, sub_handlers);
diff --git a/upb/bindings/googlepb/bridge.h b/upb/bindings/googlepb/bridge.h
index ec8ac41..ce55dc6 100644
--- a/upb/bindings/googlepb/bridge.h
+++ b/upb/bindings/googlepb/bridge.h
@@ -128,7 +128,7 @@ class DefBuilder {
template <class T>
T* AddToCache(const void *proto2_descriptor, reffed_ptr<T> def) {
- assert(def_cache_.find(proto2_descriptor) == def_cache_.end());
+ UPB_ASSERT(def_cache_.find(proto2_descriptor) == def_cache_.end());
def_cache_[proto2_descriptor] = def;
return def.get(); // Continued lifetime is guaranteed by cache.
}
@@ -207,7 +207,7 @@ class CodeCache {
const MessageDef* md, const ::google::protobuf::Message& m);
Handlers* AddToCache(const MessageDef* md, reffed_ptr<Handlers> handlers) {
- assert(handlers_cache_.find(md) == handlers_cache_.end());
+ UPB_ASSERT(handlers_cache_.find(md) == handlers_cache_.end());
handlers_cache_[md] = handlers;
return handlers.get(); // Continue lifetime is guaranteed by the cache.
}
diff --git a/upb/bindings/googlepb/proto1.cc b/upb/bindings/googlepb/proto1.cc
index fa51f79..c85bfca 100644
--- a/upb/bindings/googlepb/proto1.cc
+++ b/upb/bindings/googlepb/proto1.cc
@@ -35,7 +35,7 @@ namespace proto2 { class Arena; }
#include "upb/sink.h"
// Unconditionally evaluate, but also assert in debug mode.
-#define CHKRET(x) do { bool ok = (x); UPB_UNUSED(ok); assert(ok); } while (0)
+#define CHKRET(x) do { bool ok = (x); UPB_ASSERT(ok); } while (0)
template <class T> static T* GetPointer(void* message, size_t offset) {
return reinterpret_cast<T*>(static_cast<char*>(message) + offset);
@@ -58,7 +58,7 @@ class P2R_Handlers {
dynamic_cast<const _pi::Proto2Reflection*>(base_r);
if (!r) return false;
// Extensions don't exist in proto1.
- assert(!proto2_f->is_extension());
+ UPB_ASSERT(!proto2_f->is_extension());
#define PRIMITIVE(name, type_name) \
case _pi::CREP_REQUIRED_##name: \
@@ -107,7 +107,7 @@ class P2R_Handlers {
SetWeakMessageHandlers(proto2_f, m, r, upb_f, h);
return true;
default:
- assert(false);
+ UPB_ASSERT(false);
return false;
}
}
@@ -147,10 +147,10 @@ class P2R_Handlers {
} else if (dynamic_cast<const _pi::Proto2Reflection*>(m.GetReflection())) {
// Since proto1 has no dynamic message, it must be from the generated
// factory.
- assert(f->cpp_type() == proto2::FieldDescriptor::CPPTYPE_MESSAGE);
+ UPB_ASSERT(f->cpp_type() == proto2::FieldDescriptor::CPPTYPE_MESSAGE);
ret = proto2::MessageFactory::generated_factory()->GetPrototype(
f->message_type());
- assert(ret);
+ UPB_ASSERT(ret);
return ret;
} else {
return NULL;
@@ -175,7 +175,7 @@ class P2R_Handlers {
}
void SetHasbit(void* message) const {
- assert(!is_repeated_);
+ UPB_ASSERT(!is_repeated_);
uint8_t* byte = GetPointer<uint8_t>(message, hasbyte_);
*byte |= mask_;
}
@@ -193,13 +193,13 @@ class P2R_Handlers {
upb::Handlers::Type type) {
upb::Handlers::Selector selector;
bool ok = upb::Handlers::GetSelector(f, type, &selector);
- UPB_ASSERT_VAR(ok, ok);
+ UPB_ASSERT(ok);
return selector;
}
static int16_t GetHasbit(const proto2::FieldDescriptor* f,
const _pi::Proto2Reflection* r) {
- assert(!f->is_repeated());
+ UPB_ASSERT(!f->is_repeated());
return (r->layout_->has_bit_offset * 8) + r->GetFieldLayout(f)->has_index;
}
@@ -303,7 +303,7 @@ class P2R_Handlers {
const proto2::FieldDescriptor* proto2_f, const _pi::Proto2Reflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
// This type is only used for non-repeated string fields.
- assert(!f->IsSequence());
+ UPB_ASSERT(!f->IsSequence());
CHKRET(h->SetStartStringHandler(
f, UpbBind(StartOutOfLineString, new FieldOffset(proto2_f, r))));
CHKRET(h->SetStringHandler(f, UpbMakeHandler(OnStringBuf)));
@@ -452,7 +452,7 @@ class P2R_Handlers {
// around waiting for reuse, which we will not do.
static void Delete(Type* t) {
UPB_UNUSED(t);
- assert(false);
+ UPB_ASSERT(false);
}
#else
static ::proto2::Arena* GetArena(Type* t) {
@@ -470,7 +470,7 @@ class P2R_Handlers {
static void Delete(Type* t, ::proto2::Arena* arena) {
UPB_UNUSED(t);
UPB_UNUSED(arena);
- assert(false);
+ UPB_ASSERT(false);
}
static void Merge(const Type& from, Type* to) {
to->MergeFrom(from);
diff --git a/upb/bindings/googlepb/proto2.cc b/upb/bindings/googlepb/proto2.cc
index ee31d34..bfd5ba2 100644
--- a/upb/bindings/googlepb/proto2.cc
+++ b/upb/bindings/googlepb/proto2.cc
@@ -21,14 +21,14 @@
namespace {
template<typename To, typename From> To CheckDownCast(From* f) {
- assert(f == NULL || dynamic_cast<To>(f) != NULL);
+ UPB_ASSERT(f == NULL || dynamic_cast<To>(f) != NULL);
return static_cast<To>(f);
}
}
// Unconditionally evaluate, but also assert in debug mode.
-#define CHKRET(x) do { bool ok = (x); UPB_UNUSED(ok); assert(ok); } while (0)
+#define CHKRET(x) do { bool ok = (x); UPB_ASSERT(ok); } while (0)
namespace upb {
namespace google_google3 { class GMR_Handlers; }
@@ -222,7 +222,7 @@ case goog::FieldDescriptor::cpptype: \
upb::Handlers::Type type) {
upb::Handlers::Selector selector;
bool ok = upb::Handlers::GetSelector(f, type, &selector);
- UPB_ASSERT_VAR(ok, ok);
+ UPB_ASSERT(ok);
return selector;
}
@@ -230,7 +230,7 @@ case goog::FieldDescriptor::cpptype: \
const goog::FieldDescriptor* f,
const goog::internal::GeneratedMessageReflection* r) {
// proto2 does not store hasbits for repeated fields.
- assert(!f->is_repeated());
+ UPB_ASSERT(!f->is_repeated());
return (r->has_bits_offset_ * 8) + f->index();
}
@@ -238,7 +238,7 @@ case goog::FieldDescriptor::cpptype: \
static size_t GetOneofDiscriminantOffset(
const goog::FieldDescriptor* f,
const goog::internal::GeneratedMessageReflection* r) {
- assert(f->containing_oneof());
+ UPB_ASSERT(f->containing_oneof());
return r->oneof_case_offset_ + f->containing_oneof()->index();
}
#endif
@@ -326,7 +326,7 @@ case goog::FieldDescriptor::cpptype: \
}
void SetHasbit(void* m) const {
- assert(!is_repeated_);
+ UPB_ASSERT(!is_repeated_);
uint8_t* byte = GetPointer<uint8_t>(m, hasbyte_);
*byte |= mask_;
}
@@ -470,7 +470,7 @@ case goog::FieldDescriptor::cpptype: \
return ONEOF_TYPE_STRINGPIECE;
#endif
default:
- assert(false);
+ UPB_ASSERT(false);
return ONEOF_TYPE_NONE;
}
}
@@ -582,7 +582,7 @@ case goog::FieldDescriptor::cpptype: \
}
#ifdef GOOGLE_PROTOBUF_HAS_ONEOF
else if (proto2_f->containing_oneof()) {
- assert(!proto2_f->is_repeated());
+ UPB_ASSERT(!proto2_f->is_repeated());
CHKRET(h->SetValueHandler<T>(
f, UpbBindT(SetOneofPrimitive<T>,
new OneofFieldHandlerData(proto2_f, r))));
@@ -656,7 +656,7 @@ case goog::FieldDescriptor::cpptype: \
const goog::FieldDescriptor* proto2_f,
const goog::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
- assert(!proto2_f->is_extension());
+ UPB_ASSERT(!proto2_f->is_extension());
scoped_ptr<EnumHandlerData> data(new EnumHandlerData(proto2_f, r, f));
if (f->IsSequence()) {
CHKRET(h->SetInt32Handler(f, UpbBind(AppendEnum, data.release())));
@@ -696,7 +696,7 @@ case goog::FieldDescriptor::cpptype: \
const goog::FieldDescriptor* proto2_f,
const goog::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
- assert(proto2_f->is_extension());
+ UPB_ASSERT(proto2_f->is_extension());
scoped_ptr<ExtensionFieldData> data(new ExtensionFieldData(proto2_f, r));
if (f->IsSequence()) {
CHKRET(
@@ -745,11 +745,11 @@ case goog::FieldDescriptor::cpptype: \
const goog::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f,
upb::Handlers* h) {
- assert(!proto2_f->is_extension());
+ UPB_ASSERT(!proto2_f->is_extension());
CHKRET(h->SetStringHandler(f, UpbMakeHandlerT(&OnStringBuf<T>)));
#ifdef GOOGLE_PROTOBUF_HAS_ONEOF
if (proto2_f->containing_oneof()) {
- assert(!f->IsSequence());
+ UPB_ASSERT(!f->IsSequence());
CHKRET(h->SetStartStringHandler(
f, UpbBindT(&StartOneofString<T>,
new OneofFieldHandlerData(proto2_f, r))));
@@ -835,7 +835,7 @@ case goog::FieldDescriptor::cpptype: \
const goog::FieldDescriptor* proto2_f,
const goog::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
- assert(proto2_f->is_extension());
+ UPB_ASSERT(proto2_f->is_extension());
CHKRET(h->SetStringHandler(f, UpbMakeHandlerT(OnStringBuf<T>)));
scoped_ptr<ExtensionFieldData> data(new ExtensionFieldData(proto2_f, r));
if (f->IsSequence()) {
@@ -908,7 +908,7 @@ case goog::FieldDescriptor::cpptype: \
new SubMessageHandlerData(proto2_f, r, field_prototype));
#ifdef GOOGLE_PROTOBUF_HAS_ONEOF
if (proto2_f->containing_oneof()) {
- assert(!f->IsSequence());
+ UPB_ASSERT(!f->IsSequence());
CHKRET(h->SetStartSubMessageHandler(
f, UpbBind(StartOneofSubMessage, new OneofSubMessageHandlerData(
proto2_f, r, field_prototype))));
@@ -965,7 +965,7 @@ case goog::FieldDescriptor::cpptype: \
// around waiting for reuse, which we will not do.
static void Delete(Type* t) {
UPB_UNUSED(t);
- assert(false);
+ UPB_ASSERT(false);
}
#endif // ifdef GOOGLE_PROTOBUF_HAS_ARENAS
@@ -1089,7 +1089,7 @@ case goog::FieldDescriptor::cpptype: \
// "We could speed this up by using CordReader internals."
Cord piece(*source_cord);
piece.RemovePrefix(handle->object_offset() + (buf - handle->buffer()));
- assert(piece.size() >= n);
+ UPB_ASSERT(piece.size() >= n);
piece.RemoveSuffix(piece.size() - n);
c->Append(piece);
@@ -1102,7 +1102,7 @@ case goog::FieldDescriptor::cpptype: \
const proto2::FieldDescriptor* proto2_f,
const proto2::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
- assert(!proto2_f->is_extension());
+ UPB_ASSERT(!proto2_f->is_extension());
CHKRET(h->SetStringHandler(f, UpbMakeHandler(&OnCordBuf)));
if (f->IsSequence()) {
SetStartRepeatedField<Cord>(proto2_f, r, f, h);
@@ -1139,7 +1139,7 @@ case goog::FieldDescriptor::cpptype: \
const proto2::FieldDescriptor* proto2_f,
const proto2::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
- assert(!proto2_f->is_extension());
+ UPB_ASSERT(!proto2_f->is_extension());
CHKRET(h->SetStringHandler(f, UpbMakeHandler(OnStringPieceBuf)));
if (f->IsSequence()) {
SetStartRepeatedPtrField<proto2::internal::StringPieceField>(proto2_f, r,
@@ -1194,7 +1194,7 @@ case goog::FieldDescriptor::cpptype: \
const proto2::Message& m,
const proto2::internal::GeneratedMessageReflection* r,
const upb::FieldDef* f, upb::Handlers* h) {
- assert(!proto2_f->is_repeated());
+ UPB_ASSERT(!proto2_f->is_repeated());
const goog::Message* field_prototype = GetFieldPrototype(m, proto2_f);
CHKRET(h->SetStringHandler(f, UpbMakeHandler(OnLazyFieldBuf)));
if (proto2_f->is_extension()) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback