From 8f11ec57d25bc3385565a82dbf9acfe97c9c3f8e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 15 Jun 2020 09:28:47 -0700 Subject: [PATCH] Applied changes from google3. --- bazel/upb_proto_library.bzl | 3 +++ tests/test_cpp.cc | 6 +++--- upb/handlers.h | 6 ++++-- upbc/generator.cc | 4 +++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl index 4dce00826d..732239b7a5 100644 --- a/bazel/upb_proto_library.bzl +++ b/bazel/upb_proto_library.bzl @@ -120,6 +120,9 @@ _WrappedGeneratedSrcsInfo = provider(fields = ["srcs"]) _WrappedDefsGeneratedSrcsInfo = provider(fields = ["srcs"]) def _compile_upb_protos(ctx, proto_info, proto_sources, ext): + if len(proto_sources) == 0: + return GeneratedSrcsInfo(srcs = [], hdrs = []) + srcs = [_generate_output_file(ctx, name, ext + ".c") for name in proto_sources] hdrs = [_generate_output_file(ctx, name, ext + ".h") for name in proto_sources] transitive_sets = proto_info.transitive_descriptor_sets.to_list() diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index 4ca81e1c35..c3d7d63ae7 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -50,7 +50,7 @@ static const int kExpectedHandlerData = 1232323; class StringBufTesterBase { public: - static const int kFieldNumber = 3; + static constexpr int kFieldNumber = 3; StringBufTesterBase() : seen_(false), handler_data_val_(0) {} @@ -286,7 +286,7 @@ class StartMsgTesterBase { public: // We don't need the FieldDef it will create, but the test harness still // requires that we provide one. - static const int kFieldNumber = 3; + static constexpr int kFieldNumber = 3; StartMsgTesterBase() : seen_(false), handler_data_val_(0) {} @@ -437,7 +437,7 @@ class StartMsgTesterBoolMethodWithHandlerData : public StartMsgTesterBase { class Int32ValueTesterBase { public: - static const int kFieldNumber = 1; + static constexpr int kFieldNumber = 1; Int32ValueTesterBase() : seen_(false), val_(0), handler_data_val_(0) {} diff --git a/upb/handlers.h b/upb/handlers.h index 9ed70e959c..53904b6022 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -106,7 +106,7 @@ typedef struct { #define UPB_HANDLERATTR_INIT {NULL, NULL, NULL, false} /* Bufhandle, data passed along with a buffer to indicate its provenance. */ -typedef struct { +struct upb_bufhandle { /* The beginning of the buffer. This may be different than the pointer * passed to a StringBuf handler because the handler may receive data * that is from the middle or end of a larger buffer. */ @@ -133,7 +133,9 @@ typedef struct { : NULL; } #endif -} upb_bufhandle; +}; + +typedef struct upb_bufhandle upb_bufhandle; #define UPB_BUFHANDLE_INIT {NULL, 0, NULL, NULL} diff --git a/upbc/generator.cc b/upbc/generator.cc index d5c27fb2af..1d0290c634 100644 --- a/upbc/generator.cc +++ b/upbc/generator.cc @@ -281,7 +281,9 @@ std::string FieldDefault(const protobuf::FieldDescriptor* field) { case protobuf::FieldDescriptor::CPPTYPE_BOOL: return field->default_value_bool() ? "true" : "false"; case protobuf::FieldDescriptor::CPPTYPE_ENUM: - return EnumValueSymbol(field->default_value_enum()); + // Use a number instead of a symbolic name so that we don't require + // this enum's header to be included. + return absl::StrCat(field->default_value_enum()->number()); } ABSL_ASSERT(false); return "XXX";