diff --git a/Makefile b/Makefile index 9496ce5983..cc30814b44 100644 --- a/Makefile +++ b/Makefile @@ -74,10 +74,15 @@ python: $(LIBUPB_PIC) cd lang_ext/python && python setup.py build # Tests +tests/test.proto.pb: tests/test.proto + # TODO: replace with upbc + protoc tests/test.proto -otests/test.proto.pb + tests: tests/tests \ tests/test_table \ tests/t.test_vs_proto2.googlemessage1 \ - tests/t.test_vs_proto2.googlemessage2 + tests/t.test_vs_proto2.googlemessage2 \ + tests/test.proto.pb #VALGRIND=valgrind --leak-check=full --error-exitcode=1 VALGRIND= diff --git a/src/upb_def.c b/src/upb_def.c index 08140e4c17..bc4f293196 100644 --- a/src/upb_def.c +++ b/src/upb_def.c @@ -27,8 +27,9 @@ static int div_round_up(int numerator, int denominator) { // // Our scheme is as follows. First we give each def a flag indicating whether // it is part of a cycle or not. Because defs are immutable, this flag will -// never change. For acyclic defs, we can use a naive algorithm and avoid -// the overhead of dealing with cycles. Most defs will be acyclic. +// never change. For acyclic defs, we can use a naive algorithm and avoid the +// overhead of dealing with cycles. Most defs will be acyclic, and most cycles +// will be very short. // // For defs that participate in cycles we keep two reference counts. One // tracks references that come from outside the cycle (we call these external diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index 926d731073..58c8e50c30 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -131,8 +131,8 @@ void compare(const google::protobuf::Message& proto2_msg, const google::protobuf::Descriptor *d = proto2_msg.GetDescriptor(); struct upb_msgdef *def = upb_msg->def; - ASSERT((uint32_t)d->field_count() == def->num_fields); - for(uint32_t i = 0; i < def->num_fields; i++) { + ASSERT((upb_field_count_t)d->field_count() == def->num_fields); + for(upb_field_count_t i = 0; i < def->num_fields; i++) { struct upb_fielddef *upb_f = &def->fields[i]; const google::protobuf::FieldDescriptor *proto2_f = d->FindFieldByNumber(upb_f->number); diff --git a/tests/tests.c b/tests/tests.c index 9fbfa3af20..3580c2ef36 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -228,9 +228,18 @@ static void test_get_f_uint32_t() } static void test_upb_symtab() { - struct upb_symtab *c = upb_symtab_new(); - ASSERT(c); - upb_symtab_unref(c); + struct upb_symtab *s = upb_symtab_new(); + ASSERT(s); + struct upb_string *descriptor = upb_strreadfile("tests/test.proto.pb"); + if(!descriptor) { + fprintf(stderr, "Couldn't read input file tests/test.proto.pb\n"); + exit(1); + } + struct upb_status status = UPB_STATUS_INIT; + upb_symtab_add_desc(s, descriptor, &status); + ASSERT(upb_ok(&status)); + upb_string_unref(descriptor); + upb_symtab_unref(s); } diff --git a/tools/upbc.c b/tools/upbc.c index cb41eccc0a..8d41abc792 100644 --- a/tools/upbc.c +++ b/tools/upbc.c @@ -708,6 +708,7 @@ int main(int argc, char *argv[]) int symcount; struct upb_def **defs = upb_symtab_getandref_defs(s, &symcount); + upb_symtab_unref(s); write_h(defs, symcount, h_filename, cident, h_file); write_const_h(defs, symcount, h_filename, h_const_file); for (int i = 0; i < symcount; i++) upb_def_unref(defs[i]); @@ -719,7 +720,6 @@ int main(int argc, char *argv[]) fclose(c_file); } upb_msg_unref(fds_msg); - upb_symtab_unref(s); upb_string_unref(descriptor); fclose(h_file); fclose(h_const_file);