Merge pull request #251 from haberman/emptyfix

Fixed code generator for upbdefs when a file has no messages.
pull/13171/head
Joshua Haberman 5 years ago committed by GitHub
commit e70853d71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      BUILD
  2. 2
      tests/empty.proto
  3. 18
      upbc/generator.cc

12
BUILD

@ -389,11 +389,23 @@ cc_test(
srcs = ["tests/test_generated_code.c"],
deps = [
":test_messages_proto3_proto_upb",
":empty_upbdefs_proto",
":test_upbproto",
":upb_test",
],
)
proto_library(
name = "empty_proto",
srcs = ["tests/empty.proto"],
)
upb_proto_reflection_library(
name = "empty_upbdefs_proto",
testonly = 1,
deps = [":empty_proto"],
)
upb_proto_library(
name = "test_messages_proto3_proto_upb",
testonly = 1,

@ -0,0 +1,2 @@
syntax = "proto2";

@ -853,12 +853,14 @@ void WriteDefSource(const protobuf::FileDescriptor* file, Output& output) {
}
output("\n");
output("static const upb_msglayout *layouts[$0] = {\n", file_messages.size());
for (auto message : file_messages) {
output(" &$0,\n", MessageInit(message));
if (!file_messages.empty()) {
output("static const upb_msglayout *layouts[$0] = {\n", file_messages.size());
for (auto message : file_messages) {
output(" &$0,\n", MessageInit(message));
}
output("};\n");
output("\n");
}
output("};\n");
output("\n");
protobuf::FileDescriptorProto file_proto;
file->CopyTo(&file_proto);
@ -905,7 +907,11 @@ void WriteDefSource(const protobuf::FileDescriptor* file, Output& output) {
output("upb_def_init $0 = {\n", DefInitSymbol(file));
output(" deps,\n");
output(" layouts,\n");
if (file_messages.empty()) {
output(" NULL,\n");
} else {
output(" layouts,\n");
}
output(" \"$0\",\n", file->name());
output(" UPB_STRVIEW_INIT(descriptor, $0)\n", file_data.size());
output("};\n");

Loading…
Cancel
Save