upb_symtab_add() returns upb_filedef* instead of bool.

pull/13171/head
Joshua Haberman 6 years ago
parent 84fb01ad0f
commit 01557462cc
  1. 6
      tests/pb/test_encoder.cc
  2. 6
      upb/def.c
  3. 9
      upb/def.h

@ -31,8 +31,8 @@ void test_pb_roundtrip() {
google_protobuf_FileDescriptorSet_file(set, &n);
ASSERT(n == 1);
upb::Status status;
bool ok = symtab.AddFile(files[0], &status);
if (!ok) {
upb::FileDefPtr file_def = symtab.AddFile(files[0], &status);
if (!file_def) {
fprintf(stderr, "Error building def: %s\n", status.error_message());
ASSERT(false);
}
@ -49,7 +49,7 @@ void test_pb_roundtrip() {
upb::pb::EncoderPtr::Create(&arena, encoder_handlers, string_sink.input());
upb::pb::DecoderPtr decoder =
upb::pb::DecoderPtr::Create(&arena, method, encoder.input(), &status);
ok = upb::PutBuffer(input, decoder.input());
bool ok = upb::PutBuffer(input, decoder.input());
ASSERT(ok);
ASSERT(input == output);
}

@ -1649,8 +1649,8 @@ static bool upb_symtab_addtotabs(upb_symtab *s, symtab_addctx *ctx,
return true;
}
bool upb_symtab_addfile(upb_symtab *s,
const google_protobuf_FileDescriptorProto *file_proto,
const upb_filedef *upb_symtab_addfile(
upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto,
upb_status *status) {
upb_arena *tmparena = upb_arena_new();
upb_strtable addtab;
@ -1672,7 +1672,7 @@ bool upb_symtab_addfile(upb_symtab *s,
upb_symtab_addtotabs(s, &ctx, status);
upb_arena_free(tmparena);
return ok;
return ok ? file : NULL;
}
/* Include here since we want most of this file to be stdio-free. */

@ -788,8 +788,8 @@ const upb_msgdef *upb_symtab_lookupmsg2(
const upb_symtab *s, const char *sym, size_t len);
const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
int upb_symtab_filecount(const upb_symtab *s);
bool upb_symtab_addfile(upb_symtab *s,
const google_protobuf_FileDescriptorProto* file,
const upb_filedef *upb_symtab_addfile(
upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
upb_status *status);
/* For generated code only: loads a generated descriptor. */
@ -826,9 +826,10 @@ class upb::SymbolTable {
/* TODO: iteration? */
/* Adds the given serialized FileDescriptorProto to the pool. */
bool AddFile(const google_protobuf_FileDescriptorProto *file_proto,
FileDefPtr AddFile(const google_protobuf_FileDescriptorProto *file_proto,
Status *status) {
return upb_symtab_addfile(ptr_.get(), file_proto, status->ptr());
return FileDefPtr(
upb_symtab_addfile(ptr_.get(), file_proto, status->ptr()));
}
private:

Loading…
Cancel
Save