From 96307d28f69662eb04edcaeb9d1d1ed25e692d88 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 22 Mar 2021 13:05:55 -0700 Subject: [PATCH 1/2] Sync from Piper @364389596 PROTOBUF_SYNC_PIPER --- .github/mergeable.yml | 4 +- BUILD | 44 +--- CHANGES.txt | 43 ++++ Makefile.am | 1 - Protobuf.podspec | 2 +- WORKSPACE | 21 +- benchmarks/BUILD | 65 ++++++ benchmarks/cpp/BUILD | 15 ++ benchmarks/datasets/BUILD | 59 +++++ .../datasets/google_message1/proto2/BUILD | 44 ++++ .../datasets/google_message1/proto3/BUILD | 44 ++++ benchmarks/datasets/google_message2/BUILD | 44 ++++ benchmarks/datasets/google_message3/BUILD | 50 ++++ benchmarks/datasets/google_message4/BUILD | 45 ++++ conformance/text_format_conformance_suite.cc | 21 ++ csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 340024 -> 340187 bytes .../Google.Protobuf/Google.Protobuf.csproj | 2 +- .../Google.Protobuf/Reflection/Descriptor.cs | 95 ++++---- docs/implementing_proto3_presence.md | 4 +- docs/options.md | 8 + docs/third_party.md | 2 +- java/README.md | 4 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- .../java/com/google/protobuf/ByteString.java | 6 +- .../com/google/protobuf/RopeByteString.java | 7 +- .../google/protobuf/AbstractMessageTest.java | 4 +- .../google/protobuf/DynamicMessageTest.java | 2 +- .../google/protobuf/GeneratedMessageTest.java | 1 + .../com/google/protobuf/MapForProto2Test.java | 4 +- .../java/com/google/protobuf/MapTest.java | 4 +- .../google/protobuf/TestBadIdentifiers.java | 6 +- .../protobuf/TestBadIdentifiersLite.java | 6 +- .../protobuf/test_extra_interfaces.proto | 56 ----- java/lite/generate-test-sources-build.xml | 1 + java/lite/pom.xml | 2 +- .../java/com/google/protobuf/LiteTest.java | 38 ++-- java/pom.xml | 6 +- java/util/pom.xml | 2 +- kokoro/release/protoc/linux/build.sh | 2 +- php/ext/google/protobuf/message.c | 2 +- php/ext/google/protobuf/package.xml | 63 ++++-- php/ext/google/protobuf/php-upb.c | 3 +- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/README.md | 2 +- protoc-artifacts/build-protoc.sh | 6 +- protoc-artifacts/build-zip.sh | 4 +- protoc-artifacts/pom.xml | 6 +- .../protobuf/internal/text_format_test.py | 55 +++++ python/google/protobuf/pyext/descriptor.cc | 15 +- .../protobuf/pyext/descriptor_database.cc | 4 +- .../google/protobuf/pyext/extension_dict.cc | 6 +- python/google/protobuf/pyext/map_container.cc | 7 +- python/google/protobuf/pyext/map_container.h | 3 +- python/google/protobuf/pyext/message.cc | 9 +- python/google/protobuf/pyext/message.h | 9 +- .../pyext/repeated_scalar_container.cc | 9 +- python/google/protobuf/text_format.py | 4 +- python/tox.ini | 7 +- .../v3.0.0/tests/repeated_field_test.rb | 12 - ruby/ext/google/protobuf_c/convert.c | 2 +- ruby/ext/google/protobuf_c/message.c | 4 +- ruby/ext/google/protobuf_c/protobuf.c | 6 +- ruby/ext/google/protobuf_c/ruby-upb.c | 3 +- ruby/google-protobuf.gemspec | 2 +- ruby/tests/basic.rb | 11 +- ruby/tests/common_tests.rb | 12 + ruby/tests/repeated_field_test.rb | 12 - src/google/protobuf/any.pb.cc | 4 +- src/google/protobuf/api.pb.cc | 12 +- src/google/protobuf/arenastring.cc | 8 + src/google/protobuf/arenastring.h | 12 +- .../protobuf/compiler/annotation_test_util.cc | 5 +- .../compiler/command_line_interface.cc | 4 +- .../compiler/command_line_interface.h | 3 +- .../command_line_interface_unittest.cc | 4 +- src/google/protobuf/compiler/cpp/cpp_enum.cc | 10 +- src/google/protobuf/compiler/cpp/cpp_field.cc | 4 +- src/google/protobuf/compiler/cpp/cpp_field.h | 3 +- .../protobuf/compiler/cpp/cpp_helpers.cc | 40 ++-- .../protobuf/compiler/cpp/cpp_helpers.h | 7 +- .../protobuf/compiler/cpp/cpp_message.cc | 129 ++++++++--- .../protobuf/compiler/cpp/cpp_message.h | 4 +- src/google/protobuf/compiler/cpp/cpp_names.h | 5 + .../compiler/cpp/cpp_primitive_field.cc | 32 +-- .../protobuf/compiler/cpp/cpp_unittest.inc | 52 +++-- .../protobuf/compiler/java/java_enum_field.cc | 6 +- .../compiler/java/java_enum_field_lite.cc | 12 +- .../compiler/java/java_enum_field_lite.h | 8 +- .../protobuf/compiler/java/java_field.h | 3 +- .../protobuf/compiler/java/java_helpers.cc | 17 +- .../protobuf/compiler/java/java_helpers.h | 11 +- .../compiler/java/java_map_field_lite.cc | 4 +- .../compiler/java/java_map_field_lite.h | 4 +- .../protobuf/compiler/java/java_message.cc | 9 +- .../compiler/java/java_message_field_lite.cc | 10 +- .../compiler/java/java_message_field_lite.h | 8 +- .../compiler/java/java_message_lite.cc | 5 +- .../compiler/java/java_primitive_field.cc | 6 +- .../java/java_primitive_field_lite.cc | 9 +- .../compiler/java/java_primitive_field_lite.h | 8 +- .../compiler/java/java_string_field.cc | 6 +- .../compiler/java/java_string_field_lite.cc | 12 +- .../compiler/java/java_string_field_lite.h | 8 +- .../protobuf/compiler/mock_code_generator.cc | 5 +- .../protobuf/compiler/mock_code_generator.h | 5 +- src/google/protobuf/compiler/parser.cc | 53 +++-- src/google/protobuf/compiler/parser.h | 10 +- src/google/protobuf/compiler/plugin.pb.cc | 16 +- src/google/protobuf/compiler/zip_writer.cc | 35 +-- src/google/protobuf/compiler/zip_writer.h | 8 +- src/google/protobuf/descriptor.pb.cc | 213 +++++++++--------- src/google/protobuf/descriptor.proto | 2 + src/google/protobuf/duration.pb.cc | 4 +- src/google/protobuf/empty.pb.cc | 4 +- src/google/protobuf/field_mask.pb.cc | 4 +- src/google/protobuf/io/coded_stream.cc | 20 ++ src/google/protobuf/io/coded_stream.h | 31 ++- src/google/protobuf/message_unittest.inc | 32 +++ src/google/protobuf/parse_context.cc | 12 + src/google/protobuf/parse_context.h | 20 +- src/google/protobuf/repeated_field.h | 51 ++++- .../protobuf/repeated_field_unittest.cc | 87 +++++++ src/google/protobuf/source_context.pb.cc | 4 +- src/google/protobuf/struct.pb.cc | 12 +- src/google/protobuf/timestamp.pb.cc | 4 +- src/google/protobuf/type.pb.cc | 20 +- src/google/protobuf/unittest.proto | 30 +++ src/google/protobuf/util/field_comparator.cc | 43 ++-- src/google/protobuf/util/field_comparator.h | 69 ++++-- src/google/protobuf/util/field_mask_util.cc | 7 +- src/google/protobuf/util/field_mask_util.h | 3 +- .../protobuf/util/field_mask_util_test.cc | 3 +- src/google/protobuf/util/json_util_test.cc | 3 +- .../protobuf/util/message_differencer.cc | 43 ++-- .../protobuf/util/message_differencer.h | 2 +- .../util/message_differencer_unittest.cc | 6 +- src/google/protobuf/util/time_util.cc | 127 ++++++----- src/google/protobuf/util/time_util.h | 59 ++--- src/google/protobuf/util/time_util_test.cc | 24 +- .../protobuf/util/type_resolver_util_test.cc | 5 +- src/google/protobuf/wire_format_lite.h | 2 +- src/google/protobuf/wrappers.pb.cc | 36 +-- 144 files changed, 1781 insertions(+), 867 deletions(-) create mode 100644 benchmarks/BUILD create mode 100644 benchmarks/cpp/BUILD create mode 100644 benchmarks/datasets/BUILD create mode 100644 benchmarks/datasets/google_message1/proto2/BUILD create mode 100644 benchmarks/datasets/google_message1/proto3/BUILD create mode 100644 benchmarks/datasets/google_message2/BUILD create mode 100644 benchmarks/datasets/google_message3/BUILD create mode 100644 benchmarks/datasets/google_message4/BUILD delete mode 100644 java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto diff --git a/.github/mergeable.yml b/.github/mergeable.yml index 8577f086ee..4027cf5a9f 100644 --- a/.github/mergeable.yml +++ b/.github/mergeable.yml @@ -11,8 +11,8 @@ mergeable: regex: 'release notes: yes' message: 'Please include release notes: yes' - must_include: - regex: '^(c#|c\+\+|cleanup|conformance tests|integration|java|javascript|go|objective-c|php|python|ruby|bazel|cmake|protoc)' - message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: bazel, cmake, cleanup, conformance tests, integration, protoc.' + regex: '^(autotools|bazel|c#|c\+\+|cleanup|cmake|conformance tests|integration|go|java|javascript|objective-c|php|protoc|python|ruby)' + message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: autotools, bazel, cmake, cleanup, conformance tests, integration, protoc.' - must_include: regex: 'release notes: no' message: 'Please include release notes: no' diff --git a/BUILD b/BUILD index 1124321602..07ee629a18 100644 --- a/BUILD +++ b/BUILD @@ -14,38 +14,6 @@ exports_files(["LICENSE"]) # build configuration ################################################################################ -# TODO(yannic): Remove in 3.14.0. -string_flag( - name = "incompatible_use_com_google_googletest", - build_setting_default = "true", - values = ["true", "false"] -) - -config_setting( - name = "use_com_google_googletest", - flag_values = { - "//:incompatible_use_com_google_googletest": "true" - }, -) - -GTEST = select({ - "//:use_com_google_googletest": [ - "@com_google_googletest//:gtest", - ], - "//conditions:default": [ - "//external:gtest", - ], -}) - -GTEST_MAIN = select({ - "//:use_com_google_googletest": [ - "@com_google_googletest//:gtest_main", - ], - "//conditions:default": [ - "//external:gtest_main", - ], -}) - ################################################################################ # ZLIB configuration ################################################################################ @@ -571,6 +539,7 @@ COMMON_TEST_SRCS = [ cc_binary( name = "test_plugin", + testonly = True, srcs = [ # AUTOGEN(test_plugin_srcs) "src/google/protobuf/compiler/mock_code_generator.cc", @@ -580,7 +549,8 @@ cc_binary( deps = [ ":protobuf", ":protoc_lib", - ] + GTEST, + "@com_google_googletest//:gtest", + ], ) cc_test( @@ -592,7 +562,9 @@ cc_test( ], deps = [ ":protobuf_lite", - ] + GTEST_MAIN, + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], ) cc_test( @@ -695,7 +667,9 @@ cc_test( ":cc_test_protos", ":protobuf", ":protoc_lib", - ] + PROTOBUF_DEPS + GTEST_MAIN, + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ] + PROTOBUF_DEPS, ) ################################################################################ diff --git a/CHANGES.txt b/CHANGES.txt index d73ef274c5..ef79313b59 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,46 @@ +Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + C++ + * Allow MessageDifferencer::TreatAsSet() (and friends) to override previous + calls instead of crashing. + * Reduce the size of generated proto headers for protos with `string` or + `bytes` fields. + * Move arena() operation on uncommon path to out-of-line routine + * For iterator-pair function parameter types, take both iterators by value. + * Code-space savings and perhaps some modest performance improvements in + RepeatedPtrField. + + Java: + * Exceptions thrown while reading from an InputStream in parseFrom are now included as causes. + +2021-03-10 version 3.15.6 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Fixed bug in string comparison logic (#8386) + +2021-03-04 version 3.15.5 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Fixed quadratic memory use in array append (#8379) + + PHP + * Fixed quadratic memory use in array append (#8379) + + C++ + * Do not disable RTTI by default in the CMake build (#8377) + +2021-03-02 version 3.15.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Fixed SEGV when users pass nil messages (#8363) + * Fixed quadratic memory usage when appending to arrays (#8364) + + C++ + * Create a CMake option to control whether or not RTTI is enabled (#8361) + + PHP + * read_property() handler is not supposed to return NULL (#8362) + 2021-02-25 version 3.15.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Ruby diff --git a/Makefile.am b/Makefile.am index 53b259480a..915184213c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -529,7 +529,6 @@ java_EXTRA_DIST= java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto \ java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto \ java/core/src/test/proto/com/google/protobuf/test_custom_options.proto \ - java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto \ java/core/src/test/proto/com/google/protobuf/wrappers_test.proto \ java/lite.md \ java/lite/BUILD \ diff --git a/Protobuf.podspec b/Protobuf.podspec index b2958e0283..b61cafc518 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.15.3' + s.version = '3.15.6' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/WORKSPACE b/WORKSPACE index 5a767a97c0..4346dbd906 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,6 +17,15 @@ http_archive( ], ) +http_archive( + name = "com_github_google_benchmark", + sha256 = "2a778d821997df7d8646c9c59b8edb9a573a6e04c534c01892a40aa524a7b68c", + strip_prefix = "benchmark-bf585a2789e30585b4e3ce6baf11ef2750b54677", + urls = [ + "https://github.com/google/benchmark/archive/bf585a2789e30585b4e3ce6baf11ef2750b54677.zip", + ], +) + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("//:protobuf_deps.bzl", "protobuf_deps") @@ -29,18 +38,6 @@ bind( actual = "//util/python:python_headers", ) -# TODO(yannic): Remove in 3.14.0. -bind( - name = "gtest", - actual = "@com_google_googletest//:gtest", -) - -# TODO(yannic): Remove in 3.14.0. -bind( - name = "gtest_main", - actual = "@com_google_googletest//:gtest_main", -) - jvm_maven_import_external( name = "guava_maven", artifact = "com.google.guava:guava:18.0", diff --git a/benchmarks/BUILD b/benchmarks/BUILD new file mode 100644 index 0000000000..8e6063ba83 --- /dev/null +++ b/benchmarks/BUILD @@ -0,0 +1,65 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "benchmarks_proto", + srcs = [ + "benchmarks.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +cc_proto_library( + name = "benchmarks_cc_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "benchmarks_proto", + ], +) + +java_proto_library( + name = "benchmarks_java_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "benchmarks_proto", + ], +) + +proto_library( + name = "google_size_proto", + srcs = [ + "google_size.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +cc_proto_library( + name = "google_size_cc_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "google_size_proto", + ], +) + +java_proto_library( + name = "google_size_java_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "google_size_proto", + ], +) diff --git a/benchmarks/cpp/BUILD b/benchmarks/cpp/BUILD new file mode 100644 index 0000000000..b744f896ad --- /dev/null +++ b/benchmarks/cpp/BUILD @@ -0,0 +1,15 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") + +cc_binary( + name = "cpp", + srcs = [ + "cpp_benchmark.cc", + ], + tags = ["benchmark"], + deps = [ + "//:protobuf", + "//benchmarks:benchmarks_cc_proto", + "//benchmarks/datasets:cc_protos", + "@com_github_google_benchmark//:benchmark_main", + ], +) diff --git a/benchmarks/datasets/BUILD b/benchmarks/datasets/BUILD new file mode 100644 index 0000000000..f29a27650b --- /dev/null +++ b/benchmarks/datasets/BUILD @@ -0,0 +1,59 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_java//java:defs.bzl", "java_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "//benchmarks/datasets/google_message1/proto2:datasets", + "//benchmarks/datasets/google_message1/proto3:datasets", + "//benchmarks/datasets/google_message2:datasets", + "//benchmarks/datasets/google_message3:datasets", + "//benchmarks/datasets/google_message4:datasets", + ], + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +proto_library( + name = "protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_proto", + ], +) + +cc_library( + name = "cc_protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_cc_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_cc_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_cc_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_cc_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_cc_proto", + ], +) + +java_library( + name = "java_protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + exports = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_java_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_java_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_java_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_java_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_java_proto", + ], +) diff --git a/benchmarks/datasets/google_message1/proto2/BUILD b/benchmarks/datasets/google_message1/proto2/BUILD new file mode 100644 index 0000000000..d4d38cec22 --- /dev/null +++ b/benchmarks/datasets/google_message1/proto2/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto2_proto", + srcs = [ + "benchmark_message1_proto2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) diff --git a/benchmarks/datasets/google_message1/proto3/BUILD b/benchmarks/datasets/google_message1/proto3/BUILD new file mode 100644 index 0000000000..c2d627acd8 --- /dev/null +++ b/benchmarks/datasets/google_message1/proto3/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto3.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto3_proto", + srcs = [ + "benchmark_message1_proto3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) diff --git a/benchmarks/datasets/google_message2/BUILD b/benchmarks/datasets/google_message2/BUILD new file mode 100644 index 0000000000..1ca87fb64f --- /dev/null +++ b/benchmarks/datasets/google_message2/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message2_proto", + srcs = [ + "benchmark_message2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) + +java_proto_library( + name = "benchmark_message2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) diff --git a/benchmarks/datasets/google_message3/BUILD b/benchmarks/datasets/google_message3/BUILD new file mode 100644 index 0000000000..9a00294464 --- /dev/null +++ b/benchmarks/datasets/google_message3/BUILD @@ -0,0 +1,50 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message3_proto", + srcs = [ + "benchmark_message3.proto", + "benchmark_message3_1.proto", + "benchmark_message3_2.proto", + "benchmark_message3_3.proto", + "benchmark_message3_4.proto", + "benchmark_message3_5.proto", + "benchmark_message3_6.proto", + "benchmark_message3_7.proto", + "benchmark_message3_8.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) + +java_proto_library( + name = "benchmark_message3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) diff --git a/benchmarks/datasets/google_message4/BUILD b/benchmarks/datasets/google_message4/BUILD new file mode 100644 index 0000000000..b23a4c955c --- /dev/null +++ b/benchmarks/datasets/google_message4/BUILD @@ -0,0 +1,45 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message4_proto", + srcs = [ + "benchmark_message4.proto", + "benchmark_message4_1.proto", + "benchmark_message4_2.proto", + "benchmark_message4_3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message4_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) + +java_proto_library( + name = "benchmark_message4_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) diff --git a/conformance/text_format_conformance_suite.cc b/conformance/text_format_conformance_suite.cc index 4c9dc7dbe0..460bc24900 100644 --- a/conformance/text_format_conformance_suite.cc +++ b/conformance/text_format_conformance_suite.cc @@ -451,6 +451,27 @@ void TextFormatConformanceTestSuite::RunSuiteImpl() { } )", prototype); + + prototype.Clear(); + ConformanceRequestSetting setting_map( + REQUIRED, conformance::TEXT_FORMAT, conformance::PROTOBUF, + conformance::TEXT_FORMAT_TEST, prototype, "DuplicateMapKey", R"( + map_string_nested_message { + key: "duplicate" + value: { a: 123 } + } + map_string_nested_message { + key: "duplicate" + value: { corecursive: {} } + } + )"); + // The last-specified value will be retained in a parsed map + RunValidInputTest(setting_map, R"( + map_string_nested_message { + key: "duplicate" + value: { corecursive: {} } + } + )"); } } // namespace protobuf diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 60c7fecda9..c6f019a13c 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.15.3 + 3.15.6 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 3cf55f9d4d7a6ff7869236b76c3fe6858e2bb371..06a17c1038c06c8a5879a2950630314fab7d1126 100644 GIT binary patch delta 4980 zcmZ8lYiv}<72df!Gk0_MeRp{o8$YlykD%ZrYK16@C^QKq%A=`Dd4!e_TGFOJ5~Ajz zN^8|P4#uRGh`Fdn7?o7jR!E?LypDwBHasi0M13gYq1uExUSmhZyi`y?^gDBB_HO&b zXumUO&N<(i@18rCzDwDQpJxvrKgB<24Ljbz@^I~uu~Qpe_U|LB&aY%io)W8gM5HAC zl_~p3=Y_Ecru_BKmSel3G4#I8oIfNT7IVXmg};5uo{&fWIX?Uh`=D@iF*_%6Q76o! z54ik#*vdFDhXaHNMPp9f5ro+PLQ6y6S1l%z+L!$wRK8gCeHBW(+SgLPRRK23`z2Lj zgV#GpLALYM46{m`cx9DSuUYNzZho81ehB6ryu^q$ zl|v*}uv%~G@E%{zW;Jn_cLbX_HkCtcQt(+-EPOk;cX%^fa3ny2w2A1nK1;L7fx_LCE;sIh)H&0JB5CwJf85IUb2+mw+ zpiOYjgHD1H@Q^F_a_ayO`^%hS?d5jNsdgkSQw94tPgZ!ZJkF|e_~|%F$M%=NV;_$v z5X$$(-u;}%OAaI^7$SiIJNDCwm>s~s<$OxXfg}Y(DljOIOxC$T4UsW&$QPndu=Q+d zKIjNT-}6RPa3U|BG96*)NS-?K8=<<2n7xG$pJaQjTyGG=LRWiv)IX(|MVWfJ>z^SY zV)XKvmAZ`1p^C%>=g8IBQ;p+e8o z>@~S=C?HQy^yi_=r^W4tzS20s`@ie40OHVwOPsBClAW;|s(u@`m{ije;2IV8R~-%K*S;B1j|EqMij< zMVbjS3jmR3!pwpgD!NLuV0BYW;J~k%fdGVUfLdyTj{GVOgi0C#80C}RhVQdkD<{qH zim4f14zWW)8X<94-r%7-dW6Ig`v#2=A`>U2-O_U{xf*lrmf?aWaJgmX8Xz{_GF$+` z<(A2Zoi9ja33@tPy-0YU_=LW>L#B4`y58NEajID|IuA8T0c!Zx8_I|+3N| zXh5XeDf9~@>B>$K+N&F#glDISOn3f6ZAwz7yS(qNV|UhenWA7srY_SaK7c%#*06o0zX( z*=nkECmIxiM1Qmj+N`k-RH48JiT4hC6>_CZ4%tK@2E10u^o zLpz0n4*3V3q60rNng0!M)#b2L$(i;yy`|O4F6$6Jee5Uf;yNTKVC& z?3DYs;Fap-tuWHSFfA~E$8k|H6Sq4_k*JX;yboVybLvhAo+x`JAP7N4G1A~9_1jNyt7Eynq03!KmQR!cd z0MUfgVv+ww2SgLj2-#plp$TV1x<0BDkfy|gz5?(YX$FHd^vDky1z;6v28{v$k!H{+ zAdO==s}%5PniO!>C;$lC0DT1jBH>w5z>Y8`zU#_!BJ^e9)Q?#^%bXLDna&{HkK8a0 zXGmC|7dCBSt5|MGIMf@w!@}xxh6S%v%~KdlJiEO1BLOGIF7lo}?gk=`Nl%R=37p*HnQPhJgB8Ps{#~^xwP*;L( z!+Bg-hCCbynoxA78V`!1JJq;Io1>vS)i{ZP?v<{(H3`dq^neg)B8c>eM5u|NDs^uX zZmlj#-J3*xgL8pF-5K0xMChh>?^Sj_b%W;muhK}7A!+m!Mt{z>MK<(ET_vp0M32;( z07R8NGV5Q|0a0a-tgcZbB16x|eres1{`U?ryz#l}IxRLH6JScxS2*(v)*81` zRN29xPsZKAfUSKp<4-r`fmD4G(~YFA445H(vT}iwaw6IQJ@v_|`Oe=hoen_;B!95t zPgc#cSKr+D_STv$8@JYMerw~VHwu4whb?7WupCrD;vFcjf*z-V@+wHc1LalFBpWEN zf<;ip09En3n63hb$--;DWQ{U6S)Ps*J}LD`AWEe1NtvxLaU@w!N~oO140!-wlYD;3 zfrJi2K!K!wtvn`){hG`+s4Y1aLj{>TuM`w9u1o%KDJW?kh9D@Z{(5;((*1RrT^MXZ z%r`8yVRCndR6q#57Vs%B*et7cnkP8qPZ+18p<2Bd1XwdRxor`>F8&G`l#ZnKTkepY8g zj27>?ciHnRTFR4=v|4O^*0htP)naF>OXZNXTI{;n&YLtA#1$fBMq0 zLynjo_$0*a;|ZHZo#5>J`Y+iEdHT-1o2%Gw@`Fp*S0Zvu+MGwMpu_j%zxgdz7hJlB zTecmu1z82mJd!Yw5ll`ukT&t^8oR*`^2ij2?{(eftp51`e(^}u^O_RCrc!8WSgSX6 zx}(e4j79M3^f$5pgV>~2-%`bLhwta^AJ(&#uSP7cP_bk#X)!WG*T@lQKd*hkK$N_n zzqG_&L)pRZ0C(SB%idWP5vckAk4^I&1yv20G7tqE;N{cosBQ76BMim-ZH0Hhj}P!*V>Ynse&HP6P0ds1*^&8r)?+fkhcULJvI#AS-?I7$a&b^ssayu9dOVFwIJ-=I9o()Lwqh>Vg$E`M?bdzUTC`5j^C ze$HqMPUOXtrXvg;$x%lR3)NM`?9H!eVm(&2*NRp!Xgx%KB_SE-)Qc_?PjR-Izh)jYIT>27#~HP+#$X&RPL zU7jaX_FV0Yy=UCtzrp6$ohkKW@HCCO*~lA_($BeEK}I3i3m|VXi&GR0iCkVK@E*cJIAmKLJOA zVLt&~rD2{lBIQUh%xk=h7PUAM4D;HBIsr$5VLtD9`(+g$kqX>eP`RjU%f#Xq8ZJ>w zASsOAtN~O$de#6UTfwIzkgdR{dZP!c$X4K$^K~|XYz5vp&!+hhB~^^-`2c`4qkbBx z7WI6xtQPF*GKDd8>hlvIE&3uTe`2eVuCrAPJX+BibM8GHeupoxL~$KLe`4a`vCsYPTJ~uib!1wNL1eOTv-+Mc}Y*cLK5Zi|{o2F*Pee{qA!Avz9$s(`D*`5lOmCvjDND z%QOoR^>mqL0is!5rdfb!Ru?skNGFKOAw~KX{D#yH`B@lPA2O`5O0I@AAhH}XtP?1x zn^>=2l^~^c8|pyV2Ix@-1odu1J?Y3E5jd%-C*j#6!WH(FAWBOT^;~}EI(Ch%$(gEP zMXH?P4v0-T!yOP+Dg$PYm zUwYUn_gTTK)rVbSq=8|oZvc<8qOuAPKuM9Ph3DKAEo@fZIl;?{e)QctCn~1e-_U-* z=iN_R*plpd!Q(|gx^w46%2A)>6r#xs!WtB_)Oi6zkT7^33_u*s1rhP)3LuhS5Y^tJ z2@p-VAQpOGdq6Z{P{>9T3QZUksfLI;`xGU<=;;YGhHm>sqX4WT%|)XCK%}{7 z6p+HPTv7^nF+~cvWE22|ZGfHv0Fm$#DPUg^h1A^WVGwbkF1_Kh&En(HDz5^j3 zpm&6T=6XCzt%sEASo8q7?S5|yJDR=i$DoRC3;hOkR6Vza zQ>R0c3~r0YS-Kjuy&$Z)dXY{V&{Sg~Qo)ZzCtVOugKW)a&8)vn5)@)rAw%!$%Sp-vpCK5fu?)pVh5AKRA`c020^aP>q z`rU@}h_DQKdSL;YQ1rqY@r$At)`&=%qoEhp2#LWvH=N9VfKok8}DV%2+N#jUFNm~fl1elWa<+to$?ZIpx z{^U_IRdz7wlQG9PU~8W&^QN2fK&n28=|)ml2F#E?Sv}uQ+F@;gp890XJo}%PPKO`^ zk}s${Yh_;fU`O-LZJEu@+cGU5H*egY-}(!-jAgOxS3%+(D6N97(?DqzB;bM4Drk}o zlvcsQsA7Ps_$;ccfMHDXxs?Z_nWjyd?VDS-Wxl`lXCG~BS-v$t|CcN&vsm`4AmNWm zJt>GONq{(=Ven(p4Hz$tNq1merW@6ktcsz6%$ZvZ ziWn1;FD?e9s{n%^lrFaIZR1C+ z8(OxZA?}jh>{{Zn3{ST|h8EK#lc#QdJNx;2PmL5|gcP63NV$?VAd)?m6&VAO>Zz=6 zP*O~j6u*|%zK|zHV0eEm?X>+VL(hOI$E0-s+s=NSoiwbJ9jqpe2$TU^CyfY{0jVa9 z2$TULm^32r3^?;i62V(K8)EDV@rKHmGfnTee7L=JQ>$X$lG)Vyfg9Pwmb`{#ueB6_ zl(;LTHJ}VCK)P17RvA#lu25aQy+da}#&)-358L^Adub$6Q+r6?EZRtFY7do7D@G#q zw1+U*ubI}s(CL1=gI#~IvosWmsIxQ_iKsJFR#6N^f97`XS-qFxpM`(H{OY}YckX|w C-(NKV diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 23517d4ca3..9969a45f52 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.15.3 + 3.15.6 7.2 Google Inc. diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 0a1f4a7440..5c5b2ffaf4 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -107,57 +107,58 @@ namespace Google.Protobuf.Reflection { "eV9wYWNrYWdlGC0gASgJEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMo", "CzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIjoKDE9w", "dGltaXplTW9kZRIJCgVTUEVFRBABEg0KCUNPREVfU0laRRACEhAKDExJVEVf", - "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECci8gEKDk1lc3NhZ2VPcHRpb25z", + "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECcihAIKDk1lc3NhZ2VPcHRpb25z", "EiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9ybWF0GAEgASgIOgVmYWxzZRIuCh9u", "b19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZRIZ", "CgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRIRCgltYXBfZW50cnkYByABKAgS", "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", - "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAgQCUoECAkQ", - "CiKeAwoMRmllbGRPcHRpb25zEjoKBWN0eXBlGAEgASgOMiMuZ29vZ2xlLnBy", - "b3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToGU1RSSU5HEg4KBnBhY2tlZBgC", - "IAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29nbGUucHJvdG9idWYuRmllbGRP", - "cHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMKBGxhenkYBSABKAg6BWZhbHNl", - "EhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEhMKBHdlYWsYCiABKAg6BWZh", - "bHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5w", - "cm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIi8KBUNUeXBlEgoKBlNUUklO", - "RxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElFQ0UQAiI1CgZKU1R5cGUSDQoJ", - "SlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAESDQoJSlNfTlVNQkVSEAIqCQjo", - "BxCAgICAAkoECAQQBSJeCgxPbmVvZk9wdGlvbnMSQwoUdW5pbnRlcnByZXRl", - "ZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0", - "ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoLRW51bU9wdGlvbnMSEwoLYWxsb3df", - "YWxpYXMYAiABKAgSGQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USQwoUdW5p", - "bnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVu", - "aW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAUQBiJ9ChBFbnVtVmFs", - "dWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQYASABKAg6BWZhbHNlEkMKFHVuaW50", - "ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu", - "dGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIiewoOU2VydmljZU9wdGlvbnMS", - "GQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9v", - "cHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRP", - "cHRpb24qCQjoBxCAgICAAiKtAgoNTWV0aG9kT3B0aW9ucxIZCgpkZXByZWNh", - "dGVkGCEgASgIOgVmYWxzZRJfChFpZGVtcG90ZW5jeV9sZXZlbBgiIAEoDjIv", - "Lmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRpb25zLklkZW1wb3RlbmN5TGV2", - "ZWw6E0lERU1QT1RFTkNZX1VOS05PV04SQwoUdW5pbnRlcnByZXRlZF9vcHRp", - "b24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRp", - "b24iUAoQSWRlbXBvdGVuY3lMZXZlbBIXChNJREVNUE9URU5DWV9VTktOT1dO", - "EAASEwoPTk9fU0lERV9FRkZFQ1RTEAESDgoKSURFTVBPVEVOVBACKgkI6AcQ", - "gICAgAIingIKE1VuaW50ZXJwcmV0ZWRPcHRpb24SOwoEbmFtZRgCIAMoCzIt", - "Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uLk5hbWVQYXJ0", - "EhgKEGlkZW50aWZpZXJfdmFsdWUYAyABKAkSGgoScG9zaXRpdmVfaW50X3Zh", - "bHVlGAQgASgEEhoKEm5lZ2F0aXZlX2ludF92YWx1ZRgFIAEoAxIUCgxkb3Vi", - "bGVfdmFsdWUYBiABKAESFAoMc3RyaW5nX3ZhbHVlGAcgASgMEhcKD2FnZ3Jl", - "Z2F0ZV92YWx1ZRgIIAEoCRozCghOYW1lUGFydBIRCgluYW1lX3BhcnQYASAC", - "KAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigIItUBCg5Tb3VyY2VDb2RlSW5mbxI6", - "Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2Rl", - "SW5mby5Mb2NhdGlvbhqGAQoITG9jYXRpb24SEAoEcGF0aBgBIAMoBUICEAES", - "EAoEc3BhbhgCIAMoBUICEAESGAoQbGVhZGluZ19jb21tZW50cxgDIAEoCRIZ", - "ChF0cmFpbGluZ19jb21tZW50cxgEIAEoCRIhChlsZWFkaW5nX2RldGFjaGVk", - "X2NvbW1lbnRzGAYgAygJIqcBChFHZW5lcmF0ZWRDb2RlSW5mbxJBCgphbm5v", - "dGF0aW9uGAEgAygLMi0uZ29vZ2xlLnByb3RvYnVmLkdlbmVyYXRlZENvZGVJ", - "bmZvLkFubm90YXRpb24aTwoKQW5ub3RhdGlvbhIQCgRwYXRoGAEgAygFQgIQ", - "ARITCgtzb3VyY2VfZmlsZRgCIAEoCRINCgViZWdpbhgDIAEoBRILCgNlbmQY", - "BCABKAVCfgoTY29tLmdvb2dsZS5wcm90b2J1ZkIQRGVzY3JpcHRvclByb3Rv", - "c0gBWi1nb29nbGUuZ29sYW5nLm9yZy9wcm90b2J1Zi90eXBlcy9kZXNjcmlw", - "dG9ycGL4AQGiAgNHUEKqAhpHb29nbGUuUHJvdG9idWYuUmVmbGVjdGlvbg==")); + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAQQBUoECAUQ", + "BkoECAYQB0oECAgQCUoECAkQCiKeAwoMRmllbGRPcHRpb25zEjoKBWN0eXBl", + "GAEgASgOMiMuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToG", + "U1RSSU5HEg4KBnBhY2tlZBgCIAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29n", + "bGUucHJvdG9idWYuRmllbGRPcHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMK", + "BGxhenkYBSABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNl", + "EhMKBHdlYWsYCiABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9u", + "GOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9u", + "Ii8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElF", + "Q0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAES", + "DQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJeCgxPbmVvZk9wdGlv", + "bnMSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnBy", + "b3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoLRW51", + "bU9wdGlvbnMSEwoLYWxsb3dfYWxpYXMYAiABKAgSGQoKZGVwcmVjYXRlZBgD", + "IAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQu", + "Z29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICA", + "AkoECAUQBiJ9ChBFbnVtVmFsdWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQYASAB", + "KAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdv", + "b2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIi", + "ewoOU2VydmljZU9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2US", + "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKtAgoNTWV0aG9k", + "T3B0aW9ucxIZCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZRJfChFpZGVtcG90", + "ZW5jeV9sZXZlbBgiIAEoDjIvLmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRp", + "b25zLklkZW1wb3RlbmN5TGV2ZWw6E0lERU1QT1RFTkNZX1VOS05PV04SQwoU", + "dW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVm", + "LlVuaW50ZXJwcmV0ZWRPcHRpb24iUAoQSWRlbXBvdGVuY3lMZXZlbBIXChNJ", + "REVNUE9URU5DWV9VTktOT1dOEAASEwoPTk9fU0lERV9FRkZFQ1RTEAESDgoK", + "SURFTVBPVEVOVBACKgkI6AcQgICAgAIingIKE1VuaW50ZXJwcmV0ZWRPcHRp", + "b24SOwoEbmFtZRgCIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJl", + "dGVkT3B0aW9uLk5hbWVQYXJ0EhgKEGlkZW50aWZpZXJfdmFsdWUYAyABKAkS", + "GgoScG9zaXRpdmVfaW50X3ZhbHVlGAQgASgEEhoKEm5lZ2F0aXZlX2ludF92", + "YWx1ZRgFIAEoAxIUCgxkb3VibGVfdmFsdWUYBiABKAESFAoMc3RyaW5nX3Zh", + "bHVlGAcgASgMEhcKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCRozCghOYW1lUGFy", + "dBIRCgluYW1lX3BhcnQYASACKAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigIItUB", + "Cg5Tb3VyY2VDb2RlSW5mbxI6Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5w", + "cm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvbhqGAQoITG9jYXRpb24S", + "EAoEcGF0aBgBIAMoBUICEAESEAoEc3BhbhgCIAMoBUICEAESGAoQbGVhZGlu", + "Z19jb21tZW50cxgDIAEoCRIZChF0cmFpbGluZ19jb21tZW50cxgEIAEoCRIh", + "ChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJIqcBChFHZW5lcmF0", + "ZWRDb2RlSW5mbxJBCgphbm5vdGF0aW9uGAEgAygLMi0uZ29vZ2xlLnByb3Rv", + "YnVmLkdlbmVyYXRlZENvZGVJbmZvLkFubm90YXRpb24aTwoKQW5ub3RhdGlv", + "bhIQCgRwYXRoGAEgAygFQgIQARITCgtzb3VyY2VfZmlsZRgCIAEoCRINCgVi", + "ZWdpbhgDIAEoBRILCgNlbmQYBCABKAVCfgoTY29tLmdvb2dsZS5wcm90b2J1", + "ZkIQRGVzY3JpcHRvclByb3Rvc0gBWi1nb29nbGUuZ29sYW5nLm9yZy9wcm90", + "b2J1Zi90eXBlcy9kZXNjcmlwdG9ycGL4AQGiAgNHUEKqAhpHb29nbGUuUHJv", + "dG9idWYuUmVmbGVjdGlvbg==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { diff --git a/docs/implementing_proto3_presence.md b/docs/implementing_proto3_presence.md index 73f21a3829..ae8b369579 100644 --- a/docs/implementing_proto3_presence.md +++ b/docs/implementing_proto3_presence.md @@ -261,7 +261,7 @@ bool FieldHasPresence(const google::protobuf::FieldDescriptor* field) { Old: ```c++ -bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { +bool FieldIsInOneof(const google::protobuf::FieldDescriptor* field) { return field->containing_oneof() != nullptr; } ``` @@ -269,7 +269,7 @@ bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { New: ```c++ -bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { +bool FieldIsInOneof(const google::protobuf::FieldDescriptor* field) { // real_containing_oneof() returns nullptr for synthetic oneofs. return field->real_containing_oneof() != nullptr; } diff --git a/docs/options.md b/docs/options.md index 907fe5aa02..79a085e0be 100644 --- a/docs/options.md +++ b/docs/options.md @@ -268,3 +268,11 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-sanitize * Website: https://github.com/Intrinsec/protoc-gen-sanitize * Extension: 1102-1106 + +1. Coach Client Connect (planned release in March 2021) + * Website: https://www.coachclientconnect.com + * Extension: 1107 + +1. Kratos API Errors + * Website: https://go-kratos.dev + * Extension: 1108 diff --git a/docs/third_party.md b/docs/third_party.md index 7799e308a7..9d490c0a6e 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -11,6 +11,7 @@ These are projects we know about implementing Protocol Buffers for other program * Action Script: https://code.google.com/p/protoc-gen-as3/ * Action Script: https://github.com/matrix3d/JProtoc * Action Script: https://github.com/zhongfq/protobuf-as3/ +* Ada: https://github.com/reznikmm/protobuf * C: https://github.com/protobuf-c/protobuf-c * C: http://koti.kapsi.fi/jpa/nanopb/ * C: https://github.com/cloudwu/pbc/ @@ -101,7 +102,6 @@ These are projects we know about implementing Protocol Buffers for other program * Solidity: https://github.com/celer-network/pb3-gen-sol * Swift: https://github.com/alexeyxo/protobuf-swift * Swift: https://github.com/apple/swift-protobuf/ -* Typescript: https://github.com/y3llowcake/protoc-gen-ts * Vala: https://launchpad.net/protobuf-vala * Visual Basic: http://code.google.com/p/protobuf-net/ diff --git a/java/README.md b/java/README.md index c8050893e0..c3434144b1 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.11.0 + 3.15.3 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.11.0 + 3.15.3 ``` diff --git a/java/bom/pom.xml b/java/bom/pom.xml index cec091173e..af2d7025ab 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.15.3 + 3.15.6 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 4fc530b9db..4df7d434df 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 protobuf-java diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 17b7c98c99..74c9a71b6c 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -1043,8 +1043,10 @@ public abstract class ByteString implements Iterable, Serializable { } /** - * Creates a byte string. Its size is the current size of this output stream and its output has - * been copied to it. + * Creates a byte string with the size and contents of this output stream. This does not create + * a new copy of the underlying bytes. If the stream size grows dynamically, the runtime is + * O(log n) in respect to the number of bytes written to the {@link Output}. If the stream size + * stays within the initial capacity, the runtime is O(1). * * @return the current contents of this output stream, as a byte string. */ diff --git a/java/core/src/main/java/com/google/protobuf/RopeByteString.java b/java/core/src/main/java/com/google/protobuf/RopeByteString.java index cc6e0445b0..f584164410 100644 --- a/java/core/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/core/src/main/java/com/google/protobuf/RopeByteString.java @@ -603,7 +603,12 @@ final class RopeByteString extends ByteString { @Override public CodedInputStream newCodedInput() { - return CodedInputStream.newInstance(new RopeInputStream()); + // Passing along direct references to internal ByteBuffers can support more efficient parsing + // via aliasing in CodedInputStream for users who wish to use it. + // + // Otherwise we force data copies, both in copying as an input stream and in buffering in the + // CodedInputSteam. + return CodedInputStream.newInstance(asReadOnlyByteBufferList(), /* bufferIsImmutable= */ true); } @Override diff --git a/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java index cc979ac513..4bc8d10130 100644 --- a/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java @@ -283,7 +283,7 @@ public class AbstractMessageTest extends TestCase { Message.Builder abstractMessageBuilder = new AbstractMessageWrapper.Builder(TestRequiredForeign.newBuilder()); // mergeFrom() should not throw initialization error. - abstractMessageBuilder.mergeFrom(bytes).buildPartial(); + Message unused1 = abstractMessageBuilder.mergeFrom(bytes).buildPartial(); try { abstractMessageBuilder.mergeFrom(bytes).build(); fail(); @@ -295,7 +295,7 @@ public class AbstractMessageTest extends TestCase { Message.Builder dynamicMessageBuilder = DynamicMessage.newBuilder(TestRequiredForeign.getDescriptor()); // mergeFrom() should not throw initialization error. - dynamicMessageBuilder.mergeFrom(bytes).buildPartial(); + Message unused2 = dynamicMessageBuilder.mergeFrom(bytes).buildPartial(); try { dynamicMessageBuilder.mergeFrom(bytes).build(); fail(); diff --git a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java index fe37ea8087..cd40ffaeeb 100644 --- a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java @@ -69,7 +69,7 @@ public class DynamicMessageTest extends TestCase { Message.Builder builder = DynamicMessage.newBuilder(TestAllTypes.getDescriptor()); Message firstMessage = builder.build(); // double build() - builder.build(); + Message unused = builder.build(); // clear() after build() builder.clear(); // setters after build() diff --git a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 9261a36122..840e13e877 100644 --- a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java @@ -76,6 +76,7 @@ import junit.framework.TestCase; * * @author kenton@google.com Kenton Varda */ +@SuppressWarnings({"ProtoBuilderReturnValueIgnored", "ReturnValueIgnored"}) public class GeneratedMessageTest extends TestCase { TestUtil.ReflectionTester reflectionTester = new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null); diff --git a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index d2565ca157..25c5625f40 100644 --- a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java @@ -1163,8 +1163,8 @@ public class MapForProto2Test extends TestCase { } public void testReservedWordsFieldNames() { - ReservedAsMapField.newBuilder().build(); - ReservedAsMapFieldWithEnumValue.newBuilder().build(); + ReservedAsMapField unused1 = ReservedAsMapField.newBuilder().build(); + ReservedAsMapFieldWithEnumValue unused2 = ReservedAsMapFieldWithEnumValue.newBuilder().build(); } public void testGetMap() { diff --git a/java/core/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java index 2f55328b51..c3b1fa3804 100644 --- a/java/core/src/test/java/com/google/protobuf/MapTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapTest.java @@ -1294,8 +1294,8 @@ public class MapTest extends TestCase { } public void testReservedWordsFieldNames() { - ReservedAsMapField.newBuilder().build(); - ReservedAsMapFieldWithEnumValue.newBuilder().build(); + ReservedAsMapField unused1 = ReservedAsMapField.newBuilder().build(); + ReservedAsMapFieldWithEnumValue unused2 = ReservedAsMapFieldWithEnumValue.newBuilder().build(); } public void testDeterministicSerialziation() throws Exception { diff --git a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java index 3d82c5f9af..08a23bab94 100644 --- a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java @@ -43,8 +43,10 @@ public class TestBadIdentifiers extends TestCase { public void testCompilation() { // If this compiles, it means the generation was correct. - TestBadIdentifiersProto.Deprecated.newBuilder(); - TestBadIdentifiersProto.Override.newBuilder(); + TestBadIdentifiersProto.Deprecated unused1 = + TestBadIdentifiersProto.Deprecated.newBuilder().build(); + TestBadIdentifiersProto.Override unused2 = + TestBadIdentifiersProto.Override.getDefaultInstance(); } public void testGetDescriptor() { diff --git a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java index 798d7ca612..523e23aa76 100644 --- a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java @@ -45,8 +45,10 @@ public final class TestBadIdentifiersLite extends TestCase { public void testCompilation() { // If this compiles, it means the generation was correct. - TestBadIdentifiersProto.Deprecated.newBuilder(); - TestBadIdentifiersProto.Override.newBuilder(); + TestBadIdentifiersProto.Deprecated.Builder builder1 = + TestBadIdentifiersProto.Deprecated.newBuilder(); + TestBadIdentifiersProto.Override.Builder builder2 = + TestBadIdentifiersProto.Override.newBuilder(); } public void testConflictingFieldNames() throws Exception { diff --git a/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto b/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto deleted file mode 100644 index d41b7a11cc..0000000000 --- a/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto +++ /dev/null @@ -1,56 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: Darick Tong (darick@google.com) -syntax = "proto2"; - -package protobuf_unittest; - -message Proto1 { - option experimental_java_message_interface = - "com.google.protobuf.ExtraInterfaces.HasBoolValue"; - option experimental_java_message_interface = - "com.google.protobuf.ExtraInterfaces.HasStringValue"; - option experimental_java_builder_interface = - "com.google.protobuf.ExtraInterfaces.HasStringValueBuilder" - ""; - - optional string string_value = 1; - optional bool bool_value = 2; - optional bytes byte_value = 3; - optional int32 int_value = 4; -} - -message Proto2 { - option experimental_java_message_interface = - "com.google.protobuf.ExtraInterfaces.HasBoolValue"; - - optional bool bool_value = 1; -} diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 62bca93c86..65e62ce4fb 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -4,6 +4,7 @@ + diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 478ba0e15c..021eac0ac4 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 protobuf-javalite diff --git a/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/java/lite/src/test/java/com/google/protobuf/LiteTest.java index 06d244a643..f2ce4614c7 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -2406,24 +2406,26 @@ public class LiteTest extends TestCase { } public void testAddAllIteratesOnce() { - TestAllTypesLite.newBuilder() - .addAllRepeatedBool(new OneTimeIterableList<>(false)) - .addAllRepeatedInt32(new OneTimeIterableList<>(0)) - .addAllRepeatedInt64(new OneTimeIterableList<>(0L)) - .addAllRepeatedFloat(new OneTimeIterableList<>(0f)) - .addAllRepeatedDouble(new OneTimeIterableList<>(0d)) - .addAllRepeatedBytes(new OneTimeIterableList<>(ByteString.EMPTY)) - .addAllRepeatedString(new OneTimeIterableList<>("")) - .addAllRepeatedNestedMessage(new OneTimeIterableList<>(NestedMessage.getDefaultInstance())) - .addAllRepeatedBool(new OneTimeIterable<>(false)) - .addAllRepeatedInt32(new OneTimeIterable<>(0)) - .addAllRepeatedInt64(new OneTimeIterable<>(0L)) - .addAllRepeatedFloat(new OneTimeIterable<>(0f)) - .addAllRepeatedDouble(new OneTimeIterable<>(0d)) - .addAllRepeatedBytes(new OneTimeIterable<>(ByteString.EMPTY)) - .addAllRepeatedString(new OneTimeIterable<>("")) - .addAllRepeatedNestedMessage(new OneTimeIterable<>(NestedMessage.getDefaultInstance())) - .build(); + TestAllTypesLite unused = + TestAllTypesLite.newBuilder() + .addAllRepeatedBool(new OneTimeIterableList<>(false)) + .addAllRepeatedInt32(new OneTimeIterableList<>(0)) + .addAllRepeatedInt64(new OneTimeIterableList<>(0L)) + .addAllRepeatedFloat(new OneTimeIterableList<>(0f)) + .addAllRepeatedDouble(new OneTimeIterableList<>(0d)) + .addAllRepeatedBytes(new OneTimeIterableList<>(ByteString.EMPTY)) + .addAllRepeatedString(new OneTimeIterableList<>("")) + .addAllRepeatedNestedMessage( + new OneTimeIterableList<>(NestedMessage.getDefaultInstance())) + .addAllRepeatedBool(new OneTimeIterable<>(false)) + .addAllRepeatedInt32(new OneTimeIterable<>(0)) + .addAllRepeatedInt64(new OneTimeIterable<>(0L)) + .addAllRepeatedFloat(new OneTimeIterable<>(0f)) + .addAllRepeatedDouble(new OneTimeIterable<>(0d)) + .addAllRepeatedBytes(new OneTimeIterable<>(ByteString.EMPTY)) + .addAllRepeatedString(new OneTimeIterable<>("")) + .addAllRepeatedNestedMessage(new OneTimeIterable<>(NestedMessage.getDefaultInstance())) + .build(); } public void testAddAllIteratesOnce_throwsOnNull() { diff --git a/java/pom.xml b/java/pom.xml index dc3e89f884..649ec0ce11 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 pom Protocol Buffers [Parent] @@ -75,7 +75,7 @@ junit junit - 4.13.1 + 4.13.2 test @@ -104,7 +104,7 @@ com.google.truth truth - 1.0.1 + 1.1.2 test diff --git a/java/util/pom.xml b/java/util/pom.xml index 9028b1b2f0..37d7c0fb85 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 protobuf-java-util diff --git a/kokoro/release/protoc/linux/build.sh b/kokoro/release/protoc/linux/build.sh index efc3ee62ca..44a95aab35 100755 --- a/kokoro/release/protoc/linux/build.sh +++ b/kokoro/release/protoc/linux/build.sh @@ -23,7 +23,7 @@ sudo apt install -y g++-powerpc64le-linux-gnu protoc-artifacts/build-protoc.sh linux ppcle_64 protoc sudo apt install -y g++-s390x-linux-gnu -protoc-artifacts/build-protoc.sh linux s390x protoc +protoc-artifacts/build-protoc.sh linux s390_64 protoc # Use docker image to build linux artifacts. DOCKER_IMAGE_NAME=protobuf/protoc_$(sha1sum protoc-artifacts/Dockerfile | cut -f1 -d " ") diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 7f27670320..0f1f4c964e 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -334,7 +334,7 @@ static zval *Message_read_property(PROTO_VAL *obj, PROTO_STR *member, Message* intern = PROTO_VAL_P(obj); const upb_fielddef *f = get_field(intern, member); - if (!f) return NULL; + if (!f) return &EG(uninitialized_zval); Message_get(intern, f, rv); return rv; } diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 75a440cd55..48e403bf72 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2021-02-24 - + 2021-03-10 + - 3.15.3 - 3.15.3 + 3.15.6 + 3.15.6 stable @@ -22,15 +22,7 @@ 3-Clause BSD License - New changes in 3.15.0: - * unregister INI entries and fix invalid read on shutdown (#8042) - * Fix PhpDoc comments for message accessors to include "|null". (#8136) - * fix: convert native PHP floats to single precision (#8187) - * Fixed PHP to support field numbers >=2**28. (#8235) - * feat: add support for deprecated fields to PHP compiler (#8223) - * Protect against stack overflow if the user derives from Message. (#8248) - * Fixed clone for Message, RepeatedField, and MapField. (#8245) - * Updated upb to allow nonzero offset minutes in JSON timestamps. (#8258) + No new changes in 3.15.6 @@ -850,5 +842,50 @@ G A release. + + + 3.15.4 + 3.15.4 + + + stable + stable + + 2021-03-02 + + 3-Clause BSD License + + + + + + 3.15.5 + 3.15.5 + + + stable + stable + + 2021-03-04 + + 3-Clause BSD License + + + + + + 3.15.6 + 3.15.6 + + + stable + stable + + 2021-03-10 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index c56a567ca3..913dfad7e9 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7047,10 +7047,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { } bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { - if (!_upb_array_realloc(arr, arr->len + 1, arena)) { + if (!upb_array_resize(arr, arr->len + 1, arena)) { return false; } - arr->len++; upb_array_set(arr, arr->len - 1, val); return true; } diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index a03261c295..1a2069bfbb 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -76,7 +76,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.15.3" +#define PHP_PROTOBUF_VERSION "3.15.6" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protoc-artifacts/README.md b/protoc-artifacts/README.md index 2c45fefe78..1706ddc0d8 100644 --- a/protoc-artifacts/README.md +++ b/protoc-artifacts/README.md @@ -123,7 +123,7 @@ target directory layout: protoc.exe + ppcle_64 protoc.exe - + s390x + + s390_64 protoc.exe + osx + x86_64 diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh index 7f65d37643..4602842622 100755 --- a/protoc-artifacts/build-protoc.sh +++ b/protoc-artifacts/build-protoc.sh @@ -93,7 +93,7 @@ checkArch () assertEq $format "elf64-x86-64" $LINENO elif [[ "$ARCH" == aarch_64 ]]; then assertEq $format "elf64-little" $LINENO - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine == s390x ]];then assertEq $format "elf64-s390" $LINENO else @@ -149,7 +149,7 @@ checkDependencies () white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2" elif [[ "$ARCH" == x86_64 ]]; then white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2" - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine != s390x ]];then dump_cmd='objdump -p '"$1"' | grep NEEDED' fi @@ -226,7 +226,7 @@ elif [[ "$(uname)" == Linux* ]]; then elif [[ "$ARCH" == ppcle_64 ]]; then CXXFLAGS="$CXXFLAGS -m64" CONFIGURE_ARGS="$CONFIGURE_ARGS --host=powerpc64le-linux-gnu" - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then CXXFLAGS="$CXXFLAGS -m64" CONFIGURE_ARGS="$CONFIGURE_ARGS --host=s390x-linux-gnu" else diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index 2a25d3cd7e..7d1923e6e6 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -21,7 +21,7 @@ included. Each invocation will create 8 zip packages: dist/--linux-x86_64.zip dist/--linux-aarch_64.zip dist/--linux-ppcle_64.zip - dist/--linux-s390x.zip + dist/--linux-s390_64.zip EOF exit 1 fi @@ -38,7 +38,7 @@ declare -a FILE_NAMES=( \ linux-x86_64.zip linux-x86_64.exe \ linux-aarch_64.zip linux-aarch_64.exe \ linux-ppcle_64.zip linux-ppcle_64.exe \ - linux-s390x.zip linux-s390x.exe \ + linux-s390_64.zip linux-s390_64.exe \ ) # List of all well-known types to be included. diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 591ab09284..9cb0b63e5a 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.15.3 + 3.15.6 pom Protobuf Compiler @@ -81,8 +81,8 @@ exe - ${basedir}/target/linux/s390x/protoc.exe - linux-s390x + ${basedir}/target/linux/s390_64/protoc.exe + linux-s390_64 exe diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 987116a106..6f75251dbe 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -1176,6 +1176,54 @@ class OnlyWorksWithProto2RightNowTests(TextFormatBase): ' }\n' '}\n') + def testDuplicateMapKey(self): + message = map_unittest_pb2.TestMap() + text = ( + 'map_uint64_uint64 {\n' + ' key: 123\n' + ' value: 17179869184\n' + '}\n' + 'map_string_string {\n' + ' key: "abc"\n' + ' value: "first"\n' + '}\n' + 'map_int32_foreign_message {\n' + ' key: 111\n' + ' value {\n' + ' c: 5\n' + ' }\n' + '}\n' + 'map_uint64_uint64 {\n' + ' key: 123\n' + ' value: 321\n' + '}\n' + 'map_string_string {\n' + ' key: "abc"\n' + ' value: "second"\n' + '}\n' + 'map_int32_foreign_message {\n' + ' key: 111\n' + ' value {\n' + ' d: 5\n' + ' }\n' + '}\n') + text_format.Parse(text, message) + self.CompareToGoldenText( + text_format.MessageToString(message), 'map_uint64_uint64 {\n' + ' key: 123\n' + ' value: 321\n' + '}\n' + 'map_string_string {\n' + ' key: "abc"\n' + ' value: "second"\n' + '}\n' + 'map_int32_foreign_message {\n' + ' key: 111\n' + ' value {\n' + ' d: 5\n' + ' }\n' + '}\n') + # In cpp implementation, __str__ calls the cpp implementation of text format. def testPrintMapUsingCppImplementation(self): message = map_unittest_pb2.TestMap() @@ -2348,6 +2396,13 @@ class OptionalColonMessageToStringTest(unittest.TestCase): '}\n') self.assertEqual(expected, output) + def testPrintShortFormatRepeatedFields(self): + message = unittest_pb2.TestAllTypes() + message.repeated_int32.append(1) + output = text_format.MessageToString( + message, use_short_repeated_primitives=True, force_colon=True) + self.assertEqual('repeated_int32: [1]\n', output) + if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 75f1760ccf..42d99e8fc8 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -30,15 +30,18 @@ // Author: petar@google.com (Petar Petrov) +#include + #include #include + +#include #include #include #include #include #include -#include #include #include #include @@ -195,7 +198,7 @@ bool Reparse( std::string serialized; from.SerializeToString(&serialized); io::CodedInputStream input( - reinterpret_cast(serialized.c_str()), serialized.size()); + reinterpret_cast(serialized.c_str()), serialized.size()); input.SetExtensionRegistry(message_factory->pool->pool, message_factory->message_factory); bool success = to->ParseFromCodedStream(&input); @@ -804,22 +807,22 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) { switch (_GetDescriptor(self)->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { - int32 value = _GetDescriptor(self)->default_value_int32(); + int32_t value = _GetDescriptor(self)->default_value_int32(); result = PyInt_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { - int64 value = _GetDescriptor(self)->default_value_int64(); + int64_t value = _GetDescriptor(self)->default_value_int64(); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT32: { - uint32 value = _GetDescriptor(self)->default_value_uint32(); + uint32_t value = _GetDescriptor(self)->default_value_uint32(); result = PyInt_FromSize_t(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { - uint64 value = _GetDescriptor(self)->default_value_uint64(); + uint64_t value = _GetDescriptor(self)->default_value_uint64(); result = PyLong_FromUnsignedLongLong(value); break; } diff --git a/python/google/protobuf/pyext/descriptor_database.cc b/python/google/protobuf/pyext/descriptor_database.cc index 26f1b5fb42..da1c84a465 100644 --- a/python/google/protobuf/pyext/descriptor_database.cc +++ b/python/google/protobuf/pyext/descriptor_database.cc @@ -33,6 +33,8 @@ #include +#include + #include #include #include @@ -164,7 +166,7 @@ bool PyDescriptorDatabase::FindAllExtensionNumbers( return false; } Py_ssize_t size = PyList_Size(py_list.get()); - int64 item_value; + int64_t item_value; for (Py_ssize_t i = 0 ; i < size; ++i) { ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i)); item_value = PyLong_AsLong(item.get()); diff --git a/python/google/protobuf/pyext/extension_dict.cc b/python/google/protobuf/pyext/extension_dict.cc index e9ac71409e..37b414c375 100644 --- a/python/google/protobuf/pyext/extension_dict.cc +++ b/python/google/protobuf/pyext/extension_dict.cc @@ -32,14 +32,16 @@ // Author: tibell@google.com (Johan Tibell) #include + +#include #include #include #include +#include #include #include #include -#include #include #include #include @@ -263,7 +265,7 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) { } PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) { - int64 number = PyLong_AsLong(arg); + int64_t number = PyLong_AsLong(arg); if (number == -1 && PyErr_Occurred()) { return NULL; } diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index a0ee16fe86..2573327e3b 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -32,15 +32,16 @@ #include +#include #include #include #include -#include #include +#include #include -#include #include +#include #include #include #include @@ -99,7 +100,7 @@ struct MapIterator { // // We store this so that if the map is modified during iteration we can throw // an error. - uint64 version; + uint64_t version; }; Message* MapContainer::GetMutableMessage() { diff --git a/python/google/protobuf/pyext/map_container.h b/python/google/protobuf/pyext/map_container.h index a28945da07..842602e79f 100644 --- a/python/google/protobuf/pyext/map_container.h +++ b/python/google/protobuf/pyext/map_container.h @@ -33,6 +33,7 @@ #include +#include #include #include @@ -56,7 +57,7 @@ struct MapContainer : public ContainerBase { // We bump this whenever we perform a mutation, to invalidate existing // iterators. - uint64 version; + uint64_t version; }; struct MessageMapContainer : public MapContainer { diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 4e74386e2d..33034bf3f4 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -35,6 +35,7 @@ #include // A Python header file. +#include #include #include #include @@ -2191,22 +2192,22 @@ PyObject* InternalGetScalar(const Message* message, PyObject* result = NULL; switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { - int32 value = reflection->GetInt32(*message, field_descriptor); + int32_t value = reflection->GetInt32(*message, field_descriptor); result = PyInt_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { - int64 value = reflection->GetInt64(*message, field_descriptor); + int64_t value = reflection->GetInt64(*message, field_descriptor); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT32: { - uint32 value = reflection->GetUInt32(*message, field_descriptor); + uint32_t value = reflection->GetUInt32(*message, field_descriptor); result = PyInt_FromSize_t(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { - uint64 value = reflection->GetUInt64(*message, field_descriptor); + uint64_t value = reflection->GetUInt64(*message, field_descriptor); result = PyLong_FromUnsignedLongLong(value); break; } diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index a1e8326512..6a175dd667 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -36,6 +36,7 @@ #include +#include #include #include #include @@ -286,25 +287,25 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg); ((field_descriptor)->label() == FieldDescriptor::LABEL_REPEATED) #define GOOGLE_CHECK_GET_INT32(arg, value, err) \ - int32 value; \ + int32_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } #define GOOGLE_CHECK_GET_INT64(arg, value, err) \ - int64 value; \ + int64_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } #define GOOGLE_CHECK_GET_UINT32(arg, value, err) \ - uint32 value; \ + uint32_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } #define GOOGLE_CHECK_GET_UINT64(arg, value, err) \ - uint64 value; \ + uint64_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } diff --git a/python/google/protobuf/pyext/repeated_scalar_container.cc b/python/google/protobuf/pyext/repeated_scalar_container.cc index 5a5c4db16e..d76114bbae 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.cc +++ b/python/google/protobuf/pyext/repeated_scalar_container.cc @@ -33,6 +33,7 @@ #include +#include #include #include @@ -207,25 +208,25 @@ static PyObject* Item(PyObject* pself, Py_ssize_t index) { PyObject* result = nullptr; switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { - int32 value = + int32_t value = reflection->GetRepeatedInt32(*message, field_descriptor, index); result = PyInt_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { - int64 value = + int64_t value = reflection->GetRepeatedInt64(*message, field_descriptor, index); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT32: { - uint32 value = + uint32_t value = reflection->GetRepeatedUInt32(*message, field_descriptor, index); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { - uint64 value = + uint64_t value = reflection->GetRepeatedUInt64(*message, field_descriptor, index); result = PyLong_FromUnsignedLongLong(value); break; diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index c376c7bac7..9c4ca90ee6 100644 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -567,8 +567,6 @@ class _Printer(object): self.out.write(', ') self.PrintFieldValue(field, value[-1]) self.out.write(']') - if self.force_colon: - self.out.write(':') self.out.write(' ' if self.as_one_line else '\n') def _PrintMessageFieldValue(self, value): @@ -1060,7 +1058,7 @@ class _Parser(object): value_cpptype = field.message_type.fields_by_name['value'].cpp_type if value_cpptype == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: value = getattr(message, field.name)[sub_message.key] - value.MergeFrom(sub_message.value) + value.CopyFrom(sub_message.value) else: getattr(message, field.name)[sub_message.key] = sub_message.value diff --git a/python/tox.ini b/python/tox.ini index 9fabb6ddbb..f9eee920fd 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -14,10 +14,9 @@ setenv = commands = python setup.py -q build_py python: python setup.py -q build - # --warnings_as_errors disabled until we update the Python C extension. See: - # https://github.com/protocolbuffers/protobuf/issues/7930 - # cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension - cpp: python setup.py -q build --cpp_implementation --compile_static_extension + # --warnings_as_errors disabled for Python 2.7 because _POSIX_C_SOURCE and _XOPEN_SOURCE are redefined + py27-cpp: python setup.py -q build --cpp_implementation --compile_static_extension + py{33,34,35,36,37,38,39}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension python: python setup.py -q test -q cpp: python setup.py -q test -q --cpp_implementation python: python setup.py -q test_conformance diff --git a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb index b4a158f37c..4f70f52dc4 100755 --- a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb @@ -326,18 +326,6 @@ class RepeatedFieldTest < Test::Unit::TestCase end end - def test_compact! - m = TestMessage.new - m.repeated_msg << TestMessage2.new(:foo => 1) - m.repeated_msg << nil - m.repeated_msg << TestMessage2.new(:foo => 2) - reference_arr = m.repeated_string.to_a - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.compact! - end - end - def test_delete m = TestMessage.new reference_arr = %w(foo bar baz) diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index bc3e35a5ed..2fddc09629 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -315,7 +315,7 @@ bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) { return memcmp(&val1, &val2, 8) == 0; case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - return val1.str_val.size != val2.str_val.size || + return val1.str_val.size == val2.str_val.size && memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) == 0; case UPB_TYPE_MESSAGE: diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 67f22212c6..b01741b61c 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1250,7 +1250,9 @@ upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m, const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m, const char* name, upb_arena* arena) { - if (value == Qnil) return NULL; + if (value == Qnil) { + rb_raise(cTypeError, "nil message not allowed here."); + } VALUE klass = CLASS_OF(value); VALUE desc_rb = rb_ivar_get(klass, descriptor_instancevar_interned); diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index c27f30aa2d..c9eecee11e 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -37,7 +37,7 @@ #include "message.h" #include "repeated_field.h" -VALUE cError; +VALUE cParseError; VALUE cTypeError; const upb_fielddef* map_field_key(const upb_fielddef* field) { @@ -368,8 +368,10 @@ void Init_protobuf_c() { Map_register(protobuf); Message_register(protobuf); - cError = rb_const_get(protobuf, rb_intern("Error")); + cParseError = rb_const_get(protobuf, rb_intern("ParseError")); + rb_gc_register_mark_object(cParseError); cTypeError = rb_const_get(protobuf, rb_intern("TypeError")); + rb_gc_register_mark_object(cTypeError); rb_define_singleton_method(protobuf, "discard_unknown", Google_Protobuf_discard_unknown, 1); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index a7aeda2df2..61762fcd99 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6663,10 +6663,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { } bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { - if (!_upb_array_realloc(arr, arr->len + 1, arena)) { + if (!upb_array_resize(arr, arr->len + 1, arena)) { return false; } - arr->len++; upb_array_set(arr, arr->len - 1, val); return true; } diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index dde0c30183..0602bab4e7 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.15.3" + s.version = "3.15.6" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 107084e664..8ddf72b81e 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -52,10 +52,15 @@ module BasicTest outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass - outer_proto = outer.new( + outer.new( inners: [] - ) - outer_proto['inners'].to_s + )['inners'].to_s + + assert_raise Google::Protobuf::TypeError do + outer.new( + inners: [nil] + ).to_s + end end def test_has_field diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 1957422fa9..40c7726d83 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -436,6 +436,18 @@ module CommonTests end end + def test_b_8385 + m1 = Google::Protobuf::Map.new(:string, :string) + m2 = Google::Protobuf::Map.new(:string, :string) + + assert_equal m1, m2 + + m1["counter"] = "a" + m2["counter"] = "aa" + + assert_not_equal m1, m2 + end + def test_map_ctor m = Google::Protobuf::Map.new(:string, :int32, {"a" => 1, "b" => 2, "c" => 3}) diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 6307447bc3..1df6e1d4f1 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -339,18 +339,6 @@ class RepeatedFieldTest < Test::Unit::TestCase end end - def test_compact! - m = TestMessage.new - m.repeated_msg << TestMessage2.new(:foo => 1) - m.repeated_msg << nil - m.repeated_msg << TestMessage2.new(:foo => 2) - reference_arr = m.repeated_string.to_a - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.compact! - end - end - def test_delete m = TestMessage.new reference_arr = %w(foo bar baz) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index c16e188071..5ecf63f8c4 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -163,7 +163,6 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string type_url = 1; case 1: @@ -184,7 +183,8 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 1ee6112b8a..0f4facd1f4 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -268,7 +268,6 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -341,7 +340,8 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -673,7 +673,6 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -738,7 +737,8 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1043,7 +1043,6 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1065,7 +1064,8 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index 452d2bfec8..da49325ec1 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -62,6 +62,14 @@ const std::string& LazyString::Init() const { } +std::string* ArenaStringPtr::SetAndReturnNewString() { + std::string* new_string = new std::string(); + tagged_ptr_.Set(new_string); + return new_string; +} + +void ArenaStringPtr::DestroyNoArenaSlowPath() { delete UnsafeMutablePointer(); } + void ArenaStringPtr::Set(const std::string* default_value, ConstStringParam value, ::google::protobuf::Arena* arena) { if (IsDefault(default_value)) { diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 4238579bb4..a9eb5de33e 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -328,6 +328,12 @@ struct PROTOBUF_EXPORT ArenaStringPtr { template std::string* MutableSlow(::google::protobuf::Arena* arena, const Lazy&... lazy_default); + // Sets value to a newly allocated string and returns it + std::string* SetAndReturnNewString(); + + // Destroys the non-default string value out-of-line + void DestroyNoArenaSlowPath(); + }; inline void ArenaStringPtr::UnsafeSetDefault(const std::string* value) { @@ -379,9 +385,7 @@ inline std::string* ArenaStringPtr::MutableNoArenaNoDefault( // static global) and a branch to the slowpath (which calls operator new and // the ctor). DO NOT add any tagged-pointer operations here. if (IsDefault(default_value)) { - std::string* new_string = new std::string(); - tagged_ptr_.Set(new_string); - return new_string; + return SetAndReturnNewString(); } else { return UnsafeMutablePointer(); } @@ -389,7 +393,7 @@ inline std::string* ArenaStringPtr::MutableNoArenaNoDefault( inline void ArenaStringPtr::DestroyNoArena(const std::string* default_value) { if (!IsDefault(default_value)) { - delete UnsafeMutablePointer(); + DestroyNoArenaSlowPath(); } } diff --git a/src/google/protobuf/compiler/annotation_test_util.cc b/src/google/protobuf/compiler/annotation_test_util.cc index fb659f627f..3c47aa42db 100644 --- a/src/google/protobuf/compiler/annotation_test_util.cc +++ b/src/google/protobuf/compiler/annotation_test_util.cc @@ -30,6 +30,7 @@ #include +#include #include #include @@ -141,8 +142,8 @@ bool AtLeastOneAnnotationMatchesSubstring( e = annotations.end(); i != e; ++i) { const GeneratedCodeInfo::Annotation* annotation = *i; - uint32 begin = annotation->begin(); - uint32 end = annotation->end(); + uint32_t begin = annotation->begin(); + uint32_t end = annotation->end(); if (end < begin || end > file_content.size()) { return false; } diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 28b0bfa933..ff1fdd0511 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -34,6 +34,8 @@ #include +#include + #include #include @@ -2087,7 +2089,7 @@ Parse PROTO_FILES and generate output based on the options given: } bool CommandLineInterface::EnforceProto3OptionalSupport( - const std::string& codegen_name, uint64 supported_features, + const std::string& codegen_name, uint64_t supported_features, const std::vector& parsed_files) const { bool supports_proto3_optional = supported_features & CodeGenerator::FEATURE_PROTO3_OPTIONAL; diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 4ff2471c76..73551f0b8d 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -38,6 +38,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ #define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ +#include #include #include #include @@ -229,7 +230,7 @@ class PROTOC_EXPORT CommandLineInterface { // Fails if these files use proto3 optional and the code generator doesn't // support it. This is a permanent check. bool EnforceProto3OptionalSupport( - const std::string& codegen_name, uint64 supported_features, + const std::string& codegen_name, uint64_t supported_features, const std::vector& parsed_files) const; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 74dc9bffdb..92f3d08eb7 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -36,6 +36,8 @@ #include #include +#include + #ifndef _MSC_VER #include #endif @@ -211,7 +213,7 @@ class CommandLineInterfaceTest : public testing::Test { // code generator that omits the given feature(s). void CreateGeneratorWithMissingFeatures(const std::string& name, const std::string& description, - uint64 features) { + uint64_t features) { MockCodeGenerator* generator = new MockCodeGenerator(name); generator->SuppressFeatures(features); mock_generators_to_delete_.push_back(generator); diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 7f9754f67f..c9b9c20b9c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -32,10 +32,14 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include +#include #include -#include #include +#include #include #include @@ -49,13 +53,13 @@ namespace { // is kint32max, GOOGLE_ARRAYSIZE will overflow. In such cases we should omit the // generation of the GOOGLE_ARRAYSIZE constant. bool ShouldGenerateArraySize(const EnumDescriptor* descriptor) { - int32 max_value = descriptor->value(0)->number(); + int32_t max_value = descriptor->value(0)->number(); for (int i = 0; i < descriptor->value_count(); i++) { if (descriptor->value(i)->number() > max_value) { max_value = descriptor->value(i)->number(); } } - return max_value != kint32max; + return max_value != std::numeric_limits::max(); } // Returns the number of unique numeric enum values. This is less than diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc index f95e14e58b..b28f6f2d27 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_field.cc @@ -33,6 +33,8 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include + +#include #include #include @@ -89,7 +91,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["}"] = ""; } -void FieldGenerator::SetHasBitIndex(int32 has_bit_index) { +void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { if (!HasHasbit(descriptor_)) { GOOGLE_CHECK_EQ(has_bit_index, -1); return; diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h index 5a77639407..b210ef92b9 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_field.h @@ -35,6 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ +#include #include #include #include @@ -180,7 +181,7 @@ class FieldGenerator { // are placed in the message's ByteSize() method. virtual void GenerateByteSize(io::Printer* printer) const = 0; - void SetHasBitIndex(int32 has_bit_index); + void SetHasBitIndex(int32_t has_bit_index); protected: const FieldDescriptor* descriptor_; diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 5825af2181..ceecb95078 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -642,7 +643,7 @@ const char* DeclaredTypeMethodName(FieldDescriptor::Type type) { } std::string Int32ToString(int number) { - if (number == kint32min) { + if (number == std::numeric_limits::min()) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 return StrCat(number + 1, " - 1"); @@ -651,8 +652,8 @@ std::string Int32ToString(int number) { } } -std::string Int64ToString(const std::string& macro_prefix, int64 number) { - if (number == kint64min) { +std::string Int64ToString(const std::string& macro_prefix, int64_t number) { + if (number == std::numeric_limits::min()) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 return StrCat(macro_prefix, "_LONGLONG(", number + 1, ") - 1"); @@ -660,7 +661,7 @@ std::string Int64ToString(const std::string& macro_prefix, int64 number) { return StrCat(macro_prefix, "_LONGLONG(", number, ")"); } -std::string UInt64ToString(const std::string& macro_prefix, uint64 number) { +std::string UInt64ToString(const std::string& macro_prefix, uint64_t number) { return StrCat(macro_prefix, "_ULONGLONG(", number, ")"); } @@ -748,7 +749,8 @@ std::string FilenameIdentifier(const std::string& filename) { } else { // Not alphanumeric. To avoid any possibility of name conflicts we // use the hex code for the character. - StrAppend(&result, "_", strings::Hex(static_cast(filename[i]))); + StrAppend(&result, "_", + strings::Hex(static_cast(filename[i]))); } } return result; @@ -1612,7 +1614,7 @@ class ParseLoopGenerator { } // Convert a 1 or 2 byte varint into the equivalent value upon a direct load. - static uint32 SmallVarintValue(uint32 x) { + static uint32_t SmallVarintValue(uint32_t x) { GOOGLE_DCHECK(x < 128 * 128); if (x >= 128) x += (x & 0xFF80) + 128; return x; @@ -1629,7 +1631,7 @@ class ParseLoopGenerator { void GenerateFieldBody(internal::WireFormatLite::WireType wiretype, const FieldDescriptor* field) { - uint32 tag = WireFormatLite::MakeTag(field->number(), wiretype); + uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype); switch (wiretype) { case WireFormatLite::WIRETYPE_VARINT: { std::string type = PrimitiveTypeName(options_, field->cpp_type()); @@ -1724,16 +1726,16 @@ class ParseLoopGenerator { // Returns the tag for this field and in case of repeated packable fields, // sets a fallback tag in fallback_tag_ptr. - static uint32 ExpectedTag(const FieldDescriptor* field, - uint32* fallback_tag_ptr) { - uint32 expected_tag; + static uint32_t ExpectedTag(const FieldDescriptor* field, + uint32_t* fallback_tag_ptr) { + uint32_t expected_tag; if (field->is_packable()) { auto expected_wiretype = WireFormat::WireTypeForFieldType(field->type()); expected_tag = WireFormatLite::MakeTag(field->number(), expected_wiretype); GOOGLE_CHECK(expected_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED); auto fallback_wiretype = WireFormatLite::WIRETYPE_LENGTH_DELIMITED; - uint32 fallback_tag = + uint32_t fallback_tag = WireFormatLite::MakeTag(field->number(), fallback_wiretype); if (field->is_packed()) std::swap(expected_tag, fallback_tag); @@ -1752,8 +1754,7 @@ class ParseLoopGenerator { format_( "while (!ctx->Done(&ptr)) {\n" " $uint32$ tag;\n" - " ptr = $pi_ns$::ReadTag(ptr, &tag);\n" - " CHK_(ptr);\n"); + " ptr = $pi_ns$::ReadTag(ptr, &tag);\n"); if (!ordered_fields.empty()) format_(" switch (tag >> 3) {\n"); format_.Indent(); @@ -1763,14 +1764,14 @@ class ParseLoopGenerator { PrintFieldComment(format_, field); format_("case $1$:\n", field->number()); format_.Indent(); - uint32 fallback_tag = 0; - uint32 expected_tag = ExpectedTag(field, &fallback_tag); + uint32_t fallback_tag = 0; + uint32_t expected_tag = ExpectedTag(field, &fallback_tag); format_( "if (PROTOBUF_PREDICT_TRUE(static_cast<$uint8$>(tag) == $1$)) {\n", expected_tag & 0xFF); format_.Indent(); auto wiretype = WireFormatLite::GetTagWireType(expected_tag); - uint32 tag = WireFormatLite::MakeTag(field->number(), wiretype); + uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype); int tag_size = io::CodedOutputStream::VarintSize32(tag); bool is_repeat = ShouldRepeat(field, wiretype); if (is_repeat) { @@ -1807,7 +1808,8 @@ class ParseLoopGenerator { if (!ordered_fields.empty()) format_("default: {\n"); if (!ordered_fields.empty()) format_("handle_unusual:\n"); format_( - " if ((tag & 7) == 4 || tag == 0) {\n" + " if ((tag == 0) || ((tag & 7) == 4)) {\n" + " CHK_(ptr);\n" " ctx->SetLastTag(tag);\n" " goto success;\n" " }\n"); @@ -1821,9 +1823,9 @@ class ParseLoopGenerator { descriptor->extension_range(i); if (i > 0) format_(" ||\n "); - uint32 start_tag = WireFormatLite::MakeTag( + uint32_t start_tag = WireFormatLite::MakeTag( range->start, static_cast(0)); - uint32 end_tag = WireFormatLite::MakeTag( + uint32_t end_tag = WireFormatLite::MakeTag( range->end, static_cast(0)); if (range->end > FieldDescriptor::kMaxNumber) { diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index 46d9477f5e..43faf1cdaf 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -36,11 +36,13 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ #include +#include #include #include #include #include +#include #include #include #include @@ -184,9 +186,6 @@ std::string ResolveKeyword(const std::string& name); // anyway, so normally this just returns field->name(). std::string FieldName(const FieldDescriptor* field); -// Get the sanitized name that should be used for the given enum in C++ code. -std::string EnumValueName(const EnumValueDescriptor* enum_value); - // Returns an estimate of the compiler's alignment for the field. This // can't guarantee to be correct because the generated code could be compiled on // different systems with different alignment rules. The estimates below assume @@ -222,7 +221,7 @@ const char* DeclaredTypeMethodName(FieldDescriptor::Type type); std::string Int32ToString(int number); // Return the code that evaluates to the number when compiled. -std::string Int64ToString(const Options& options, int64 number); +std::string Int64ToString(const Options& options, int64_t number); // Get code that evaluates to the field's default value. std::string DefaultValue(const Options& options, const FieldDescriptor* field); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 73e66ae90f..2e2c2d4e3d 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,7 @@ static constexpr int kNoHasbit = -1; // masks is allowed to be shorter than _has_bits_, but at least one element of // masks must be non-zero. std::string ConditionalToCheckBitmasks( - const std::vector& masks, bool return_success = true, + const std::vector& masks, bool return_success = true, StringPiece has_bits_var = "_has_bits_") { std::vector parts; for (int i = 0; i < masks.size(); i++) { @@ -405,23 +406,23 @@ std::vector> CollectFields( // Returns a bit mask based on has_bit index of "fields" that are typically on // the same chunk. It is used in a group presence check where _has_bits_ is // masked to tell if any thing in "fields" is present. -uint32 GenChunkMask(const std::vector& fields, - const std::vector& has_bit_indices) { +uint32_t GenChunkMask(const std::vector& fields, + const std::vector& has_bit_indices) { GOOGLE_CHECK(!fields.empty()); int first_index_offset = has_bit_indices[fields.front()->index()] / 32; - uint32 chunk_mask = 0; + uint32_t chunk_mask = 0; for (auto field : fields) { // "index" defines where in the _has_bits_ the field appears. int index = has_bit_indices[field->index()]; GOOGLE_CHECK_EQ(first_index_offset, index / 32); - chunk_mask |= static_cast(1) << (index % 32); + chunk_mask |= static_cast(1) << (index % 32); } GOOGLE_CHECK_NE(0, chunk_mask); return chunk_mask; } // Return the number of bits set in n, a non-negative integer. -static int popcnt(uint32 n) { +static int popcnt(uint32_t n) { int result = 0; while (n != 0) { result += (n & 1); @@ -507,7 +508,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, format("if (PROTOBUF_PREDICT_FALSE("); int first_word = HasbitWord(chunk, 0); while (chunk < limit_chunk_) { - uint32 mask = 0; + uint32_t mask = 0; int this_word = HasbitWord(chunk, 0); // Generate mask for chunks on the same word. for (; chunk < limit_chunk_ && HasbitWord(chunk, 0) == this_word; chunk++) { @@ -1654,8 +1655,8 @@ namespace { // We need to calculate for each field what function the table driven code // should use to serialize it. This returns the index in a lookup table. -uint32 CalcFieldNum(const FieldGenerator& generator, - const FieldDescriptor* field, const Options& options) { +uint32_t CalcFieldNum(const FieldGenerator& generator, + const FieldDescriptor* field, const Options& options) { bool is_a_map = IsMapEntryMessage(field->containing_type()); int type = field->type(); if (type == FieldDescriptor::TYPE_STRING || @@ -1707,7 +1708,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { const FieldDescriptor* field = sorted[i]; const FieldGenerator& generator = field_generators_.get(field); - uint32 tag = internal::WireFormatLite::MakeTag( + uint32_t tag = internal::WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); std::map vars; @@ -1764,7 +1765,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { if (i == sorted.size()) break; const FieldDescriptor* field = sorted[i]; - uint32 tag = internal::WireFormatLite::MakeTag( + uint32_t tag = internal::WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); if (field->is_packed()) { tag = internal::WireFormatLite::MakeTag( @@ -1827,7 +1828,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { tag); } else if (field->real_containing_oneof()) { format.Set("oneofoffset", - sizeof(uint32) * field->containing_oneof()->index()); + sizeof(uint32_t) * field->containing_oneof()->index()); format( "{PROTOBUF_FIELD_OFFSET($classtype$, $field_name$_), $1$," " PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_) + " @@ -1933,7 +1934,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { } } if (num_required_fields_ > 0) { - const std::vector masks_for_has_bits = RequiredFieldsBitMask(); + const std::vector masks_for_has_bits = RequiredFieldsBitMask(); format( "static bool MissingRequiredFields(const HasBits& has_bits) " "{\n" @@ -2751,7 +2752,7 @@ void MessageGenerator::GenerateClear(io::Printer* printer) { if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. - uint32 chunk_mask = GenChunkMask(chunk, has_bit_indices_); + uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); @@ -3055,7 +3056,7 @@ void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) { if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. - uint32 chunk_mask = GenChunkMask(chunk, has_bit_indices_); + uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); @@ -3445,6 +3446,12 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( } } + void EmitIfNotNull(const FieldDescriptor* field) { + if (field != nullptr) { + Emit(field); + } + } + void Flush() { if (!v_.empty()) { mg_->GenerateSerializeOneofFields(format_.printer(), v_); @@ -3471,6 +3478,61 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( int cached_has_bit_index_; }; + class LazyExtensionRangeEmitter { + public: + LazyExtensionRangeEmitter(MessageGenerator* mg, io::Printer* printer) + : mg_(mg), format_(printer) {} + + void AddToRange(const Descriptor::ExtensionRange* range) { + if (!has_current_range_) { + current_combined_range_ = *range; + has_current_range_ = true; + } else { + current_combined_range_.start = + std::min(current_combined_range_.start, range->start); + current_combined_range_.end = + std::max(current_combined_range_.end, range->end); + } + } + + void Flush() { + if (has_current_range_) { + mg_->GenerateSerializeOneExtensionRange(format_.printer(), + ¤t_combined_range_); + } + has_current_range_ = false; + } + + private: + MessageGenerator* mg_; + Formatter format_; + bool has_current_range_ = false; + Descriptor::ExtensionRange current_combined_range_; + }; + + // We need to track the largest weak field, because weak fields are serialized + // differently than normal fields. The WeakFieldMap::FieldWriter will + // serialize all weak fields that are ordinally between the last serialized + // weak field and the current field. In order to guarantee that all weak + // fields are serialized, we need to make sure to emit the code to serialize + // the largest weak field present at some point. + class LargestWeakFieldHolder { + public: + const FieldDescriptor* Release() { + const FieldDescriptor* result = field_; + field_ = nullptr; + return result; + } + void ReplaceIfLarger(const FieldDescriptor* field) { + if (field_ == nullptr || field_->number() < field->number()) { + field_ = field; + } + } + + private: + const FieldDescriptor* field_ = nullptr; + }; + std::vector ordered_fields = SortFieldsByNumber(descriptor_); @@ -3494,7 +3556,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( // Merge the fields and the extension ranges, both sorted by field number. { LazySerializerEmitter e(this, printer); - const FieldDescriptor* last_weak_field = nullptr; + LazyExtensionRangeEmitter re(this, printer); + LargestWeakFieldHolder largest_weak_field; int i, j; for (i = 0, j = 0; i < ordered_fields.size() || j < sorted_extensions.size();) { @@ -3505,31 +3568,22 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( if (IsFieldStripped(field, options_)) { continue; } + re.Flush(); if (field->options().weak()) { - if (last_weak_field == nullptr || - last_weak_field->number() < field->number()) { - last_weak_field = field; - } + largest_weak_field.ReplaceIfLarger(field); PrintFieldComment(format, field); } else { - if (last_weak_field != nullptr) { - e.Emit(last_weak_field); - last_weak_field = nullptr; - } + e.EmitIfNotNull(largest_weak_field.Release()); e.Emit(field); } } else { - if (last_weak_field != nullptr) { - e.Emit(last_weak_field); - last_weak_field = nullptr; - } + e.EmitIfNotNull(largest_weak_field.Release()); e.Flush(); - GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); + re.AddToRange(sorted_extensions[j++]); } } - if (last_weak_field != nullptr) { - e.Emit(last_weak_field); - } + re.Flush(); + e.EmitIfNotNull(largest_weak_field.Release()); } std::map vars; @@ -3644,9 +3698,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( format("}\n"); } -std::vector MessageGenerator::RequiredFieldsBitMask() const { +std::vector MessageGenerator::RequiredFieldsBitMask() const { const int array_size = HasBitsSize(); - std::vector masks(array_size, 0); + std::vector masks(array_size, 0); for (auto field : FieldRange(descriptor_)) { if (!field->is_required()) { @@ -3654,7 +3708,8 @@ std::vector MessageGenerator::RequiredFieldsBitMask() const { } const int has_bit_index = has_bit_indices_[field->index()]; - masks[has_bit_index / 32] |= static_cast(1) << (has_bit_index % 32); + masks[has_bit_index / 32] |= static_cast(1) + << (has_bit_index % 32); } return masks; } @@ -3735,7 +3790,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) { // present then the fast path executes; otherwise the slow path executes. if (num_required_fields_ > 1) { // The fast path works if all required fields are present. - const std::vector masks_for_has_bits = RequiredFieldsBitMask(); + const std::vector masks_for_has_bits = RequiredFieldsBitMask(); format("if ($1$) { // All required fields are present.\n", ConditionalToCheckBitmasks(masks_for_has_bits)); format.Indent(); @@ -3791,7 +3846,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) { if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. - uint32 chunk_mask = GenChunkMask(chunk, has_bit_indices_); + uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index 4e3f4b9822..cb1d77c9be 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -35,9 +35,11 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ +#include #include #include #include + #include #include #include @@ -179,7 +181,7 @@ class MessageGenerator { int HasByteIndex(const FieldDescriptor* a) const; int HasWordIndex(const FieldDescriptor* a) const; bool SameHasByte(const FieldDescriptor* a, const FieldDescriptor* b) const; - std::vector RequiredFieldsBitMask() const; + std::vector RequiredFieldsBitMask() const; const Descriptor* descriptor_; int index_in_file_messages_; diff --git a/src/google/protobuf/compiler/cpp/cpp_names.h b/src/google/protobuf/compiler/cpp/cpp_names.h index 9bede74fc8..cbc69a7cb7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_names.h +++ b/src/google/protobuf/compiler/cpp/cpp_names.h @@ -40,6 +40,7 @@ namespace protobuf { class Descriptor; class EnumDescriptor; +class EnumValueDescriptor; class FieldDescriptor; namespace compiler { @@ -72,6 +73,10 @@ std::string QualifiedExtensionName(const FieldDescriptor* d); // anyway, so normally this just returns field->name(). std::string FieldName(const FieldDescriptor* field); +// Get the (unqualified) name that should be used for this enum value in C++ +// code. +std::string EnumValueName(const EnumValueDescriptor* enum_value); + // Strips ".proto" or ".protodevel" from the end of a filename. PROTOC_EXPORT std::string StripProto(const std::string& filename); diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index d840492b68..9f7f61e169 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -33,6 +33,7 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include + #include #include #include @@ -301,7 +302,7 @@ void RepeatedPrimitiveFieldGenerator::GeneratePrivateMembers( io::Printer* printer) const { Formatter format(printer, variables_); format("::$proto_ns$::RepeatedField< $type$ > $name$_;\n"); - if (descriptor_->is_packed() && + if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 && HasGeneratedMethods(descriptor_->file(), options_)) { format("mutable std::atomic _$name$_cached_byte_size_;\n"); } @@ -409,13 +410,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( io::Printer* printer) const { Formatter format(printer, variables_); if (descriptor_->is_packed()) { - if (FixedSize(descriptor_->type()) > 0) { - format( - "if (this->_internal_$name$_size() > 0) {\n" - " target = stream->WriteFixedPacked($number$, _internal_$name$(), " - "target);\n" - "}\n"); - } else { + if (FixedSize(descriptor_->type()) == -1) { format( "{\n" " int byte_size = " @@ -425,6 +420,12 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( " $number$, _internal_$name$(), byte_size, target);\n" " }\n" "}\n"); + } else { + format( + "if (this->_internal_$name$_size() > 0) {\n" + " target = stream->WriteFixedPacked($number$, _internal_$name$(), " + "target);\n" + "}\n"); } } else { format( @@ -460,11 +461,14 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize( " total_size += $tag_size$ +\n" " ::$proto_ns$::internal::WireFormatLite::Int32Size(\n" " static_cast<$int32$>(data_size));\n" - "}\n" - "int cached_size = ::$proto_ns$::internal::ToCachedSize(data_size);\n" - "_$name$_cached_byte_size_.store(cached_size,\n" - " std::memory_order_relaxed);\n" - "total_size += data_size;\n"); + "}\n"); + if (FixedSize(descriptor_->type()) == -1) { + format( + "int cached_size = ::$proto_ns$::internal::ToCachedSize(data_size);\n" + "_$name$_cached_byte_size_.store(cached_size,\n" + " std::memory_order_relaxed);\n"); + } + format("total_size += data_size;\n"); } else { format( "total_size += $tag_size$ *\n" @@ -480,7 +484,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateConstinitInitializer( io::Printer* printer) const { Formatter format(printer, variables_); format("$name$_()"); - if (descriptor_->is_packed() && + if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 && HasGeneratedMethods(descriptor_->file(), options_)) { format("\n, _$name$_cached_byte_size_()"); } diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.inc b/src/google/protobuf/compiler/cpp/cpp_unittest.inc index c8238abdef..a717f99e4d 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.inc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.inc @@ -44,6 +44,8 @@ // correctly and produces the interfaces we expect, which is why this test // is written this way. +#include +#include #include #include @@ -203,10 +205,13 @@ TEST(GENERATED_MESSAGE_TEST_NAME, Trigraph) { TEST(GENERATED_MESSAGE_TEST_NAME, ExtremeSmallIntegerDefault) { const UNITTEST::TestExtremeDefaultValues& extreme_default = UNITTEST::TestExtremeDefaultValues::default_instance(); - EXPECT_EQ(~0x7fffffff, kint32min); - EXPECT_EQ(PROTOBUF_LONGLONG(~0x7fffffffffffffff), kint64min); - EXPECT_EQ(kint32min, extreme_default.really_small_int32()); - EXPECT_EQ(kint64min, extreme_default.really_small_int64()); + EXPECT_EQ(~0x7fffffff, std::numeric_limits::min()); + EXPECT_EQ(PROTOBUF_LONGLONG(~0x7fffffffffffffff), + std::numeric_limits::min()); + EXPECT_EQ(std::numeric_limits::min(), + extreme_default.really_small_int32()); + EXPECT_EQ(std::numeric_limits::min(), + extreme_default.really_small_int64()); } TEST(GENERATED_MESSAGE_TEST_NAME, Accessors) { @@ -369,7 +374,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ClearOneField) { UNITTEST::TestAllTypes message; TestUtil::SetAllFields(&message); - int64 original_value = message.optional_int64(); + int64_t original_value = message.optional_int64(); // Clear the field and make sure it shows up as cleared. message.clear_optional_int64(); @@ -498,7 +503,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ADLSwap) { // Note the address of one of the repeated fields, to verify it was swapped // rather than copied. - const int32* addr = &message1.repeated_int32().Get(0); + const int32_t* addr = &message1.repeated_int32().Get(0); using std::swap; swap(message1, message2); @@ -648,7 +653,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, NonEmptyMergeFrom) { // This tests concatenating. message2.add_repeated_int32(message1.repeated_int32(1)); - int32 i = message1.repeated_int32(0); + int32_t i = message1.repeated_int32(0); message1.clear_repeated_int32(); message1.add_repeated_int32(i); @@ -665,8 +670,8 @@ TEST(GENERATED_MESSAGE_TEST_NAME, SerializationToArray) { TestUtil::SetAllFields(&message1); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); TestUtil::ExpectAllFieldsSet(message2); @@ -679,8 +684,9 @@ TEST(GENERATED_MESSAGE_TEST_NAME, PackedFieldsSerializationToArray) { TestUtil::SetPackedFields(&packed_message1); int packed_size = packed_message1.ByteSizeLong(); packed_data.resize(packed_size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&packed_data)); - uint8* end = packed_message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = + reinterpret_cast(::google::protobuf::string_as_array(&packed_data)); + uint8_t* end = packed_message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(packed_size, end - start); EXPECT_TRUE(packed_message2.ParseFromString(packed_data)); TestUtil::ExpectPackedFieldsSet(packed_message2); @@ -1846,8 +1852,8 @@ std::string data; message1.set_foo_int(123); int size = message1.ByteSizeLong(); data.resize(size); -uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); -uint8* end = message1.SerializeWithCachedSizesToArray(start); +uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); +uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_int(), 123); @@ -1860,8 +1866,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_string("foo"); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_string(), "foo"); @@ -1875,8 +1881,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_bytes("qux"); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_bytes(), "qux"); @@ -1889,8 +1895,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_enum(UNITTEST::TestOneof2::FOO); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_enum(), UNITTEST::TestOneof2::FOO); @@ -1903,8 +1909,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.mutable_foo_message()->set_qux_int(234); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_message().qux_int(), 234); @@ -1917,8 +1923,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.mutable_foogroup()->set_a(345); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foogroup().a(), 345); diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc index 9706c6d027..9a0799ee46 100644 --- a/src/google/protobuf/compiler/java/java_enum_field.cc +++ b/src/google/protobuf/compiler/java/java_enum_field.cc @@ -32,6 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -39,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -67,7 +69,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["default_number"] = StrCat(descriptor->default_value_enum()->number()); (*variables)["tag"] = StrCat( - static_cast(internal::WireFormat::MakeTag(descriptor))); + static_cast(internal::WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/src/google/protobuf/compiler/java/java_enum_field_lite.cc index dfa051c16d..8403f95fbd 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.cc @@ -32,6 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -39,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -74,7 +76,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["default_number"] = StrCat(descriptor->default_value_enum()->number()); (*variables)["tag"] = StrCat( - static_cast(internal::WireFormat::MakeTag(descriptor))); + static_cast(internal::WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported @@ -281,7 +283,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateInitializationCode( } void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -377,7 +379,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( } void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -632,7 +634,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( } void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.h b/src/google/protobuf/compiler/java/java_enum_field_lite.h index b5e9807728..fbc11279b5 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.h +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.h @@ -35,8 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -70,7 +72,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -95,7 +97,7 @@ class ImmutableEnumOneofFieldLiteGenerator void GenerateMembers(io::Printer* printer) const; void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldLiteGenerator); @@ -115,7 +117,7 @@ class RepeatedImmutableEnumFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_field.h b/src/google/protobuf/compiler/java/java_field.h index 9d04dc8455..df6c38d752 100644 --- a/src/google/protobuf/compiler/java/java_field.h +++ b/src/google/protobuf/compiler/java/java_field.h @@ -35,6 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ +#include #include #include #include @@ -104,7 +105,7 @@ class ImmutableFieldLiteGenerator { virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; virtual void GenerateInitializationCode(io::Printer* printer) const = 0; virtual void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const = 0; + std::vector* output) const = 0; virtual std::string GetBoxedType() const = 0; diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc index 3aebf72c7e..e32b6e32b5 100644 --- a/src/google/protobuf/compiler/java/java_helpers.cc +++ b/src/google/protobuf/compiler/java/java_helpers.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -500,11 +501,11 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable, return StrCat(field->default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: // Need to print as a signed int since Java has no unsigned. - return StrCat(static_cast(field->default_value_uint32())); + return StrCat(static_cast(field->default_value_uint32())); case FieldDescriptor::CPPTYPE_INT64: return StrCat(field->default_value_int64()) + "L"; case FieldDescriptor::CPPTYPE_UINT64: - return StrCat(static_cast(field->default_value_uint64())) + + return StrCat(static_cast(field->default_value_uint64())) + "L"; case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field->default_value_double(); @@ -896,11 +897,11 @@ bool HasRepeatedFields(const Descriptor* descriptor) { // // Note that we only use code points in [0x0000, 0xD7FF] and [0xE000, 0xFFFF]. // There will be no surrogate pairs in the encoded character sequence. -void WriteUInt32ToUtf16CharSequence(uint32 number, - std::vector* output) { +void WriteUInt32ToUtf16CharSequence(uint32_t number, + std::vector* output) { // For values in [0x0000, 0xD7FF], only use one char to encode it. if (number < 0xD800) { - output->push_back(static_cast(number)); + output->push_back(static_cast(number)); return; } // Encode into multiple chars. All except the last char will be in the range @@ -910,10 +911,10 @@ void WriteUInt32ToUtf16CharSequence(uint32 number, // them. while (number >= 0xD800) { // [0xE000, 0xFFFF] can represent 13 bits of info. - output->push_back(static_cast(0xE000 | (number & 0x1FFF))); + output->push_back(static_cast(0xE000 | (number & 0x1FFF))); number >>= 13; } - output->push_back(static_cast(number)); + output->push_back(static_cast(number)); } int GetExperimentalJavaFieldTypeForSingular(const FieldDescriptor* field) { @@ -994,7 +995,7 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) { } // Escape a UTF-16 character to be embedded in a Java string. -void EscapeUtf16ToString(uint16 code, std::string* output) { +void EscapeUtf16ToString(uint16_t code, std::string* output) { if (code == '\t') { output->append("\\t"); } else if (code == '\b') { diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h index 8cc2f5af80..5ede13cc77 100644 --- a/src/google/protobuf/compiler/java/java_helpers.h +++ b/src/google/protobuf/compiler/java/java_helpers.h @@ -35,7 +35,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ +#include #include + #include #include #include @@ -412,15 +414,16 @@ inline std::string GeneratedCodeVersionSuffix() { return "V3"; } -void WriteUInt32ToUtf16CharSequence(uint32 number, std::vector* output); +void WriteUInt32ToUtf16CharSequence(uint32_t number, + std::vector* output); inline void WriteIntToUtf16CharSequence(int value, - std::vector* output) { - WriteUInt32ToUtf16CharSequence(static_cast(value), output); + std::vector* output) { + WriteUInt32ToUtf16CharSequence(static_cast(value), output); } // Escape a UTF-16 character so it can be embedded in a Java string literal. -void EscapeUtf16ToString(uint16 code, std::string* output); +void EscapeUtf16ToString(uint16_t code, std::string* output); // Only the lowest two bytes of the return value are used. The lowest byte // is the integer value of a j/c/g/protobuf/FieldType enum. For the other diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc index 63c1ad3ebd..8db281d93e 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -505,7 +507,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( } void ImmutableMapFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.h b/src/google/protobuf/compiler/java/java_map_field_lite.h index 49cbf6cca7..37aec06398 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.h +++ b/src/google/protobuf/compiler/java/java_map_field_lite.h @@ -31,6 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ +#include + #include namespace google { @@ -52,7 +54,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index ba31775334..f2df25f0fe 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -1213,11 +1214,11 @@ void ImmutableMessageGenerator::GenerateParsingConstructor( for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = sorted_fields[i]; - uint32 tag = WireFormatLite::MakeTag( + uint32_t tag = WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); printer->Print("case $tag$: {\n", "tag", - StrCat(static_cast(tag))); + StrCat(static_cast(tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCode(printer); @@ -1230,10 +1231,10 @@ void ImmutableMessageGenerator::GenerateParsingConstructor( if (field->is_packable()) { // To make packed = true wire compatible, we generate parsing code from a // packed version of this field regardless of field->options().packed(). - uint32 packed_tag = WireFormatLite::MakeTag( + uint32_t packed_tag = WireFormatLite::MakeTag( field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); printer->Print("case $tag$: {\n", "tag", - StrCat(static_cast(packed_tag))); + StrCat(static_cast(packed_tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCodeFromPacked(printer); diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc index b17859d6b3..73f1bcf543 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -32,13 +32,15 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include #include #include #include -#include #include #include #include @@ -276,7 +278,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( } void ImmutableMessageFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -366,7 +368,7 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateMembers( } void ImmutableMessageOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -731,7 +733,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( } void RepeatedImmutableMessageFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.h b/src/google/protobuf/compiler/java/java_message_field_lite.h index c0a9b37f4f..8b935e68f9 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.h +++ b/src/google/protobuf/compiler/java/java_message_field_lite.h @@ -35,8 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -70,7 +72,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -95,7 +97,7 @@ class ImmutableMessageOneofFieldLiteGenerator void GenerateMembers(io::Printer* printer) const; void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator); @@ -115,7 +117,7 @@ class RepeatedImmutableMessageFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 4afffdc7a9..cae9963759 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -471,7 +472,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( // Collect field info into a sequence of UTF-16 chars. It will be embedded // as a Java string in the generated code. - std::vector chars; + std::vector chars; int flags = 0; if (IsProto2(descriptor_->file())) { @@ -553,7 +554,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( printer->Print("java.lang.String info =\n"); std::string line; for (size_t i = 0; i < chars.size(); i++) { - uint16 code = chars[i]; + uint16_t code = chars[i]; EscapeUtf16ToString(code, &line); if (line.size() >= 80) { printer->Print(" \"$string$\" +\n", "string", line); diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc index 8bc68b7b22..65cc05adcf 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field.cc @@ -32,6 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -41,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -112,7 +114,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_type"] = GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); if (IsReferenceType(GetJavaType(descriptor))) { diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc index 11facdd0a7..1932e99a27 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc @@ -34,6 +34,7 @@ #include +#include #include #include @@ -78,7 +79,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_type"] = GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; @@ -304,7 +305,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( void ImmutablePrimitiveFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -385,7 +386,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers( } void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -615,7 +616,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( } void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/src/google/protobuf/compiler/java/java_primitive_field_lite.h index 5867cee746..22a25579a7 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.h @@ -35,8 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -70,7 +72,7 @@ class ImmutablePrimitiveFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -96,7 +98,7 @@ class ImmutablePrimitiveOneofFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator); @@ -116,7 +118,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index 485fcf812e..2e9a9e789a 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -33,6 +33,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -42,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -71,7 +73,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "String"; (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["null_check"] = diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc index a0c27735c1..63702c1992 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -33,6 +33,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -42,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -72,7 +74,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "java.lang.String"; (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // We use `x.getClass()` as a null check because it generates less bytecode @@ -303,7 +305,7 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( } void ImmutableStringFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -407,7 +409,7 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( } void ImmutableStringOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -703,7 +705,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( } void RepeatedImmutableStringFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.h b/src/google/protobuf/compiler/java/java_string_field_lite.h index b67135cd81..194a19ddc2 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.h +++ b/src/google/protobuf/compiler/java/java_string_field_lite.h @@ -36,8 +36,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -71,7 +73,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -96,7 +98,7 @@ class ImmutableStringOneofFieldLiteGenerator void GenerateMembers(io::Printer* printer) const; void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator); }; @@ -115,7 +117,7 @@ class RepeatedImmutableStringFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 3abb5c0b13..1fce106096 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -88,11 +89,11 @@ MockCodeGenerator::MockCodeGenerator(const std::string& name) : name_(name) {} MockCodeGenerator::~MockCodeGenerator() {} uint64_t MockCodeGenerator::GetSupportedFeatures() const { - uint64 all_features = CodeGenerator::FEATURE_PROTO3_OPTIONAL; + uint64_t all_features = CodeGenerator::FEATURE_PROTO3_OPTIONAL; return all_features & ~suppressed_features_; } -void MockCodeGenerator::SuppressFeatures(uint64 features) { +void MockCodeGenerator::SuppressFeatures(uint64_t features) { suppressed_features_ = features; } diff --git a/src/google/protobuf/compiler/mock_code_generator.h b/src/google/protobuf/compiler/mock_code_generator.h index 9677d1904d..6e101055de 100644 --- a/src/google/protobuf/compiler/mock_code_generator.h +++ b/src/google/protobuf/compiler/mock_code_generator.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ +#include #include #include @@ -112,11 +113,11 @@ class MockCodeGenerator : public CodeGenerator { GeneratorContext* context, std::string* error) const override; uint64_t GetSupportedFeatures() const override; - void SuppressFeatures(uint64 features); + void SuppressFeatures(uint64_t features); private: std::string name_; - uint64 suppressed_features_ = 0; + uint64_t suppressed_features_ = 0; static std::string GetOutputFileContent(const std::string& generator_name, const std::string& parameter, diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index d92cd55873..b1bf2882e3 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -38,6 +38,7 @@ #include +#include #include #include #include @@ -243,8 +244,9 @@ bool Parser::ConsumeIdentifier(std::string* output, const char* error) { bool Parser::ConsumeInteger(int* output, const char* error) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { - uint64 value = 0; - if (!io::Tokenizer::ParseInteger(input_->current().text, kint32max, + uint64_t value = 0; + if (!io::Tokenizer::ParseInteger(input_->current().text, + std::numeric_limits::max(), &value)) { AddError("Integer out of range."); // We still return true because we did, in fact, parse an integer. @@ -260,19 +262,19 @@ bool Parser::ConsumeInteger(int* output, const char* error) { bool Parser::ConsumeSignedInteger(int* output, const char* error) { bool is_negative = false; - uint64 max_value = kint32max; + uint64_t max_value = std::numeric_limits::max(); if (TryConsume("-")) { is_negative = true; max_value += 1; } - uint64 value = 0; + uint64_t value = 0; DO(ConsumeInteger64(max_value, &value, error)); if (is_negative) value *= -1; *output = value; return true; } -bool Parser::ConsumeInteger64(uint64 max_value, uint64* output, +bool Parser::ConsumeInteger64(uint64_t max_value, uint64_t* output, const char* error) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (!io::Tokenizer::ParseInteger(input_->current().text, max_value, @@ -296,8 +298,9 @@ bool Parser::ConsumeNumber(double* output, const char* error) { return true; } else if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { // Also accept integers. - uint64 value = 0; - if (!io::Tokenizer::ParseInteger(input_->current().text, kuint64max, + uint64_t value = 0; + if (!io::Tokenizer::ParseInteger(input_->current().text, + std::numeric_limits::max(), &value)) { AddError("Integer out of range."); // We still return true because we did, in fact, parse a number. @@ -829,8 +832,9 @@ bool IsMessageSetWireFormatMessage(const DescriptorProto& message) { // tag number can only be determined after all options have been parsed. void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) { const bool is_message_set = IsMessageSetWireFormatMessage(*message); - const int max_extension_number = - is_message_set ? kint32max : FieldDescriptor::kMaxNumber + 1; + const int max_extension_number = is_message_set + ? std::numeric_limits::max() + : FieldDescriptor::kMaxNumber + 1; for (int i = 0; i < message->extension_range_size(); ++i) { if (message->extension_range(i).end() == kMaxRangeSentinel) { message->mutable_extension_range(i)->set_end(max_extension_number); @@ -843,8 +847,9 @@ void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) { // tag number can only be determined after all options have been parsed. void AdjustReservedRangesWithMaxEndNumber(DescriptorProto* message) { const bool is_message_set = IsMessageSetWireFormatMessage(*message); - const int max_field_number = - is_message_set ? kint32max : FieldDescriptor::kMaxNumber + 1; + const int max_field_number = is_message_set + ? std::numeric_limits::max() + : FieldDescriptor::kMaxNumber + 1; for (int i = 0; i < message->reserved_range_size(); ++i) { if (message->reserved_range(i).end() == kMaxRangeSentinel) { message->mutable_reserved_range(i)->set_end(max_field_number); @@ -1260,11 +1265,11 @@ bool Parser::ParseDefaultAssignment( case FieldDescriptorProto::TYPE_SINT64: case FieldDescriptorProto::TYPE_SFIXED32: case FieldDescriptorProto::TYPE_SFIXED64: { - uint64 max_value = kint64max; + uint64_t max_value = std::numeric_limits::max(); if (field->type() == FieldDescriptorProto::TYPE_INT32 || field->type() == FieldDescriptorProto::TYPE_SINT32 || field->type() == FieldDescriptorProto::TYPE_SFIXED32) { - max_value = kint32max; + max_value = std::numeric_limits::max(); } // These types can be negative. @@ -1274,7 +1279,7 @@ bool Parser::ParseDefaultAssignment( ++max_value; } // Parse the integer to verify that it is not out-of-range. - uint64 value; + uint64_t value; DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. @@ -1286,10 +1291,10 @@ bool Parser::ParseDefaultAssignment( case FieldDescriptorProto::TYPE_UINT64: case FieldDescriptorProto::TYPE_FIXED32: case FieldDescriptorProto::TYPE_FIXED64: { - uint64 max_value = kuint64max; + uint64_t max_value = std::numeric_limits::max(); if (field->type() == FieldDescriptorProto::TYPE_UINT32 || field->type() == FieldDescriptorProto::TYPE_FIXED32) { - max_value = kuint32max; + max_value = std::numeric_limits::max(); } // Numeric, not negative. @@ -1297,7 +1302,7 @@ bool Parser::ParseDefaultAssignment( AddError("Unsigned field can't have negative default value."); } // Parse the integer to verify that it is not out-of-range. - uint64 value; + uint64_t value; DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. @@ -1529,15 +1534,17 @@ bool Parser::ParseOption(Message* options, } case io::Tokenizer::TYPE_INTEGER: { - uint64 value; - uint64 max_value = - is_negative ? static_cast(kint64max) + 1 : kuint64max; + uint64_t value; + uint64_t max_value = + is_negative + ? static_cast(std::numeric_limits::max()) + 1 + : std::numeric_limits::max(); DO(ConsumeInteger64(max_value, &value, "Expected integer.")); if (is_negative) { value_location.AddPath( UninterpretedOption::kNegativeIntValueFieldNumber); uninterpreted_option->set_negative_int_value( - static_cast(-value)); + static_cast(-value)); } else { value_location.AddPath( UninterpretedOption::kPositiveIntValueFieldNumber); @@ -2338,8 +2345,8 @@ bool Parser::ParsePackage(FileDescriptorProto* file, } bool Parser::ParseImport(RepeatedPtrField* dependency, - RepeatedField* public_dependency, - RepeatedField* weak_dependency, + RepeatedField* public_dependency, + RepeatedField* weak_dependency, const LocationRecorder& root_location, const FileDescriptorProto* containing_file) { LocationRecorder location(root_location, diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index e8afdbc4d8..e0ba90f921 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -37,14 +37,17 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PARSER_H__ #define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ +#include #include #include #include + #include #include #include #include +// Must be included last. #include namespace google { @@ -172,7 +175,8 @@ class PROTOBUF_EXPORT Parser { bool ConsumeSignedInteger(int* output, const char* error); // Consume a 64-bit integer and store its value in "output". If the value // is greater than max_value, an error will be reported. - bool ConsumeInteger64(uint64 max_value, uint64* output, const char* error); + bool ConsumeInteger64(uint64_t max_value, uint64_t* output, + const char* error); // Consume a number and store its value in "output". This will accept // tokens of either INTEGER or FLOAT type. bool ConsumeNumber(double* output, const char* error); @@ -323,8 +327,8 @@ class PROTOBUF_EXPORT Parser { const LocationRecorder& root_location, const FileDescriptorProto* containing_file); bool ParseImport(RepeatedPtrField* dependency, - RepeatedField* public_dependency, - RepeatedField* weak_dependency, + RepeatedField* public_dependency, + RepeatedField* weak_dependency, const LocationRecorder& root_location, const FileDescriptorProto* containing_file); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 564e237e5e..374a444a9e 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -305,7 +305,6 @@ const char* Version::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 major = 1; case 1: @@ -344,7 +343,8 @@ const char* Version::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -636,7 +636,6 @@ const char* CodeGeneratorRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAM while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated string file_to_generate = 1; case 1: @@ -686,7 +685,8 @@ const char* CodeGeneratorRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAM continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1001,7 +1001,6 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* ptr, ::PROTOB while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -1045,7 +1044,8 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* ptr, ::PROTOB continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1322,7 +1322,6 @@ const char* CodeGeneratorResponse::_InternalParse(const char* ptr, ::PROTOBUF_NA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string error = 1; case 1: @@ -1357,7 +1356,8 @@ const char* CodeGeneratorResponse::_InternalParse(const char* ptr, ::PROTOBUF_NA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/compiler/zip_writer.cc b/src/google/protobuf/compiler/zip_writer.cc index 5ae026154b..72e1d7114d 100644 --- a/src/google/protobuf/compiler/zip_writer.cc +++ b/src/google/protobuf/compiler/zip_writer.cc @@ -34,6 +34,9 @@ // Based on http://www.pkware.com/documents/casestudies/APPNOTE.TXT #include + +#include + #include namespace google { @@ -42,9 +45,9 @@ namespace compiler { // January 1, 1980 as a DOS date. // see https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx -static const uint16 kDosEpoch = 1 << 5 | 1; +static const uint16_t kDosEpoch = 1 << 5 | 1; -static const uint32 kCRC32Table[256] = { +static const uint32_t kCRC32Table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, @@ -89,8 +92,8 @@ static const uint32 kCRC32Table[256] = { 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; -static uint32 ComputeCRC32(const std::string& buf) { - uint32 x = ~0U; +static uint32_t ComputeCRC32(const std::string& buf) { + uint32_t x = ~0U; for (int i = 0; i < buf.size(); ++i) { unsigned char c = buf[i]; x = kCRC32Table[(x ^ c) & 0xff] ^ (x >> 8); @@ -98,10 +101,10 @@ static uint32 ComputeCRC32(const std::string& buf) { return ~x; } -static void WriteShort(io::CodedOutputStream* out, uint16 val) { - uint8 p[2]; - p[0] = static_cast(val); - p[1] = static_cast(val >> 8); +static void WriteShort(io::CodedOutputStream* out, uint16_t val) { + uint8_t p[2]; + p[0] = static_cast(val); + p[1] = static_cast(val >> 8); out->WriteRaw(p, 2); } @@ -114,7 +117,7 @@ bool ZipWriter::Write(const std::string& filename, FileInfo info; info.name = filename; - uint16 filename_size = filename.size(); + uint16_t filename_size = filename.size(); info.offset = raw_output_->ByteCount(); info.size = contents.size(); info.crc32 = ComputeCRC32(contents); @@ -141,17 +144,17 @@ bool ZipWriter::Write(const std::string& filename, } bool ZipWriter::WriteDirectory() { - uint16 num_entries = files_.size(); - uint32 dir_ofs = raw_output_->ByteCount(); + uint16_t num_entries = files_.size(); + uint32_t dir_ofs = raw_output_->ByteCount(); // write central directory io::CodedOutputStream output(raw_output_); for (int i = 0; i < num_entries; ++i) { const std::string& filename = files_[i].name; - uint16 filename_size = filename.size(); - uint32 crc32 = files_[i].crc32; - uint32 size = files_[i].size; - uint32 offset = files_[i].offset; + uint16_t filename_size = filename.size(); + uint32_t crc32 = files_[i].crc32; + uint32_t size = files_[i].size; + uint32_t offset = files_[i].offset; output.WriteLittleEndian32(0x02014b50); // magic WriteShort(&output, 10); // version made by @@ -172,7 +175,7 @@ bool ZipWriter::WriteDirectory() { output.WriteLittleEndian32(offset); // local header offset output.WriteString(filename); // file name } - uint32 dir_len = output.ByteCount(); + uint32_t dir_len = output.ByteCount(); // write end of central directory marker output.WriteLittleEndian32(0x06054b50); // magic diff --git a/src/google/protobuf/compiler/zip_writer.h b/src/google/protobuf/compiler/zip_writer.h index 3a8903a3f3..0a8a773552 100644 --- a/src/google/protobuf/compiler/zip_writer.h +++ b/src/google/protobuf/compiler/zip_writer.h @@ -30,7 +30,9 @@ // Author: kenton@google.com (Kenton Varda) +#include #include + #include #include @@ -49,9 +51,9 @@ class ZipWriter { private: struct FileInfo { std::string name; - uint32 offset; - uint32 size; - uint32 crc32; + uint32_t offset; + uint32_t size; + uint32_t crc32; }; io::ZeroCopyOutputStream* raw_output_; diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index d51236cf3a..c22ae431c0 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -990,67 +990,68 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] PR "\347\007 \003(\0132$.google.protobuf.UninterpretedOp" "tion\":\n\014OptimizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_" "SIZE\020\002\022\020\n\014LITE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020" - "\'\"\362\001\n\016MessageOptions\022&\n\027message_set_wire" + "\'\"\204\002\n\016MessageOptions\022&\n\027message_set_wire" "_format\030\001 \001(\010:\005false\022.\n\037no_standard_desc" "riptor_accessor\030\002 \001(\010:\005false\022\031\n\ndeprecat" "ed\030\003 \001(\010:\005false\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024un" "interpreted_option\030\347\007 \003(\0132$.google.proto" - "buf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\t" - "J\004\010\t\020\n\"\236\003\n\014FieldOptions\022:\n\005ctype\030\001 \001(\0162#" - ".google.protobuf.FieldOptions.CType:\006STR" - "ING\022\016\n\006packed\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.go" - "ogle.protobuf.FieldOptions.JSType:\tJS_NO" - "RMAL\022\023\n\004lazy\030\005 \001(\010:\005false\022\031\n\ndeprecated\030" - "\003 \001(\010:\005false\022\023\n\004weak\030\n \001(\010:\005false\022C\n\024uni" - "nterpreted_option\030\347\007 \003(\0132$.google.protob" - "uf.UninterpretedOption\"/\n\005CType\022\n\n\006STRIN" - "G\020\000\022\010\n\004CORD\020\001\022\020\n\014STRING_PIECE\020\002\"5\n\006JSTyp" - "e\022\r\n\tJS_NORMAL\020\000\022\r\n\tJS_STRING\020\001\022\r\n\tJS_NU" - "MBER\020\002*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005\"^\n\014OneofOptions\022" - "C\n\024uninterpreted_option\030\347\007 \003(\0132$.google." - "protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"" - "\223\001\n\013EnumOptions\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\n" - "deprecated\030\003 \001(\010:\005false\022C\n\024uninterpreted" - "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" - "pretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\005\020\006\"}\n\020EnumVal" - "ueOptions\022\031\n\ndeprecated\030\001 \001(\010:\005false\022C\n\024" - "uninterpreted_option\030\347\007 \003(\0132$.google.pro" - "tobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016" - "ServiceOptions\022\031\n\ndeprecated\030! \001(\010:\005fals" + "buf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005" + "J\004\010\005\020\006J\004\010\006\020\007J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n\014FieldOption" + "s\022:\n\005ctype\030\001 \001(\0162#.google.protobuf.Field" + "Options.CType:\006STRING\022\016\n\006packed\030\002 \001(\010\022\?\n" + "\006jstype\030\006 \001(\0162$.google.protobuf.FieldOpt" + "ions.JSType:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010:\005fa" + "lse\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\023\n\004weak\030\n" + " \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003" + "(\0132$.google.protobuf.UninterpretedOption" + "\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014STRIN" + "G_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NORMAL\020\000\022\r\n\tJS" + "_STRING\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020" + "\005\"^\n\014OneofOptions\022C\n\024uninterpreted_optio" + "n\030\347\007 \003(\0132$.google.protobuf.Uninterpreted" + "Option*\t\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOptions\022\023\n\013all" + "ow_alias\030\002 \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005fals" "e\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" "e.protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200" - "\002\"\255\002\n\rMethodOptions\022\031\n\ndeprecated\030! \001(\010:" - "\005false\022_\n\021idempotency_level\030\" \001(\0162/.goog" - "le.protobuf.MethodOptions.IdempotencyLev" - "el:\023IDEMPOTENCY_UNKNOWN\022C\n\024uninterpreted" - "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" - "pretedOption\"P\n\020IdempotencyLevel\022\027\n\023IDEM" - "POTENCY_UNKNOWN\020\000\022\023\n\017NO_SIDE_EFFECTS\020\001\022\016" - "\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023Uninterpre" - "tedOption\022;\n\004name\030\002 \003(\0132-.google.protobu" - "f.UninterpretedOption.NamePart\022\030\n\020identi" - "fier_value\030\003 \001(\t\022\032\n\022positive_int_value\030\004" - " \001(\004\022\032\n\022negative_int_value\030\005 \001(\003\022\024\n\014doub" - "le_value\030\006 \001(\001\022\024\n\014string_value\030\007 \001(\014\022\027\n\017" - "aggregate_value\030\010 \001(\t\0323\n\010NamePart\022\021\n\tnam" - "e_part\030\001 \002(\t\022\024\n\014is_extension\030\002 \002(\010\"\325\001\n\016S" - "ourceCodeInfo\022:\n\010location\030\001 \003(\0132(.google" - ".protobuf.SourceCodeInfo.Location\032\206\001\n\010Lo" - "cation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002" - "\020\001\022\030\n\020leading_comments\030\003 \001(\t\022\031\n\021trailing" - "_comments\030\004 \001(\t\022!\n\031leading_detached_comm" - "ents\030\006 \003(\t\"\247\001\n\021GeneratedCodeInfo\022A\n\nanno" - "tation\030\001 \003(\0132-.google.protobuf.Generated" - "CodeInfo.Annotation\032O\n\nAnnotation\022\020\n\004pat" - "h\030\001 \003(\005B\002\020\001\022\023\n\013source_file\030\002 \001(\t\022\r\n\005begi" - "n\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B~\n\023com.google.proto" - "bufB\020DescriptorProtosH\001Z-google.golang.o" - "rg/protobuf/types/descriptorpb\370\001\001\242\002\003GPB\252" - "\002\032Google.Protobuf.Reflection" + "\002J\004\010\005\020\006\"}\n\020EnumValueOptions\022\031\n\ndeprecate" + "d\030\001 \001(\010:\005false\022C\n\024uninterpreted_option\030\347" + "\007 \003(\0132$.google.protobuf.UninterpretedOpt" + "ion*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOptions\022\031\n\ndepr" + "ecated\030! \001(\010:\005false\022C\n\024uninterpreted_opt" + "ion\030\347\007 \003(\0132$.google.protobuf.Uninterpret" + "edOption*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n" + "\ndeprecated\030! \001(\010:\005false\022_\n\021idempotency_" + "level\030\" \001(\0162/.google.protobuf.MethodOpti" + "ons.IdempotencyLevel:\023IDEMPOTENCY_UNKNOW" + "N\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" + "e.protobuf.UninterpretedOption\"P\n\020Idempo" + "tencyLevel\022\027\n\023IDEMPOTENCY_UNKNOWN\020\000\022\023\n\017N" + "O_SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200" + "\200\200\002\"\236\002\n\023UninterpretedOption\022;\n\004name\030\002 \003(" + "\0132-.google.protobuf.UninterpretedOption." + "NamePart\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022po" + "sitive_int_value\030\004 \001(\004\022\032\n\022negative_int_v" + "alue\030\005 \001(\003\022\024\n\014double_value\030\006 \001(\001\022\024\n\014stri" + "ng_value\030\007 \001(\014\022\027\n\017aggregate_value\030\010 \001(\t\032" + "3\n\010NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_ext" + "ension\030\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010locat" + "ion\030\001 \003(\0132(.google.protobuf.SourceCodeIn" + "fo.Location\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002" + "\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments" + "\030\003 \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031lea" + "ding_detached_comments\030\006 \003(\t\"\247\001\n\021Generat" + "edCodeInfo\022A\n\nannotation\030\001 \003(\0132-.google." + "protobuf.GeneratedCodeInfo.Annotation\032O\n" + "\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_" + "file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B~" + "\n\023com.google.protobufB\020DescriptorProtosH" + "\001Z-google.golang.org/protobuf/types/desc" + "riptorpb\370\001\001\242\002\003GPB\252\002\032Google.Protobuf.Refl" + "ection" ; static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once; const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = { - false, false, 6028, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, "google/protobuf/descriptor.proto", + false, false, 6046, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, "google/protobuf/descriptor.proto", &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, nullptr, 0, 27, schemas, file_default_instances, TableStruct_google_2fprotobuf_2fdescriptor_2eproto::offsets, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto, file_level_service_descriptors_google_2fprotobuf_2fdescriptor_2eproto, @@ -1289,7 +1290,6 @@ const char* FileDescriptorSet::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.FileDescriptorProto file = 1; case 1: @@ -1305,7 +1305,8 @@ const char* FileDescriptorSet::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1589,7 +1590,6 @@ const char* FileDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -1734,7 +1734,8 @@ const char* FileDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -2177,7 +2178,6 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* ptr, ::PR while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: @@ -2204,7 +2204,8 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* ptr, ::PR continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -2455,7 +2456,6 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* ptr, ::PRO while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: @@ -2475,7 +2475,8 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* ptr, ::PRO continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -2745,7 +2746,6 @@ const char* DescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -2867,7 +2867,8 @@ const char* DescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -3229,7 +3230,6 @@ const char* ExtensionRangeOptions::_InternalParse(const char* ptr, ::PROTOBUF_NA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: @@ -3245,7 +3245,8 @@ const char* ExtensionRangeOptions::_InternalParse(const char* ptr, ::PROTOBUF_NA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -3564,7 +3565,6 @@ const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -3678,7 +3678,8 @@ const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -4103,7 +4104,6 @@ const char* OneofDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -4125,7 +4125,8 @@ const char* OneofDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -4359,7 +4360,6 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* pt while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: @@ -4379,7 +4379,8 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* pt continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -4634,7 +4635,6 @@ const char* EnumDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -4696,7 +4696,8 @@ const char* EnumDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -5009,7 +5010,6 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -5039,7 +5039,8 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -5314,7 +5315,6 @@ const char* ServiceDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_N while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -5348,7 +5348,8 @@ const char* ServiceDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_N continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -5657,7 +5658,6 @@ const char* MethodDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -5717,7 +5717,8 @@ const char* MethodDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -6200,7 +6201,6 @@ const char* FileOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string java_package = 1; case 1: @@ -6410,7 +6410,8 @@ const char* FileOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7016,7 +7017,6 @@ const char* MessageOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool message_set_wire_format = 1 [default = false]; case 1: @@ -7064,7 +7064,8 @@ const char* MessageOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7372,7 +7373,6 @@ const char* FieldOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; case 1: @@ -7444,7 +7444,8 @@ const char* FieldOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7749,7 +7750,6 @@ const char* OneofOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: @@ -7765,7 +7765,8 @@ const char* OneofOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7986,7 +7987,6 @@ const char* EnumOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool allow_alias = 2; case 2: @@ -8018,7 +8018,8 @@ const char* EnumOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -8273,7 +8274,6 @@ const char* EnumValueOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool deprecated = 1 [default = false]; case 1: @@ -8297,7 +8297,8 @@ const char* EnumValueOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -8527,7 +8528,6 @@ const char* ServiceOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool deprecated = 33 [default = false]; case 33: @@ -8551,7 +8551,8 @@ const char* ServiceOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -8794,7 +8795,6 @@ const char* MethodOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool deprecated = 33 [default = false]; case 33: @@ -8830,7 +8830,8 @@ const char* MethodOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -9098,7 +9099,6 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* ptr, ::PROT while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // required string name_part = 1; case 1: @@ -9121,7 +9121,8 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* ptr, ::PROT continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -9412,7 +9413,6 @@ const char* UninterpretedOption::_InternalParse(const char* ptr, ::PROTOBUF_NAME while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; case 2: @@ -9482,7 +9482,8 @@ const char* UninterpretedOption::_InternalParse(const char* ptr, ::PROTOBUF_NAME continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -9822,7 +9823,6 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* ptr, ::PROTOBUF_ while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated int32 path = 1 [packed = true]; case 1: @@ -9884,7 +9884,8 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* ptr, ::PROTOBUF_ continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -10169,7 +10170,6 @@ const char* SourceCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.SourceCodeInfo.Location location = 1; case 1: @@ -10185,7 +10185,8 @@ const char* SourceCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -10400,7 +10401,6 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* ptr, ::PROT while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated int32 path = 1 [packed = true]; case 1: @@ -10441,7 +10441,8 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* ptr, ::PROT continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -10698,7 +10699,6 @@ const char* GeneratedCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; case 1: @@ -10714,7 +10714,8 @@ const char* GeneratedCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 9f0ce6cde0..69c75208ee 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -496,6 +496,8 @@ message MessageOptions { // this is a formalization for deprecating messages. optional bool deprecated = 3 [default = false]; + reserved 4, 5, 6; + // Whether the message is an automatically generated map entry type for the // maps field. // diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index d00883ddb8..01cd8d75b3 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -140,7 +140,6 @@ const char* Duration::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // int64 seconds = 1; case 1: @@ -158,7 +157,8 @@ const char* Duration::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index c86d5f2be5..b2149abb7b 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -125,8 +125,8 @@ const char* Empty::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index d368693b9e..5890bb2c70 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -131,7 +131,6 @@ const char* FieldMask::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated string paths = 1; case 1: @@ -149,7 +148,8 @@ const char* FieldMask::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index 2b20e0a5ce..a318da404a 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -951,6 +951,26 @@ uint8* CodedOutputStream::WriteStringWithSizeToArray(const std::string& str, return WriteStringToArray(str, target); } +uint8* CodedOutputStream::WriteVarint32ToArrayOutOfLineHelper(uint32 value, + uint8* target) { + GOOGLE_DCHECK_GE(value, 0x80); + target[0] |= static_cast(0x80); + value >>= 7; + target[1] = static_cast(value); + if (value < 0x80) { + return target + 2; + } + target += 2; + do { + // Turn on continuation bit in the byte we just wrote. + target[-1] |= static_cast(0x80); + value >>= 7; + *target = static_cast(value); + ++target; + } while (value >= 0x80); + return target; +} + } // namespace io } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 97626f74a3..5ce3ce06f4 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -904,23 +904,25 @@ class PROTOBUF_EXPORT EpsCopyOutputStream { PROTOBUF_ALWAYS_INLINE static uint8* UnsafeVarint(T value, uint8* ptr) { static_assert(std::is_unsigned::value, "Varint serialization must be unsigned"); + ptr[0] = static_cast(value); if (value < 0x80) { - ptr[0] = static_cast(value); return ptr + 1; } - ptr[0] = static_cast(value | 0x80); + // Turn on continuation bit in the byte we just wrote. + ptr[0] |= static_cast(0x80); value >>= 7; + ptr[1] = static_cast(value); if (value < 0x80) { - ptr[1] = static_cast(value); return ptr + 2; } - ptr++; + ptr += 2; do { - *ptr = static_cast(value | 0x80); + // Turn on continuation bit in the byte we just wrote. + ptr[-1] |= static_cast(0x80); value >>= 7; + *ptr = static_cast(value); ++ptr; - } while (PROTOBUF_PREDICT_FALSE(value >= 0x80)); - *ptr++ = static_cast(value); + } while (value >= 0x80); return ptr; } @@ -1149,6 +1151,9 @@ class PROTOBUF_EXPORT CodedOutputStream { void WriteVarint32(uint32 value); // Like WriteVarint32() but writing directly to the target array. static uint8* WriteVarint32ToArray(uint32 value, uint8* target); + // Like WriteVarint32() but writing directly to the target array, and with the + // less common-case paths being out of line rather than inlined. + static uint8* WriteVarint32ToArrayOutOfLine(uint32 value, uint8* target); // Write an unsigned integer with Varint encoding. void WriteVarint64(uint64 value); // Like WriteVarint64() but writing directly to the target array. @@ -1263,6 +1268,8 @@ class PROTOBUF_EXPORT CodedOutputStream { static void SetDefaultSerializationDeterministic() { default_serialization_deterministic_.store(true, std::memory_order_relaxed); } + // REQUIRES: value >= 0x80, and that (value & 7f) has been written to *target. + static uint8* WriteVarint32ToArrayOutOfLineHelper(uint32 value, uint8* target); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); }; @@ -1593,6 +1600,16 @@ inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value, return EpsCopyOutputStream::UnsafeVarint(value, target); } +inline uint8* CodedOutputStream::WriteVarint32ToArrayOutOfLine(uint32 value, + uint8* target) { + target[0] = static_cast(value); + if (value < 0x80) { + return target + 1; + } else { + return WriteVarint32ToArrayOutOfLineHelper(value, target); + } +} + inline uint8* CodedOutputStream::WriteVarint64ToArray(uint64 value, uint8* target) { return EpsCopyOutputStream::UnsafeVarint(value, target); diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index 003f1fe859..0d97d407f1 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -661,5 +661,37 @@ TEST(MESSAGE_TEST_NAME, MOMIParserEdgeCases) { } +TEST(MESSAGE_TEST_NAME, CheckSerializationWhenInterleavedExtensions) { + UNITTEST::TestExtensionRangeSerialize in_message; + + in_message.set_foo_one(1); + in_message.set_foo_two(2); + in_message.set_foo_three(3); + in_message.set_foo_four(4); + + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_one, 1); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_two, 2); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_three, 3); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_four, 4); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_five, 5); + + std::string buffer; + in_message.SerializeToString(&buffer); + + UNITTEST::TestExtensionRangeSerialize out_message; + out_message.ParseFromString(buffer); + + EXPECT_EQ(1, out_message.foo_one()); + EXPECT_EQ(2, out_message.foo_two()); + EXPECT_EQ(3, out_message.foo_three()); + EXPECT_EQ(4, out_message.foo_four()); + + EXPECT_EQ(1, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_one)); + EXPECT_EQ(2, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_two)); + EXPECT_EQ(3, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_three)); + EXPECT_EQ(4, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_four)); + EXPECT_EQ(5, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_five)); +} + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 8143af8d8b..e141c43439 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -326,6 +326,18 @@ const char* EpsCopyInputStream::InitFrom(io::ZeroCopyInputStream* zcis) { return buffer_; } +const char* ParseContext::ReadSizeAndPushLimitAndDepth(const char* ptr, + int* old_limit) { + int size = ReadSize(&ptr); + if (PROTOBUF_PREDICT_FALSE(!ptr)) { + *old_limit = 0; // Make sure this isn't uninitialized even on error return + return nullptr; + } + *old_limit = PushLimit(ptr, size); + if (--depth_ < 0) return nullptr; + return ptr; +} + const char* ParseContext::ParseMessage(MessageLite* msg, const char* ptr) { return ParseMessage(msg, ptr); } diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 7966d99d57..b8e16446b5 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -413,6 +413,17 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { } private: + // Out-of-line routine to save space in ParseContext::ParseMessage + // int old; + // ptr = ReadSizeAndPushLimitAndDepth(ptr, &old) + // is equivalent to: + // int size = ReadSize(&ptr); + // if (!ptr) return nullptr; + // int old = PushLimit(ptr, size); + // if (--depth_ < 0) return nullptr; + PROTOBUF_MUST_USE_RESULT const char* ReadSizeAndPushLimitAndDepth( + const char* ptr, int* old_limit); + // The context keeps an internal stack to keep track of the recursive // part of the parse state. // Current depth of the active parser, depth counts down. @@ -640,12 +651,9 @@ inline int32 ReadVarintZigZag32(const char** p) { template PROTOBUF_MUST_USE_RESULT const char* ParseContext::ParseMessage( T* msg, const char* ptr) { - int size = ReadSize(&ptr); - if (!ptr) return nullptr; - auto old = PushLimit(ptr, size); - if (--depth_ < 0) return nullptr; - ptr = msg->_InternalParse(ptr, this); - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) return nullptr; + int old; + ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); + ptr = ptr ? msg->_InternalParse(ptr, this) : nullptr; depth_++; if (!PopLimit(old)) return nullptr; return ptr; diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 43ca45844b..58190e3d85 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -221,6 +221,10 @@ class RepeatedField final { void MergeFrom(const RepeatedField& other); void CopyFrom(const RepeatedField& other); + // Replaces the contents with RepeatedField(begin, end). + template + void Assign(Iter begin, Iter end); + // Reserve space to expand the field to at least the given size. If the // array is grown, it will always be at least doubled in size. void Reserve(int new_size); @@ -765,8 +769,9 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { int)); template - void MergeFromInnerLoop(void** our_elems, void** other_elems, int length, - int already_allocated); + PROTOBUF_NOINLINE void MergeFromInnerLoop(void** our_elems, + void** other_elems, int length, + int already_allocated); // Internal helper: extend array space if necessary to contain |extend_amount| // more elements, and return a pointer to the element immediately following @@ -953,6 +958,10 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { Element* Mutable(int index); Element* Add(); void Add(Element&& value); + // Append elements in the range [begin, end) after reserving + // the appropriate number of elements. + template + void Add(Iter begin, Iter end); const Element& operator[](int index) const { return Get(index); } Element& operator[](int index) { return *Mutable(index); } @@ -973,6 +982,10 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { void MergeFrom(const RepeatedPtrField& other); void CopyFrom(const RepeatedPtrField& other); + // Replaces the contents with RepeatedPtrField(begin, end). + template + void Assign(Iter begin, Iter end); + // Reserve space to expand the field to at least the given size. This only // resizes the pointer array; it doesn't allocate any objects. If the // array is grown, it will always be at least doubled in size. @@ -1447,6 +1460,13 @@ inline void RepeatedField::CopyFrom(const RepeatedField& other) { MergeFrom(other); } +template +template +inline void RepeatedField::Assign(Iter begin, Iter end) { + Clear(); + Add(begin, end); +} + template inline typename RepeatedField::iterator RepeatedField::erase( const_iterator position) { @@ -2122,13 +2142,7 @@ inline RepeatedPtrField::RepeatedPtrField( template template inline RepeatedPtrField::RepeatedPtrField(Iter begin, Iter end) { - int reserve = internal::CalculateReserve(begin, end); - if (reserve != -1) { - Reserve(reserve); - } - for (; begin != end; ++begin) { - *Add() = *begin; - } + Add(begin, end); } template @@ -2213,6 +2227,18 @@ inline void RepeatedPtrField::Add(Element&& value) { RepeatedPtrFieldBase::Add(std::move(value)); } +template +template +inline void RepeatedPtrField::Add(Iter begin, Iter end) { + int reserve = internal::CalculateReserve(begin, end); + if (reserve != -1) { + Reserve(size() + reserve); + } + for (; begin != end; ++begin) { + *Add() = *begin; + } +} + template inline void RepeatedPtrField::RemoveLast() { RepeatedPtrFieldBase::RemoveLast(); @@ -2319,6 +2345,13 @@ inline void RepeatedPtrField::CopyFrom(const RepeatedPtrField& other) { RepeatedPtrFieldBase::CopyFrom(other); } +template +template +inline void RepeatedPtrField::Assign(Iter begin, Iter end) { + Clear(); + Add(begin, end); +} + template inline typename RepeatedPtrField::iterator RepeatedPtrField::erase(const_iterator position) { diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index a396b619f2..f3e8c2d5fa 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -488,6 +488,30 @@ TEST(RepeatedField, AddRange5) { ASSERT_EQ(me.Get(1), 2); } +TEST(RepeatedField, AddAndAssignRanges) { + RepeatedField field; + + int vals[] = {2, 27, 2875, 609250}; + field.Assign(std::begin(vals), std::end(vals)); + + ASSERT_EQ(field.size(), 4); + EXPECT_EQ(field.Get(0), 2); + EXPECT_EQ(field.Get(1), 27); + EXPECT_EQ(field.Get(2), 2875); + EXPECT_EQ(field.Get(3), 609250); + + field.Add(std::begin(vals), std::end(vals)); + ASSERT_EQ(field.size(), 8); + EXPECT_EQ(field.Get(0), 2); + EXPECT_EQ(field.Get(1), 27); + EXPECT_EQ(field.Get(2), 2875); + EXPECT_EQ(field.Get(3), 609250); + EXPECT_EQ(field.Get(4), 2); + EXPECT_EQ(field.Get(5), 27); + EXPECT_EQ(field.Get(6), 2875); + EXPECT_EQ(field.Get(7), 609250); +} + TEST(RepeatedField, CopyConstruct) { RepeatedField source; source.Add(1); @@ -837,6 +861,45 @@ TEST(RepeatedPtrField, ConstInit) { EXPECT_TRUE(field.empty()); } +// This helper overload set tests whether X::f can be called with a braced pair, +// X::f({a, b}) of std::string iterators (specifically, pointers: That call is +// ambiguous if and only if the call to ValidResolutionPointerRange is not. +template +auto ValidResolutionPointerRange(const std::string* p) + -> decltype(X::f({p, p + 2}), std::true_type{}); +template +std::false_type ValidResolutionPointerRange(void*); + +TEST(RepeatedPtrField, UnambiguousConstructor) { + struct X { + static bool f(std::vector) { return false; } + static bool f(google::protobuf::RepeatedPtrField) { return true; } + + static bool g(std::vector) { return false; } + static bool g(google::protobuf::RepeatedPtrField) { return true; } + }; + + // RepeatedPtrField has no initializer-list constructor, and a constructor + // from to const char* values is excluded by its constraints. + EXPECT_FALSE(X::f({"abc", "xyz"})); + + // Construction from a pair of int* is also not ambiguous. + int a[5] = {}; + EXPECT_FALSE(X::g({a, a + 5})); + + // Construction from string iterators for the unique string overload "g" + // works. + std::string b[2] = {"abc", "xyz"}; + // Disabling this for now, this is actually ambiguous with libstdc++. + // EXPECT_TRUE(X::g({b, b + 2})); + + // Construction from string iterators for "f" is ambiguous, since both + // containers are equally good. + // + // X::f({b, b + 2}); // error => ValidResolutionPointerRange is unambiguous. + EXPECT_FALSE(decltype(ValidResolutionPointerRange(nullptr))::value); +} + TEST(RepeatedPtrField, Small) { RepeatedPtrField field; @@ -899,6 +962,30 @@ TEST(RepeatedPtrField, Large) { EXPECT_GE(field.SpaceUsedExcludingSelf(), min_expected_usage); } +TEST(RepeatedPtrField, AddAndAssignRanges) { + RepeatedPtrField field; + + const char* vals[] = {"abc", "x", "yz", "xyzzy"}; + field.Assign(std::begin(vals), std::end(vals)); + + ASSERT_EQ(field.size(), 4); + EXPECT_EQ(field.Get(0), "abc"); + EXPECT_EQ(field.Get(1), "x"); + EXPECT_EQ(field.Get(2), "yz"); + EXPECT_EQ(field.Get(3), "xyzzy"); + + field.Add(std::begin(vals), std::end(vals)); + ASSERT_EQ(field.size(), 8); + EXPECT_EQ(field.Get(0), "abc"); + EXPECT_EQ(field.Get(1), "x"); + EXPECT_EQ(field.Get(2), "yz"); + EXPECT_EQ(field.Get(3), "xyzzy"); + EXPECT_EQ(field.Get(4), "abc"); + EXPECT_EQ(field.Get(5), "x"); + EXPECT_EQ(field.Get(6), "yz"); + EXPECT_EQ(field.Get(7), "xyzzy"); +} + TEST(RepeatedPtrField, SwapSmallSmall) { RepeatedPtrField field1; RepeatedPtrField field2; diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index aed802b473..3994ceba89 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -136,7 +136,6 @@ const char* SourceContext::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string file_name = 1; case 1: @@ -149,7 +148,8 @@ const char* SourceContext::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 7f461f1904..fbe98e786d 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -241,7 +241,6 @@ const char* Struct::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // map fields = 1; case 1: @@ -257,7 +256,8 @@ const char* Struct::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -582,7 +582,6 @@ const char* Value::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // .google.protobuf.NullValue null_value = 1; case 1: @@ -631,7 +630,8 @@ const char* Value::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -911,7 +911,6 @@ const char* ListValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.Value values = 1; case 1: @@ -927,7 +926,8 @@ const char* ListValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 1ca2e71d92..a3040a62b3 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -140,7 +140,6 @@ const char* Timestamp::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // int64 seconds = 1; case 1: @@ -158,7 +157,8 @@ const char* Timestamp::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index cff9744773..024b277519 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -430,7 +430,6 @@ const char* Type::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -496,7 +495,8 @@ const char* Type::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -815,7 +815,6 @@ const char* Field::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // .google.protobuf.Field.Kind kind = 1; case 1: @@ -904,7 +903,8 @@ const char* Field::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1289,7 +1289,6 @@ const char* Enum::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1341,7 +1340,8 @@ const char* Enum::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1609,7 +1609,6 @@ const char* EnumValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1641,7 +1640,8 @@ const char* EnumValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1885,7 +1885,6 @@ const char* Option::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1905,7 +1904,8 @@ const char* Option::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index a4d5045710..75b65f0249 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -1115,3 +1115,33 @@ enum VeryLargeEnum { ENUM_LABEL_99 = 99; ENUM_LABEL_100 = 100; }; + +message TestExtensionRangeSerialize { + optional int32 foo_one = 1; + + extensions 2 to 2; + extensions 3 to 4; + + optional int32 foo_two = 6; + optional int32 foo_three = 7; + + extensions 9 to 10; + + optional int32 foo_four = 13; + + extensions 15 to 15; + extensions 17 to 17; + extensions 19 to 19; + + extend TestExtensionRangeSerialize { + optional int32 bar_one = 2; + optional int32 bar_two = 4; + + optional int32 bar_three = 10; + + optional int32 bar_four = 15; + optional int32 bar_five = 19; + } +} + + diff --git a/src/google/protobuf/util/field_comparator.cc b/src/google/protobuf/util/field_comparator.cc index 54abcd43a4..46d5dbaf3d 100644 --- a/src/google/protobuf/util/field_comparator.cc +++ b/src/google/protobuf/util/field_comparator.cc @@ -48,14 +48,14 @@ namespace util { FieldComparator::FieldComparator() {} FieldComparator::~FieldComparator() {} -DefaultFieldComparator::DefaultFieldComparator() +SimpleFieldComparator::SimpleFieldComparator() : float_comparison_(EXACT), treat_nan_as_equal_(false), has_default_tolerance_(false) {} -DefaultFieldComparator::~DefaultFieldComparator() {} +SimpleFieldComparator::~SimpleFieldComparator() {} -FieldComparator::ComparisonResult DefaultFieldComparator::Compare( +FieldComparator::ComparisonResult SimpleFieldComparator::SimpleCompare( const Message& message_1, const Message& message_2, const FieldDescriptor* field, int index_1, int index_2, const util::FieldContext* field_context) { @@ -127,23 +127,22 @@ FieldComparator::ComparisonResult DefaultFieldComparator::Compare( } } -bool DefaultFieldComparator::Compare(MessageDifferencer* differencer, - const Message& message1, - const Message& message2, - const util::FieldContext* field_context) { +bool SimpleFieldComparator::CompareWithDifferencer( + MessageDifferencer* differencer, const Message& message1, + const Message& message2, const util::FieldContext* field_context) { return differencer->Compare(message1, message2, field_context->parent_fields()); } -void DefaultFieldComparator::SetDefaultFractionAndMargin(double fraction, - double margin) { +void SimpleFieldComparator::SetDefaultFractionAndMargin(double fraction, + double margin) { default_tolerance_ = Tolerance(fraction, margin); has_default_tolerance_ = true; } -void DefaultFieldComparator::SetFractionAndMargin(const FieldDescriptor* field, - double fraction, - double margin) { +void SimpleFieldComparator::SetFractionAndMargin(const FieldDescriptor* field, + double fraction, + double margin) { GOOGLE_CHECK(FieldDescriptor::CPPTYPE_FLOAT == field->cpp_type() || FieldDescriptor::CPPTYPE_DOUBLE == field->cpp_type()) << "Field has to be float or double type. Field name is: " @@ -151,25 +150,25 @@ void DefaultFieldComparator::SetFractionAndMargin(const FieldDescriptor* field, map_tolerance_[field] = Tolerance(fraction, margin); } -bool DefaultFieldComparator::CompareDouble(const FieldDescriptor& field, - double value_1, double value_2) { +bool SimpleFieldComparator::CompareDouble(const FieldDescriptor& field, + double value_1, double value_2) { return CompareDoubleOrFloat(field, value_1, value_2); } -bool DefaultFieldComparator::CompareEnum(const FieldDescriptor& field, - const EnumValueDescriptor* value_1, - const EnumValueDescriptor* value_2) { +bool SimpleFieldComparator::CompareEnum(const FieldDescriptor& field, + const EnumValueDescriptor* value_1, + const EnumValueDescriptor* value_2) { return value_1->number() == value_2->number(); } -bool DefaultFieldComparator::CompareFloat(const FieldDescriptor& field, - float value_1, float value_2) { +bool SimpleFieldComparator::CompareFloat(const FieldDescriptor& field, + float value_1, float value_2) { return CompareDoubleOrFloat(field, value_1, value_2); } template -bool DefaultFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, - T value_1, T value_2) { +bool SimpleFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, + T value_1, T value_2) { if (value_1 == value_2) { // Covers +inf and -inf (which are not within margin or fraction of // themselves), and is a shortcut for finite values. @@ -201,7 +200,7 @@ bool DefaultFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, } } -FieldComparator::ComparisonResult DefaultFieldComparator::ResultFromBoolean( +FieldComparator::ComparisonResult SimpleFieldComparator::ResultFromBoolean( bool boolean_result) const { return boolean_result ? FieldComparator::SAME : FieldComparator::DIFFERENT; } diff --git a/src/google/protobuf/util/field_comparator.h b/src/google/protobuf/util/field_comparator.h index 9058bbef15..7ad715b201 100644 --- a/src/google/protobuf/util/field_comparator.h +++ b/src/google/protobuf/util/field_comparator.h @@ -33,12 +33,12 @@ #ifndef GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__ #define GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__ +#include #include #include #include #include - #include namespace google { @@ -97,7 +97,7 @@ class PROTOBUF_EXPORT FieldComparator { // Basic implementation of FieldComparator. Supports three modes of floating // point value comparison: exact, approximate using MathUtil::AlmostEqual // method, and arbitrarily precise using MathUtil::WithinFractionOrMargin. -class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { +class PROTOBUF_EXPORT SimpleFieldComparator : public FieldComparator { public: enum FloatComparison { EXACT, // Floats and doubles are compared exactly. @@ -109,14 +109,9 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { }; // Creates new comparator with float comparison set to EXACT. - DefaultFieldComparator(); - - ~DefaultFieldComparator() override; + SimpleFieldComparator(); - ComparisonResult Compare(const Message& message_1, const Message& message_2, - const FieldDescriptor* field, int index_1, - int index_2, - const util::FieldContext* field_context) override; + ~SimpleFieldComparator() override; void set_float_comparison(FloatComparison float_comparison) { float_comparison_ = float_comparison; @@ -151,12 +146,32 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { void SetDefaultFractionAndMargin(double fraction, double margin); protected: + // NOTE: this will go away. + ComparisonResult Compare(const Message& message_1, const Message& message_2, + const FieldDescriptor* field, int index_1, + int index_2, + const util::FieldContext* field_context) override { + return SimpleCompare(message_1, message_2, field, index_1, index_2, + field_context); + } + + // Returns the comparison result for the given field in two messages. + // + // This function is called directly by DefaultFieldComparator::Compare. + // Subclasses can call this function to compare fields they do not need to + // handle specially. + ComparisonResult SimpleCompare(const Message& message_1, + const Message& message_2, + const FieldDescriptor* field, int index_1, + int index_2, + const util::FieldContext* field_context); + // Compare using the provided message_differencer. For example, a subclass can // use this method to compare some field in a certain way using the same // message_differencer instance and the field context. - bool Compare(MessageDifferencer* differencer, const Message& message1, - const Message& message2, - const util::FieldContext* field_context); + bool CompareWithDifferencer(MessageDifferencer* differencer, + const Message& message1, const Message& message2, + const util::FieldContext* field_context); private: // Defines the tolerance for floating point comparison (fraction and margin). @@ -193,13 +208,13 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { // CompareFloat. bool CompareFloat(const FieldDescriptor& field, float value_1, float value_2); - bool CompareInt32(const FieldDescriptor& /* unused */, int32 value_1, - int32 value_2) { + bool CompareInt32(const FieldDescriptor& /* unused */, int32_t value_1, + int32_t value_2) { return value_1 == value_2; } - bool CompareInt64(const FieldDescriptor& /* unused */, int64 value_1, - int64 value_2) { + bool CompareInt64(const FieldDescriptor& /* unused */, int64_t value_1, + int64_t value_2) { return value_1 == value_2; } @@ -208,13 +223,13 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { return value_1 == value_2; } - bool CompareUInt32(const FieldDescriptor& /* unused */, uint32 value_1, - uint32 value_2) { + bool CompareUInt32(const FieldDescriptor& /* unused */, uint32_t value_1, + uint32_t value_2) { return value_1 == value_2; } - bool CompareUInt64(const FieldDescriptor& /* unused */, uint64 value_1, - uint64 value_2) { + bool CompareUInt64(const FieldDescriptor& /* unused */, uint64_t value_1, + uint64_t value_2) { return value_1 == value_2; } @@ -249,7 +264,19 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { // those particular fields. ToleranceMap map_tolerance_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DefaultFieldComparator); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleFieldComparator); +}; + +// Default field comparison: use the basic implementation of FieldComparator. +class PROTOBUF_EXPORT DefaultFieldComparator : public SimpleFieldComparator { + public: + ComparisonResult Compare(const Message& message_1, const Message& message_2, + const FieldDescriptor* field, int index_1, + int index_2, + const util::FieldContext* field_context) override { + return SimpleCompare(message_1, message_2, field, index_1, index_2, + field_context); + } }; } // namespace util diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc index 23800181b4..c5f713f4c3 100644 --- a/src/google/protobuf/util/field_mask_util.cc +++ b/src/google/protobuf/util/field_mask_util.cc @@ -30,10 +30,13 @@ #include +#include + #include #include #include +// Must be included last. #include namespace google { @@ -552,7 +555,7 @@ void FieldMaskTree::MergeMessage(const Node* node, const Message& source, void FieldMaskTree::AddRequiredFieldPath(Node* node, const Descriptor* descriptor) { - const int32 field_count = descriptor->field_count(); + const int32_t field_count = descriptor->field_count(); for (int index = 0; index < field_count; ++index) { const FieldDescriptor* field = descriptor->field(index); if (field->is_required()) { @@ -589,7 +592,7 @@ bool FieldMaskTree::TrimMessage(const Node* node, Message* message) { GOOGLE_DCHECK(!node->children.empty()); const Reflection* reflection = message->GetReflection(); const Descriptor* descriptor = message->GetDescriptor(); - const int32 field_count = descriptor->field_count(); + const int32_t field_count = descriptor->field_count(); bool modified = false; for (int index = 0; index < field_count; ++index) { const FieldDescriptor* field = descriptor->field(index); diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h index 3ca93597c9..84cd1202ef 100644 --- a/src/google/protobuf/util/field_mask_util.h +++ b/src/google/protobuf/util/field_mask_util.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ #define GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ +#include #include #include @@ -58,7 +59,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // Populates the FieldMask with the paths corresponding to the fields with the // given numbers, after checking that all field numbers are valid. template - static void FromFieldNumbers(const std::vector& field_numbers, + static void FromFieldNumbers(const std::vector& field_numbers, FieldMask* out) { for (const auto field_number : field_numbers) { const FieldDescriptor* field_desc = diff --git a/src/google/protobuf/util/field_mask_util_test.cc b/src/google/protobuf/util/field_mask_util_test.cc index f639b32678..df5d087379 100644 --- a/src/google/protobuf/util/field_mask_util_test.cc +++ b/src/google/protobuf/util/field_mask_util_test.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -164,7 +165,7 @@ TEST(FieldMaskUtilTest, JsonStringFormat) { TEST(FieldMaskUtilTest, FromFieldNumbers) { FieldMask mask; - std::vector field_numbers = { + std::vector field_numbers = { TestAllTypes::kOptionalInt64FieldNumber, TestAllTypes::kOptionalBoolFieldNumber, TestAllTypes::kRepeatedStringFieldNumber, diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 9851cc5d7f..a736ea80bf 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -30,6 +30,7 @@ #include +#include #include #include @@ -524,7 +525,7 @@ class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { private: std::list segments_; Segment last_segment_; - int64 byte_count_; + int64_t byte_count_; }; // This test splits the output buffer and also the input data into multiple diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index 47e3031185..10fdc021a2 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -36,7 +36,9 @@ #include #include +#include #include +#include #include #include @@ -71,7 +73,7 @@ class NumDiffsReporter : public google::protobuf::util::MessageDifferencer::Repo NumDiffsReporter() : num_diffs_(0) {} // Returns the total number of diffs. - int32 GetNumDiffs() const { return num_diffs_; } + int32_t GetNumDiffs() const { return num_diffs_; } void Reset() { num_diffs_ = 0; } // Report that a field has been added into Message2. @@ -99,7 +101,7 @@ class NumDiffsReporter : public google::protobuf::util::MessageDifferencer::Repo } private: - int32 num_diffs_; + int32_t num_diffs_; }; // When comparing a repeated field as map, MultipleFieldMapKeyComparator can @@ -145,7 +147,7 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator int path_index) const { const FieldDescriptor* field = key_field_path[path_index]; std::vector current_parent_fields(parent_fields); - if (path_index == static_cast(key_field_path.size() - 1)) { + if (path_index == static_cast(key_field_path.size() - 1)) { if (field->is_repeated()) { if (!message_differencer_->CompareRepeatedField( message1, message2, field, ¤t_parent_fields)) { @@ -913,6 +915,11 @@ bool MessageDifferencer::CompareMapFieldByMapReflection( const Message& message1, const Message& message2, const FieldDescriptor* map_field, std::vector* parent_fields, DefaultFieldComparator* comparator) { + GOOGLE_DCHECK_EQ(nullptr, reporter_); + GOOGLE_DCHECK(map_field->is_map()); + GOOGLE_DCHECK(map_field_key_comparator_.find(map_field) == + map_field_key_comparator_.end()); + GOOGLE_DCHECK_EQ(repeated_field_comparison_, AS_LIST); const Reflection* reflection1 = message1.GetReflection(); const Reflection* reflection2 = message2.GetReflection(); const int count1 = reflection1->MapSize(message1, map_field); @@ -924,18 +931,28 @@ bool MessageDifferencer::CompareMapFieldByMapReflection( if (count1 > count2) { return false; } + + // First pass: check whether the same keys are present. + for (MapIterator it = reflection1->MapBegin(const_cast(&message1), + map_field), + it_end = reflection1->MapEnd(const_cast(&message1), + map_field); + it != it_end; ++it) { + if (!reflection2->ContainsMapKey(message2, map_field, it.GetKey())) { + return false; + } + } + + // Second pass: compare values for matching keys. const FieldDescriptor* val_des = map_field->message_type()->map_value(); switch (val_des->cpp_type()) { #define HANDLE_TYPE(CPPTYPE, METHOD, COMPAREMETHOD) \ case FieldDescriptor::CPPTYPE_##CPPTYPE: { \ for (MapIterator it = reflection1->MapBegin( \ - const_cast(&message1), map_field); \ - it != \ - reflection1->MapEnd(const_cast(&message1), map_field); \ - ++it) { \ - if (!reflection2->ContainsMapKey(message2, map_field, it.GetKey())) { \ - return false; \ - } \ + const_cast(&message1), map_field), \ + it_end = reflection1->MapEnd( \ + const_cast(&message1), map_field); \ + it != it_end; ++it) { \ MapValueConstRef value2; \ reflection2->LookupMapValue(message2, map_field, it.GetKey(), &value2); \ if (!comparator->Compare##COMPAREMETHOD(*val_des, \ @@ -1716,9 +1733,9 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( Reporter* reporter = reporter_; reporter_ = NULL; NumDiffsReporter num_diffs_reporter; - std::vector num_diffs_list1; + std::vector num_diffs_list1; if (is_treated_as_smart_set) { - num_diffs_list1.assign(count1, kint32max); + num_diffs_list1.assign(count1, std::numeric_limits::max()); } bool success = true; @@ -1786,7 +1803,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( } else if (repeated_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { // Replace with the one with fewer diffs. - const int32 num_diffs = num_diffs_reporter.GetNumDiffs(); + const int32_t num_diffs = num_diffs_reporter.GetNumDiffs(); if (num_diffs < num_diffs_list1[i]) { // If j has been already matched to some element, ensure the // current num_diffs is smaller. diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index 4f2983e9d1..57588b9e3d 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -708,7 +708,7 @@ class PROTOBUF_EXPORT MessageDifferencer { }; private: - friend class DefaultFieldComparator; + friend class SimpleFieldComparator; // A MapKeyComparator to be used in TreatAsMapUsingKeyComparator. // Implementation of this class needs to do field value comparison which diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index ada26552f4..fbbcd3c8be 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -3375,7 +3375,11 @@ TEST_F(ComparisonTest, MapEntryPartialEmptyKeyTest) { util::MessageDifferencer differencer; differencer.set_scope(util::MessageDifferencer::PARTIAL); - EXPECT_TRUE(differencer.Compare(map1, map2)); + // TODO(jieluo): Remove the round trip + std::string serialized_value; + map1.SerializeToString(&serialized_value); + map1.ParseFromString(serialized_value); + EXPECT_FALSE(differencer.Compare(map1, map2)); } TEST_F(ComparisonTest, MapEntryMissingEmptyFieldIsOkTest) { diff --git a/src/google/protobuf/util/time_util.cc b/src/google/protobuf/util/time_util.cc index 08c6e9c1d8..6b9c6654b6 100644 --- a/src/google/protobuf/util/time_util.cc +++ b/src/google/protobuf/util/time_util.cc @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -57,10 +59,10 @@ static const int kSecondsPerMinute = 60; // Note that we ignore leap seconds. static const int kSecondsPerHour = 3600; template -T CreateNormalized(int64 seconds, int64 nanos); +T CreateNormalized(int64_t seconds, int64_t nanos); template <> -Timestamp CreateNormalized(int64 seconds, int64 nanos) { +Timestamp CreateNormalized(int64_t seconds, int64_t nanos) { // Make sure nanos is in the range. if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { seconds += nanos / kNanosPerSecond; @@ -75,12 +77,12 @@ Timestamp CreateNormalized(int64 seconds, int64 nanos) { seconds <= TimeUtil::kTimestampMaxSeconds); Timestamp result; result.set_seconds(seconds); - result.set_nanos(static_cast(nanos)); + result.set_nanos(static_cast(nanos)); return result; } template <> -Duration CreateNormalized(int64 seconds, int64 nanos) { +Duration CreateNormalized(int64_t seconds, int64_t nanos) { // Make sure nanos is in the range. if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { seconds += nanos / kNanosPerSecond; @@ -98,13 +100,13 @@ Duration CreateNormalized(int64 seconds, int64 nanos) { seconds <= TimeUtil::kDurationMaxSeconds); Duration result; result.set_seconds(seconds); - result.set_nanos(static_cast(nanos)); + result.set_nanos(static_cast(nanos)); return result; } // Format nanoseconds with either 3, 6, or 9 digits depending on the required // precision to represent the exact value. -std::string FormatNanos(int32 nanos) { +std::string FormatNanos(int32_t nanos) { if (nanos % kNanosPerMillisecond == 0) { return StringPrintf("%03d", nanos / kNanosPerMillisecond); } else if (nanos % kNanosPerMicrosecond == 0) { @@ -127,9 +129,9 @@ void CurrentTime(int64* seconds, int32* nanos) { } // Truncates the remainder part after division. -int64 RoundTowardZero(int64 value, int64 divider) { - int64 result = value / divider; - int64 remainder = value % divider; +int64_t RoundTowardZero(int64_t value, int64_t divider) { + int64_t result = value / divider; + int64_t remainder = value % divider; // Before C++11, the sign of the remainder is implementation dependent if // any of the operands is negative. Here we try to enforce C++11's "rounded // toward zero" semantics. For example, for (-5) / 2 an implementation may @@ -146,10 +148,10 @@ int64 RoundTowardZero(int64 value, int64 divider) { // Actually define these static const integers. Required by C++ standard (but // some compilers don't like it). #ifndef _MSC_VER -const int64 TimeUtil::kTimestampMinSeconds; -const int64 TimeUtil::kTimestampMaxSeconds; -const int64 TimeUtil::kDurationMaxSeconds; -const int64 TimeUtil::kDurationMinSeconds; +const int64_t TimeUtil::kTimestampMinSeconds; +const int64_t TimeUtil::kTimestampMaxSeconds; +const int64_t TimeUtil::kDurationMaxSeconds; +const int64_t TimeUtil::kDurationMinSeconds; #endif // !_MSC_VER std::string TimeUtil::ToString(const Timestamp& timestamp) { @@ -157,8 +159,8 @@ std::string TimeUtil::ToString(const Timestamp& timestamp) { } bool TimeUtil::FromString(const std::string& value, Timestamp* timestamp) { - int64 seconds; - int32 nanos; + int64_t seconds; + int32_t nanos; if (!ParseTime(value, &seconds, &nanos)) { return false; } @@ -167,8 +169,8 @@ bool TimeUtil::FromString(const std::string& value, Timestamp* timestamp) { } Timestamp TimeUtil::GetCurrentTime() { - int64 seconds; - int32 nanos; + int64_t seconds; + int32_t nanos; CurrentTime(&seconds, &nanos); return CreateNormalized(seconds, nanos); } @@ -177,8 +179,8 @@ Timestamp TimeUtil::GetEpoch() { return Timestamp(); } std::string TimeUtil::ToString(const Duration& duration) { std::string result; - int64 seconds = duration.seconds(); - int32 nanos = duration.nanos(); + int64_t seconds = duration.seconds(); + int32_t nanos = duration.nanos(); if (seconds < 0 || nanos < 0) { result += "-"; seconds = -seconds; @@ -192,8 +194,8 @@ std::string TimeUtil::ToString(const Duration& duration) { return result; } -static int64 Pow(int64 x, int y) { - int64 result = 1; +static int64_t Pow(int64_t x, int y) { + int64_t result = 1; for (int i = 0; i < y; ++i) { result *= x; } @@ -218,11 +220,11 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) { nanos_part = value.substr(pos + 1, value.length() - pos - 2); } char* end; - int64 seconds = strto64(seconds_part.c_str(), &end, 10); + int64_t seconds = strto64(seconds_part.c_str(), &end, 10); if (end != seconds_part.c_str() + seconds_part.length()) { return false; } - int64 nanos = strto64(nanos_part.c_str(), &end, 10); + int64_t nanos = strto64(nanos_part.c_str(), &end, 10); if (end != nanos_part.c_str() + nanos_part.length()) { return false; } @@ -233,106 +235,106 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) { nanos = -nanos; } duration->set_seconds(seconds); - duration->set_nanos(static_cast(nanos)); + duration->set_nanos(static_cast(nanos)); return true; } -Duration TimeUtil::NanosecondsToDuration(int64 nanos) { +Duration TimeUtil::NanosecondsToDuration(int64_t nanos) { return CreateNormalized(nanos / kNanosPerSecond, nanos % kNanosPerSecond); } -Duration TimeUtil::MicrosecondsToDuration(int64 micros) { +Duration TimeUtil::MicrosecondsToDuration(int64_t micros) { return CreateNormalized( micros / kMicrosPerSecond, (micros % kMicrosPerSecond) * kNanosPerMicrosecond); } -Duration TimeUtil::MillisecondsToDuration(int64 millis) { +Duration TimeUtil::MillisecondsToDuration(int64_t millis) { return CreateNormalized( millis / kMillisPerSecond, (millis % kMillisPerSecond) * kNanosPerMillisecond); } -Duration TimeUtil::SecondsToDuration(int64 seconds) { +Duration TimeUtil::SecondsToDuration(int64_t seconds) { return CreateNormalized(seconds, 0); } -Duration TimeUtil::MinutesToDuration(int64 minutes) { +Duration TimeUtil::MinutesToDuration(int64_t minutes) { return CreateNormalized(minutes * kSecondsPerMinute, 0); } -Duration TimeUtil::HoursToDuration(int64 hours) { +Duration TimeUtil::HoursToDuration(int64_t hours) { return CreateNormalized(hours * kSecondsPerHour, 0); } -int64 TimeUtil::DurationToNanoseconds(const Duration& duration) { +int64_t TimeUtil::DurationToNanoseconds(const Duration& duration) { return duration.seconds() * kNanosPerSecond + duration.nanos(); } -int64 TimeUtil::DurationToMicroseconds(const Duration& duration) { +int64_t TimeUtil::DurationToMicroseconds(const Duration& duration) { return duration.seconds() * kMicrosPerSecond + RoundTowardZero(duration.nanos(), kNanosPerMicrosecond); } -int64 TimeUtil::DurationToMilliseconds(const Duration& duration) { +int64_t TimeUtil::DurationToMilliseconds(const Duration& duration) { return duration.seconds() * kMillisPerSecond + RoundTowardZero(duration.nanos(), kNanosPerMillisecond); } -int64 TimeUtil::DurationToSeconds(const Duration& duration) { +int64_t TimeUtil::DurationToSeconds(const Duration& duration) { return duration.seconds(); } -int64 TimeUtil::DurationToMinutes(const Duration& duration) { +int64_t TimeUtil::DurationToMinutes(const Duration& duration) { return RoundTowardZero(duration.seconds(), kSecondsPerMinute); } -int64 TimeUtil::DurationToHours(const Duration& duration) { +int64_t TimeUtil::DurationToHours(const Duration& duration) { return RoundTowardZero(duration.seconds(), kSecondsPerHour); } -Timestamp TimeUtil::NanosecondsToTimestamp(int64 nanos) { +Timestamp TimeUtil::NanosecondsToTimestamp(int64_t nanos) { return CreateNormalized(nanos / kNanosPerSecond, nanos % kNanosPerSecond); } -Timestamp TimeUtil::MicrosecondsToTimestamp(int64 micros) { +Timestamp TimeUtil::MicrosecondsToTimestamp(int64_t micros) { return CreateNormalized( micros / kMicrosPerSecond, micros % kMicrosPerSecond * kNanosPerMicrosecond); } -Timestamp TimeUtil::MillisecondsToTimestamp(int64 millis) { +Timestamp TimeUtil::MillisecondsToTimestamp(int64_t millis) { return CreateNormalized( millis / kMillisPerSecond, millis % kMillisPerSecond * kNanosPerMillisecond); } -Timestamp TimeUtil::SecondsToTimestamp(int64 seconds) { +Timestamp TimeUtil::SecondsToTimestamp(int64_t seconds) { return CreateNormalized(seconds, 0); } -int64 TimeUtil::TimestampToNanoseconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToNanoseconds(const Timestamp& timestamp) { return timestamp.seconds() * kNanosPerSecond + timestamp.nanos(); } -int64 TimeUtil::TimestampToMicroseconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToMicroseconds(const Timestamp& timestamp) { return timestamp.seconds() * kMicrosPerSecond + RoundTowardZero(timestamp.nanos(), kNanosPerMicrosecond); } -int64 TimeUtil::TimestampToMilliseconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToMilliseconds(const Timestamp& timestamp) { return timestamp.seconds() * kMillisPerSecond + RoundTowardZero(timestamp.nanos(), kNanosPerMillisecond); } -int64 TimeUtil::TimestampToSeconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToSeconds(const Timestamp& timestamp) { return timestamp.seconds(); } Timestamp TimeUtil::TimeTToTimestamp(time_t value) { - return CreateNormalized(static_cast(value), 0); + return CreateNormalized(static_cast(value), 0); } time_t TimeUtil::TimestampToTimeT(const Timestamp& value) { @@ -382,19 +384,20 @@ using ::PROTOBUF_NAMESPACE_ID::util::kNanosPerSecond; void ToUint128(const Duration& value, uint128* result, bool* negative) { if (value.seconds() < 0 || value.nanos() < 0) { *negative = true; - *result = static_cast(-value.seconds()); - *result = *result * kNanosPerSecond + static_cast(-value.nanos()); + *result = static_cast(-value.seconds()); + *result = *result * kNanosPerSecond + static_cast(-value.nanos()); } else { *negative = false; - *result = static_cast(value.seconds()); - *result = *result * kNanosPerSecond + static_cast(value.nanos()); + *result = static_cast(value.seconds()); + *result = *result * kNanosPerSecond + static_cast(value.nanos()); } } void ToDuration(const uint128& value, bool negative, Duration* duration) { - int64 seconds = - static_cast(Uint128Low64(value / kNanosPerSecond)); - int32 nanos = static_cast(Uint128Low64(value % kNanosPerSecond)); + int64_t seconds = + static_cast(Uint128Low64(value / kNanosPerSecond)); + int32_t nanos = + static_cast(Uint128Low64(value % kNanosPerSecond)); if (negative) { seconds = -seconds; nanos = -nanos; @@ -416,15 +419,15 @@ Duration& operator-=(Duration& d1, const Duration& d2) { // NOLINT return d1; } -Duration& operator*=(Duration& d, int64 r) { // NOLINT +Duration& operator*=(Duration& d, int64_t r) { // NOLINT bool negative; uint128 value; ToUint128(d, &value, &negative); if (r > 0) { - value *= static_cast(r); + value *= static_cast(r); } else { negative = !negative; - value *= static_cast(-r); + value *= static_cast(-r); } ToDuration(value, negative, &d); return d; @@ -432,8 +435,8 @@ Duration& operator*=(Duration& d, int64 r) { // NOLINT Duration& operator*=(Duration& d, double r) { // NOLINT double result = (d.seconds() * 1.0 + 1.0 * d.nanos() / kNanosPerSecond) * r; - int64 seconds = static_cast(result); - int32 nanos = static_cast((result - seconds) * kNanosPerSecond); + int64_t seconds = static_cast(result); + int32_t nanos = static_cast((result - seconds) * kNanosPerSecond); // Note that we normalize here not just because nanos can have a different // sign from seconds but also that nanos can be any arbitrary value when // overflow happens (i.e., the result is a much larger value than what @@ -442,15 +445,15 @@ Duration& operator*=(Duration& d, double r) { // NOLINT return d; } -Duration& operator/=(Duration& d, int64 r) { // NOLINT +Duration& operator/=(Duration& d, int64_t r) { // NOLINT bool negative; uint128 value; ToUint128(d, &value, &negative); if (r > 0) { - value /= static_cast(r); + value /= static_cast(r); } else { negative = !negative; - value /= static_cast(-r); + value /= static_cast(-r); } ToDuration(value, negative, &d); return d; @@ -476,12 +479,12 @@ Duration& operator%=(Duration& d1, const Duration& d2) { // NOLINT return d1; } -int64 operator/(const Duration& d1, const Duration& d2) { +int64_t operator/(const Duration& d1, const Duration& d2) { bool negative1, negative2; uint128 value1, value2; ToUint128(d1, &value1, &negative1); ToUint128(d2, &value2, &negative2); - int64 result = Uint128Low64(value1 / value2); + int64_t result = Uint128Low64(value1 / value2); if (negative1 != negative2) { result = -result; } diff --git a/src/google/protobuf/util/time_util.h b/src/google/protobuf/util/time_util.h index 95063fc49c..96b1aac46b 100644 --- a/src/google/protobuf/util/time_util.h +++ b/src/google/protobuf/util/time_util.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__ #define GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__ +#include #include #include #include @@ -67,11 +68,11 @@ class PROTOBUF_EXPORT TimeUtil { // The min/max Timestamp/Duration values we support. // // For "0001-01-01T00:00:00Z". - static const int64 kTimestampMinSeconds = -62135596800LL; + static const int64_t kTimestampMinSeconds = -62135596800LL; // For "9999-12-31T23:59:59.999999999Z". - static const int64 kTimestampMaxSeconds = 253402300799LL; - static const int64 kDurationMinSeconds = -315576000000LL; - static const int64 kDurationMaxSeconds = 315576000000LL; + static const int64_t kTimestampMaxSeconds = 253402300799LL; + static const int64_t kDurationMinSeconds = -315576000000LL; + static const int64_t kDurationMaxSeconds = 315576000000LL; // Converts Timestamp to/from RFC 3339 date string format. // Generated output will always be Z-normalized and uses 3, 6 or 9 @@ -110,12 +111,12 @@ class PROTOBUF_EXPORT TimeUtil { // Converts between Duration and integer types. The behavior is undefined if // the input value is not in the valid range of Duration. - static Duration NanosecondsToDuration(int64 nanos); - static Duration MicrosecondsToDuration(int64 micros); - static Duration MillisecondsToDuration(int64 millis); - static Duration SecondsToDuration(int64 seconds); - static Duration MinutesToDuration(int64 minutes); - static Duration HoursToDuration(int64 hours); + static Duration NanosecondsToDuration(int64_t nanos); + static Duration MicrosecondsToDuration(int64_t micros); + static Duration MillisecondsToDuration(int64_t millis); + static Duration SecondsToDuration(int64_t seconds); + static Duration MinutesToDuration(int64_t minutes); + static Duration HoursToDuration(int64_t hours); // Result will be truncated towards zero. For example, "-1.5s" will be // truncated to "-1s", and "1.5s" to "1s" when converting to seconds. // It's undefined behavior if the input duration is not valid or the result @@ -123,28 +124,28 @@ class PROTOBUF_EXPORT TimeUtil { // valid range of Duration, or have an invalid nanos value (i.e., larger // than 999999999, less than -999999999, or have a different sign from the // seconds part). - static int64 DurationToNanoseconds(const Duration& duration); - static int64 DurationToMicroseconds(const Duration& duration); - static int64 DurationToMilliseconds(const Duration& duration); - static int64 DurationToSeconds(const Duration& duration); - static int64 DurationToMinutes(const Duration& duration); - static int64 DurationToHours(const Duration& duration); + static int64_t DurationToNanoseconds(const Duration& duration); + static int64_t DurationToMicroseconds(const Duration& duration); + static int64_t DurationToMilliseconds(const Duration& duration); + static int64_t DurationToSeconds(const Duration& duration); + static int64_t DurationToMinutes(const Duration& duration); + static int64_t DurationToHours(const Duration& duration); // Creates Timestamp from integer types. The integer value indicates the // time elapsed from Epoch time. The behavior is undefined if the input // value is not in the valid range of Timestamp. - static Timestamp NanosecondsToTimestamp(int64 nanos); - static Timestamp MicrosecondsToTimestamp(int64 micros); - static Timestamp MillisecondsToTimestamp(int64 millis); - static Timestamp SecondsToTimestamp(int64 seconds); + static Timestamp NanosecondsToTimestamp(int64_t nanos); + static Timestamp MicrosecondsToTimestamp(int64_t micros); + static Timestamp MillisecondsToTimestamp(int64_t millis); + static Timestamp SecondsToTimestamp(int64_t seconds); // Result will be truncated down to the nearest integer value. For example, // with "1969-12-31T23:59:59.9Z", TimestampToMilliseconds() returns -100 // and TimestampToSeconds() returns -1. It's undefined behavior if the input // Timestamp is not valid (i.e., its seconds part or nanos part does not fall // in the valid range) or the return value doesn't fit into int64. - static int64 TimestampToNanoseconds(const Timestamp& timestamp); - static int64 TimestampToMicroseconds(const Timestamp& timestamp); - static int64 TimestampToMilliseconds(const Timestamp& timestamp); - static int64 TimestampToSeconds(const Timestamp& timestamp); + static int64_t TimestampToNanoseconds(const Timestamp& timestamp); + static int64_t TimestampToMicroseconds(const Timestamp& timestamp); + static int64_t TimestampToMilliseconds(const Timestamp& timestamp); + static int64_t TimestampToSeconds(const Timestamp& timestamp); // Conversion to/from other time/date types. Note that these types may // have a different precision and time range from Timestamp/Duration. @@ -176,19 +177,19 @@ PROTOBUF_EXPORT Duration& operator+=(Duration& d1, const Duration& d2); // NOLINT PROTOBUF_EXPORT Duration& operator-=(Duration& d1, const Duration& d2); // NOLINT -PROTOBUF_EXPORT Duration& operator*=(Duration& d, int64 r); // NOLINT +PROTOBUF_EXPORT Duration& operator*=(Duration& d, int64_t r); // NOLINT PROTOBUF_EXPORT Duration& operator*=(Duration& d, double r); // NOLINT -PROTOBUF_EXPORT Duration& operator/=(Duration& d, int64 r); // NOLINT +PROTOBUF_EXPORT Duration& operator/=(Duration& d, int64_t r); // NOLINT PROTOBUF_EXPORT Duration& operator/=(Duration& d, double r); // NOLINT // Overload for other integer types. template Duration& operator*=(Duration& d, T r) { // NOLINT - int64 x = r; + int64_t x = r; return d *= x; } template Duration& operator/=(Duration& d, T r) { // NOLINT - int64 x = r; + int64_t x = r; return d /= x; } PROTOBUF_EXPORT Duration& operator%=(Duration& d1, @@ -243,7 +244,7 @@ template inline Duration operator/(Duration d, T r) { return d /= r; } -PROTOBUF_EXPORT int64 operator/(const Duration& d1, const Duration& d2); +PROTOBUF_EXPORT int64_t operator/(const Duration& d1, const Duration& d2); inline Duration operator%(const Duration& d1, const Duration& d2) { Duration result = d1; diff --git a/src/google/protobuf/util/time_util_test.cc b/src/google/protobuf/util/time_util_test.cc index b6d3813264..d38a27d955 100644 --- a/src/google/protobuf/util/time_util_test.cc +++ b/src/google/protobuf/util/time_util_test.cc @@ -30,6 +30,7 @@ #include +#include #include #include @@ -119,10 +120,10 @@ TEST(TimeUtilTest, DurationStringFormat) { // Duration must support range from -315,576,000,000s to +315576000000s // which includes negative values. EXPECT_TRUE(TimeUtil::FromString("315576000000.999999999s", &d)); - EXPECT_EQ(int64{315576000000}, d.seconds()); + EXPECT_EQ(int64_t{315576000000}, d.seconds()); EXPECT_EQ(999999999, d.nanos()); EXPECT_TRUE(TimeUtil::FromString("-315576000000.999999999s", &d)); - EXPECT_EQ(int64{-315576000000}, d.seconds()); + EXPECT_EQ(int64_t{-315576000000}, d.seconds()); EXPECT_EQ(-999999999, d.nanos()); } @@ -277,23 +278,24 @@ TEST(TimeUtilTest, DurationOperators) { EXPECT_EQ("-0.999999999s", TimeUtil::ToString(b * 0.5)); // Multiplication should not overflow if the result fits into the supported // range of Duration (intermediate result may be larger than int64). - EXPECT_EQ("315575999684.424s", - TimeUtil::ToString((one_second - one_nano) * int64{315576000000})); - EXPECT_EQ("-315575999684.424s", - TimeUtil::ToString((one_nano - one_second) * int64{315576000000})); + EXPECT_EQ("315575999684.424s", TimeUtil::ToString((one_second - one_nano) * + int64_t{315576000000})); + EXPECT_EQ("-315575999684.424s", TimeUtil::ToString((one_nano - one_second) * + int64_t{315576000000})); EXPECT_EQ("-315575999684.424s", TimeUtil::ToString((one_second - one_nano) * - (int64{-315576000000}))); + (int64_t{-315576000000}))); // Test / and % EXPECT_EQ("0.999999999s", TimeUtil::ToString(a / 2)); EXPECT_EQ("-0.999999999s", TimeUtil::ToString(b / 2)); - Duration large = TimeUtil::SecondsToDuration(int64{315576000000}) - one_nano; + Duration large = + TimeUtil::SecondsToDuration(int64_t{315576000000}) - one_nano; // We have to handle division with values beyond 64 bits. - EXPECT_EQ("0.999999999s", TimeUtil::ToString(large / int64{315576000000})); + EXPECT_EQ("0.999999999s", TimeUtil::ToString(large / int64_t{315576000000})); EXPECT_EQ("-0.999999999s", - TimeUtil::ToString((-large) / int64{315576000000})); + TimeUtil::ToString((-large) / int64_t{315576000000})); EXPECT_EQ("-0.999999999s", - TimeUtil::ToString(large / (int64{-315576000000}))); + TimeUtil::ToString(large / (int64_t{-315576000000}))); Duration large2 = large + one_nano; EXPECT_EQ(large, large % large2); EXPECT_EQ(-large, (-large) % large2); diff --git a/src/google/protobuf/util/type_resolver_util_test.cc b/src/google/protobuf/util/type_resolver_util_test.cc index d90fdffd9e..f0a0a74aaf 100644 --- a/src/google/protobuf/util/type_resolver_util_test.cc +++ b/src/google/protobuf/util/type_resolver_util_test.cc @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -135,12 +136,12 @@ class DescriptorPoolTypeResolverTest : public testing::Test { } bool HasInt32Option(const RepeatedPtrField