From 244bbd6f9501a386e76a4f5739b6021a3a6fe2fb Mon Sep 17 00:00:00 2001 From: FaBrand <21087362+FaBrand@users.noreply.github.com> Date: Fri, 29 Apr 2022 19:24:10 +0200 Subject: [PATCH 01/11] Make genrule portable for windows (#9889) * Make genrule portable for windows Using this does remove a user dependency on a bash under windows * Use portable genrule for zlib dependency --- protobuf.bzl | 8 +++++--- third_party/zlib.BUILD | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/protobuf.bzl b/protobuf.bzl index 2dc4ecdee3..c5b8dab385 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -477,10 +477,12 @@ def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs): name = name + "_genrule", srcs = srcs, outs = outs, - cmd = " && ".join( + cmd_bash = " && ".join( ["cp $(location %s) $(location %s)" % - (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs], - ), + (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs]), + cmd_bat = " && ".join( + ["@copy /Y $(location %s) $(location %s) >NUL" % + (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs]), ) native.filegroup( diff --git a/third_party/zlib.BUILD b/third_party/zlib.BUILD index 098f7bdd89..187bec2123 100644 --- a/third_party/zlib.BUILD +++ b/third_party/zlib.BUILD @@ -27,7 +27,11 @@ genrule( name = "copy_public_headers", srcs = _ZLIB_HEADERS, outs = _ZLIB_PREFIXED_HEADERS, - cmd = "cp $(SRCS) $(@D)/zlib/include/", + cmd_bash = "cp $(SRCS) $(@D)/zlib/include/", + cmd_bat = " && ".join( + ["@copy /Y $(location %s) $(@D)\\zlib\\include\\ >NUL" % + s for s in _ZLIB_HEADERS], + ), ) cc_library( From 7d48c4accd5a28430ced86a9e09bc1378ec02892 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Fri, 29 Apr 2022 12:14:16 -0700 Subject: [PATCH 02/11] Add forwarding lang_generator.h headers for cpp, java, and python. (#9883) These filenames stutter, but are still being used by some users. So, these forward to the correct header. They should eventually be deprecated and removed. --- cmake/extract_includes.bat.in | 3 +++ cmake/libprotoc.cmake | 3 +++ src/Makefile.am | 3 +++ src/google/protobuf/compiler/cpp/cpp_generator.h | 6 ++++++ src/google/protobuf/compiler/java/java_generator.h | 6 ++++++ src/google/protobuf/compiler/python/python_generator.h | 6 ++++++ 6 files changed, 27 insertions(+) create mode 100644 src/google/protobuf/compiler/cpp/cpp_generator.h create mode 100644 src/google/protobuf/compiler/java/java_generator.h create mode 100644 src/google/protobuf/compiler/python/python_generator.h diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index 83058f3e1b..061b240aeb 100644 --- a/cmake/extract_includes.bat.in +++ b/cmake/extract_includes.bat.in @@ -22,6 +22,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenaz_sampler.h" inc copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\code_generator.h" include\google\protobuf\compiler\code_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_interface.h" include\google\protobuf\compiler\command_line_interface.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\file.h" include\google\protobuf\compiler\cpp\file.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h" include\google\protobuf\compiler\cpp\cpp_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\generator.h" include\google\protobuf\compiler\cpp\generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\helpers.h" include\google\protobuf\compiler\cpp\helpers.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\names.h" include\google\protobuf\compiler\cpp\names.h @@ -31,6 +32,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\cshar copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_options.h" include\google\protobuf\compiler\csharp\csharp_options.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h" include\google\protobuf\compiler\importer.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\generator.h" include\google\protobuf\compiler\java\generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h" include\google\protobuf\compiler\java\java_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\kotlin_generator.h" include\google\protobuf\compiler\java\kotlin_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\names.h" include\google\protobuf\compiler\java\names.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_generator.h" include\google\protobuf\compiler\objectivec\objectivec_generator.h @@ -41,6 +43,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h" in copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h" include\google\protobuf\compiler\plugin.pb.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\generator.h" include\google\protobuf\compiler\python\generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\pyi_generator.h" include\google\protobuf\compiler\python\pyi_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h" include\google\protobuf\compiler\python\python_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h" include\google\protobuf\compiler\ruby\ruby_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h" include\google\protobuf\descriptor.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.pb.h" include\google\protobuf\descriptor.pb.h diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 0ece6593ac..dcb091e02f 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -88,6 +88,7 @@ set(libprotoc_headers ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/code_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/file.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/cpp_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/helpers.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/names.h @@ -96,6 +97,7 @@ set(libprotoc_headers ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_names.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_options.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/java_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_generator.h @@ -104,6 +106,7 @@ set(libprotoc_headers ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/pyi_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/python_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.h ) diff --git a/src/Makefile.am b/src/Makefile.am index 8cb05f78c0..9c63fbff22 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -75,6 +75,7 @@ nobase_include_HEADERS = \ google/protobuf/compiler/code_generator.h \ google/protobuf/compiler/command_line_interface.h \ google/protobuf/compiler/cpp/file.h \ + google/protobuf/compiler/cpp/cpp_generator.h \ google/protobuf/compiler/cpp/generator.h \ google/protobuf/compiler/cpp/helpers.h \ google/protobuf/compiler/cpp/names.h \ @@ -84,6 +85,7 @@ nobase_include_HEADERS = \ google/protobuf/compiler/csharp/csharp_options.h \ google/protobuf/compiler/importer.h \ google/protobuf/compiler/java/generator.h \ + google/protobuf/compiler/java/java_generator.h \ google/protobuf/compiler/java/kotlin_generator.h \ google/protobuf/compiler/java/names.h \ google/protobuf/compiler/objectivec/objectivec_generator.h \ @@ -94,6 +96,7 @@ nobase_include_HEADERS = \ google/protobuf/compiler/plugin.pb.h \ google/protobuf/compiler/python/generator.h \ google/protobuf/compiler/python/pyi_generator.h \ + google/protobuf/compiler/python/python_generator.h \ google/protobuf/compiler/ruby/ruby_generator.h \ google/protobuf/descriptor.h \ google/protobuf/descriptor.pb.h \ diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.h b/src/google/protobuf/compiler/cpp/cpp_generator.h new file mode 100644 index 0000000000..1716ab20de --- /dev/null +++ b/src/google/protobuf/compiler/cpp/cpp_generator.h @@ -0,0 +1,6 @@ +#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ +#define GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ + +#include + +#endif // GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ diff --git a/src/google/protobuf/compiler/java/java_generator.h b/src/google/protobuf/compiler/java/java_generator.h new file mode 100644 index 0000000000..294b1bde02 --- /dev/null +++ b/src/google/protobuf/compiler/java/java_generator.h @@ -0,0 +1,6 @@ +#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ +#define GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ + +#include + +#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h new file mode 100644 index 0000000000..21d48cd9a0 --- /dev/null +++ b/src/google/protobuf/compiler/python/python_generator.h @@ -0,0 +1,6 @@ +#ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ +#define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ + +#include + +#endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ From cd4a8156faa916c2cf23e1794bf46f14d8a58929 Mon Sep 17 00:00:00 2001 From: FaBrand <21087362+FaBrand@users.noreply.github.com> Date: Fri, 29 Apr 2022 22:12:35 +0200 Subject: [PATCH 03/11] Be explicit with empty globs (#9890) There are empty globs that prevent to use com_google_protobuf with --incompatible_disallow_empty_glob Introduced in https://github.com/bazelbuild/bazel/issues/8195 --- BUILD | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BUILD b/BUILD index c639927777..aaff71a0cb 100644 --- a/BUILD +++ b/BUILD @@ -801,8 +801,10 @@ cc_test( "src/google/protobuf/**/*", # Files for csharp_bootstrap_unittest.cc. "conformance/**/*", + ]) + glob([ + # Files for csharp_bootstrap_unittest.cc. "csharp/src/**/*", - ]), + ], allow_empty=True), includes = [ "src/", ], @@ -1493,7 +1495,7 @@ pkg_files( "missing", "protobuf*.pc.in", "test-driver", - ]) + [ + ], allow_empty = True) + [ "BUILD", "CHANGES.txt", "CMakeLists.txt", From 95da0ba5b43e5ac6cc12590566ca945b0c848793 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Fri, 29 Apr 2022 17:57:55 -0700 Subject: [PATCH 04/11] Rename all BUILD files to BUILD.bazel (#9892) This avoids conflicting names in a couple of cases. 1. Within google, we want to sync files but not name them BUILD (since the structure doesn't match). 2. On case-insensitive filesystems, `build` may be used for a build directory. Naming `BUILD.bazel` avoids potentioal conflicts. --- BUILD => BUILD.bazel | 4 +- Makefile.am | 44 +++++++++---------- benchmarks/{BUILD => BUILD.bazel} | 2 +- benchmarks/cpp/{BUILD => BUILD.bazel} | 0 benchmarks/datasets/{BUILD => BUILD.bazel} | 2 +- .../proto2/{BUILD => BUILD.bazel} | 0 .../proto3/{BUILD => BUILD.bazel} | 0 .../google_message2/{BUILD => BUILD.bazel} | 0 .../google_message3/{BUILD => BUILD.bazel} | 0 .../google_message4/{BUILD => BUILD.bazel} | 0 csharp/{BUILD => BUILD.bazel} | 2 +- examples/{BUILD => BUILD.bazel} | 2 +- java/{BUILD => BUILD.bazel} | 2 +- java/core/{BUILD => BUILD.bazel} | 2 +- java/internal/{BUILD => BUILD.bazel} | 2 +- java/kotlin-lite/{BUILD => BUILD.bazel} | 2 +- java/kotlin/{BUILD => BUILD.bazel} | 2 +- java/lite/{BUILD => BUILD.bazel} | 2 +- java/util/{BUILD => BUILD.bazel} | 2 +- objectivec/{BUILD => BUILD.bazel} | 2 +- php/{BUILD => BUILD.bazel} | 2 +- pkg/{BUILD => BUILD.bazel} | 0 ruby/{BUILD => BUILD.bazel} | 2 +- third_party/{BUILD => BUILD.bazel} | 0 third_party/utf8_range/{BUILD => BUILD.bazel} | 0 toolchain/{BUILD => BUILD.bazel} | 0 util/python/{BUILD => BUILD.bazel} | 2 +- 27 files changed, 39 insertions(+), 39 deletions(-) rename BUILD => BUILD.bazel (99%) rename benchmarks/{BUILD => BUILD.bazel} (98%) rename benchmarks/cpp/{BUILD => BUILD.bazel} (100%) rename benchmarks/datasets/{BUILD => BUILD.bazel} (98%) rename benchmarks/datasets/google_message1/proto2/{BUILD => BUILD.bazel} (100%) rename benchmarks/datasets/google_message1/proto3/{BUILD => BUILD.bazel} (100%) rename benchmarks/datasets/google_message2/{BUILD => BUILD.bazel} (100%) rename benchmarks/datasets/google_message3/{BUILD => BUILD.bazel} (100%) rename benchmarks/datasets/google_message4/{BUILD => BUILD.bazel} (100%) rename csharp/{BUILD => BUILD.bazel} (97%) rename examples/{BUILD => BUILD.bazel} (99%) rename java/{BUILD => BUILD.bazel} (98%) rename java/core/{BUILD => BUILD.bazel} (99%) rename java/internal/{BUILD => BUILD.bazel} (92%) rename java/kotlin-lite/{BUILD => BUILD.bazel} (99%) rename java/kotlin/{BUILD => BUILD.bazel} (99%) rename java/lite/{BUILD => BUILD.bazel} (99%) rename java/util/{BUILD => BUILD.bazel} (99%) rename objectivec/{BUILD => BUILD.bazel} (99%) rename php/{BUILD => BUILD.bazel} (97%) rename pkg/{BUILD => BUILD.bazel} (100%) rename ruby/{BUILD => BUILD.bazel} (97%) rename third_party/{BUILD => BUILD.bazel} (100%) rename third_party/utf8_range/{BUILD => BUILD.bazel} (100%) rename toolchain/{BUILD => BUILD.bazel} (100%) rename util/python/{BUILD => BUILD.bazel} (96%) diff --git a/BUILD b/BUILD.bazel similarity index 99% rename from BUILD rename to BUILD.bazel index aaff71a0cb..335261439c 100644 --- a/BUILD +++ b/BUILD.bazel @@ -1496,7 +1496,7 @@ pkg_files( "protobuf*.pc.in", "test-driver", ], allow_empty = True) + [ - "BUILD", + "BUILD.bazel", "CHANGES.txt", "CMakeLists.txt", "CONTRIBUTORS.txt", @@ -1512,7 +1512,7 @@ pkg_files( "maven_install.json", "update_file_lists.sh", "//third_party:zlib.BUILD", - "//util/python:BUILD", + "//util/python:BUILD.bazel", ], strip_prefix = strip_prefix.from_root(""), visibility = ["//pkg:__pkg__"], diff --git a/Makefile.am b/Makefile.am index 6c1bf316cf..7480999501 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,7 @@ SUBDIRS = . src # Always include third_party directories in distributions. # # Note that distribution artifacts will be produced by Bazel in the future. -# See pkg/BUILD for overall definitions. +# See pkg/BUILD.bazel for overall definitions. DIST_SUBDIRS = src conformance benchmarks third_party/googletest # Build gmock before we build protobuf tests. We don't add gmock to SUBDIRS @@ -51,7 +51,7 @@ clean-local: pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = protobuf.pc protobuf-lite.pc -# Note: please keep this in sync with the dist_files rule in csharp/BUILD. +# Note: please keep this in sync with the dist_files rule in csharp/BUILD.bazel. csharp_EXTRA_DIST= \ global.json \ csharp/.editorconfig \ @@ -283,11 +283,11 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/UnknownFieldSet.cs \ csharp/src/Google.Protobuf/UnsafeByteOperations.cs -# Note: please keep this in sync with the dist_files rules under java/.../BUILD. +# Note: please keep this in sync with the dist_files rules under java/.../BUILD.bazel. java_EXTRA_DIST= \ java/README.md \ java/bom/pom.xml \ - java/core/BUILD \ + java/core/BUILD.bazel \ java/core/generate-sources-build.xml \ java/core/generate-test-sources-build.xml \ java/core/pom.xml \ @@ -543,9 +543,9 @@ java_EXTRA_DIST= 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/wrappers_test.proto \ - java/internal/BUILD \ + java/internal/BUILD.bazel \ java/internal/testing.bzl \ - java/kotlin/BUILD \ + java/kotlin/BUILD.bazel \ java/kotlin/generate-sources-build.xml \ java/kotlin/generate-test-sources-build.xml \ java/kotlin/pom.xml \ @@ -572,7 +572,7 @@ java_EXTRA_DIST= java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto \ java/kotlin/src/test/proto/com/google/protobuf/example_extensible_message.proto \ java/kotlin/src/test/proto/com/google/protobuf/multiple_files_proto3.proto \ - java/kotlin-lite/BUILD \ + java/kotlin-lite/BUILD.bazel \ java/kotlin-lite/generate-sources-build.xml \ java/kotlin-lite/generate-test-sources-build.xml \ java/kotlin-lite/lite.awk \ @@ -583,7 +583,7 @@ java_EXTRA_DIST= java/kotlin-lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt\ java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt \ java/lite.md \ - java/lite/BUILD \ + java/lite/BUILD.bazel \ java/lite/generate-sources-build.xml \ java/lite/generate-test-sources-build.xml \ java/lite/lite.awk \ @@ -591,9 +591,9 @@ java_EXTRA_DIST= java/lite/pom_template.xml \ java/lite/process-lite-sources-build.xml \ java/lite/src/test/java/com/google/protobuf/LiteTest.java \ - java/BUILD \ + java/BUILD.bazel \ java/pom.xml \ - java/util/BUILD \ + java/util/BUILD.bazel \ java/util/pom.xml \ java/util/pom_template.xml \ java/util/src/main/java/com/google/protobuf/util/Durations.java \ @@ -612,10 +612,10 @@ java_EXTRA_DIST= java/util/src/test/java/com/google/protobuf/util/ValuesTest.java \ java/util/src/test/proto/com/google/protobuf/util/json_test.proto -# Note: please keep this in sync with the dist_files rule in objectivec/BUILD. +# Note: please keep this in sync with the dist_files rule in objectivec/BUILD.bazel. objectivec_EXTRA_DIST= \ objectivec/.clang-format \ - objectivec/BUILD \ + objectivec/BUILD.bazel \ objectivec/DevTools/check_version_stamps.sh \ objectivec/DevTools/compile_testing_protos.sh \ objectivec/DevTools/full_mac_build.sh \ @@ -821,7 +821,7 @@ objectivec_EXTRA_DIST= \ objectivec/Tests/UnitTests-Info.plist \ Protobuf.podspec -# Note: please keep this in sync with the dist_files rule in php/BUILD. +# Note: please keep this in sync with the dist_files rule in php/BUILD.bazel. php_EXTRA_DIST= \ php/README.md \ php/REFCOUNTING.md \ @@ -1018,7 +1018,7 @@ php_EXTRA_DIST= \ php/tests/WellKnownTest.php \ php/tests/WrapperTypeSettersTest.php -# Note: please keep this in sync with the python_dist_files rule in BUILD. +# Note: please keep this in sync with the python_dist_files rule in BUILD.bazel. python_EXTRA_DIST= \ python/MANIFEST.in \ python/google/__init__.py \ @@ -1142,7 +1142,7 @@ python_EXTRA_DIST= \ python/tox.ini \ python/README.md -# Note: please keep this in sync with the dist_files rule in ruby/BUILD. +# Note: please keep this in sync with the dist_files rule in ruby/BUILD.bazel. ruby_EXTRA_DIST= \ ruby/Gemfile \ ruby/.gitignore \ @@ -1220,7 +1220,7 @@ ruby_EXTRA_DIST= \ all_EXTRA_DIST=$(csharp_EXTRA_DIST) $(java_EXTRA_DIST) $(objectivec_EXTRA_DIST) $(php_EXTRA_DIST) $(python_EXTRA_DIST) $(ruby_EXTRA_DIST) -# Note: please keep this in sync with the common_dist_files rule in BUILD. +# Note: please keep this in sync with the common_dist_files rule in BUILD.bazel. EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ autogen.sh \ generate_descriptor_proto.sh \ @@ -1229,7 +1229,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ CONTRIBUTORS.txt \ CHANGES.txt \ update_file_lists.sh \ - BUILD \ + BUILD.bazel \ WORKSPACE \ CMakeLists.txt \ cmake/abseil-cpp.cmake \ @@ -1254,12 +1254,12 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ compiler_config_setting.bzl \ build_files_updated_unittest.sh \ cc_proto_blacklist_test.bzl \ - csharp/BUILD \ + csharp/BUILD.bazel \ editors/README.txt \ editors/proto.vim \ editors/protobuf-mode.el \ examples/AddPerson.java \ - examples/BUILD \ + examples/BUILD.bazel \ examples/CMakeLists.txt \ examples/ListPeople.java \ examples/Makefile \ @@ -1281,14 +1281,14 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ examples/pubspec.yaml \ internal.bzl \ maven_install.json \ - php/BUILD \ + php/BUILD.bazel \ protobuf.bzl \ protobuf_deps.bzl \ protobuf_release.bzl \ protobuf_version.bzl \ - ruby/BUILD \ + ruby/BUILD.bazel \ third_party/zlib.BUILD \ - util/python/BUILD + util/python/BUILD.bazel # Deletes all the files generated by autogen.sh. MAINTAINERCLEANFILES = \ diff --git a/benchmarks/BUILD b/benchmarks/BUILD.bazel similarity index 98% rename from benchmarks/BUILD rename to benchmarks/BUILD.bazel index 2f7b4c749f..83b2c7ee59 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD.bazel @@ -75,7 +75,7 @@ pkg_files( ], exclude = [ "__init__.py", # not in autotools dist - "BUILD", + "BUILD.bazel", "go/*", ], ), diff --git a/benchmarks/cpp/BUILD b/benchmarks/cpp/BUILD.bazel similarity index 100% rename from benchmarks/cpp/BUILD rename to benchmarks/cpp/BUILD.bazel diff --git a/benchmarks/datasets/BUILD b/benchmarks/datasets/BUILD.bazel similarity index 98% rename from benchmarks/datasets/BUILD rename to benchmarks/datasets/BUILD.bazel index 1cb11bddad..2a8b402668 100644 --- a/benchmarks/datasets/BUILD +++ b/benchmarks/datasets/BUILD.bazel @@ -61,7 +61,7 @@ java_library( pkg_files( name = "dist_files", - srcs = ["BUILD"], + srcs = ["BUILD.bazel"], strip_prefix = strip_prefix.from_root(""), visibility = ["//benchmarks:__pkg__"], ) diff --git a/benchmarks/datasets/google_message1/proto2/BUILD b/benchmarks/datasets/google_message1/proto2/BUILD.bazel similarity index 100% rename from benchmarks/datasets/google_message1/proto2/BUILD rename to benchmarks/datasets/google_message1/proto2/BUILD.bazel diff --git a/benchmarks/datasets/google_message1/proto3/BUILD b/benchmarks/datasets/google_message1/proto3/BUILD.bazel similarity index 100% rename from benchmarks/datasets/google_message1/proto3/BUILD rename to benchmarks/datasets/google_message1/proto3/BUILD.bazel diff --git a/benchmarks/datasets/google_message2/BUILD b/benchmarks/datasets/google_message2/BUILD.bazel similarity index 100% rename from benchmarks/datasets/google_message2/BUILD rename to benchmarks/datasets/google_message2/BUILD.bazel diff --git a/benchmarks/datasets/google_message3/BUILD b/benchmarks/datasets/google_message3/BUILD.bazel similarity index 100% rename from benchmarks/datasets/google_message3/BUILD rename to benchmarks/datasets/google_message3/BUILD.bazel diff --git a/benchmarks/datasets/google_message4/BUILD b/benchmarks/datasets/google_message4/BUILD.bazel similarity index 100% rename from benchmarks/datasets/google_message4/BUILD rename to benchmarks/datasets/google_message4/BUILD.bazel diff --git a/csharp/BUILD b/csharp/BUILD.bazel similarity index 97% rename from csharp/BUILD rename to csharp/BUILD.bazel index 6d31ba0cc6..2c150841b4 100644 --- a/csharp/BUILD +++ b/csharp/BUILD.bazel @@ -13,7 +13,7 @@ pkg_files( ]) + [ ".editorconfig", ".gitignore", - "BUILD", + "BUILD.bazel", "CHANGES.txt", "Google.Protobuf.Tools.nuspec", "Google.Protobuf.Tools.targets", diff --git a/examples/BUILD b/examples/BUILD.bazel similarity index 99% rename from examples/BUILD rename to examples/BUILD.bazel index 358a1529bc..d5a719ca88 100644 --- a/examples/BUILD +++ b/examples/BUILD.bazel @@ -110,7 +110,7 @@ pkg_files( name = "dist_files", srcs = [ "AddPerson.java", - "BUILD", + "BUILD.bazel", "CMakeLists.txt", "ListPeople.java", "Makefile", diff --git a/java/BUILD b/java/BUILD.bazel similarity index 98% rename from java/BUILD rename to java/BUILD.bazel index c084db6390..b3178c9f84 100644 --- a/java/BUILD +++ b/java/BUILD.bazel @@ -28,7 +28,7 @@ filegroup( pkg_files( name = "dist_files", srcs = [ - "BUILD", + "BUILD.bazel", "README.md", "bom/pom.xml", "lite.md", diff --git a/java/core/BUILD b/java/core/BUILD.bazel similarity index 99% rename from java/core/BUILD rename to java/core/BUILD.bazel index 685ebd0981..4a38847683 100644 --- a/java/core/BUILD +++ b/java/core/BUILD.bazel @@ -420,7 +420,7 @@ pkg_files( "src/test/java/**/*.java", "src/test/proto/**/*.proto", ]) + [ - "BUILD", + "BUILD.bazel", "generate-sources-build.xml", "generate-test-sources-build.xml", "pom.xml", diff --git a/java/internal/BUILD b/java/internal/BUILD.bazel similarity index 92% rename from java/internal/BUILD rename to java/internal/BUILD.bazel index d2e0b538ff..662dabd562 100644 --- a/java/internal/BUILD +++ b/java/internal/BUILD.bazel @@ -5,7 +5,7 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") pkg_files( name = "dist_files", srcs = [ - "BUILD", + "BUILD.bazel", "testing.bzl", ], strip_prefix = strip_prefix.from_root(""), diff --git a/java/kotlin-lite/BUILD b/java/kotlin-lite/BUILD.bazel similarity index 99% rename from java/kotlin-lite/BUILD rename to java/kotlin-lite/BUILD.bazel index 18914441c9..88f6014fc3 100644 --- a/java/kotlin-lite/BUILD +++ b/java/kotlin-lite/BUILD.bazel @@ -191,7 +191,7 @@ pkg_files( "src/main/kotlin/com/google/protobuf/*.kt", "src/test/kotlin/**/*.kt", ]) + [ - "BUILD", + "BUILD.bazel", "generate-sources-build.xml", "generate-test-sources-build.xml", "lite.awk", diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD.bazel similarity index 99% rename from java/kotlin/BUILD rename to java/kotlin/BUILD.bazel index c8aae0a047..c48cb03765 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD.bazel @@ -303,7 +303,7 @@ pkg_files( "src/test/kotlin/**/*.kt", "src/test/proto/**/*.proto", ]) + [ - "BUILD", + "BUILD.bazel", "generate-sources-build.xml", "generate-test-sources-build.xml", "pom.xml", diff --git a/java/lite/BUILD b/java/lite/BUILD.bazel similarity index 99% rename from java/lite/BUILD rename to java/lite/BUILD.bazel index 6ff858e3f6..b492cdda7f 100644 --- a/java/lite/BUILD +++ b/java/lite/BUILD.bazel @@ -83,7 +83,7 @@ pkg_files( srcs = glob([ "**/*.java", ]) + [ - "BUILD", + "BUILD.bazel", "generate-sources-build.xml", "generate-test-sources-build.xml", "lite.awk", diff --git a/java/util/BUILD b/java/util/BUILD.bazel similarity index 99% rename from java/util/BUILD rename to java/util/BUILD.bazel index 820adb9a01..ac9b5fde30 100644 --- a/java/util/BUILD +++ b/java/util/BUILD.bazel @@ -83,7 +83,7 @@ pkg_files( "src/test/**/*.java", "src/test/**/*.proto", ]) + [ - "BUILD", + "BUILD.bazel", "pom.xml", "pom_template.xml", ], diff --git a/objectivec/BUILD b/objectivec/BUILD.bazel similarity index 99% rename from objectivec/BUILD rename to objectivec/BUILD.bazel index 7b0ede6865..c18788f40d 100644 --- a/objectivec/BUILD +++ b/objectivec/BUILD.bazel @@ -111,7 +111,7 @@ pkg_files( "Tests/*.proto", ]) + [ ".clang-format", - "BUILD", + "BUILD.bazel", "README.md", "Tests/golden_message", "Tests/golden_packed_fields_message", diff --git a/php/BUILD b/php/BUILD.bazel similarity index 97% rename from php/BUILD rename to php/BUILD.bazel index cf94be1cd4..3460959574 100644 --- a/php/BUILD +++ b/php/BUILD.bazel @@ -14,7 +14,7 @@ pkg_files( "tests/*.sh", "tests/proto/**/*.proto", ]) + [ - "BUILD", + "BUILD.bazel", "README.md", "REFCOUNTING.md", "composer.json", diff --git a/pkg/BUILD b/pkg/BUILD.bazel similarity index 100% rename from pkg/BUILD rename to pkg/BUILD.bazel diff --git a/ruby/BUILD b/ruby/BUILD.bazel similarity index 97% rename from ruby/BUILD rename to ruby/BUILD.bazel index 1884c39834..fe336e549b 100644 --- a/ruby/BUILD +++ b/ruby/BUILD.bazel @@ -14,7 +14,7 @@ pkg_files( "tests/*.rb", ]) + [ ".gitignore", - "BUILD", + "BUILD.bazel", "Gemfile", "README.md", "Rakefile", diff --git a/third_party/BUILD b/third_party/BUILD.bazel similarity index 100% rename from third_party/BUILD rename to third_party/BUILD.bazel diff --git a/third_party/utf8_range/BUILD b/third_party/utf8_range/BUILD.bazel similarity index 100% rename from third_party/utf8_range/BUILD rename to third_party/utf8_range/BUILD.bazel diff --git a/toolchain/BUILD b/toolchain/BUILD.bazel similarity index 100% rename from toolchain/BUILD rename to toolchain/BUILD.bazel diff --git a/util/python/BUILD b/util/python/BUILD.bazel similarity index 96% rename from util/python/BUILD rename to util/python/BUILD.bazel index 85ede91c5b..071efd20b0 100644 --- a/util/python/BUILD +++ b/util/python/BUILD.bazel @@ -1,6 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library") -exports_files(["BUILD"]) +exports_files(["BUILD.bazel"]) # This is a placeholder for python headers. Projects needing to use # fast cpp protos in protobuf's python interface should build with From cdc11c2d2d314ce0382fe0eaa715e5e0e1270438 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 2 May 2022 15:46:43 -0700 Subject: [PATCH 05/11] Remove cuda.list from apt sources (#9896) This will fix the collect_all_artifacts.sh script, which was broken recently when NVidia stopped publishing Cuda packages for Ubuntu 16.04. --- kokoro/release/collect_all_artifacts.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kokoro/release/collect_all_artifacts.sh b/kokoro/release/collect_all_artifacts.sh index 3372a01975..6e0d152408 100755 --- a/kokoro/release/collect_all_artifacts.sh +++ b/kokoro/release/collect_all_artifacts.sh @@ -50,6 +50,9 @@ cp ${INPUT_ARTIFACTS_DIR}/build64/src/protoc protoc/macosx_x64/protoc # TODO(jtattermusch): use "mono:5.14" docker image instead so we don't have to apt-get install sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list +# NVidia has stopped publishing Cuda packages for Ubuntu 16.04, so we need to +# delete this file to allow the apt update to run successfully. +sudo rm -f /etc/apt/sources.list.d/cuda.list sudo apt update sudo apt-get install -y nuget From b37b613436ac84bf2d29f43494e4afa062db35bf Mon Sep 17 00:00:00 2001 From: zhangskz <89936743+zhangskz@users.noreply.github.com> Date: Tue, 3 May 2022 11:58:31 -0400 Subject: [PATCH 06/11] Update protobuf_version.bzl to separate protoc and per-language java major version (#9900) --- java/core/BUILD.bazel | 6 +++--- java/kotlin-lite/BUILD.bazel | 4 ++-- java/kotlin/BUILD.bazel | 4 ++-- java/util/BUILD.bazel | 4 ++-- protobuf_release.bzl | 4 ++-- protobuf_version.bzl | 3 ++- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/java/core/BUILD.bazel b/java/core/BUILD.bazel index 4a38847683..60be807190 100644 --- a/java/core/BUILD.bazel +++ b/java/core/BUILD.bazel @@ -4,7 +4,7 @@ load("@rules_jvm_external//:defs.bzl", "java_export") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("//:internal.bzl", "conformance_test") -load("//:protobuf_version.bzl", "PROTOBUF_VERSION") +load("//:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") load("//java/internal:testing.bzl", "junit_tests") LITE_SRCS = [ @@ -116,7 +116,7 @@ java_library( # Bazel users, don't depend on this target, use //java/lite. java_export( name = "lite_mvn", - maven_coordinates = "com.google.protobuf:protobuf-javalite:%s" % PROTOBUF_VERSION, + maven_coordinates = "com.google.protobuf:protobuf-javalite:%s" % PROTOBUF_JAVA_VERSION, pom_template = "//java/lite:pom_template.xml", resources = [ "//:lite_well_known_protos", @@ -151,7 +151,7 @@ java_library( # Bazel users, don't depend on this target, use :core. java_export( name = "core_mvn", - maven_coordinates = "com.google.protobuf:protobuf-java:%s" % PROTOBUF_VERSION, + maven_coordinates = "com.google.protobuf:protobuf-java:%s" % PROTOBUF_JAVA_VERSION, pom_template = "pom_template.xml", resources = [ "//:well_known_protos", diff --git a/java/kotlin-lite/BUILD.bazel b/java/kotlin-lite/BUILD.bazel index 88f6014fc3..47b02c2ae4 100644 --- a/java/kotlin-lite/BUILD.bazel +++ b/java/kotlin-lite/BUILD.bazel @@ -2,7 +2,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_lite_proto_library") load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//:protobuf_version.bzl", "PROTOBUF_VERSION") +load("//:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") load("//:protobuf.bzl", "internal_gen_kt_protos") java_lite_proto_library( @@ -34,7 +34,7 @@ kt_jvm_export( "@com_github_jetbrains_kotlin//:kotlin-stdlib", "//java/lite", ], - maven_coordinates = "com.google.protobuf:protobuf-kotlin-lite:%s" % PROTOBUF_VERSION, + maven_coordinates = "com.google.protobuf:protobuf-kotlin-lite:%s" % PROTOBUF_JAVA_VERSION, pom_template = "//java/kotlin-lite:pom_template.xml", resources = ["//:well_known_protos"], runtime_deps = [ diff --git a/java/kotlin/BUILD.bazel b/java/kotlin/BUILD.bazel index c48cb03765..a3cf83d46b 100644 --- a/java/kotlin/BUILD.bazel +++ b/java/kotlin/BUILD.bazel @@ -3,7 +3,7 @@ load("@rules_java//java:defs.bzl", "java_proto_library") load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") -load("//:protobuf_version.bzl", "PROTOBUF_VERSION") +load("//:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") load("//:protobuf.bzl", "internal_gen_kt_protos") exports_files([ @@ -56,7 +56,7 @@ kt_jvm_export( "@com_github_jetbrains_kotlin//:kotlin-stdlib", "//java/core", ], - maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION, + maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_JAVA_VERSION, pom_template = "//java/kotlin:pom_template.xml", resources = ["//:well_known_protos"], runtime_deps = [ diff --git a/java/util/BUILD.bazel b/java/util/BUILD.bazel index ac9b5fde30..bea3099daa 100644 --- a/java/util/BUILD.bazel +++ b/java/util/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_java//java:defs.bzl", "java_proto_library") load("@rules_jvm_external//:defs.bzl", "java_export") load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") -load("//:protobuf_version.bzl", "PROTOBUF_VERSION") +load("//:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") load("//java/internal:testing.bzl", "junit_tests") java_library( @@ -25,7 +25,7 @@ java_library( java_export( name = "util_mvn", deploy_env = ["//java/core"], - maven_coordinates = "com.google.protobuf:protobuf-java-util:%s" % PROTOBUF_VERSION, + maven_coordinates = "com.google.protobuf:protobuf-java-util:%s" % PROTOBUF_JAVA_VERSION, pom_template = "pom_template.xml", visibility = ["//java:__pkg__"], runtime_deps = [":util"], diff --git a/protobuf_release.bzl b/protobuf_release.bzl index c5d5f2bf2c..327ae9a0a0 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -4,11 +4,11 @@ Generates package naming variables for use with rules_pkg. load("@rules_pkg//:providers.bzl", "PackageVariablesInfo") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") -load(":protobuf_version.bzl", "PROTOBUF_VERSION") +load(":protobuf_version.bzl", "PROTOC_VERSION") def _package_naming_impl(ctx): values = {} - values["version"] = PROTOBUF_VERSION + values["version"] = PROTOC_VERSION # infer from the current cpp toolchain. toolchain = find_cpp_toolchain(ctx) diff --git a/protobuf_version.bzl b/protobuf_version.bzl index 98cf8371dc..8da8329beb 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1,2 @@ -PROTOBUF_VERSION = '3.20.1' +PROTOC_VERSION = '3.20.1' +PROTOBUF_JAVA_VERSION = '3.20.1' From 5eafa23c98b93386319a3a9d6c1c2894174b5fb0 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 3 May 2022 10:26:36 -0700 Subject: [PATCH 07/11] Update CHANGES.txt (#9897) --- CHANGES.txt | 1 + .../protobuf/ProtoCaliperBenchmark.java | 2 +- cmake/libprotoc.cmake | 2 +- .../com/google/protobuf/ArrayDecoders.java | 5 +- .../google/protobuf/GeneratedMessageLite.java | 14 +- .../google/protobuf/GeneratedMessageV3.java | 42 +- .../google/protobuf/RepeatedFieldBuilder.java | 7 +- .../protobuf/RepeatedFieldBuilderV3.java | 7 +- .../google/protobuf/CachedFieldSizeTest.java | 2 +- .../google/protobuf/CodedInputStreamTest.java | 2 +- .../protobuf/LazyStringEndToEndTest.java | 2 +- .../java/com/google/protobuf/LiteTest.java | 3 +- src/google/protobuf/any.pb.cc | 29 +- src/google/protobuf/any.pb.h | 6 +- src/google/protobuf/api.pb.cc | 116 +-- src/google/protobuf/api.pb.h | 18 +- .../protobuf/compiler/cpp/enum_field.cc | 6 +- src/google/protobuf/compiler/cpp/field.cc | 7 - src/google/protobuf/compiler/cpp/map_field.cc | 2 +- src/google/protobuf/compiler/cpp/message.cc | 61 +- src/google/protobuf/compiler/cpp/message.h | 2 +- .../protobuf/compiler/cpp/message_field.cc | 10 +- .../protobuf/compiler/cpp/primitive_field.cc | 6 +- .../protobuf/compiler/cpp/string_field.cc | 16 +- .../protobuf/compiler/java/message_lite.h | 3 - src/google/protobuf/compiler/plugin.pb.cc | 134 ++- src/google/protobuf/compiler/plugin.pb.h | 24 +- src/google/protobuf/compiler/subprocess.cc | 12 +- src/google/protobuf/descriptor.cc | 42 +- src/google/protobuf/descriptor.pb.cc | 931 ++++++++---------- src/google/protobuf/descriptor.pb.h | 162 ++- src/google/protobuf/descriptor_unittest.cc | 3 +- src/google/protobuf/duration.pb.cc | 21 +- src/google/protobuf/duration.pb.h | 6 +- src/google/protobuf/empty.pb.cc | 1 + src/google/protobuf/empty.pb.h | 4 +- src/google/protobuf/extension_set_unittest.cc | 5 +- src/google/protobuf/field_mask.pb.cc | 19 +- src/google/protobuf/field_mask.pb.h | 6 +- .../protobuf/generated_message_bases.cc | 8 +- src/google/protobuf/generated_message_bases.h | 4 +- .../protobuf/generated_message_reflection.cc | 22 +- .../protobuf/generated_message_reflection.h | 3 - .../generated_message_reflection_unittest.cc | 33 +- src/google/protobuf/io/zero_copy_stream.h | 2 - src/google/protobuf/map.h | 139 ++- src/google/protobuf/map_test.inc | 196 +++- src/google/protobuf/message.cc | 24 +- src/google/protobuf/message.h | 12 +- src/google/protobuf/parse_context.h | 8 +- src/google/protobuf/port_def.inc | 4 +- src/google/protobuf/port_undef.inc | 4 +- src/google/protobuf/repeated_field.h | 19 +- src/google/protobuf/repeated_ptr_field.cc | 2 +- src/google/protobuf/repeated_ptr_field.h | 53 +- src/google/protobuf/source_context.pb.cc | 23 +- src/google/protobuf/source_context.pb.h | 6 +- src/google/protobuf/struct.pb.cc | 85 +- src/google/protobuf/struct.pb.h | 18 +- src/google/protobuf/text_format.cc | 14 +- src/google/protobuf/text_format.h | 5 + src/google/protobuf/text_format_unittest.cc | 361 +++---- src/google/protobuf/timestamp.pb.cc | 21 +- src/google/protobuf/timestamp.pb.h | 6 +- src/google/protobuf/type.pb.cc | 184 ++-- src/google/protobuf/type.pb.h | 30 +- .../protobuf/unknown_field_set_unittest.cc | 9 +- .../protobuf/util/internal/datapiece.cc | 18 + src/google/protobuf/util/json_util_test.cc | 8 +- src/google/protobuf/wire_format.h | 2 - src/google/protobuf/wrappers.pb.cc | 193 ++-- src/google/protobuf/wrappers.pb.h | 54 +- 72 files changed, 1745 insertions(+), 1566 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5f6e297cd3..4ef9bdbac5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Refactor generated message class layout * Optimize tokenizer ParseInteger by removing division * Reserve exactly the right amount of capacity in ExtensionSet::MergeFrom + * Parse FLT_MAX correctly when represented in JSON Compiler * Protoc outputs the list of suggested field numbers when invalid field diff --git a/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java b/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java index 97c7376cd9..ef30749325 100644 --- a/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java +++ b/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java @@ -151,7 +151,7 @@ public class ProtoCaliperBenchmark { } } - + @SuppressWarnings("IgnoredPureGetter") @Benchmark void serializeToByteArray(int reps) throws IOException { if (sampleMessageList.size() == 0) { diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index dcb091e02f..8215827d87 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -123,7 +123,7 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT) endif() target_link_libraries(libprotoc PRIVATE libprotobuf) target_include_directories(libprotoc - PRIVATE ${ABSL_ROOT_DIR} + PRIVATE ${ABSL_ROOT_DIR} ) if(protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotoc diff --git a/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java b/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java index 0fc88ae450..49484276b5 100644 --- a/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java +++ b/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java @@ -32,6 +32,7 @@ package com.google.protobuf; import static com.google.protobuf.MessageSchema.getMutableUnknownFields; +import com.google.protobuf.GeneratedMessageLite.ExtensionDescriptor; import com.google.protobuf.Internal.ProtobufList; import java.io.IOException; @@ -759,7 +760,9 @@ final class ArrayDecoders { return decodeUnknownField( tag, data, position, limit, getMutableUnknownFields(message), registers); } else { - ((GeneratedMessageLite.ExtendableMessage) message).ensureExtensionsAreMutable(); + // TODO(b/230609037): remove the unused variable + FieldSet unused = + ((GeneratedMessageLite.ExtendableMessage) message).ensureExtensionsAreMutable(); return decodeExtension( tag, data, position, limit, (GeneratedMessageLite.ExtendableMessage) message, extension, unknownFieldSchema, registers); diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index 20da4d8036..9db33456d6 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -247,6 +247,7 @@ public abstract class GeneratedMessageLite< protected abstract Object dynamicMethod(MethodToInvoke method, Object arg0, Object arg1); /** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */ + @CanIgnoreReturnValue protected Object dynamicMethod(MethodToInvoke method, Object arg0) { return dynamicMethod(method, arg0, null); } @@ -571,7 +572,8 @@ public abstract class GeneratedMessageLite< return parseUnknownField(tag, input); } - ensureExtensionsAreMutable(); + // TODO(b/230609037): remove the unused variable + FieldSet unused = ensureExtensionsAreMutable(); if (packed) { int length = input.readRawVarint32(); @@ -764,7 +766,8 @@ public abstract class GeneratedMessageLite< throws IOException { int fieldNumber = typeId; int tag = WireFormat.makeTag(typeId, WireFormat.WIRETYPE_LENGTH_DELIMITED); - parseExtension(input, extensionRegistry, extension, tag, fieldNumber); + // TODO(b/230609037): remove the unused variable + boolean unused = parseExtension(input, extensionRegistry, extension, tag, fieldNumber); } private void mergeMessageSetExtensionFromBytes( @@ -787,6 +790,7 @@ public abstract class GeneratedMessageLite< .setField(extension.descriptor, extension.singularToFieldSetType(value)); } + @CanIgnoreReturnValue FieldSet ensureExtensionsAreMutable() { if (extensions.isImmutable()) { extensions = extensions.clone(); @@ -1424,8 +1428,10 @@ public abstract class GeneratedMessageLite< } boolean isInitialized = Protobuf.getInstance().schemaFor(message).isInitialized(message); if (shouldMemoize) { - message.dynamicMethod( - MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null); + // TODO(b/230609037): remove the unused variable + Object unused = + message.dynamicMethod( + MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null); } return isInitialized; } diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 4bad7e8e1d..f1e5ac7939 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -1850,6 +1850,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage } /** Calls invoke and throws a RuntimeException if it fails. */ + @CanIgnoreReturnValue private static Object invokeOrDie( final Method method, final Object object, final Object... params) { try { @@ -2130,7 +2131,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage } public void clear(final Builder builder) { - invokeOrDie(clearMethod, builder); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); } } @@ -2213,7 +2215,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void set(final GeneratedMessageV3.Builder builder, final Object value) { - invokeOrDie(setMethod, builder, value); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(setMethod, builder, value); } @Override @@ -2228,7 +2231,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void clear(final GeneratedMessageV3.Builder builder) { - invokeOrDie(clearMethod, builder); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); } } @@ -2444,13 +2448,15 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void setRepeated( final GeneratedMessageV3.Builder builder, final int index, final Object value) { - invokeOrDie(setRepeatedMethod, builder, index, value); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(setRepeatedMethod, builder, index, value); } @Override public void addRepeated( final GeneratedMessageV3.Builder builder, final Object value) { - invokeOrDie(addRepeatedMethod, builder, value); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(addRepeatedMethod, builder, value); } @Override @@ -2465,7 +2471,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void clear(final GeneratedMessageV3.Builder builder) { - invokeOrDie(clearMethod, builder); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(clearMethod, builder); } } @@ -2788,8 +2795,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void set(final Builder builder, final Object value) { if (supportUnknownEnumValue) { - invokeOrDie(setValueMethod, builder, - ((EnumValueDescriptor) value).getNumber()); + // TODO(b/230609037): remove the unused variable + Object unused = + invokeOrDie(setValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); return; } super.set(builder, invokeOrDie(valueOfMethod, null, value)); @@ -2875,8 +2883,13 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void setRepeated(final Builder builder, final int index, final Object value) { if (supportUnknownEnumValue) { - invokeOrDie(setRepeatedValueMethod, builder, index, - ((EnumValueDescriptor) value).getNumber()); + // TODO(b/230609037): remove the unused variable + Object unused = + invokeOrDie( + setRepeatedValueMethod, + builder, + index, + ((EnumValueDescriptor) value).getNumber()); return; } super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value)); @@ -2884,8 +2897,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void addRepeated(final Builder builder, final Object value) { if (supportUnknownEnumValue) { - invokeOrDie(addRepeatedValueMethod, builder, - ((EnumValueDescriptor) value).getNumber()); + // TODO(b/230609037): remove the unused variable + Object unused = + invokeOrDie( + addRepeatedValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); return; } super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value)); @@ -2939,7 +2954,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage @Override public void set(GeneratedMessageV3.Builder builder, Object value) { if (value instanceof ByteString) { - invokeOrDie(setBytesMethodBuilder, builder, value); + // TODO(b/230609037): remove the unused variable + Object unused = invokeOrDie(setBytesMethodBuilder, builder, value); } else { super.set(builder, value); } diff --git a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java index f51436c83d..d56af6b0e1 100644 --- a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.RandomAccess; /** * {@code RepeatedFieldBuilder} implements a structure that a protocol message uses to hold a @@ -572,7 +573,7 @@ public class RepeatedFieldBuilder< MType extends GeneratedMessage, BType extends GeneratedMessage.Builder, IType extends MessageOrBuilder> - extends AbstractList implements List { + extends AbstractList implements List, RandomAccess { RepeatedFieldBuilder builder; @@ -606,7 +607,7 @@ public class RepeatedFieldBuilder< MType extends GeneratedMessage, BType extends GeneratedMessage.Builder, IType extends MessageOrBuilder> - extends AbstractList implements List { + extends AbstractList implements List, RandomAccess { RepeatedFieldBuilder builder; @@ -640,7 +641,7 @@ public class RepeatedFieldBuilder< MType extends GeneratedMessage, BType extends GeneratedMessage.Builder, IType extends MessageOrBuilder> - extends AbstractList implements List { + extends AbstractList implements List, RandomAccess { RepeatedFieldBuilder builder; diff --git a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java index 91bc3e286d..f6acc77393 100644 --- a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java +++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.RandomAccess; /** * {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a @@ -572,7 +573,7 @@ public class RepeatedFieldBuilderV3< MType extends AbstractMessage, BType extends AbstractMessage.Builder, IType extends MessageOrBuilder> - extends AbstractList implements List { + extends AbstractList implements List, RandomAccess { RepeatedFieldBuilderV3 builder; @@ -606,7 +607,7 @@ public class RepeatedFieldBuilderV3< MType extends AbstractMessage, BType extends AbstractMessage.Builder, IType extends MessageOrBuilder> - extends AbstractList implements List { + extends AbstractList implements List, RandomAccess { RepeatedFieldBuilderV3 builder; @@ -640,7 +641,7 @@ public class RepeatedFieldBuilderV3< MType extends AbstractMessage, BType extends AbstractMessage.Builder, IType extends MessageOrBuilder> - extends AbstractList implements List { + extends AbstractList implements List, RandomAccess { RepeatedFieldBuilderV3 builder; diff --git a/java/core/src/test/java/com/google/protobuf/CachedFieldSizeTest.java b/java/core/src/test/java/com/google/protobuf/CachedFieldSizeTest.java index dc0ceb6012..d6f299a0d6 100644 --- a/java/core/src/test/java/com/google/protobuf/CachedFieldSizeTest.java +++ b/java/core/src/test/java/com/google/protobuf/CachedFieldSizeTest.java @@ -52,7 +52,7 @@ public final class CachedFieldSizeTest { // Serialize once to cache all field sizes. This will use the experimental runtime because // the proto has optimize_for = CODE_SIZE. - message.toByteArray(); + byte[] unused = message.toByteArray(); // Serialize individual submessages. This will use the generated implementation. If the // experimental runtime hasn't set the correct cached size, this will throw an exception. byte[] data2 = message.getProto2Child().toByteArray(); diff --git a/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java index 1ebf457a6b..db3a0c26d2 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java @@ -573,7 +573,7 @@ public class CodedInputStreamTest { // returning our big serialized message 'count' times. InputStream is = new RepeatingInputStream(serializedMessage, count); // Parse should succeed! - TestAllTypes.parseFrom(is); + TestAllTypes unused = TestAllTypes.parseFrom(is); } /** diff --git a/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java b/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java index 2ff60da8f0..e91911fa68 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java @@ -112,7 +112,7 @@ public class LazyStringEndToEndTest { assertThat(proto.getRepeatedString(1)).isSameInstanceAs(c); // Ensure serialization keeps strings cached. - proto.toByteString(); + ByteString unused = proto.toByteString(); // And now the string should stay cached. assertThat(proto.getOptionalString()).isSameInstanceAs(a); 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 6686a38864..4adc6308df 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -131,7 +131,8 @@ public class LiteTest { output.flush(); // This tests a bug we had once with removal right at the boundary of the array. It would throw // at runtime so no need to assert. - TestAllTypesLite.parseFrom(new ByteArrayInputStream(byteStream.toByteArray())); + TestAllTypesLite unused = + TestAllTypesLite.parseFrom(new ByteArrayInputStream(byteStream.toByteArray())); } @Test diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 6bedc64d15..c02f9eb7f8 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -115,6 +115,7 @@ Any::Any(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Any::Any(const Any& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Any* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.type_url_){} , decltype(_impl_.value_){} @@ -127,16 +128,16 @@ Any::Any(const Any& from) _impl_.type_url_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_type_url().empty()) { - _impl_.type_url_.Set(from._internal_type_url(), - GetArenaForAllocation()); + _this->_impl_.type_url_.Set(from._internal_type_url(), + _this->GetArenaForAllocation()); } _impl_.value_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.value_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_value().empty()) { - _impl_.value_.Set(from._internal_value(), - GetArenaForAllocation()); + _this->_impl_.value_.Set(from._internal_value(), + _this->GetArenaForAllocation()); } // @@protoc_insertion_point(copy_constructor:google.protobuf.Any) } @@ -301,26 +302,22 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Any::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Any::GetClassData() const { return &_class_data_; } -void Any::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Any::MergeFrom(const Any& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) - GOOGLE_DCHECK_NE(&from, this); +void Any::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_type_url().empty()) { - _internal_set_type_url(from._internal_type_url()); + _this->_internal_set_type_url(from._internal_type_url()); } if (!from._internal_value().empty()) { - _internal_set_value(from._internal_value()); + _this->_internal_set_value(from._internal_value()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Any::CopyFrom(const Any& from) { diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 8fa3ab074d..8ef040c894 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -171,9 +171,11 @@ class PROTOBUF_EXPORT Any final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Any& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Any& from); + void MergeFrom( const Any& from) { + Any::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 98eed9e904..24b60497cd 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -196,6 +196,7 @@ Api::Api(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Api::Api(const Api& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Api* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.methods_){from._impl_.methods_} , decltype(_impl_.options_){from._impl_.options_} @@ -212,21 +213,21 @@ Api::Api(const Api& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.version_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.version_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_version().empty()) { - _impl_.version_.Set(from._internal_version(), - GetArenaForAllocation()); + _this->_impl_.version_.Set(from._internal_version(), + _this->GetArenaForAllocation()); } if (from._internal_has_source_context()) { - _impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_); + _this->_impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_); } - _impl_.syntax_ = from._impl_.syntax_; + _this->_impl_.syntax_ = from._impl_.syntax_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Api) } @@ -538,35 +539,32 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Api::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Api::GetClassData() const { return &_class_data_; } -void Api::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Api::MergeFrom(const Api& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) - GOOGLE_DCHECK_NE(&from, this); +void Api::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.methods_.MergeFrom(from._impl_.methods_); - _impl_.options_.MergeFrom(from._impl_.options_); - _impl_.mixins_.MergeFrom(from._impl_.mixins_); + _this->_impl_.methods_.MergeFrom(from._impl_.methods_); + _this->_impl_.options_.MergeFrom(from._impl_.options_); + _this->_impl_.mixins_.MergeFrom(from._impl_.mixins_); if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (!from._internal_version().empty()) { - _internal_set_version(from._internal_version()); + _this->_internal_set_version(from._internal_version()); } if (from._internal_has_source_context()) { - _internal_mutable_source_context()->::PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context()); + _this->_internal_mutable_source_context()->::PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom( + from._internal_source_context()); } if (from._internal_syntax() != 0) { - _internal_set_syntax(from._internal_syntax()); + _this->_internal_set_syntax(from._internal_syntax()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Api::CopyFrom(const Api& from) { @@ -627,6 +625,7 @@ Method::Method(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Method::Method(const Method& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Method* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.options_){from._impl_.options_} , decltype(_impl_.name_){} @@ -643,24 +642,24 @@ Method::Method(const Method& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.request_type_url_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.request_type_url_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_request_type_url().empty()) { - _impl_.request_type_url_.Set(from._internal_request_type_url(), - GetArenaForAllocation()); + _this->_impl_.request_type_url_.Set(from._internal_request_type_url(), + _this->GetArenaForAllocation()); } _impl_.response_type_url_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.response_type_url_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_response_type_url().empty()) { - _impl_.response_type_url_.Set(from._internal_response_type_url(), - GetArenaForAllocation()); + _this->_impl_.response_type_url_.Set(from._internal_response_type_url(), + _this->GetArenaForAllocation()); } ::memcpy(&_impl_.request_streaming_, &from._impl_.request_streaming_, static_cast(reinterpret_cast(&_impl_.syntax_) - @@ -962,39 +961,35 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Method::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Method::GetClassData() const { return &_class_data_; } -void Method::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Method::MergeFrom(const Method& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) - GOOGLE_DCHECK_NE(&from, this); +void Method::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.options_.MergeFrom(from._impl_.options_); + _this->_impl_.options_.MergeFrom(from._impl_.options_); if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (!from._internal_request_type_url().empty()) { - _internal_set_request_type_url(from._internal_request_type_url()); + _this->_internal_set_request_type_url(from._internal_request_type_url()); } if (!from._internal_response_type_url().empty()) { - _internal_set_response_type_url(from._internal_response_type_url()); + _this->_internal_set_response_type_url(from._internal_response_type_url()); } if (from._internal_request_streaming() != 0) { - _internal_set_request_streaming(from._internal_request_streaming()); + _this->_internal_set_request_streaming(from._internal_request_streaming()); } if (from._internal_response_streaming() != 0) { - _internal_set_response_streaming(from._internal_response_streaming()); + _this->_internal_set_response_streaming(from._internal_response_streaming()); } if (from._internal_syntax() != 0) { - _internal_set_syntax(from._internal_syntax()); + _this->_internal_set_syntax(from._internal_syntax()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Method::CopyFrom(const Method& from) { @@ -1054,6 +1049,7 @@ Mixin::Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Mixin::Mixin(const Mixin& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Mixin* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.name_){} , decltype(_impl_.root_){} @@ -1065,16 +1061,16 @@ Mixin::Mixin(const Mixin& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.root_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.root_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_root().empty()) { - _impl_.root_.Set(from._internal_root(), - GetArenaForAllocation()); + _this->_impl_.root_.Set(from._internal_root(), + _this->GetArenaForAllocation()); } // @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin) } @@ -1242,26 +1238,22 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Mixin::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Mixin::GetClassData() const { return &_class_data_; } -void Mixin::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Mixin::MergeFrom(const Mixin& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) - GOOGLE_DCHECK_NE(&from, this); +void Mixin::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (!from._internal_root().empty()) { - _internal_set_root(from._internal_root()); + _this->_internal_set_root(from._internal_root()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Mixin::CopyFrom(const Mixin& from) { diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 744e467710..86adb0c42d 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -146,9 +146,11 @@ class PROTOBUF_EXPORT Api final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Api& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Api& from); + void MergeFrom( const Api& from) { + Api::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -404,9 +406,11 @@ class PROTOBUF_EXPORT Method final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Method& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Method& from); + void MergeFrom( const Method& from) { + Method::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -640,9 +644,11 @@ class PROTOBUF_EXPORT Mixin final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Mixin& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Mixin& from); + void MergeFrom( const Mixin& from) { + Mixin::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/compiler/cpp/enum_field.cc b/src/google/protobuf/compiler/cpp/enum_field.cc index 254ac3bb96..4b91547a32 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/enum_field.cc @@ -123,7 +123,7 @@ void EnumFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const { Formatter format(printer, variables_); - format("_internal_set_$name$(from._internal_$name$());\n"); + format("_this->_internal_set_$name$(from._internal_$name$());\n"); } void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { @@ -134,7 +134,7 @@ void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void EnumFieldGenerator::GenerateCopyConstructorCode( io::Printer* printer) const { Formatter format(printer, variables_); - format("$field$ = from.$field$;\n"); + format("_this->$field$ = from.$field$;\n"); } void EnumFieldGenerator::GenerateSerializeWithCachedSizesToArray( @@ -329,7 +329,7 @@ void RepeatedEnumFieldGenerator::GenerateClearingCode( void RepeatedEnumFieldGenerator::GenerateMergingCode( io::Printer* printer) const { Formatter format(printer, variables_); - format("$field$.MergeFrom(from.$field$);\n"); + format("_this->$field$.MergeFrom(from.$field$);\n"); } void RepeatedEnumFieldGenerator::GenerateSwappingCode( diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index ba262c230d..a242c59db5 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -252,13 +252,6 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["set_hasbit"] = ""; (*variables)["clear_hasbit"] = ""; - if (HasHasbit(descriptor)) { - (*variables)["set_hasbit_io"] = - StrCat("_Internal::set_has_", FieldName(descriptor), "(&", - (*variables)["has_bits"], ");"); - } else { - (*variables)["set_hasbit_io"] = ""; - } AddAccessorAnnotations(descriptor, options, variables); diff --git a/src/google/protobuf/compiler/cpp/map_field.cc b/src/google/protobuf/compiler/cpp/map_field.cc index f1356e7c03..0091bc9500 100644 --- a/src/google/protobuf/compiler/cpp/map_field.cc +++ b/src/google/protobuf/compiler/cpp/map_field.cc @@ -153,7 +153,7 @@ void MapFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) const { Formatter format(printer, variables_); - format("$field$.MergeFrom(from.$field$);\n"); + format("_this->$field$.MergeFrom(from.$field$);\n"); } void MapFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index a2acc26eb6..b33ee6bee5 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -645,7 +646,7 @@ MessageGenerator::MessageGenerator( MaySetAnnotationVariable(options, "bytesize", injector_template, "OnByteSize(this);\n", &variables_); MaySetAnnotationVariable(options, "mergefrom", injector_template, - "OnMergeFrom(this, &from);\n", &variables_); + "OnMergeFrom(_this, &from);\n", &variables_); } GenerateExtensionAnnotations(descriptor_, options_, &variables_); @@ -1621,27 +1622,28 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { // argument is a generic Message instance, and only define the // custom MergeFrom and CopyFrom instances when the source of the // merge/copy is known to be the same class as the destination. - // TODO(jorg): Define MergeFrom in terms of MergeImpl, rather than - // the other way around, to save even more code size. "using $superclass$::CopyFrom;\n" "void CopyFrom(const $classname$& from);\n" "" "using $superclass$::MergeFrom;\n" - "void MergeFrom(const $classname$& from);\n" + "void MergeFrom(" + " const $classname$& from) {\n" + " $classname$::MergeImpl(*this, from);\n" + "}\n" "private:\n" - "static void MergeImpl(::$proto_ns$::Message* to, const " - "::$proto_ns$::Message& from);\n" + "static void MergeImpl(::$proto_ns$::Message& to_msg, const " + "::$proto_ns$::Message& from_msg);\n" "public:\n"); } else { format( "using $superclass$::CopyFrom;\n" "inline void CopyFrom(const $classname$& from) {\n" - " $superclass$::CopyImpl(this, from);\n" + " $superclass$::CopyImpl(*this, from);\n" "}\n" "" "using $superclass$::MergeFrom;\n" "void MergeFrom(const $classname$& from) {\n" - " $superclass$::MergeImpl(this, from);\n" + " $superclass$::MergeImpl(*this, from);\n" "}\n" "public:\n"); } @@ -2142,7 +2144,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { GenerateMergeFrom(printer); format("\n"); - GenerateClassSpecificMergeFrom(printer); + GenerateClassSpecificMergeImpl(printer); format("\n"); GenerateCopyFrom(printer); @@ -2644,6 +2646,7 @@ void MessageGenerator::GenerateStructors(io::Printer* printer) { "$classname$::$classname$(const $classname$& from)\n" " : $superclass$() {\n"); format.Indent(); + format("$classname$* const _this = this; (void)_this;\n"); if (HasImplData(descriptor_, options_)) { const char* field_sep = " "; @@ -3151,12 +3154,6 @@ void MessageGenerator::GenerateMergeFrom(io::Printer* printer) { "};\n" "const ::$proto_ns$::Message::ClassData*" "$classname$::GetClassData() const { return &_class_data_; }\n" - "\n" - "void $classname$::MergeImpl(::$proto_ns$::Message* to,\n" - " const ::$proto_ns$::Message& from) {\n" - " static_cast<$classname$ *>(to)->MergeFrom(\n" - " static_cast(from));\n" - "}\n" "\n"); } else { // Generate CheckTypeAndMergeFrom(). @@ -3183,17 +3180,29 @@ void MessageGenerator::GenerateMergeFrom(io::Printer* printer) { } } -void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) { +void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; // Generate the class-specific MergeFrom, which avoids the GOOGLE_CHECK and cast. Formatter format(printer, variables_); + if (!HasDescriptorMethods(descriptor_->file(), options_)) { + // For messages that don't inherit from Message, just implement MergeFrom + // directly. + format( + "void $classname$::MergeFrom(const $classname$& from) {\n" + " $classname$* const _this = this;\n"); + } else { + format( + "void $classname$::MergeImpl(::$proto_ns$::Message& to_msg, const " + "::$proto_ns$::Message& from_msg) {\n" + " auto* const _this = static_cast<$classname$*>(&to_msg);\n" + " auto& from = static_cast(from_msg);\n"); + } + format.Indent(); format( - "void $classname$::MergeFrom(const $classname$& from) {\n" "$annotate_mergefrom$" "// @@protoc_insertion_point(class_specific_merge_from_start:" - "$full_name$)\n" - " $DCHK$_NE(&from, this);\n"); - format.Indent(); + "$full_name$)\n"); + format("$DCHK$_NE(&from, _this);\n"); format( "$uint32$ cached_has_bits = 0;\n" @@ -3295,7 +3304,8 @@ void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) { if (deferred_has_bit_changes) { // Flush the has bits for the primitives we deferred. GOOGLE_CHECK_LE(0, cached_has_word_index); - format("$has_bits$[$1$] |= cached_has_bits;\n", cached_has_word_index); + format("_this->$has_bits$[$1$] |= cached_has_bits;\n", + cached_has_word_index); } format.Outdent(); @@ -3332,7 +3342,7 @@ void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) { } if (num_weak_fields_) { format( - "$weak_field_map$.MergeFrom(from.$weak_field_map$);" + "_this->$weak_field_map$.MergeFrom(from.$weak_field_map$);" "\n"); } @@ -3340,12 +3350,13 @@ void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) { // the opportunity for tail calls. if (descriptor_->extension_range_count() > 0) { format( - "$extensions$.MergeFrom(internal_default_instance(), " + "_this->$extensions$.MergeFrom(internal_default_instance(), " "from.$extensions$);\n"); } format( - "_internal_metadata_.MergeFrom<$unknown_fields_type$>(from._internal_" + "_this->_internal_metadata_.MergeFrom<$unknown_fields_type$>(from._" + "internal_" "metadata_);\n"); format.Outdent(); @@ -3388,7 +3399,7 @@ void MessageGenerator::GenerateCopyFrom(io::Printer* printer) { // has changed after Clear. format("#ifndef NDEBUG\n"); if (HasDescriptorMethods(descriptor_->file(), options_)) { - format("FailIfCopyFromDescendant(this, from);\n"); + format("FailIfCopyFromDescendant(*this, from);\n"); } else { format("size_t from_size = from.ByteSizeLong();\n"); } diff --git a/src/google/protobuf/compiler/cpp/message.h b/src/google/protobuf/compiler/cpp/message.h index ec23c44081..ba2e215774 100644 --- a/src/google/protobuf/compiler/cpp/message.h +++ b/src/google/protobuf/compiler/cpp/message.h @@ -129,7 +129,7 @@ class MessageGenerator { void GenerateSerializeWithCachedSizesBodyShuffled(io::Printer* printer); void GenerateByteSize(io::Printer* printer); void GenerateMergeFrom(io::Printer* printer); - void GenerateClassSpecificMergeFrom(io::Printer* printer); + void GenerateClassSpecificMergeImpl(io::Printer* printer); void GenerateCopyFrom(io::Printer* printer); void GenerateSwap(io::Printer* printer); void GenerateIsInitialized(io::Printer* printer); diff --git a/src/google/protobuf/compiler/cpp/message_field.cc b/src/google/protobuf/compiler/cpp/message_field.cc index 65b63ae47a..9c8b8a060b 100644 --- a/src/google/protobuf/compiler/cpp/message_field.cc +++ b/src/google/protobuf/compiler/cpp/message_field.cc @@ -406,12 +406,12 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const { Formatter format(printer, variables_); if (implicit_weak_field_) { format( - "_Internal::mutable_$name$(this)->CheckTypeAndMergeFrom(\n" + "_Internal::mutable_$name$(_this)->CheckTypeAndMergeFrom(\n" " _Internal::$name$(&from));\n"); } else { format( - "_internal_mutable_$name$()->$type$::MergeFrom(from._internal_$name$())" - ";\n"); + "_this->_internal_mutable_$name$()->$type$::MergeFrom(\n" + " from._internal_$name$());\n"); } } @@ -444,7 +444,7 @@ void MessageFieldGenerator::GenerateCopyConstructorCode( Formatter format(printer, variables_); format( "if (from._internal_has_$name$()) {\n" - " $field$ = new $type$(*from.$field$);\n" + " _this->$field$ = new $type$(*from.$field$);\n" "}\n"); } @@ -831,7 +831,7 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode( GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); - format("$field$.MergeFrom(from.$field$);\n"); + format("_this->$field$.MergeFrom(from.$field$);\n"); } void RepeatedMessageFieldGenerator::GenerateSwappingCode( diff --git a/src/google/protobuf/compiler/cpp/primitive_field.cc b/src/google/protobuf/compiler/cpp/primitive_field.cc index 9ffbe76ef1..db0ae2d606 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -178,7 +178,7 @@ void PrimitiveFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) const { Formatter format(printer, variables_); - format("_internal_set_$name$(from._internal_$name$());\n"); + format("_this->_internal_set_$name$(from._internal_$name$());\n"); } void PrimitiveFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { @@ -189,7 +189,7 @@ void PrimitiveFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void PrimitiveFieldGenerator::GenerateCopyConstructorCode( io::Printer* printer) const { Formatter format(printer, variables_); - format("$field$ = from.$field$;\n"); + format("_this->$field$ = from.$field$;\n"); } void PrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( @@ -404,7 +404,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateClearingCode( void RepeatedPrimitiveFieldGenerator::GenerateMergingCode( io::Printer* printer) const { Formatter format(printer, variables_); - format("$field$.MergeFrom(from.$field$);\n"); + format("_this->$field$.MergeFrom(from.$field$);\n"); } void RepeatedPrimitiveFieldGenerator::GenerateSwappingCode( diff --git a/src/google/protobuf/compiler/cpp/string_field.cc b/src/google/protobuf/compiler/cpp/string_field.cc index 8974b6afe6..a8d1f58a34 100644 --- a/src/google/protobuf/compiler/cpp/string_field.cc +++ b/src/google/protobuf/compiler/cpp/string_field.cc @@ -403,7 +403,7 @@ void StringFieldGenerator::GenerateMessageClearingCode( void StringFieldGenerator::GenerateMergingCode(io::Printer* printer) const { Formatter format(printer, variables_); // TODO(gpike): improve this - format("_internal_set_$name$(from._internal_$name$());\n"); + format("_this->_internal_set_$name$(from._internal_$name$());\n"); } void StringFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { @@ -445,7 +445,7 @@ void StringFieldGenerator::GenerateCopyConstructorCode( Formatter format(printer, variables_); GenerateConstructorCode(printer); if (inlined_) { - format("new (&$field$) ::_pbi::InlinedStringField();\n"); + format("new (&_this->$field$) ::_pbi::InlinedStringField();\n"); } if (HasHasbit(descriptor_)) { @@ -458,13 +458,13 @@ void StringFieldGenerator::GenerateCopyConstructorCode( if (!inlined_) { format( - "$field$.Set(from._internal_$name$(), \n" - " GetArenaForAllocation());\n"); + "_this->$field$.Set(from._internal_$name$(), \n" + " _this->GetArenaForAllocation());\n"); } else { format( - "$field$.Set(from._internal_$name$(),\n" - " GetArenaForAllocation(), _internal_$name$_donated(), " - "&$donating_states_word$, $mask_for_undonate$, this);\n"); + "_this->$field$.Set(from._internal_$name$(),\n" + " _this->GetArenaForAllocation(), _this->_internal_$name$_donated(), " + "&_this->$donating_states_word$, $mask_for_undonate$, _this);\n"); } format.Outdent(); @@ -874,7 +874,7 @@ void RepeatedStringFieldGenerator::GenerateClearingCode( void RepeatedStringFieldGenerator::GenerateMergingCode( io::Printer* printer) const { Formatter format(printer, variables_); - format("$field$.MergeFrom(from.$field$);\n"); + format("_this->$field$.MergeFrom(from.$field$);\n"); } void RepeatedStringFieldGenerator::GenerateSwappingCode( diff --git a/src/google/protobuf/compiler/java/message_lite.h b/src/google/protobuf/compiler/java/message_lite.h index 3999132355..d1e4b68949 100644 --- a/src/google/protobuf/compiler/java/message_lite.h +++ b/src/google/protobuf/compiler/java/message_lite.h @@ -35,9 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ -#include -#include - #include #include diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 0a25b0c16d..8f8d83f02e 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -256,6 +256,7 @@ Version::Version(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Version::Version(const Version& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Version* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -270,8 +271,8 @@ Version::Version(const Version& from) _impl_.suffix_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_suffix()) { - _impl_.suffix_.Set(from._internal_suffix(), - GetArenaForAllocation()); + _this->_impl_.suffix_.Set(from._internal_suffix(), + _this->GetArenaForAllocation()); } ::memcpy(&_impl_.major_, &from._impl_.major_, static_cast(reinterpret_cast(&_impl_.patch_) - @@ -489,36 +490,32 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Version::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Version::GetClassData() const { return &_class_data_; } -void Version::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Version::MergeFrom(const Version& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.Version) - GOOGLE_DCHECK_NE(&from, this); +void Version::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.Version) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000000fu) { if (cached_has_bits & 0x00000001u) { - _internal_set_suffix(from._internal_suffix()); + _this->_internal_set_suffix(from._internal_suffix()); } if (cached_has_bits & 0x00000002u) { - _impl_.major_ = from._impl_.major_; + _this->_impl_.major_ = from._impl_.major_; } if (cached_has_bits & 0x00000004u) { - _impl_.minor_ = from._impl_.minor_; + _this->_impl_.minor_ = from._impl_.minor_; } if (cached_has_bits & 0x00000008u) { - _impl_.patch_ = from._impl_.patch_; + _this->_impl_.patch_ = from._impl_.patch_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Version::CopyFrom(const Version& from) { @@ -585,6 +582,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena } CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + CodeGeneratorRequest* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -599,11 +597,11 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from) _impl_.parameter_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_parameter()) { - _impl_.parameter_.Set(from._internal_parameter(), - GetArenaForAllocation()); + _this->_impl_.parameter_.Set(from._internal_parameter(), + _this->GetArenaForAllocation()); } if (from._internal_has_compiler_version()) { - _impl_.compiler_version_ = new ::PROTOBUF_NAMESPACE_ID::compiler::Version(*from._impl_.compiler_version_); + _this->_impl_.compiler_version_ = new ::PROTOBUF_NAMESPACE_ID::compiler::Version(*from._impl_.compiler_version_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorRequest) } @@ -849,31 +847,28 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData CodeGeneratorRequest::_class_d }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorRequest::GetClassData() const { return &_class_data_; } -void CodeGeneratorRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) - GOOGLE_DCHECK_NE(&from, this); +void CodeGeneratorRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.file_to_generate_.MergeFrom(from._impl_.file_to_generate_); - _impl_.proto_file_.MergeFrom(from._impl_.proto_file_); + _this->_impl_.file_to_generate_.MergeFrom(from._impl_.file_to_generate_); + _this->_impl_.proto_file_.MergeFrom(from._impl_.proto_file_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_parameter(from._internal_parameter()); + _this->_internal_set_parameter(from._internal_parameter()); } if (cached_has_bits & 0x00000002u) { - _internal_mutable_compiler_version()->::PROTOBUF_NAMESPACE_ID::compiler::Version::MergeFrom(from._internal_compiler_version()); + _this->_internal_mutable_compiler_version()->::PROTOBUF_NAMESPACE_ID::compiler::Version::MergeFrom( + from._internal_compiler_version()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void CodeGeneratorRequest::CopyFrom(const CodeGeneratorRequest& from) { @@ -946,6 +941,7 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(::PROTOBUF_NAMESPACE_ID:: } CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorResponse_File& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + CodeGeneratorResponse_File* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -960,27 +956,27 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.insertion_point_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.insertion_point_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_insertion_point()) { - _impl_.insertion_point_.Set(from._internal_insertion_point(), - GetArenaForAllocation()); + _this->_impl_.insertion_point_.Set(from._internal_insertion_point(), + _this->GetArenaForAllocation()); } _impl_.content_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.content_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_content()) { - _impl_.content_.Set(from._internal_content(), - GetArenaForAllocation()); + _this->_impl_.content_.Set(from._internal_content(), + _this->GetArenaForAllocation()); } if (from._internal_has_generated_code_info()) { - _impl_.generated_code_info_ = new ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo(*from._impl_.generated_code_info_); + _this->_impl_.generated_code_info_ = new ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo(*from._impl_.generated_code_info_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse.File) } @@ -1233,35 +1229,32 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData CodeGeneratorResponse_File::_c }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorResponse_File::GetClassData() const { return &_class_data_; } -void CodeGeneratorResponse_File::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) - GOOGLE_DCHECK_NE(&from, this); +void CodeGeneratorResponse_File::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000000fu) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_set_insertion_point(from._internal_insertion_point()); + _this->_internal_set_insertion_point(from._internal_insertion_point()); } if (cached_has_bits & 0x00000004u) { - _internal_set_content(from._internal_content()); + _this->_internal_set_content(from._internal_content()); } if (cached_has_bits & 0x00000008u) { - _internal_mutable_generated_code_info()->::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo::MergeFrom(from._internal_generated_code_info()); + _this->_internal_mutable_generated_code_info()->::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo::MergeFrom( + from._internal_generated_code_info()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void CodeGeneratorResponse_File::CopyFrom(const CodeGeneratorResponse_File& from) { @@ -1323,6 +1316,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(::PROTOBUF_NAMESPACE_ID::Arena* are } CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + CodeGeneratorResponse* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -1336,10 +1330,10 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from) _impl_.error_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_error()) { - _impl_.error_.Set(from._internal_error(), - GetArenaForAllocation()); + _this->_impl_.error_.Set(from._internal_error(), + _this->GetArenaForAllocation()); } - _impl_.supported_features_ = from._impl_.supported_features_; + _this->_impl_.supported_features_ = from._impl_.supported_features_; // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse) } @@ -1538,31 +1532,27 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData CodeGeneratorResponse::_class_ }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorResponse::GetClassData() const { return &_class_data_; } -void CodeGeneratorResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) - GOOGLE_DCHECK_NE(&from, this); +void CodeGeneratorResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.file_.MergeFrom(from._impl_.file_); + _this->_impl_.file_.MergeFrom(from._impl_.file_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_error(from._internal_error()); + _this->_internal_set_error(from._internal_error()); } if (cached_has_bits & 0x00000002u) { - _impl_.supported_features_ = from._impl_.supported_features_; + _this->_impl_.supported_features_ = from._impl_.supported_features_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void CodeGeneratorResponse::CopyFrom(const CodeGeneratorResponse& from) { diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 07bbaa38db..2bbe3b5b66 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -189,9 +189,11 @@ class PROTOC_EXPORT Version final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Version& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Version& from); + void MergeFrom( const Version& from) { + Version::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -397,9 +399,11 @@ class PROTOC_EXPORT CodeGeneratorRequest final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const CodeGeneratorRequest& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const CodeGeneratorRequest& from); + void MergeFrom( const CodeGeneratorRequest& from) { + CodeGeneratorRequest::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -626,9 +630,11 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const CodeGeneratorResponse_File& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const CodeGeneratorResponse_File& from); + void MergeFrom( const CodeGeneratorResponse_File& from) { + CodeGeneratorResponse_File::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -849,9 +855,11 @@ class PROTOC_EXPORT CodeGeneratorResponse final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const CodeGeneratorResponse& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const CodeGeneratorResponse& from); + void MergeFrom( const CodeGeneratorResponse& from) { + CodeGeneratorResponse::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index c591173985..764f9aba38 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -167,7 +167,11 @@ bool Subprocess::Communicate(const Message& input, Message* output, GOOGLE_CHECK(child_handle_ != nullptr) << "Must call Start() first."; - std::string input_data = input.SerializeAsString(); + std::string input_data; + if (!input.SerializeToString(&input_data)) { + *error = "Failed to serialize request."; + return false; + } std::string output_data; int input_pos = 0; @@ -369,7 +373,11 @@ bool Subprocess::Communicate(const Message& input, Message* output, // Make sure SIGPIPE is disabled so that if the child dies it doesn't kill us. SignalHandler* old_pipe_handler = signal(SIGPIPE, SIG_IGN); - std::string input_data = input.SerializeAsString(); + std::string input_data; + if (!input.SerializeToString(&input_data)) { + *error = "Failed to serialize request."; + return false; + } std::string output_data; int input_pos = 0; diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 123b22aba9..5f3427dc72 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -3709,11 +3709,12 @@ class DescriptorBuilder { void RequestHintOnFieldNumbers( const Message& reason, DescriptorPool::ErrorCollector::ErrorLocation reason_location, - int fields_count = 1) { - constexpr int kMaxSuggestions = 3; + int range_start = 0, int range_end = 1) { + auto fit = [](int value) { + return std::min(std::max(value, 0), FieldDescriptor::kMaxNumber); + }; fields_to_suggest = - std::min(kMaxSuggestions, - fields_to_suggest + std::min(kMaxSuggestions, fields_count)); + fit(fields_to_suggest + fit(fit(range_end) - fit(range_start))); if (first_reason) return; first_reason = &reason; first_reason_location = reason_location; @@ -5825,8 +5826,8 @@ void DescriptorBuilder::BuildExtensionRange( result->end = proto.end(); if (result->start <= 0) { message_hints_[parent].RequestHintOnFieldNumbers( - proto, DescriptorPool::ErrorCollector::NUMBER, - std::max(0, result->end - result->start)); + proto, DescriptorPool::ErrorCollector::NUMBER, result->start, + result->end); AddError(parent->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, "Extension numbers must be positive integers."); } @@ -5865,8 +5866,8 @@ void DescriptorBuilder::BuildReservedRange( result->end = proto.end(); if (result->start <= 0) { message_hints_[parent].RequestHintOnFieldNumbers( - proto, DescriptorPool::ErrorCollector::NUMBER, - std::max(0, result->end - result->start)); + proto, DescriptorPool::ErrorCollector::NUMBER, result->start, + result->end); AddError(parent->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, "Reserved numbers must be positive integers."); } @@ -6709,7 +6710,8 @@ void DescriptorBuilder::SuggestFieldNumbers(FileDescriptor* file, const Descriptor* message = &file->message_types_[message_index]; auto* hints = FindOrNull(message_hints_, message); if (!hints) continue; - int fields_to_suggest = hints->fields_to_suggest; + constexpr int kMaxSuggestions = 3; + int fields_to_suggest = std::min(kMaxSuggestions, hints->fields_to_suggest); if (fields_to_suggest <= 0) continue; struct Range { int from; @@ -6717,18 +6719,18 @@ void DescriptorBuilder::SuggestFieldNumbers(FileDescriptor* file, }; std::vector used_ordinals; auto add_ordinal = [&](int ordinal) { + if (ordinal <= 0 || ordinal > FieldDescriptor::kMaxNumber) return; if (!used_ordinals.empty() && - used_ordinals.back().to < FieldDescriptor::kMaxNumber && - ordinal == used_ordinals.back().to + 1) { - used_ordinals.back().to = ordinal; + ordinal == used_ordinals.back().to) { + used_ordinals.back().to = ordinal + 1; } else { - used_ordinals.push_back({ordinal, ordinal}); + used_ordinals.push_back({ordinal, ordinal + 1}); } }; auto add_range = [&](int from, int to) { - from = std::max(0, std::min(FieldDescriptor::kMaxNumber, from)); - to = std::max(0, std::min(FieldDescriptor::kMaxNumber, to)); - if (from > to) return; + from = std::max(0, std::min(FieldDescriptor::kMaxNumber + 1, from)); + to = std::max(0, std::min(FieldDescriptor::kMaxNumber + 1, to)); + if (from >= to) return; used_ordinals.push_back({from, to}); }; for (int i = 0; i < message->field_count(); i++) { @@ -6739,14 +6741,14 @@ void DescriptorBuilder::SuggestFieldNumbers(FileDescriptor* file, } for (int i = 0; i < message->reserved_range_count(); i++) { auto range = message->reserved_range(i); - add_range(range->start, range->end - 1); + add_range(range->start, range->end); } for (int i = 0; i < message->extension_range_count(); i++) { auto range = message->extension_range(i); - add_range(range->start, range->end - 1); + add_range(range->start, range->end); } used_ordinals.push_back( - {FieldDescriptor::kMaxNumber, std::numeric_limits::max()}); + {FieldDescriptor::kMaxNumber, FieldDescriptor::kMaxNumber + 1}); used_ordinals.push_back({FieldDescriptor::kFirstReservedNumber, FieldDescriptor::kLastReservedNumber}); std::sort(used_ordinals.begin(), used_ordinals.end(), @@ -6764,7 +6766,7 @@ void DescriptorBuilder::SuggestFieldNumbers(FileDescriptor* file, fields_to_suggest--; } if (fields_to_suggest == 0) break; - current_ordinal = std::max(current_ordinal, current_range.to + 1); + current_ordinal = std::max(current_ordinal, current_range.to); } if (hints->first_reason) { AddError(message->full_name(), *hints->first_reason, diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 535a439bf1..d3bfb461ea 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1334,6 +1334,7 @@ FileDescriptorSet::FileDescriptorSet(::PROTOBUF_NAMESPACE_ID::Arena* arena, } FileDescriptorSet::FileDescriptorSet(const FileDescriptorSet& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + FileDescriptorSet* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.file_){from._impl_.file_} , /*decltype(_impl_._cached_size_)*/{}}; @@ -1468,21 +1469,17 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FileDescriptorSet::_class_data }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileDescriptorSet::GetClassData() const { return &_class_data_; } -void FileDescriptorSet::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void FileDescriptorSet::MergeFrom(const FileDescriptorSet& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorSet) - GOOGLE_DCHECK_NE(&from, this); +void FileDescriptorSet::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorSet) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.file_.MergeFrom(from._impl_.file_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.file_.MergeFrom(from._impl_.file_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void FileDescriptorSet::CopyFrom(const FileDescriptorSet& from) { @@ -1550,6 +1547,7 @@ FileDescriptorProto::FileDescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* arena, } FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + FileDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -1572,30 +1570,30 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.package_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.package_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_package()) { - _impl_.package_.Set(from._internal_package(), - GetArenaForAllocation()); + _this->_impl_.package_.Set(from._internal_package(), + _this->GetArenaForAllocation()); } _impl_.syntax_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.syntax_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_syntax()) { - _impl_.syntax_.Set(from._internal_syntax(), - GetArenaForAllocation()); + _this->_impl_.syntax_.Set(from._internal_syntax(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::FileOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::FileOptions(*from._impl_.options_); } if (from._internal_has_source_code_info()) { - _impl_.source_code_info_ = new ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo(*from._impl_.source_code_info_); + _this->_impl_.source_code_info_ = new ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo(*from._impl_.source_code_info_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.FileDescriptorProto) } @@ -2106,45 +2104,43 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FileDescriptorProto::_class_da }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileDescriptorProto::GetClassData() const { return &_class_data_; } -void FileDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void FileDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.dependency_.MergeFrom(from._impl_.dependency_); - _impl_.message_type_.MergeFrom(from._impl_.message_type_); - _impl_.enum_type_.MergeFrom(from._impl_.enum_type_); - _impl_.service_.MergeFrom(from._impl_.service_); - _impl_.extension_.MergeFrom(from._impl_.extension_); - _impl_.public_dependency_.MergeFrom(from._impl_.public_dependency_); - _impl_.weak_dependency_.MergeFrom(from._impl_.weak_dependency_); + _this->_impl_.dependency_.MergeFrom(from._impl_.dependency_); + _this->_impl_.message_type_.MergeFrom(from._impl_.message_type_); + _this->_impl_.enum_type_.MergeFrom(from._impl_.enum_type_); + _this->_impl_.service_.MergeFrom(from._impl_.service_); + _this->_impl_.extension_.MergeFrom(from._impl_.extension_); + _this->_impl_.public_dependency_.MergeFrom(from._impl_.public_dependency_); + _this->_impl_.weak_dependency_.MergeFrom(from._impl_.weak_dependency_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000001fu) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_set_package(from._internal_package()); + _this->_internal_set_package(from._internal_package()); } if (cached_has_bits & 0x00000004u) { - _internal_set_syntax(from._internal_syntax()); + _this->_internal_set_syntax(from._internal_syntax()); } if (cached_has_bits & 0x00000008u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::FileOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::FileOptions::MergeFrom( + from._internal_options()); } if (cached_has_bits & 0x00000010u) { - _internal_mutable_source_code_info()->::PROTOBUF_NAMESPACE_ID::SourceCodeInfo::MergeFrom(from._internal_source_code_info()); + _this->_internal_mutable_source_code_info()->::PROTOBUF_NAMESPACE_ID::SourceCodeInfo::MergeFrom( + from._internal_source_code_info()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void FileDescriptorProto::CopyFrom(const FileDescriptorProto& from) { @@ -2237,6 +2233,7 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(::PROTOBUF_NAMESP } DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorProto_ExtensionRange& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + DescriptorProto_ExtensionRange* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -2246,7 +2243,7 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorP _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions(*from._impl_.options_); } ::memcpy(&_impl_.start_, &from._impl_.start_, static_cast(reinterpret_cast(&_impl_.end_) - @@ -2433,33 +2430,30 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DescriptorProto_ExtensionRange }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto_ExtensionRange::GetClassData() const { return &_class_data_; } -void DescriptorProto_ExtensionRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRange& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) - GOOGLE_DCHECK_NE(&from, this); +void DescriptorProto_ExtensionRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions::MergeFrom( + from._internal_options()); } if (cached_has_bits & 0x00000002u) { - _impl_.start_ = from._impl_.start_; + _this->_impl_.start_ = from._impl_.start_; } if (cached_has_bits & 0x00000004u) { - _impl_.end_ = from._impl_.end_; + _this->_impl_.end_ = from._impl_.end_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void DescriptorProto_ExtensionRange::CopyFrom(const DescriptorProto_ExtensionRange& from) { @@ -2515,6 +2509,7 @@ DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(::PROTOBUF_NAMESPAC } DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(const DescriptorProto_ReservedRange& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + DescriptorProto_ReservedRange* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -2679,30 +2674,26 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DescriptorProto_ReservedRange: }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto_ReservedRange::GetClassData() const { return &_class_data_; } -void DescriptorProto_ReservedRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void DescriptorProto_ReservedRange::MergeFrom(const DescriptorProto_ReservedRange& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) - GOOGLE_DCHECK_NE(&from, this); +void DescriptorProto_ReservedRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _impl_.start_ = from._impl_.start_; + _this->_impl_.start_ = from._impl_.start_; } if (cached_has_bits & 0x00000002u) { - _impl_.end_ = from._impl_.end_; + _this->_impl_.end_ = from._impl_.end_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void DescriptorProto_ReservedRange::CopyFrom(const DescriptorProto_ReservedRange& from) { @@ -2760,6 +2751,7 @@ DescriptorProto::DescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* arena, } DescriptorProto::DescriptorProto(const DescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + DescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -2780,11 +2772,11 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::MessageOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::MessageOptions(*from._impl_.options_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto) } @@ -3216,37 +3208,34 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DescriptorProto::_class_data_ }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto::GetClassData() const { return &_class_data_; } -void DescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void DescriptorProto::MergeFrom(const DescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void DescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.field_.MergeFrom(from._impl_.field_); - _impl_.nested_type_.MergeFrom(from._impl_.nested_type_); - _impl_.enum_type_.MergeFrom(from._impl_.enum_type_); - _impl_.extension_range_.MergeFrom(from._impl_.extension_range_); - _impl_.extension_.MergeFrom(from._impl_.extension_); - _impl_.oneof_decl_.MergeFrom(from._impl_.oneof_decl_); - _impl_.reserved_range_.MergeFrom(from._impl_.reserved_range_); - _impl_.reserved_name_.MergeFrom(from._impl_.reserved_name_); + _this->_impl_.field_.MergeFrom(from._impl_.field_); + _this->_impl_.nested_type_.MergeFrom(from._impl_.nested_type_); + _this->_impl_.enum_type_.MergeFrom(from._impl_.enum_type_); + _this->_impl_.extension_range_.MergeFrom(from._impl_.extension_range_); + _this->_impl_.extension_.MergeFrom(from._impl_.extension_); + _this->_impl_.oneof_decl_.MergeFrom(from._impl_.oneof_decl_); + _this->_impl_.reserved_range_.MergeFrom(from._impl_.reserved_range_); + _this->_impl_.reserved_name_.MergeFrom(from._impl_.reserved_name_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::MessageOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::MessageOptions::MergeFrom( + from._internal_options()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void DescriptorProto::CopyFrom(const DescriptorProto& from) { @@ -3316,6 +3305,7 @@ ExtensionRangeOptions::ExtensionRangeOptions(::PROTOBUF_NAMESPACE_ID::Arena* are } ExtensionRangeOptions::ExtensionRangeOptions(const ExtensionRangeOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + ExtensionRangeOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_.uninterpreted_option_){from._impl_.uninterpreted_option_} @@ -3466,22 +3456,18 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ExtensionRangeOptions::_class_ }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ExtensionRangeOptions::GetClassData() const { return &_class_data_; } -void ExtensionRangeOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void ExtensionRangeOptions::MergeFrom(const ExtensionRangeOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ExtensionRangeOptions) - GOOGLE_DCHECK_NE(&from, this); +void ExtensionRangeOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ExtensionRangeOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void ExtensionRangeOptions::CopyFrom(const ExtensionRangeOptions& from) { @@ -3567,6 +3553,7 @@ FieldDescriptorProto::FieldDescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* arena } FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + FieldDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -3588,43 +3575,43 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.extendee_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.extendee_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_extendee()) { - _impl_.extendee_.Set(from._internal_extendee(), - GetArenaForAllocation()); + _this->_impl_.extendee_.Set(from._internal_extendee(), + _this->GetArenaForAllocation()); } _impl_.type_name_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.type_name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_type_name()) { - _impl_.type_name_.Set(from._internal_type_name(), - GetArenaForAllocation()); + _this->_impl_.type_name_.Set(from._internal_type_name(), + _this->GetArenaForAllocation()); } _impl_.default_value_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.default_value_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_default_value()) { - _impl_.default_value_.Set(from._internal_default_value(), - GetArenaForAllocation()); + _this->_impl_.default_value_.Set(from._internal_default_value(), + _this->GetArenaForAllocation()); } _impl_.json_name_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.json_name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_json_name()) { - _impl_.json_name_.Set(from._internal_json_name(), - GetArenaForAllocation()); + _this->_impl_.json_name_.Set(from._internal_json_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::FieldOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::FieldOptions(*from._impl_.options_); } ::memcpy(&_impl_.number_, &from._impl_.number_, static_cast(reinterpret_cast(&_impl_.type_) - @@ -4085,60 +4072,57 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldDescriptorProto::_class_d }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldDescriptorProto::GetClassData() const { return &_class_data_; } -void FieldDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void FieldDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x000000ffu) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_set_extendee(from._internal_extendee()); + _this->_internal_set_extendee(from._internal_extendee()); } if (cached_has_bits & 0x00000004u) { - _internal_set_type_name(from._internal_type_name()); + _this->_internal_set_type_name(from._internal_type_name()); } if (cached_has_bits & 0x00000008u) { - _internal_set_default_value(from._internal_default_value()); + _this->_internal_set_default_value(from._internal_default_value()); } if (cached_has_bits & 0x00000010u) { - _internal_set_json_name(from._internal_json_name()); + _this->_internal_set_json_name(from._internal_json_name()); } if (cached_has_bits & 0x00000020u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::FieldOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::FieldOptions::MergeFrom( + from._internal_options()); } if (cached_has_bits & 0x00000040u) { - _impl_.number_ = from._impl_.number_; + _this->_impl_.number_ = from._impl_.number_; } if (cached_has_bits & 0x00000080u) { - _impl_.oneof_index_ = from._impl_.oneof_index_; + _this->_impl_.oneof_index_ = from._impl_.oneof_index_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } if (cached_has_bits & 0x00000700u) { if (cached_has_bits & 0x00000100u) { - _impl_.proto3_optional_ = from._impl_.proto3_optional_; + _this->_impl_.proto3_optional_ = from._impl_.proto3_optional_; } if (cached_has_bits & 0x00000200u) { - _impl_.label_ = from._impl_.label_; + _this->_impl_.label_ = from._impl_.label_; } if (cached_has_bits & 0x00000400u) { - _impl_.type_ = from._impl_.type_; + _this->_impl_.type_ = from._impl_.type_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void FieldDescriptorProto::CopyFrom(const FieldDescriptorProto& from) { @@ -4223,6 +4207,7 @@ OneofDescriptorProto::OneofDescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* arena } OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + OneofDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -4235,11 +4220,11 @@ OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::OneofOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::OneofOptions(*from._impl_.options_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.OneofDescriptorProto) } @@ -4416,29 +4401,26 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData OneofDescriptorProto::_class_d }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*OneofDescriptorProto::GetClassData() const { return &_class_data_; } -void OneofDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void OneofDescriptorProto::MergeFrom(const OneofDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void OneofDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::OneofOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::OneofOptions::MergeFrom( + from._internal_options()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void OneofDescriptorProto::CopyFrom(const OneofDescriptorProto& from) { @@ -4495,6 +4477,7 @@ EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange(::P } EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange(const EnumDescriptorProto_EnumReservedRange& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumDescriptorProto_EnumReservedRange* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -4659,30 +4642,26 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumDescriptorProto_EnumReserv }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumDescriptorProto_EnumReservedRange::GetClassData() const { return &_class_data_; } -void EnumDescriptorProto_EnumReservedRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void EnumDescriptorProto_EnumReservedRange::MergeFrom(const EnumDescriptorProto_EnumReservedRange& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) - GOOGLE_DCHECK_NE(&from, this); +void EnumDescriptorProto_EnumReservedRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _impl_.start_ = from._impl_.start_; + _this->_impl_.start_ = from._impl_.start_; } if (cached_has_bits & 0x00000002u) { - _impl_.end_ = from._impl_.end_; + _this->_impl_.end_ = from._impl_.end_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void EnumDescriptorProto_EnumReservedRange::CopyFrom(const EnumDescriptorProto_EnumReservedRange& from) { @@ -4740,6 +4719,7 @@ EnumDescriptorProto::EnumDescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* arena, } EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -4755,11 +4735,11 @@ EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::EnumOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::EnumOptions(*from._impl_.options_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumDescriptorProto) } @@ -5036,32 +5016,29 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumDescriptorProto::_class_da }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumDescriptorProto::GetClassData() const { return &_class_data_; } -void EnumDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void EnumDescriptorProto::MergeFrom(const EnumDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void EnumDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.value_.MergeFrom(from._impl_.value_); - _impl_.reserved_range_.MergeFrom(from._impl_.reserved_range_); - _impl_.reserved_name_.MergeFrom(from._impl_.reserved_name_); + _this->_impl_.value_.MergeFrom(from._impl_.value_); + _this->_impl_.reserved_range_.MergeFrom(from._impl_.reserved_range_); + _this->_impl_.reserved_name_.MergeFrom(from._impl_.reserved_name_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::EnumOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::EnumOptions::MergeFrom( + from._internal_options()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void EnumDescriptorProto::CopyFrom(const EnumDescriptorProto& from) { @@ -5131,6 +5108,7 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(::PROTOBUF_NAMESPACE_ID::Aren } EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumValueDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -5144,13 +5122,13 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProt _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::EnumValueOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::EnumValueOptions(*from._impl_.options_); } - _impl_.number_ = from._impl_.number_; + _this->_impl_.number_ = from._impl_.number_; // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueDescriptorProto) } @@ -5348,33 +5326,30 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumValueDescriptorProto::_cla }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValueDescriptorProto::GetClassData() const { return &_class_data_; } -void EnumValueDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void EnumValueDescriptorProto::MergeFrom(const EnumValueDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void EnumValueDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::EnumValueOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::EnumValueOptions::MergeFrom( + from._internal_options()); } if (cached_has_bits & 0x00000004u) { - _impl_.number_ = from._impl_.number_; + _this->_impl_.number_ = from._impl_.number_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void EnumValueDescriptorProto::CopyFrom(const EnumValueDescriptorProto& from) { @@ -5441,6 +5416,7 @@ ServiceDescriptorProto::ServiceDescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* a } ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + ServiceDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -5454,11 +5430,11 @@ ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& fro _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::ServiceOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::ServiceOptions(*from._impl_.options_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceDescriptorProto) } @@ -5666,30 +5642,27 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ServiceDescriptorProto::_class }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ServiceDescriptorProto::GetClassData() const { return &_class_data_; } -void ServiceDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void ServiceDescriptorProto::MergeFrom(const ServiceDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void ServiceDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.method_.MergeFrom(from._impl_.method_); + _this->_impl_.method_.MergeFrom(from._impl_.method_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::ServiceOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::ServiceOptions::MergeFrom( + from._internal_options()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void ServiceDescriptorProto::CopyFrom(const ServiceDescriptorProto& from) { @@ -5766,6 +5739,7 @@ MethodDescriptorProto::MethodDescriptorProto(::PROTOBUF_NAMESPACE_ID::Arena* are } MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + MethodDescriptorProto* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -5782,27 +5756,27 @@ MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.input_type_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.input_type_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_input_type()) { - _impl_.input_type_.Set(from._internal_input_type(), - GetArenaForAllocation()); + _this->_impl_.input_type_.Set(from._internal_input_type(), + _this->GetArenaForAllocation()); } _impl_.output_type_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.output_type_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_output_type()) { - _impl_.output_type_.Set(from._internal_output_type(), - GetArenaForAllocation()); + _this->_impl_.output_type_.Set(from._internal_output_type(), + _this->GetArenaForAllocation()); } if (from._internal_has_options()) { - _impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::MethodOptions(*from._impl_.options_); + _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::MethodOptions(*from._impl_.options_); } ::memcpy(&_impl_.client_streaming_, &from._impl_.client_streaming_, static_cast(reinterpret_cast(&_impl_.server_streaming_) - @@ -6103,42 +6077,39 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData MethodDescriptorProto::_class_ }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MethodDescriptorProto::GetClassData() const { return &_class_data_; } -void MethodDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void MethodDescriptorProto::MergeFrom(const MethodDescriptorProto& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) - GOOGLE_DCHECK_NE(&from, this); +void MethodDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000003fu) { if (cached_has_bits & 0x00000001u) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _internal_set_input_type(from._internal_input_type()); + _this->_internal_set_input_type(from._internal_input_type()); } if (cached_has_bits & 0x00000004u) { - _internal_set_output_type(from._internal_output_type()); + _this->_internal_set_output_type(from._internal_output_type()); } if (cached_has_bits & 0x00000008u) { - _internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::MethodOptions::MergeFrom(from._internal_options()); + _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::MethodOptions::MergeFrom( + from._internal_options()); } if (cached_has_bits & 0x00000010u) { - _impl_.client_streaming_ = from._impl_.client_streaming_; + _this->_impl_.client_streaming_ = from._impl_.client_streaming_; } if (cached_has_bits & 0x00000020u) { - _impl_.server_streaming_ = from._impl_.server_streaming_; + _this->_impl_.server_streaming_ = from._impl_.server_streaming_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void MethodDescriptorProto::CopyFrom(const MethodDescriptorProto& from) { @@ -6262,6 +6233,7 @@ FileOptions::FileOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } FileOptions::FileOptions(const FileOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + FileOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -6295,80 +6267,80 @@ FileOptions::FileOptions(const FileOptions& from) _impl_.java_package_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_java_package()) { - _impl_.java_package_.Set(from._internal_java_package(), - GetArenaForAllocation()); + _this->_impl_.java_package_.Set(from._internal_java_package(), + _this->GetArenaForAllocation()); } _impl_.java_outer_classname_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.java_outer_classname_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_java_outer_classname()) { - _impl_.java_outer_classname_.Set(from._internal_java_outer_classname(), - GetArenaForAllocation()); + _this->_impl_.java_outer_classname_.Set(from._internal_java_outer_classname(), + _this->GetArenaForAllocation()); } _impl_.go_package_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.go_package_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_go_package()) { - _impl_.go_package_.Set(from._internal_go_package(), - GetArenaForAllocation()); + _this->_impl_.go_package_.Set(from._internal_go_package(), + _this->GetArenaForAllocation()); } _impl_.objc_class_prefix_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.objc_class_prefix_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_objc_class_prefix()) { - _impl_.objc_class_prefix_.Set(from._internal_objc_class_prefix(), - GetArenaForAllocation()); + _this->_impl_.objc_class_prefix_.Set(from._internal_objc_class_prefix(), + _this->GetArenaForAllocation()); } _impl_.csharp_namespace_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.csharp_namespace_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_csharp_namespace()) { - _impl_.csharp_namespace_.Set(from._internal_csharp_namespace(), - GetArenaForAllocation()); + _this->_impl_.csharp_namespace_.Set(from._internal_csharp_namespace(), + _this->GetArenaForAllocation()); } _impl_.swift_prefix_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.swift_prefix_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_swift_prefix()) { - _impl_.swift_prefix_.Set(from._internal_swift_prefix(), - GetArenaForAllocation()); + _this->_impl_.swift_prefix_.Set(from._internal_swift_prefix(), + _this->GetArenaForAllocation()); } _impl_.php_class_prefix_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.php_class_prefix_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_php_class_prefix()) { - _impl_.php_class_prefix_.Set(from._internal_php_class_prefix(), - GetArenaForAllocation()); + _this->_impl_.php_class_prefix_.Set(from._internal_php_class_prefix(), + _this->GetArenaForAllocation()); } _impl_.php_namespace_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.php_namespace_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_php_namespace()) { - _impl_.php_namespace_.Set(from._internal_php_namespace(), - GetArenaForAllocation()); + _this->_impl_.php_namespace_.Set(from._internal_php_namespace(), + _this->GetArenaForAllocation()); } _impl_.php_metadata_namespace_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.php_metadata_namespace_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_php_metadata_namespace()) { - _impl_.php_metadata_namespace_.Set(from._internal_php_metadata_namespace(), - GetArenaForAllocation()); + _this->_impl_.php_metadata_namespace_.Set(from._internal_php_metadata_namespace(), + _this->GetArenaForAllocation()); } _impl_.ruby_package_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.ruby_package_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_ruby_package()) { - _impl_.ruby_package_.Set(from._internal_ruby_package(), - GetArenaForAllocation()); + _this->_impl_.ruby_package_.Set(from._internal_ruby_package(), + _this->GetArenaForAllocation()); } ::memcpy(&_impl_.java_multiple_files_, &from._impl_.java_multiple_files_, static_cast(reinterpret_cast(&_impl_.cc_enable_arenas_) - @@ -7141,91 +7113,87 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FileOptions::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileOptions::GetClassData() const { return &_class_data_; } -void FileOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void FileOptions::MergeFrom(const FileOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileOptions) - GOOGLE_DCHECK_NE(&from, this); +void FileOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x000000ffu) { if (cached_has_bits & 0x00000001u) { - _internal_set_java_package(from._internal_java_package()); + _this->_internal_set_java_package(from._internal_java_package()); } if (cached_has_bits & 0x00000002u) { - _internal_set_java_outer_classname(from._internal_java_outer_classname()); + _this->_internal_set_java_outer_classname(from._internal_java_outer_classname()); } if (cached_has_bits & 0x00000004u) { - _internal_set_go_package(from._internal_go_package()); + _this->_internal_set_go_package(from._internal_go_package()); } if (cached_has_bits & 0x00000008u) { - _internal_set_objc_class_prefix(from._internal_objc_class_prefix()); + _this->_internal_set_objc_class_prefix(from._internal_objc_class_prefix()); } if (cached_has_bits & 0x00000010u) { - _internal_set_csharp_namespace(from._internal_csharp_namespace()); + _this->_internal_set_csharp_namespace(from._internal_csharp_namespace()); } if (cached_has_bits & 0x00000020u) { - _internal_set_swift_prefix(from._internal_swift_prefix()); + _this->_internal_set_swift_prefix(from._internal_swift_prefix()); } if (cached_has_bits & 0x00000040u) { - _internal_set_php_class_prefix(from._internal_php_class_prefix()); + _this->_internal_set_php_class_prefix(from._internal_php_class_prefix()); } if (cached_has_bits & 0x00000080u) { - _internal_set_php_namespace(from._internal_php_namespace()); + _this->_internal_set_php_namespace(from._internal_php_namespace()); } } if (cached_has_bits & 0x0000ff00u) { if (cached_has_bits & 0x00000100u) { - _internal_set_php_metadata_namespace(from._internal_php_metadata_namespace()); + _this->_internal_set_php_metadata_namespace(from._internal_php_metadata_namespace()); } if (cached_has_bits & 0x00000200u) { - _internal_set_ruby_package(from._internal_ruby_package()); + _this->_internal_set_ruby_package(from._internal_ruby_package()); } if (cached_has_bits & 0x00000400u) { - _impl_.java_multiple_files_ = from._impl_.java_multiple_files_; + _this->_impl_.java_multiple_files_ = from._impl_.java_multiple_files_; } if (cached_has_bits & 0x00000800u) { - _impl_.java_generate_equals_and_hash_ = from._impl_.java_generate_equals_and_hash_; + _this->_impl_.java_generate_equals_and_hash_ = from._impl_.java_generate_equals_and_hash_; } if (cached_has_bits & 0x00001000u) { - _impl_.java_string_check_utf8_ = from._impl_.java_string_check_utf8_; + _this->_impl_.java_string_check_utf8_ = from._impl_.java_string_check_utf8_; } if (cached_has_bits & 0x00002000u) { - _impl_.cc_generic_services_ = from._impl_.cc_generic_services_; + _this->_impl_.cc_generic_services_ = from._impl_.cc_generic_services_; } if (cached_has_bits & 0x00004000u) { - _impl_.java_generic_services_ = from._impl_.java_generic_services_; + _this->_impl_.java_generic_services_ = from._impl_.java_generic_services_; } if (cached_has_bits & 0x00008000u) { - _impl_.py_generic_services_ = from._impl_.py_generic_services_; + _this->_impl_.py_generic_services_ = from._impl_.py_generic_services_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } if (cached_has_bits & 0x000f0000u) { if (cached_has_bits & 0x00010000u) { - _impl_.php_generic_services_ = from._impl_.php_generic_services_; + _this->_impl_.php_generic_services_ = from._impl_.php_generic_services_; } if (cached_has_bits & 0x00020000u) { - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; } if (cached_has_bits & 0x00040000u) { - _impl_.optimize_for_ = from._impl_.optimize_for_; + _this->_impl_.optimize_for_ = from._impl_.optimize_for_; } if (cached_has_bits & 0x00080000u) { - _impl_.cc_enable_arenas_ = from._impl_.cc_enable_arenas_; + _this->_impl_.cc_enable_arenas_ = from._impl_.cc_enable_arenas_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void FileOptions::CopyFrom(const FileOptions& from) { @@ -7336,6 +7304,7 @@ MessageOptions::MessageOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } MessageOptions::MessageOptions(const MessageOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + MessageOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -7589,38 +7558,34 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData MessageOptions::_class_data_ = }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MessageOptions::GetClassData() const { return &_class_data_; } -void MessageOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void MessageOptions::MergeFrom(const MessageOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MessageOptions) - GOOGLE_DCHECK_NE(&from, this); +void MessageOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MessageOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000000fu) { if (cached_has_bits & 0x00000001u) { - _impl_.message_set_wire_format_ = from._impl_.message_set_wire_format_; + _this->_impl_.message_set_wire_format_ = from._impl_.message_set_wire_format_; } if (cached_has_bits & 0x00000002u) { - _impl_.no_standard_descriptor_accessor_ = from._impl_.no_standard_descriptor_accessor_; + _this->_impl_.no_standard_descriptor_accessor_ = from._impl_.no_standard_descriptor_accessor_; } if (cached_has_bits & 0x00000004u) { - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; } if (cached_has_bits & 0x00000008u) { - _impl_.map_entry_ = from._impl_.map_entry_; + _this->_impl_.map_entry_ = from._impl_.map_entry_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void MessageOptions::CopyFrom(const MessageOptions& from) { @@ -7696,6 +7661,7 @@ FieldOptions::FieldOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } FieldOptions::FieldOptions(const FieldOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + FieldOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -8030,47 +7996,43 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldOptions::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldOptions::GetClassData() const { return &_class_data_; } -void FieldOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void FieldOptions::MergeFrom(const FieldOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldOptions) - GOOGLE_DCHECK_NE(&from, this); +void FieldOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000007fu) { if (cached_has_bits & 0x00000001u) { - _impl_.ctype_ = from._impl_.ctype_; + _this->_impl_.ctype_ = from._impl_.ctype_; } if (cached_has_bits & 0x00000002u) { - _impl_.jstype_ = from._impl_.jstype_; + _this->_impl_.jstype_ = from._impl_.jstype_; } if (cached_has_bits & 0x00000004u) { - _impl_.packed_ = from._impl_.packed_; + _this->_impl_.packed_ = from._impl_.packed_; } if (cached_has_bits & 0x00000008u) { - _impl_.lazy_ = from._impl_.lazy_; + _this->_impl_.lazy_ = from._impl_.lazy_; } if (cached_has_bits & 0x00000010u) { - _impl_.unverified_lazy_ = from._impl_.unverified_lazy_; + _this->_impl_.unverified_lazy_ = from._impl_.unverified_lazy_; } if (cached_has_bits & 0x00000020u) { - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; } if (cached_has_bits & 0x00000040u) { - _impl_.weak_ = from._impl_.weak_; + _this->_impl_.weak_ = from._impl_.weak_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void FieldOptions::CopyFrom(const FieldOptions& from) { @@ -8124,6 +8086,7 @@ OneofOptions::OneofOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } OneofOptions::OneofOptions(const OneofOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + OneofOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_.uninterpreted_option_){from._impl_.uninterpreted_option_} @@ -8274,22 +8237,18 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData OneofOptions::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*OneofOptions::GetClassData() const { return &_class_data_; } -void OneofOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void OneofOptions::MergeFrom(const OneofOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofOptions) - GOOGLE_DCHECK_NE(&from, this); +void OneofOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void OneofOptions::CopyFrom(const OneofOptions& from) { @@ -8343,6 +8302,7 @@ EnumOptions::EnumOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } EnumOptions::EnumOptions(const EnumOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -8552,32 +8512,28 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumOptions::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumOptions::GetClassData() const { return &_class_data_; } -void EnumOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void EnumOptions::MergeFrom(const EnumOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumOptions) - GOOGLE_DCHECK_NE(&from, this); +void EnumOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _impl_.allow_alias_ = from._impl_.allow_alias_; + _this->_impl_.allow_alias_ = from._impl_.allow_alias_; } if (cached_has_bits & 0x00000002u) { - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void EnumOptions::CopyFrom(const EnumOptions& from) { @@ -8635,6 +8591,7 @@ EnumValueOptions::EnumValueOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } EnumValueOptions::EnumValueOptions(const EnumValueOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumValueOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -8644,7 +8601,7 @@ EnumValueOptions::EnumValueOptions(const EnumValueOptions& from) _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueOptions) } @@ -8816,25 +8773,21 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumValueOptions::_class_data_ }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValueOptions::GetClassData() const { return &_class_data_; } -void EnumValueOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void EnumValueOptions::MergeFrom(const EnumValueOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueOptions) - GOOGLE_DCHECK_NE(&from, this); +void EnumValueOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); if (from._internal_has_deprecated()) { - _internal_set_deprecated(from._internal_deprecated()); + _this->_internal_set_deprecated(from._internal_deprecated()); } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void EnumValueOptions::CopyFrom(const EnumValueOptions& from) { @@ -8887,6 +8840,7 @@ ServiceOptions::ServiceOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } ServiceOptions::ServiceOptions(const ServiceOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + ServiceOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -8896,7 +8850,7 @@ ServiceOptions::ServiceOptions(const ServiceOptions& from) _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; // @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceOptions) } @@ -9068,25 +9022,21 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ServiceOptions::_class_data_ = }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ServiceOptions::GetClassData() const { return &_class_data_; } -void ServiceOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void ServiceOptions::MergeFrom(const ServiceOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceOptions) - GOOGLE_DCHECK_NE(&from, this); +void ServiceOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); if (from._internal_has_deprecated()) { - _internal_set_deprecated(from._internal_deprecated()); + _this->_internal_set_deprecated(from._internal_deprecated()); } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void ServiceOptions::CopyFrom(const ServiceOptions& from) { @@ -9142,6 +9092,7 @@ MethodOptions::MethodOptions(::PROTOBUF_NAMESPACE_ID::Arena* arena, } MethodOptions::MethodOptions(const MethodOptions& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + MethodOptions* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_._extensions_)*/{} , decltype(_impl_._has_bits_){from._impl_._has_bits_} @@ -9360,32 +9311,28 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData MethodOptions::_class_data_ = }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MethodOptions::GetClassData() const { return &_class_data_; } -void MethodOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void MethodOptions::MergeFrom(const MethodOptions& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodOptions) - GOOGLE_DCHECK_NE(&from, this); +void MethodOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodOptions) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); + _this->_impl_.uninterpreted_option_.MergeFrom(from._impl_.uninterpreted_option_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _impl_.deprecated_ = from._impl_.deprecated_; + _this->_impl_.deprecated_ = from._impl_.deprecated_; } if (cached_has_bits & 0x00000002u) { - _impl_.idempotency_level_ = from._impl_.idempotency_level_; + _this->_impl_.idempotency_level_ = from._impl_.idempotency_level_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void MethodOptions::CopyFrom(const MethodOptions& from) { @@ -9449,6 +9396,7 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(::PROTOBUF_NAMESPACE_ } UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOption_NamePart& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + UninterpretedOption_NamePart* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -9461,10 +9409,10 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp _impl_.name_part_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_name_part()) { - _impl_.name_part_.Set(from._internal_name_part(), - GetArenaForAllocation()); + _this->_impl_.name_part_.Set(from._internal_name_part(), + _this->GetArenaForAllocation()); } - _impl_.is_extension_ = from._impl_.is_extension_; + _this->_impl_.is_extension_ = from._impl_.is_extension_; // @@protoc_insertion_point(copy_constructor:google.protobuf.UninterpretedOption.NamePart) } @@ -9647,30 +9595,26 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData UninterpretedOption_NamePart:: }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UninterpretedOption_NamePart::GetClassData() const { return &_class_data_; } -void UninterpretedOption_NamePart::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void UninterpretedOption_NamePart::MergeFrom(const UninterpretedOption_NamePart& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption.NamePart) - GOOGLE_DCHECK_NE(&from, this); +void UninterpretedOption_NamePart::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption.NamePart) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_name_part(from._internal_name_part()); + _this->_internal_set_name_part(from._internal_name_part()); } if (cached_has_bits & 0x00000002u) { - _impl_.is_extension_ = from._impl_.is_extension_; + _this->_impl_.is_extension_ = from._impl_.is_extension_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void UninterpretedOption_NamePart::CopyFrom(const UninterpretedOption_NamePart& from) { @@ -9737,6 +9681,7 @@ UninterpretedOption::UninterpretedOption(::PROTOBUF_NAMESPACE_ID::Arena* arena, } UninterpretedOption::UninterpretedOption(const UninterpretedOption& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + UninterpretedOption* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -9754,24 +9699,24 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from) _impl_.identifier_value_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_identifier_value()) { - _impl_.identifier_value_.Set(from._internal_identifier_value(), - GetArenaForAllocation()); + _this->_impl_.identifier_value_.Set(from._internal_identifier_value(), + _this->GetArenaForAllocation()); } _impl_.string_value_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.string_value_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_string_value()) { - _impl_.string_value_.Set(from._internal_string_value(), - GetArenaForAllocation()); + _this->_impl_.string_value_.Set(from._internal_string_value(), + _this->GetArenaForAllocation()); } _impl_.aggregate_value_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.aggregate_value_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_aggregate_value()) { - _impl_.aggregate_value_.Set(from._internal_aggregate_value(), - GetArenaForAllocation()); + _this->_impl_.aggregate_value_.Set(from._internal_aggregate_value(), + _this->GetArenaForAllocation()); } ::memcpy(&_impl_.positive_int_value_, &from._impl_.positive_int_value_, static_cast(reinterpret_cast(&_impl_.double_value_) - @@ -10091,43 +10036,39 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData UninterpretedOption::_class_da }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UninterpretedOption::GetClassData() const { return &_class_data_; } -void UninterpretedOption::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void UninterpretedOption::MergeFrom(const UninterpretedOption& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption) - GOOGLE_DCHECK_NE(&from, this); +void UninterpretedOption::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.name_.MergeFrom(from._impl_.name_); + _this->_impl_.name_.MergeFrom(from._impl_.name_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000003fu) { if (cached_has_bits & 0x00000001u) { - _internal_set_identifier_value(from._internal_identifier_value()); + _this->_internal_set_identifier_value(from._internal_identifier_value()); } if (cached_has_bits & 0x00000002u) { - _internal_set_string_value(from._internal_string_value()); + _this->_internal_set_string_value(from._internal_string_value()); } if (cached_has_bits & 0x00000004u) { - _internal_set_aggregate_value(from._internal_aggregate_value()); + _this->_internal_set_aggregate_value(from._internal_aggregate_value()); } if (cached_has_bits & 0x00000008u) { - _impl_.positive_int_value_ = from._impl_.positive_int_value_; + _this->_impl_.positive_int_value_ = from._impl_.positive_int_value_; } if (cached_has_bits & 0x00000010u) { - _impl_.negative_int_value_ = from._impl_.negative_int_value_; + _this->_impl_.negative_int_value_ = from._impl_.negative_int_value_; } if (cached_has_bits & 0x00000020u) { - _impl_.double_value_ = from._impl_.double_value_; + _this->_impl_.double_value_ = from._impl_.double_value_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void UninterpretedOption::CopyFrom(const UninterpretedOption& from) { @@ -10197,6 +10138,7 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(::PROTOBUF_NAMESPACE_ID::Arena* } SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + SourceCodeInfo_Location* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -10214,16 +10156,16 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location& _impl_.leading_comments_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_leading_comments()) { - _impl_.leading_comments_.Set(from._internal_leading_comments(), - GetArenaForAllocation()); + _this->_impl_.leading_comments_.Set(from._internal_leading_comments(), + _this->GetArenaForAllocation()); } _impl_.trailing_comments_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.trailing_comments_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_trailing_comments()) { - _impl_.trailing_comments_.Set(from._internal_trailing_comments(), - GetArenaForAllocation()); + _this->_impl_.trailing_comments_.Set(from._internal_trailing_comments(), + _this->GetArenaForAllocation()); } // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo.Location) } @@ -10524,32 +10466,28 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceCodeInfo_Location::_clas }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceCodeInfo_Location::GetClassData() const { return &_class_data_; } -void SourceCodeInfo_Location::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void SourceCodeInfo_Location::MergeFrom(const SourceCodeInfo_Location& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo.Location) - GOOGLE_DCHECK_NE(&from, this); +void SourceCodeInfo_Location::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo.Location) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.path_.MergeFrom(from._impl_.path_); - _impl_.span_.MergeFrom(from._impl_.span_); - _impl_.leading_detached_comments_.MergeFrom(from._impl_.leading_detached_comments_); + _this->_impl_.path_.MergeFrom(from._impl_.path_); + _this->_impl_.span_.MergeFrom(from._impl_.span_); + _this->_impl_.leading_detached_comments_.MergeFrom(from._impl_.leading_detached_comments_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _internal_set_leading_comments(from._internal_leading_comments()); + _this->_internal_set_leading_comments(from._internal_leading_comments()); } if (cached_has_bits & 0x00000002u) { - _internal_set_trailing_comments(from._internal_trailing_comments()); + _this->_internal_set_trailing_comments(from._internal_trailing_comments()); } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void SourceCodeInfo_Location::CopyFrom(const SourceCodeInfo_Location& from) { @@ -10602,6 +10540,7 @@ SourceCodeInfo::SourceCodeInfo(::PROTOBUF_NAMESPACE_ID::Arena* arena, } SourceCodeInfo::SourceCodeInfo(const SourceCodeInfo& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + SourceCodeInfo* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.location_){from._impl_.location_} , /*decltype(_impl_._cached_size_)*/{}}; @@ -10736,21 +10675,17 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceCodeInfo::_class_data_ = }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceCodeInfo::GetClassData() const { return &_class_data_; } -void SourceCodeInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void SourceCodeInfo::MergeFrom(const SourceCodeInfo& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo) - GOOGLE_DCHECK_NE(&from, this); +void SourceCodeInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.location_.MergeFrom(from._impl_.location_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.location_.MergeFrom(from._impl_.location_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void SourceCodeInfo::CopyFrom(const SourceCodeInfo& from) { @@ -10800,6 +10735,7 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(::PROTOBUF_NAMESPACE_ } GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeInfo_Annotation& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + GeneratedCodeInfo_Annotation* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_._has_bits_){from._impl_._has_bits_} , /*decltype(_impl_._cached_size_)*/{} @@ -10815,8 +10751,8 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn _impl_.source_file_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (from._internal_has_source_file()) { - _impl_.source_file_.Set(from._internal_source_file(), - GetArenaForAllocation()); + _this->_impl_.source_file_.Set(from._internal_source_file(), + _this->GetArenaForAllocation()); } ::memcpy(&_impl_.begin_, &from._impl_.begin_, static_cast(reinterpret_cast(&_impl_.end_) - @@ -11051,34 +10987,30 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GeneratedCodeInfo_Annotation:: }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GeneratedCodeInfo_Annotation::GetClassData() const { return &_class_data_; } -void GeneratedCodeInfo_Annotation::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void GeneratedCodeInfo_Annotation::MergeFrom(const GeneratedCodeInfo_Annotation& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) - GOOGLE_DCHECK_NE(&from, this); +void GeneratedCodeInfo_Annotation::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.path_.MergeFrom(from._impl_.path_); + _this->_impl_.path_.MergeFrom(from._impl_.path_); cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { - _internal_set_source_file(from._internal_source_file()); + _this->_internal_set_source_file(from._internal_source_file()); } if (cached_has_bits & 0x00000002u) { - _impl_.begin_ = from._impl_.begin_; + _this->_impl_.begin_ = from._impl_.begin_; } if (cached_has_bits & 0x00000004u) { - _impl_.end_ = from._impl_.end_; + _this->_impl_.end_ = from._impl_.end_; } - _impl_._has_bits_[0] |= cached_has_bits; + _this->_impl_._has_bits_[0] |= cached_has_bits; } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void GeneratedCodeInfo_Annotation::CopyFrom(const GeneratedCodeInfo_Annotation& from) { @@ -11131,6 +11063,7 @@ GeneratedCodeInfo::GeneratedCodeInfo(::PROTOBUF_NAMESPACE_ID::Arena* arena, } GeneratedCodeInfo::GeneratedCodeInfo(const GeneratedCodeInfo& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + GeneratedCodeInfo* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.annotation_){from._impl_.annotation_} , /*decltype(_impl_._cached_size_)*/{}}; @@ -11265,21 +11198,17 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GeneratedCodeInfo::_class_data }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GeneratedCodeInfo::GetClassData() const { return &_class_data_; } -void GeneratedCodeInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void GeneratedCodeInfo::MergeFrom(const GeneratedCodeInfo& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo) - GOOGLE_DCHECK_NE(&from, this); +void GeneratedCodeInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.annotation_.MergeFrom(from._impl_.annotation_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.annotation_.MergeFrom(from._impl_.annotation_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void GeneratedCodeInfo::CopyFrom(const GeneratedCodeInfo& from) { diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 4cd97bc9ae..07ed8f4349 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -407,9 +407,11 @@ class PROTOBUF_EXPORT FileDescriptorSet final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const FileDescriptorSet& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const FileDescriptorSet& from); + void MergeFrom( const FileDescriptorSet& from) { + FileDescriptorSet::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -569,9 +571,11 @@ class PROTOBUF_EXPORT FileDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const FileDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const FileDescriptorProto& from); + void MergeFrom( const FileDescriptorProto& from) { + FileDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -966,9 +970,11 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const DescriptorProto_ExtensionRange& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const DescriptorProto_ExtensionRange& from); + void MergeFrom( const DescriptorProto_ExtensionRange& from) { + DescriptorProto_ExtensionRange::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -1159,9 +1165,11 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const DescriptorProto_ReservedRange& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const DescriptorProto_ReservedRange& from); + void MergeFrom( const DescriptorProto_ReservedRange& from) { + DescriptorProto_ReservedRange::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -1332,9 +1340,11 @@ class PROTOBUF_EXPORT DescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const DescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const DescriptorProto& from); + void MergeFrom( const DescriptorProto& from) { + DescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -1684,9 +1694,11 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const ExtensionRangeOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const ExtensionRangeOptions& from); + void MergeFrom( const ExtensionRangeOptions& from) { + ExtensionRangeOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -2038,9 +2050,11 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const FieldDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const FieldDescriptorProto& from); + void MergeFrom( const FieldDescriptorProto& from) { + FieldDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -2470,9 +2484,11 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const OneofDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const OneofDescriptorProto& from); + void MergeFrom( const OneofDescriptorProto& from) { + OneofDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -2653,9 +2669,11 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const EnumDescriptorProto_EnumReservedRange& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const EnumDescriptorProto_EnumReservedRange& from); + void MergeFrom( const EnumDescriptorProto_EnumReservedRange& from) { + EnumDescriptorProto_EnumReservedRange::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -2826,9 +2844,11 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const EnumDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const EnumDescriptorProto& from); + void MergeFrom( const EnumDescriptorProto& from) { + EnumDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -3077,9 +3097,11 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const EnumValueDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const EnumValueDescriptorProto& from); + void MergeFrom( const EnumValueDescriptorProto& from) { + EnumValueDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -3275,9 +3297,11 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const ServiceDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const ServiceDescriptorProto& from); + void MergeFrom( const ServiceDescriptorProto& from) { + ServiceDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -3478,9 +3502,11 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const MethodDescriptorProto& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const MethodDescriptorProto& from); + void MergeFrom( const MethodDescriptorProto& from) { + MethodDescriptorProto::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -3731,9 +3757,11 @@ class PROTOBUF_EXPORT FileOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const FileOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const FileOptions& from); + void MergeFrom( const FileOptions& from) { + FileOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -4468,9 +4496,11 @@ class PROTOBUF_EXPORT MessageOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const MessageOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const MessageOptions& from); + void MergeFrom( const MessageOptions& from) { + MessageOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -4883,9 +4913,11 @@ class PROTOBUF_EXPORT FieldOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const FieldOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const FieldOptions& from); + void MergeFrom( const FieldOptions& from) { + FieldOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -5407,9 +5439,11 @@ class PROTOBUF_EXPORT OneofOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const OneofOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const OneofOptions& from); + void MergeFrom( const OneofOptions& from) { + OneofOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -5761,9 +5795,11 @@ class PROTOBUF_EXPORT EnumOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const EnumOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const EnumOptions& from); + void MergeFrom( const EnumOptions& from) { + EnumOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -6146,9 +6182,11 @@ class PROTOBUF_EXPORT EnumValueOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const EnumValueOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const EnumValueOptions& from); + void MergeFrom( const EnumValueOptions& from) { + EnumValueOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -6516,9 +6554,11 @@ class PROTOBUF_EXPORT ServiceOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const ServiceOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const ServiceOptions& from); + void MergeFrom( const ServiceOptions& from) { + ServiceOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -6886,9 +6926,11 @@ class PROTOBUF_EXPORT MethodOptions final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const MethodOptions& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const MethodOptions& from); + void MergeFrom( const MethodOptions& from) { + MethodOptions::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -7303,9 +7345,11 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const UninterpretedOption_NamePart& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const UninterpretedOption_NamePart& from); + void MergeFrom( const UninterpretedOption_NamePart& from) { + UninterpretedOption_NamePart::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -7484,9 +7528,11 @@ class PROTOBUF_EXPORT UninterpretedOption final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const UninterpretedOption& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const UninterpretedOption& from); + void MergeFrom( const UninterpretedOption& from) { + UninterpretedOption::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -7754,9 +7800,11 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const SourceCodeInfo_Location& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const SourceCodeInfo_Location& from); + void MergeFrom( const SourceCodeInfo_Location& from) { + SourceCodeInfo_Location::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -8013,9 +8061,11 @@ class PROTOBUF_EXPORT SourceCodeInfo final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const SourceCodeInfo& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const SourceCodeInfo& from); + void MergeFrom( const SourceCodeInfo& from) { + SourceCodeInfo::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -8177,9 +8227,11 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const GeneratedCodeInfo_Annotation& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const GeneratedCodeInfo_Annotation& from); + void MergeFrom( const GeneratedCodeInfo_Annotation& from) { + GeneratedCodeInfo_Annotation::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -8395,9 +8447,11 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const GeneratedCodeInfo& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const GeneratedCodeInfo& from); + void MergeFrom( const GeneratedCodeInfo& from) { + GeneratedCodeInfo::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 70cfd4173d..dc47531f2a 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -4721,8 +4721,7 @@ TEST_F(ValidationErrorTest, NegativeExtensionRangeNumber) { " extension_range { start: -10 end: -1 }" "}", - "foo.proto: Foo: NUMBER: Extension numbers must be positive integers.\n" - "foo.proto: Foo: NUMBER: Suggested field numbers for Foo: 1, 2, 3\n"); + "foo.proto: Foo: NUMBER: Extension numbers must be positive integers.\n"); } TEST_F(ValidationErrorTest, HugeExtensionRangeNumber) { diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index e8baf9150b..72766bd3b4 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -97,6 +97,7 @@ Duration::Duration(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Duration::Duration(const Duration& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Duration* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.seconds_){} , decltype(_impl_.nanos_){} @@ -247,26 +248,22 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Duration::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Duration::GetClassData() const { return &_class_data_; } -void Duration::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Duration::MergeFrom(const Duration& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) - GOOGLE_DCHECK_NE(&from, this); +void Duration::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_seconds() != 0) { - _internal_set_seconds(from._internal_seconds()); + _this->_internal_set_seconds(from._internal_seconds()); } if (from._internal_nanos() != 0) { - _internal_set_nanos(from._internal_nanos()); + _this->_internal_set_nanos(from._internal_nanos()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Duration::CopyFrom(const Duration& from) { diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 12633a300d..555ae47ab1 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -136,9 +136,11 @@ class PROTOBUF_EXPORT Duration final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Duration& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Duration& from); + void MergeFrom( const Duration& from) { + Duration::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 0c49797037..3a30776386 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -90,6 +90,7 @@ Empty::Empty(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Empty::Empty(const Empty& from) : ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase() { + Empty* const _this = this; (void)_this; _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); // @@protoc_insertion_point(copy_constructor:google.protobuf.Empty) } diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 38480a78e2..8aab9f59ae 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -135,11 +135,11 @@ class PROTOBUF_EXPORT Empty final : } using ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase::CopyFrom; inline void CopyFrom(const Empty& from) { - ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase::CopyImpl(this, from); + ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase::CopyImpl(*this, from); } using ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase::MergeFrom; void MergeFrom(const Empty& from) { - ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase::MergeImpl(this, from); + ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase::MergeImpl(*this, from); } public: diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index 04b62b6d44..207e10cfcf 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -1285,6 +1286,8 @@ TEST(ExtensionSetTest, DynamicExtensions) { } // Can we print it? + std::string message_text; + TextFormat::PrintToString(message, &message_text); EXPECT_EQ( "[dynamic_extensions.scalar_extension]: 123\n" "[dynamic_extensions.enum_extension]: FOREIGN_BAR\n" @@ -1303,7 +1306,7 @@ TEST(ExtensionSetTest, DynamicExtensions) { "[dynamic_extensions.packed_extension]: -78\n" "2002: 12345\n" "54321: \"unknown\"\n", - message.DebugString()); + message_text); // Can we serialize it? EXPECT_TRUE( diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index d64b3bd5b5..7860bfbfed 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -95,6 +95,7 @@ FieldMask::FieldMask(::PROTOBUF_NAMESPACE_ID::Arena* arena, } FieldMask::FieldMask(const FieldMask& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + FieldMask* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.paths_){from._impl_.paths_} , /*decltype(_impl_._cached_size_)*/{}}; @@ -234,21 +235,17 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldMask::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldMask::GetClassData() const { return &_class_data_; } -void FieldMask::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void FieldMask::MergeFrom(const FieldMask& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) - GOOGLE_DCHECK_NE(&from, this); +void FieldMask::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.paths_.MergeFrom(from._impl_.paths_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.paths_.MergeFrom(from._impl_.paths_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void FieldMask::CopyFrom(const FieldMask& from) { diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index ae350d5610..7f47936a9d 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -136,9 +136,11 @@ class PROTOBUF_EXPORT FieldMask final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const FieldMask& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const FieldMask& from); + void MergeFrom( const FieldMask& from) { + FieldMask::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/generated_message_bases.cc b/src/google/protobuf/generated_message_bases.cc index b772d9f289..306a38eef3 100644 --- a/src/google/protobuf/generated_message_bases.cc +++ b/src/google/protobuf/generated_message_bases.cc @@ -98,15 +98,15 @@ failure: return target; } -void ZeroFieldsBase::MergeImpl(Message* to_param, const Message& from_param) { - auto* to = static_cast(to_param); +void ZeroFieldsBase::MergeImpl(Message& to_param, const Message& from_param) { + auto* to = static_cast(&to_param); const auto* from = static_cast(&from_param); GOOGLE_DCHECK_NE(from, to); to->_internal_metadata_.MergeFrom(from->_internal_metadata_); } -void ZeroFieldsBase::CopyImpl(Message* to_param, const Message& from_param) { - auto* to = static_cast(to_param); +void ZeroFieldsBase::CopyImpl(Message& to_param, const Message& from_param) { + auto* to = static_cast(&to_param); const auto* from = static_cast(&from_param); if (from == to) return; to->_internal_metadata_.Clear(); diff --git a/src/google/protobuf/generated_message_bases.h b/src/google/protobuf/generated_message_bases.h index ebd198417c..b295218a70 100644 --- a/src/google/protobuf/generated_message_bases.h +++ b/src/google/protobuf/generated_message_bases.h @@ -71,8 +71,8 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message { void SetCachedSize(int size) const final { _cached_size_.Set(size); } - static void MergeImpl(Message* to, const Message& from); - static void CopyImpl(Message* to, const Message& from); + static void MergeImpl(Message& to, const Message& from); + static void CopyImpl(Message& to, const Message& from); void InternalSwap(ZeroFieldsBase* other); mutable internal::CachedSize _cached_size_; diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 5cb5872324..2a807e066b 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -3111,10 +3111,10 @@ void UnknownFieldSetSerializer(const uint8_t* base, uint32_t offset, } } -bool IsDescendant(Message* root, const Message& message) { - const Reflection* reflection = root->GetReflection(); +bool IsDescendant(Message& root, const Message& message) { + const Reflection* reflection = root.GetReflection(); std::vector fields; - reflection->ListFieldsOmitStripped(*root, &fields); + reflection->ListFieldsOmitStripped(root, &fields); for (const auto* field : fields) { // Skip non-message fields. @@ -3122,8 +3122,8 @@ bool IsDescendant(Message* root, const Message& message) { // Optional messages. if (!field->is_repeated()) { - Message* sub_message = reflection->MutableMessage(root, field); - if (sub_message == &message || IsDescendant(sub_message, message)) { + Message* sub_message = reflection->MutableMessage(&root, field); + if (sub_message == &message || IsDescendant(*sub_message, message)) { return true; } continue; @@ -3131,11 +3131,11 @@ bool IsDescendant(Message* root, const Message& message) { // Repeated messages. if (!IsMapFieldInApi(field)) { - int count = reflection->FieldSize(*root, field); + int count = reflection->FieldSize(root, field); for (int i = 0; i < count; i++) { Message* sub_message = - reflection->MutableRepeatedMessage(root, field, i); - if (sub_message == &message || IsDescendant(sub_message, message)) { + reflection->MutableRepeatedMessage(&root, field, i); + if (sub_message == &message || IsDescendant(*sub_message, message)) { return true; } } @@ -3149,10 +3149,10 @@ bool IsDescendant(Message* root, const Message& message) { // Skip map fields whose value type is not message. if (val_field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue; - MapIterator end = reflection->MapEnd(root, field); - for (auto iter = reflection->MapBegin(root, field); iter != end; ++iter) { + MapIterator end = reflection->MapEnd(&root, field); + for (auto iter = reflection->MapBegin(&root, field); iter != end; ++iter) { Message* sub_message = iter.MutableValueRef()->MutableMessageValue(); - if (sub_message == &message || IsDescendant(sub_message, message)) { + if (sub_message == &message || IsDescendant(*sub_message, message)) { return true; } } diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index 68af374b5c..334b2ccf1d 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -38,9 +38,6 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ -#include -#include - #include #include #include diff --git a/src/google/protobuf/generated_message_reflection_unittest.cc b/src/google/protobuf/generated_message_reflection_unittest.cc index 069b5c8412..50ce399199 100644 --- a/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/src/google/protobuf/generated_message_reflection_unittest.cc @@ -1315,11 +1315,11 @@ TEST(GeneratedMessageReflection, IsDescendantMessage) { TestUtil::SetAllFields(&msg1); msg2 = msg1; - EXPECT_TRUE(IsDescendant(&msg1, msg1.optional_nested_message())); - EXPECT_TRUE(IsDescendant(&msg1, msg1.repeated_foreign_message(0))); + EXPECT_TRUE(IsDescendant(msg1, msg1.optional_nested_message())); + EXPECT_TRUE(IsDescendant(msg1, msg1.repeated_foreign_message(0))); - EXPECT_FALSE(IsDescendant(&msg1, msg2.optional_nested_message())); - EXPECT_FALSE(IsDescendant(&msg1, msg2.repeated_foreign_message(0))); + EXPECT_FALSE(IsDescendant(msg1, msg2.optional_nested_message())); + EXPECT_FALSE(IsDescendant(msg1, msg2.repeated_foreign_message(0))); } TEST(GeneratedMessageReflection, IsDescendantMap) { @@ -1328,11 +1328,11 @@ TEST(GeneratedMessageReflection, IsDescendantMap) { TestUtil::SetAllFields(&(*msg1.mutable_map_int32_all_types())[0]); msg2 = msg1; - EXPECT_TRUE(IsDescendant(&msg1, msg1.map_int32_foreign_message().at(0))); - EXPECT_TRUE(IsDescendant(&msg1, msg1.map_int32_all_types().at(0))); + EXPECT_TRUE(IsDescendant(msg1, msg1.map_int32_foreign_message().at(0))); + EXPECT_TRUE(IsDescendant(msg1, msg1.map_int32_all_types().at(0))); - EXPECT_FALSE(IsDescendant(&msg1, msg2.map_int32_foreign_message().at(0))); - EXPECT_FALSE(IsDescendant(&msg1, msg2.map_int32_all_types().at(0))); + EXPECT_FALSE(IsDescendant(msg1, msg2.map_int32_foreign_message().at(0))); + EXPECT_FALSE(IsDescendant(msg1, msg2.map_int32_all_types().at(0))); } TEST(GeneratedMessageReflection, IsDescendantExtension) { @@ -1341,15 +1341,15 @@ TEST(GeneratedMessageReflection, IsDescendantExtension) { msg2 = msg1; EXPECT_TRUE(IsDescendant( - &msg1, msg1.GetExtension(unittest::optional_nested_message_extension))); + msg1, msg1.GetExtension(unittest::optional_nested_message_extension))); EXPECT_TRUE(IsDescendant( - &msg1, + msg1, msg1.GetExtension(unittest::repeated_foreign_message_extension, 0))); EXPECT_FALSE(IsDescendant( - &msg1, msg2.GetExtension(unittest::optional_nested_message_extension))); + msg1, msg2.GetExtension(unittest::optional_nested_message_extension))); EXPECT_FALSE(IsDescendant( - &msg1, + msg1, msg2.GetExtension(unittest::repeated_foreign_message_extension, 0))); } @@ -1358,15 +1358,14 @@ TEST(GeneratedMessageReflection, IsDescendantOneof) { TestUtil::SetAllFields(msg1.mutable_foo_message()); msg2 = msg1; + EXPECT_TRUE(IsDescendant(msg1, msg1.foo_message().optional_nested_message())); EXPECT_TRUE( - IsDescendant(&msg1, msg1.foo_message().optional_nested_message())); - EXPECT_TRUE( - IsDescendant(&msg1, msg1.foo_message().repeated_foreign_message(0))); + IsDescendant(msg1, msg1.foo_message().repeated_foreign_message(0))); EXPECT_FALSE( - IsDescendant(&msg1, msg2.foo_message().optional_nested_message())); + IsDescendant(msg1, msg2.foo_message().optional_nested_message())); EXPECT_FALSE( - IsDescendant(&msg1, msg2.foo_message().repeated_foreign_message(0))); + IsDescendant(msg1, msg2.foo_message().repeated_foreign_message(0))); } } // namespace diff --git a/src/google/protobuf/io/zero_copy_stream.h b/src/google/protobuf/io/zero_copy_stream.h index e2c9737eb6..2041cbf648 100644 --- a/src/google/protobuf/io/zero_copy_stream.h +++ b/src/google/protobuf/io/zero_copy_stream.h @@ -108,8 +108,6 @@ #define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ -#include - #include diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 09d03b8129..53bfd2d233 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -692,40 +692,30 @@ class Map { return FindHelper(k).first; } - // Insert the key into the map, if not present. In that case, the value will - // be value initialized. + // Inserts a new element into the container if there is no element with the + // key in the container. + // The new element is: + // (1) Constructed in-place with the given args, if mapped_type is not + // arena constructible. + // (2) Constructed in-place with the arena and then assigned with a + // mapped_type temporary constructed with the given args, otherwise. + template + std::pair try_emplace(K&& k, Args&&... args) { + return ArenaAwareTryEmplace(Arena::is_arena_constructable(), + std::forward(k), + std::forward(args)...); + } + + // Inserts the key into the map, if not present. In that case, the value + // will be value initialized. template std::pair insert(K&& k) { - std::pair p = FindHelper(k); - // Case 1: key was already present. - if (p.first.node_ != nullptr) - return std::make_pair(iterator(p.first), false); - // Case 2: insert. - if (ResizeIfLoadIsOutOfRange(num_elements_ + 1)) { - p = FindHelper(k); - } - const size_type b = p.second; // bucket number - // If K is not key_type, make the conversion to key_type explicit. - using TypeToInit = typename std::conditional< - std::is_same::type, key_type>::value, K&&, - key_type>::type; - Node* node = Alloc(1); - // Even when arena is nullptr, CreateInArenaStorage is still used to - // ensure the arena of submessage will be consistent. Otherwise, - // submessage may have its own arena when message-owned arena is enabled. - Arena::CreateInArenaStorage(const_cast(&node->kv.first), - alloc_.arena(), - static_cast(std::forward(k))); - Arena::CreateInArenaStorage(&node->kv.second, alloc_.arena()); - - iterator result = InsertUnique(b, node); - ++num_elements_; - return std::make_pair(result, true); + return try_emplace(std::forward(k)); } template value_type& operator[](K&& k) { - return *insert(std::forward(k)).first; + return *try_emplace(std::forward(k)).first; } void erase(iterator it) { @@ -767,6 +757,79 @@ class Map { } private: + template + std::pair TryEmplaceInternal(K&& k, Args&&... args) { + std::pair p = FindHelper(k); + // Case 1: key was already present. + if (p.first.node_ != nullptr) + return std::make_pair(iterator(p.first), false); + // Case 2: insert. + if (ResizeIfLoadIsOutOfRange(num_elements_ + 1)) { + p = FindHelper(k); + } + const size_type b = p.second; // bucket number + // If K is not key_type, make the conversion to key_type explicit. + using TypeToInit = typename std::conditional< + std::is_same::type, key_type>::value, K&&, + key_type>::type; + Node* node = Alloc(1); + // Even when arena is nullptr, CreateInArenaStorage is still used to + // ensure the arena of submessage will be consistent. Otherwise, + // submessage may have its own arena when message-owned arena is enabled. + // Note: This only works if `Key` is not arena constructible. + Arena::CreateInArenaStorage(const_cast(&node->kv.first), + alloc_.arena(), + static_cast(std::forward(k))); + // Note: if `T` is arena constructible, `Args` needs to be empty. + Arena::CreateInArenaStorage(&node->kv.second, alloc_.arena(), + std::forward(args)...); + + iterator result = InsertUnique(b, node); + ++num_elements_; + return std::make_pair(result, true); + } + + // A helper function to perform an assignment of `mapped_type`. + // If the first argument is true, then it is a regular assignment. + // Otherwise, we first create a temporary and then perform an assignment. + template + static void AssignMapped(std::true_type, mapped_type& mapped, V&& v) { + mapped = std::forward(v); + } + template + static void AssignMapped(std::false_type, mapped_type& mapped, + Args&&... args) { + mapped = mapped_type(std::forward(args)...); + } + + // Case 1: `mapped_type` is arena constructible. A temporary object is + // created and then (if `Args` are not empty) assigned to a mapped value + // that was created with the arena. + template + std::pair ArenaAwareTryEmplace(std::true_type, K&& k) { + // case 1.1: "default" constructed (e.g. from arena only). + return TryEmplaceInternal(std::forward(k)); + } + template + std::pair ArenaAwareTryEmplace(std::true_type, K&& k, + Args&&... args) { + // case 1.2: "default" constructed + copy/move assignment + auto p = TryEmplaceInternal(std::forward(k)); + if (p.second) { + AssignMapped(std::is_same::type...), + void(mapped_type)>(), + p.first->second, std::forward(args)...); + } + return p; + } + // Case 2: `mapped_type` is not arena constructible. Using in-place + // construction. + template + std::pair ArenaAwareTryEmplace(std::false_type, + Args&&... args) { + return TryEmplaceInternal(std::forward(args)...); + } + const_iterator find(const Key& k, TreeIterator* it) const { return FindHelper(k, it).first; } @@ -1282,14 +1345,22 @@ class Map { } // insert - std::pair insert(const value_type& value) { - std::pair p = - elements_.insert(value.first); - if (p.second) { - p.first->second = value.second; - } + template + std::pair try_emplace(K&& k, Args&&... args) { + auto p = + elements_.try_emplace(std::forward(k), std::forward(args)...); return std::pair(iterator(p.first), p.second); } + std::pair insert(const value_type& value) { + return try_emplace(value.first, value.second); + } + std::pair insert(value_type&& value) { + return try_emplace(value.first, std::move(value.second)); + } + template + std::pair emplace(Args&&... args) { + return insert(value_type(std::forward(args)...)); + } template void insert(InputIt first, InputIt last) { for (InputIt it = first; it != last; ++it) { diff --git a/src/google/protobuf/map_test.inc b/src/google/protobuf/map_test.inc index 2199c9220a..18a7bfb758 100644 --- a/src/google/protobuf/map_test.inc +++ b/src/google/protobuf/map_test.inc @@ -687,12 +687,37 @@ TEST_F(MapImplTest, IteratorCategory) { Map::const_iterator>::iterator_category())); } -TEST_F(MapImplTest, InsertSingle) { +TEST_F(MapImplTest, InsertSingleLValue) { int32_t key = 0; int32_t value1 = 100; int32_t value2 = 101; - // Insert a non-existed key. + // Insert a non-existing key. + Map::value_type v1(key, value1); + std::pair::iterator, bool> result1 = map_.insert(v1); + ExpectSingleElement(key, value1); + + Map::iterator it1 = result1.first; + EXPECT_EQ(key, it1->first); + EXPECT_EQ(value1, it1->second); + EXPECT_TRUE(result1.second); + + // Insert an existing key. + Map::value_type v2(key, value2); + std::pair::iterator, bool> result2 = map_.insert(v2); + ExpectSingleElement(key, value1); + + Map::iterator it2 = result2.first; + EXPECT_TRUE(it1 == it2); + EXPECT_FALSE(result2.second); +} + +TEST_F(MapImplTest, InsertSingleRValue) { + int32_t key = 0; + int32_t value1 = 100; + int32_t value2 = 101; + + // Insert a non-existing key. std::pair::iterator, bool> result1 = map_.insert(Map::value_type(key, value1)); ExpectSingleElement(key, value1); @@ -702,7 +727,7 @@ TEST_F(MapImplTest, InsertSingle) { EXPECT_EQ(value1, it1->second); EXPECT_TRUE(result1.second); - // Insert an existed key. + // Insert an existing key. std::pair::iterator, bool> result2 = map_.insert(Map::value_type(key, value2)); ExpectSingleElement(key, value1); @@ -712,6 +737,167 @@ TEST_F(MapImplTest, InsertSingle) { EXPECT_FALSE(result2.second); } +TEST_F(MapImplTest, TryEmplace) { + using ::testing::Pair; + using ::testing::UnorderedElementsAre; + + Map m; + + m.try_emplace(1, "one"); + EXPECT_EQ(m.size(), 1); + + const int32_t key = 42; + m.try_emplace(key, 3, 'a'); + m.try_emplace(2, std::string("two")); + EXPECT_THAT( + m, UnorderedElementsAre(Pair(1, "one"), Pair(2, "two"), Pair(42, "aaa"))); +} + +TEST_F(MapImplTest, Emplace) { + using ::testing::Pair; + using ::testing::UnorderedElementsAre; + + Map m; + + m.emplace(1, "one"); + EXPECT_EQ(m.size(), 1); + + const int32_t key = 42; + m.emplace(key, "aaa"); + m.emplace(2, std::string("two")); + EXPECT_THAT( + m, UnorderedElementsAre(Pair(1, "one"), Pair(2, "two"), Pair(42, "aaa"))); +} + +struct CountedInstance { + CountedInstance() { ++num_created; } + CountedInstance(const CountedInstance&) : CountedInstance() {} + CountedInstance(CountedInstance&&) : CountedInstance() {} + + CountedInstance& operator=(const CountedInstance&) { + ++num_assigned; + return *this; + } + + explicit CountedInstance(int x) : CountedInstance() {} + + static int num_created; + static int num_assigned; +}; + +int CountedInstance::num_created = 0; +int CountedInstance::num_assigned = 0; + +TEST_F(MapImplTest, TryEmplaceExisting) { + Map m; + + m.try_emplace(1, 1); + ASSERT_EQ(m.size(), 1); + + CountedInstance::num_created = 0; + CountedInstance::num_assigned = 0; + m.try_emplace(1, 123); + EXPECT_EQ(m.size(), 1); + EXPECT_EQ(CountedInstance::num_created, 0); + EXPECT_EQ(CountedInstance::num_assigned, 0); +} + +struct ArenaConstructible { + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + + ArenaConstructible() = default; + ArenaConstructible(const ArenaConstructible&) = default; + ArenaConstructible(Arena*) : ArenaConstructible() {} + + ArenaConstructible& operator=(const ArenaConstructible&) = default; + + explicit ArenaConstructible(int) : ArenaConstructible() {} + + Arena* arena() const { return nullptr; } + + CountedInstance unused; +}; + +TEST_F(MapImplTest, TryEmplaceArenaConstructible) { + ASSERT_TRUE(Arena::is_arena_constructable::value); + + ArenaConstructible v1, v2; + + Map m; + + // "default" construction + CountedInstance::num_created = 0; + CountedInstance::num_assigned = 0; + m.try_emplace(1); + EXPECT_EQ(m.size(), 1); + EXPECT_EQ(CountedInstance::num_created, 1); + EXPECT_EQ(CountedInstance::num_assigned, 0); + + // "default" construction + copy assignment + CountedInstance::num_created = 0; + CountedInstance::num_assigned = 0; + m.try_emplace(2, v1); + EXPECT_EQ(m.size(), 2); + EXPECT_EQ(CountedInstance::num_created, 1); + EXPECT_EQ(CountedInstance::num_assigned, 1); + + // "default" construction + move assignment + CountedInstance::num_created = 0; + CountedInstance::num_assigned = 0; + m.try_emplace(3, std::move(v2)); + EXPECT_EQ(m.size(), 3); + EXPECT_EQ(CountedInstance::num_created, 1); + EXPECT_EQ(CountedInstance::num_assigned, 1); + + // "default" construction + in-place temporary + move assignment + CountedInstance::num_created = 0; + CountedInstance::num_assigned = 0; + m.try_emplace(4, 239); + EXPECT_EQ(m.size(), 4); + EXPECT_EQ(CountedInstance::num_created, 2); + EXPECT_EQ(CountedInstance::num_assigned, 1); +} + +TEST_F(MapImplTest, TryEmplaceExistingArenaConstructible) { + ASSERT_TRUE(Arena::is_arena_constructable::value); + + Map m; + + m.try_emplace(1, 1); + ASSERT_EQ(m.size(), 1); + + CountedInstance::num_created = 0; + CountedInstance::num_assigned = 0; + m.try_emplace(1, 123); + EXPECT_EQ(m.size(), 1); + EXPECT_EQ(CountedInstance::num_created, 0); + EXPECT_EQ(CountedInstance::num_assigned, 0); +} + +TEST_F(MapImplTest, EmplaceSingle) { + int32_t key = 0; + int32_t value1 = 100; + int32_t value2 = 101; + + // Emplace a non-existing key. + auto result1 = map_.emplace(key, value1); + ExpectSingleElement(key, value1); + + Map::iterator it1 = result1.first; + EXPECT_EQ(key, it1->first); + EXPECT_EQ(value1, it1->second); + EXPECT_TRUE(result1.second); + + // Emplace an existing key. + auto result2 = map_.emplace(key, value2); + ExpectSingleElement(key, value1); + + Map::iterator it2 = result2.first; + EXPECT_TRUE(it1 == it2); + EXPECT_FALSE(result2.second); +} + TEST_F(MapImplTest, InsertByIterator) { int32_t key1 = 0; int32_t key2 = 1; @@ -3610,7 +3796,9 @@ TEST(TextFormatMapTest, DynamicMessage) { &expected_text, true)); CleanStringLineEndings(&expected_text, false); - EXPECT_EQ(message->DebugString(), expected_text); + std::string actual_text; + TextFormat::PrintToString(*message, &actual_text); + EXPECT_EQ(actual_text, expected_text); } TEST(TextFormatMapTest, Sorted) { diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 632e66d267..6cdc6c8393 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -84,11 +84,11 @@ void Message::MergeFrom(const Message& from) { auto* class_from = from.GetClassData(); auto* merge_to_from = class_to ? class_to->merge_to_from : nullptr; if (class_to == nullptr || class_to != class_from) { - merge_to_from = [](Message* to, const Message& from) { - ReflectionOps::Merge(from, to); + merge_to_from = [](Message& to, const Message& from) { + ReflectionOps::Merge(from, &to); }; } - merge_to_from(this, from); + merge_to_from(*this, from); } void Message::CheckTypeAndMergeFrom(const MessageLite& other) { @@ -111,24 +111,24 @@ void Message::CopyFrom(const Message& from) { << ", " "from: " << from.GetDescriptor()->full_name(); - copy_to_from = [](Message* to, const Message& from) { - ReflectionOps::Copy(from, to); + copy_to_from = [](Message& to, const Message& from) { + ReflectionOps::Copy(from, &to); }; } - copy_to_from(this, from); + copy_to_from(*this, from); } -void Message::CopyWithSourceCheck(Message* to, const Message& from) { +void Message::CopyWithSourceCheck(Message& to, const Message& from) { #ifndef NDEBUG FailIfCopyFromDescendant(to, from); #endif - to->Clear(); - to->GetClassData()->merge_to_from(to, from); + to.Clear(); + to.GetClassData()->merge_to_from(to, from); } -void Message::FailIfCopyFromDescendant(Message* to, const Message& from) { - auto* arena = to->GetArenaForAllocation(); - bool same_message_owned_arena = to->GetOwningArena() == nullptr && +void Message::FailIfCopyFromDescendant(Message& to, const Message& from) { + auto* arena = to.GetArenaForAllocation(); + bool same_message_owned_arena = to.GetOwningArena() == nullptr && arena != nullptr && arena == from.GetOwningArena(); GOOGLE_CHECK(!same_message_owned_arena && !internal::IsDescendant(to, from)) diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index f58b5002e8..39ec154c34 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -221,7 +221,7 @@ const To& GetConstRefAtOffset(const Message& message, uint32_t offset) { bool CreateUnknownEnumValues(const FieldDescriptor* field); // Returns true if "message" is a descendant of "root". -PROTOBUF_EXPORT bool IsDescendant(Message* root, const Message& message); +PROTOBUF_EXPORT bool IsDescendant(Message& root, const Message& message); } // namespace internal // Abstract interface for protocol messages. @@ -371,8 +371,8 @@ class PROTOBUF_EXPORT Message : public MessageLite { // Note: The order of arguments (to, then from) is chosen so that the ABI // of this function is the same as the CopyFrom method. That is, the // hidden "this" parameter comes first. - void (*copy_to_from)(Message* to, const Message& from_msg); - void (*merge_to_from)(Message* to, const Message& from_msg); + void (*copy_to_from)(Message& to, const Message& from_msg); + void (*merge_to_from)(Message& to, const Message& from_msg); }; // GetClassData() returns a pointer to a ClassData struct which // exists in global memory and is unique to each subclass. This uniqueness @@ -385,10 +385,10 @@ class PROTOBUF_EXPORT Message : public MessageLite { // builds, checks that calling Clear() on the destination message doesn't // alter the source. It assumes the messages are known to be of the same // type, and thus uses GetClassData(). - static void CopyWithSourceCheck(Message* to, const Message& from); + static void CopyWithSourceCheck(Message& to, const Message& from); // Fail if "from" is a descendant of "to" as such copy is not allowed. - static void FailIfCopyFromDescendant(Message* to, const Message& from); + static void FailIfCopyFromDescendant(Message& to, const Message& from); inline explicit Message(Arena* arena, bool is_message_owned = false) : MessageLite(arena, is_message_owned) {} @@ -1030,7 +1030,7 @@ class PROTOBUF_EXPORT Reflection final { bool IsEagerlyVerifiedLazyField(const FieldDescriptor* field) const; friend class FastReflectionMessageMutator; - friend bool internal::IsDescendant(Message* root, const Message& message); + friend bool internal::IsDescendant(Message& root, const Message& message); const Descriptor* const descriptor_; const internal::ReflectionSchema schema_; diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 81b27b738b..cd9759698b 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -658,14 +658,14 @@ const char* ReadTagInlined(const char* ptr, uint32_t* out) { // If bit 15 of return value is set (equivalent to the continuation bits of both // bytes being set) the varint continues, otherwise the parse is done. On x86 // movsx eax, dil -// add edi, eax +// and edi, eax +// add eax, edi // adc [rsi], 1 -// add eax, eax -// and eax, edi inline uint32_t DecodeTwoBytes(const char** ptr) { uint32_t value = UnalignedLoad(*ptr); // Sign extend the low byte continuation bit uint32_t x = static_cast(value); + value &= x; // Mask out the high byte iff no continuation // This add is an amazing operation, it cancels the low byte continuation bit // from y transferring it to the carry. Simultaneously it also shifts the 7 // LSB left by one tightly against high byte varint bits. Hence value now @@ -673,7 +673,7 @@ inline uint32_t DecodeTwoBytes(const char** ptr) { value += x; // Use the carry to update the ptr appropriately. *ptr += value < x ? 2 : 1; - return value & (x + x); // Mask out the high byte iff no continuation + return value; } // More efficient varint parsing for big varints diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index a6f9cfe72c..315c775e29 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -874,9 +874,7 @@ #undef DEBUG #endif // defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER) -#if defined(__clang__) -#pragma clang diagnostic push -#elif PROTOBUF_GNUC_MIN(3, 0) +#if PROTOBUF_GNUC_MIN(3, 0) // GCC does not allow disabling diagnostics within an expression: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one // globally even though it's only used for PROTOBUF_FIELD_OFFSET. diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 757399f378..e880fa5c59 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -150,9 +150,7 @@ #pragma pop_macro("DEBUG") #endif // defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) +#if defined(__GNUC__) #pragma GCC diagnostic pop #endif diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 32ff50832e..d82e135ae7 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -547,7 +547,7 @@ RepeatedField::~RepeatedField() { #ifndef NDEBUG // Try to trigger segfault / asan failure in non-opt builds if arena_ // lifetime has ended before the destructor. - auto arena = GetArena(); + auto arena = GetOwningArena(); if (arena) (void)arena->SpaceAllocated(); #endif if (total_size_ > 0) { @@ -571,7 +571,7 @@ inline RepeatedField::RepeatedField(RepeatedField&& other) noexcept // We don't just call Swap(&other) here because it would perform 3 copies if // other is on an arena. This field can't be on an arena because arena // construction always uses the Arena* accepting constructor. - if (other.GetArena()) { + if (other.GetOwningArena()) { CopyFrom(other); } else { InternalSwap(&other); @@ -585,9 +585,9 @@ inline RepeatedField& RepeatedField::operator=( // We don't just call Swap(&other) here because it would perform 3 copies if // the two fields are on different arenas. if (this != &other) { - if (GetArena() != other.GetArena() + if (GetOwningArena() != other.GetOwningArena() #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - || GetArena() == nullptr + || GetOwningArena() == nullptr #endif // !PROTOBUF_FORCE_COPY_IN_MOVE ) { CopyFrom(other); @@ -831,13 +831,14 @@ template void RepeatedField::Swap(RepeatedField* other) { if (this == other) return; #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetArena() != nullptr && GetArena() == other->GetArena()) { + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetArena() == other->GetArena()) { + if (GetOwningArena() == other->GetOwningArena()) { #endif // !PROTOBUF_FORCE_COPY_IN_SWAP InternalSwap(other); } else { - RepeatedField temp(other->GetArena()); + RepeatedField temp(other->GetOwningArena()); temp.MergeFrom(*this); CopyFrom(*other); other->UnsafeArenaSwap(&temp); @@ -847,7 +848,7 @@ void RepeatedField::Swap(RepeatedField* other) { template void RepeatedField::UnsafeArenaSwap(RepeatedField* other) { if (this == other) return; - GOOGLE_DCHECK_EQ(GetArena(), other->GetArena()); + GOOGLE_DCHECK_EQ(GetOwningArena(), other->GetOwningArena()); InternalSwap(other); } @@ -928,7 +929,7 @@ void RepeatedField::Reserve(int new_size) { if (total_size_ >= new_size) return; Rep* old_rep = total_size_ > 0 ? rep() : nullptr; Rep* new_rep; - Arena* arena = GetArena(); + Arena* arena = GetOwningArena(); new_size = internal::CalculateReserveSize( total_size_, new_size); diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 6c322d1719..8e86727144 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -56,7 +56,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { return &rep_->elements[current_size_]; } Rep* old_rep = rep_; - Arena* arena = GetArena(); + Arena* arena = GetOwningArena(); new_size = internal::CalculateReserveSize(total_size_, new_size); GOOGLE_CHECK_LE(static_cast(new_size), diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index aa278e6b86..401230bf51 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -367,9 +367,10 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template PROTOBUF_NDEBUG_INLINE void Swap(RepeatedPtrFieldBase* other) { #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetArena() != nullptr && GetArena() == other->GetArena()) + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetArena() == other->GetArena()) + if (GetOwningArena() == other->GetOwningArena()) #endif // !PROTOBUF_FORCE_COPY_IN_SWAP { InternalSwap(other); @@ -470,8 +471,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template void AddCleared(typename TypeHandler::Type* value) { - GOOGLE_DCHECK(GetArena() == nullptr) << "AddCleared() can only be used on a " - "RepeatedPtrField not on an arena."; + GOOGLE_DCHECK(GetOwningArena() == nullptr) << "AddCleared() can only be used on a " + "RepeatedPtrField not on an arena."; GOOGLE_DCHECK(TypeHandler::GetOwningArena(value) == nullptr) << "AddCleared() can only accept values not on an arena."; if (!rep_ || rep_->allocated_size == total_size_) { @@ -482,10 +483,10 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template PROTOBUF_NODISCARD typename TypeHandler::Type* ReleaseCleared() { - GOOGLE_DCHECK(GetArena() == nullptr) + GOOGLE_DCHECK(GetOwningArena() == nullptr) << "ReleaseCleared() can only be used on a RepeatedPtrField not on " << "an arena."; - GOOGLE_DCHECK(GetArena() == nullptr); + GOOGLE_DCHECK(GetOwningArena() == nullptr); GOOGLE_DCHECK(rep_ != nullptr); GOOGLE_DCHECK_GT(rep_->allocated_size, current_size_); return cast(rep_->elements[--rep_->allocated_size]); @@ -496,7 +497,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // AddAllocated version that implements arena-safe copying behavior. Arena* element_arena = reinterpret_cast(TypeHandler::GetOwningArena(value)); - Arena* arena = GetArena(); + Arena* arena = GetOwningArena(); if (arena == element_arena && rep_ && rep_->allocated_size < total_size_) { // Fast path: underlying arena representation (tagged pointer) is equal to // our arena pointer, and we can add to array without resizing it (at @@ -566,7 +567,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // First, release an element. typename TypeHandler::Type* result = UnsafeArenaReleaseLast(); // Now perform a copy if we're on an arena. - Arena* arena = GetArena(); + Arena* arena = GetOwningArena(); typename TypeHandler::Type* new_result; #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE @@ -584,7 +585,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // this is the same as UnsafeArenaReleaseLast(). Note that we GOOGLE_DCHECK-fail if // we're on an arena, since the user really should implement the copy // operation in this case. - GOOGLE_DCHECK(GetArena() == nullptr) + GOOGLE_DCHECK(GetOwningArena() == nullptr) << "ReleaseLast() called on a RepeatedPtrField that is on an arena, " << "with a type that does not implement MergeFrom. This is unsafe; " << "please implement MergeFrom for your type."; @@ -594,15 +595,16 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template PROTOBUF_NOINLINE void SwapFallback(RepeatedPtrFieldBase* other) { #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - GOOGLE_DCHECK(GetArena() == nullptr || other->GetArena() != GetArena()); + GOOGLE_DCHECK(GetOwningArena() == nullptr || + other->GetOwningArena() != GetOwningArena()); #else // PROTOBUF_FORCE_COPY_IN_SWAP - GOOGLE_DCHECK(other->GetArena() != GetArena()); + GOOGLE_DCHECK(other->GetOwningArena() != GetOwningArena()); #endif // !PROTOBUF_FORCE_COPY_IN_SWAP // Copy semantics in this case. We try to improve efficiency by placing the // temporary on |other|'s arena so that messages are copied twice rather // than three times. - RepeatedPtrFieldBase temp(other->GetArena()); + RepeatedPtrFieldBase temp(other->GetOwningArena()); temp.MergeFrom(*this); this->Clear(); this->MergeFrom(*other); @@ -612,11 +614,12 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { inline Arena* GetArena() const { return arena_; } + protected: + inline Arena* GetOwningArena() const { return arena_; } + private: template friend class Arena::InternalHelper; - inline Arena* GetOwningArena() const { return arena_; } - static constexpr int kInitialSize = 0; // A few notes on internal representation: // @@ -676,7 +679,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { void** other_elems, int length, int already_allocated) { if (already_allocated < length) { - Arena* arena = GetArena(); + Arena* arena = GetOwningArena(); typename TypeHandler::Type* elem_prototype = reinterpret_cast(other_elems[0]); for (int i = already_allocated; i < length; i++) { @@ -1126,6 +1129,9 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // Note: RepeatedPtrField SHOULD NOT be subclassed by users. class TypeHandler; + // Internal version of GetArena(). + inline Arena* GetOwningArena() const; + // Implementations for ExtractSubrange(). The copying behavior must be // included only if the type supports the necessary operations (e.g., // MergeFrom()), so we must resolve this at compile time. ExtractSubrange() @@ -1205,7 +1211,7 @@ inline RepeatedPtrField::RepeatedPtrField( // We don't just call Swap(&other) here because it would perform 3 copies if // other is on an arena. This field can't be on an arena because arena // construction always uses the Arena* accepting constructor. - if (other.GetArena()) { + if (other.GetOwningArena()) { CopyFrom(other); } else { InternalSwap(&other); @@ -1219,9 +1225,9 @@ inline RepeatedPtrField& RepeatedPtrField::operator=( // We don't just call Swap(&other) here because it would perform 3 copies if // the two fields are on different arenas. if (this != &other) { - if (GetArena() != other.GetArena() + if (GetOwningArena() != other.GetOwningArena() #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - || GetArena() == nullptr + || GetOwningArena() == nullptr #endif // !PROTOBUF_FORCE_COPY_IN_MOVE ) { CopyFrom(other); @@ -1330,7 +1336,7 @@ inline void RepeatedPtrField::ExtractSubrangeInternal( return; } - Arena* arena = GetArena(); + Arena* arena = GetOwningArena(); #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE // Always copy. for (int i = 0; i < num; ++i) { @@ -1368,7 +1374,7 @@ inline void RepeatedPtrField::ExtractSubrangeInternal( // ExtractSubrange() must return heap-allocated objects by contract, and we // cannot fulfill this contract if we are an on arena, we must GOOGLE_DCHECK() that // we are not on an arena. - GOOGLE_DCHECK(GetArena() == nullptr) + GOOGLE_DCHECK(GetOwningArena() == nullptr) << "ExtractSubrange() when arena is non-nullptr is only supported when " << "the Element type supplies a MergeFrom() operation to make copies."; UnsafeArenaExtractSubrange(start, num, elements); @@ -1450,7 +1456,7 @@ template inline void RepeatedPtrField::UnsafeArenaSwap( RepeatedPtrField* other) { if (this == other) return; - GOOGLE_DCHECK_EQ(GetArena(), other->GetArena()); + GOOGLE_DCHECK_EQ(GetOwningArena(), other->GetOwningArena()); RepeatedPtrFieldBase::InternalSwap(other); } @@ -1464,6 +1470,11 @@ inline Arena* RepeatedPtrField::GetArena() const { return RepeatedPtrFieldBase::GetArena(); } +template +inline Arena* RepeatedPtrField::GetOwningArena() const { + return RepeatedPtrFieldBase::GetOwningArena(); +} + template inline size_t RepeatedPtrField::SpaceUsedExcludingSelfLong() const { return RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong(); diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index eb7acfab1e..e7525e99cf 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -95,6 +95,7 @@ SourceContext::SourceContext(::PROTOBUF_NAMESPACE_ID::Arena* arena, } SourceContext::SourceContext(const SourceContext& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + SourceContext* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.file_name_){} , /*decltype(_impl_._cached_size_)*/{}}; @@ -105,8 +106,8 @@ SourceContext::SourceContext(const SourceContext& from) _impl_.file_name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_file_name().empty()) { - _impl_.file_name_.Set(from._internal_file_name(), - GetArenaForAllocation()); + _this->_impl_.file_name_.Set(from._internal_file_name(), + _this->GetArenaForAllocation()); } // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext) } @@ -240,23 +241,19 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceContext::_class_data_ = }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceContext::GetClassData() const { return &_class_data_; } -void SourceContext::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void SourceContext::MergeFrom(const SourceContext& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) - GOOGLE_DCHECK_NE(&from, this); +void SourceContext::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_file_name().empty()) { - _internal_set_file_name(from._internal_file_name()); + _this->_internal_set_file_name(from._internal_file_name()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void SourceContext::CopyFrom(const SourceContext& from) { diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 275df17bbe..49ecc2e79c 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -136,9 +136,11 @@ class PROTOBUF_EXPORT SourceContext final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const SourceContext& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const SourceContext& from); + void MergeFrom( const SourceContext& from) { + SourceContext::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index afd1f8f0f7..87c72d4aa4 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -209,12 +209,13 @@ Struct::Struct(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Struct::Struct(const Struct& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Struct* const _this = this; (void)_this; new (&_impl_) Impl_{ /*decltype(_impl_.fields_)*/{} , /*decltype(_impl_._cached_size_)*/{}}; _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _impl_.fields_.MergeFrom(from._impl_.fields_); + _this->_impl_.fields_.MergeFrom(from._impl_.fields_); // @@protoc_insertion_point(copy_constructor:google.protobuf.Struct) } @@ -370,21 +371,17 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Struct::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Struct::GetClassData() const { return &_class_data_; } -void Struct::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Struct::MergeFrom(const Struct& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) - GOOGLE_DCHECK_NE(&from, this); +void Struct::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.fields_.MergeFrom(from._impl_.fields_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.fields_.MergeFrom(from._impl_.fields_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Struct::CopyFrom(const Struct& from) { @@ -464,6 +461,7 @@ Value::Value(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Value::Value(const Value& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Value* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.kind_){} , /*decltype(_impl_._cached_size_)*/{} @@ -473,27 +471,29 @@ Value::Value(const Value& from) clear_has_kind(); switch (from.kind_case()) { case kNullValue: { - _internal_set_null_value(from._internal_null_value()); + _this->_internal_set_null_value(from._internal_null_value()); break; } case kNumberValue: { - _internal_set_number_value(from._internal_number_value()); + _this->_internal_set_number_value(from._internal_number_value()); break; } case kStringValue: { - _internal_set_string_value(from._internal_string_value()); + _this->_internal_set_string_value(from._internal_string_value()); break; } case kBoolValue: { - _internal_set_bool_value(from._internal_bool_value()); + _this->_internal_set_bool_value(from._internal_bool_value()); break; } case kStructValue: { - _internal_mutable_struct_value()->::PROTOBUF_NAMESPACE_ID::Struct::MergeFrom(from._internal_struct_value()); + _this->_internal_mutable_struct_value()->::PROTOBUF_NAMESPACE_ID::Struct::MergeFrom( + from._internal_struct_value()); break; } case kListValue: { - _internal_mutable_list_value()->::PROTOBUF_NAMESPACE_ID::ListValue::MergeFrom(from._internal_list_value()); + _this->_internal_mutable_list_value()->::PROTOBUF_NAMESPACE_ID::ListValue::MergeFrom( + from._internal_list_value()); break; } case KIND_NOT_SET: { @@ -780,49 +780,47 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Value::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Value::GetClassData() const { return &_class_data_; } -void Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Value::MergeFrom(const Value& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) - GOOGLE_DCHECK_NE(&from, this); +void Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; switch (from.kind_case()) { case kNullValue: { - _internal_set_null_value(from._internal_null_value()); + _this->_internal_set_null_value(from._internal_null_value()); break; } case kNumberValue: { - _internal_set_number_value(from._internal_number_value()); + _this->_internal_set_number_value(from._internal_number_value()); break; } case kStringValue: { - _internal_set_string_value(from._internal_string_value()); + _this->_internal_set_string_value(from._internal_string_value()); break; } case kBoolValue: { - _internal_set_bool_value(from._internal_bool_value()); + _this->_internal_set_bool_value(from._internal_bool_value()); break; } case kStructValue: { - _internal_mutable_struct_value()->::PROTOBUF_NAMESPACE_ID::Struct::MergeFrom(from._internal_struct_value()); + _this->_internal_mutable_struct_value()->::PROTOBUF_NAMESPACE_ID::Struct::MergeFrom( + from._internal_struct_value()); break; } case kListValue: { - _internal_mutable_list_value()->::PROTOBUF_NAMESPACE_ID::ListValue::MergeFrom(from._internal_list_value()); + _this->_internal_mutable_list_value()->::PROTOBUF_NAMESPACE_ID::ListValue::MergeFrom( + from._internal_list_value()); break; } case KIND_NOT_SET: { break; } } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Value::CopyFrom(const Value& from) { @@ -863,6 +861,7 @@ ListValue::ListValue(::PROTOBUF_NAMESPACE_ID::Arena* arena, } ListValue::ListValue(const ListValue& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + ListValue* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.values_){from._impl_.values_} , /*decltype(_impl_._cached_size_)*/{}}; @@ -997,21 +996,17 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListValue::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListValue::GetClassData() const { return &_class_data_; } -void ListValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void ListValue::MergeFrom(const ListValue& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) - GOOGLE_DCHECK_NE(&from, this); +void ListValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.values_.MergeFrom(from._impl_.values_); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.values_.MergeFrom(from._impl_.values_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void ListValue::CopyFrom(const ListValue& from) { diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 08d23e52da..3a88ef75e1 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -202,9 +202,11 @@ class PROTOBUF_EXPORT Struct final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Struct& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Struct& from); + void MergeFrom( const Struct& from) { + Struct::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -373,9 +375,11 @@ class PROTOBUF_EXPORT Value final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Value& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Value& from); + void MergeFrom( const Value& from) { + Value::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; @@ -630,9 +634,11 @@ class PROTOBUF_EXPORT ListValue final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const ListValue& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const ListValue& from); + void MergeFrom( const ListValue& from) { + ListValue::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 5566eec780..19110499d7 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -66,8 +66,6 @@ // Must be included last. #include -#define DEBUG_STRING_SILENT_MARKER "\t " - namespace google { namespace protobuf { @@ -86,7 +84,10 @@ inline bool IsOctNumber(const std::string& str) { } // namespace namespace internal { -// Controls insertion of DEBUG_STRING_SILENT_MARKER. +const char kDebugStringSilentMarker[] = ""; +const char kDebugStringSilentMarkerForDetection[] = "\t "; + +// Controls insertion of kDebugStringSilentMarker. PROTOBUF_EXPORT std::atomic enable_debug_text_format_marker; } // namespace internal @@ -1282,7 +1283,8 @@ class TextFormat::Parser::ParserImpl { bool TryConsumeWhitespace() { had_silent_marker_ = false; if (LookingAtType(io::Tokenizer::TYPE_WHITESPACE)) { - if (tokenizer_.current().text == " " DEBUG_STRING_SILENT_MARKER) { + if (tokenizer_.current().text == + StrCat(" ", internal::kDebugStringSilentMarkerForDetection)) { had_silent_marker_ = true; } tokenizer_.Next(); @@ -1422,7 +1424,7 @@ class TextFormat::Printer::TextGenerator void PrintMaybeWithMarker(StringPiece text) { Print(text.data(), text.size()); if (ConsumeInsertSilentMarker()) { - PrintLiteral(DEBUG_STRING_SILENT_MARKER); + PrintLiteral(internal::kDebugStringSilentMarker); } } @@ -1430,7 +1432,7 @@ class TextFormat::Printer::TextGenerator StringPiece text_tail) { Print(text_head.data(), text_head.size()); if (ConsumeInsertSilentMarker()) { - PrintLiteral(DEBUG_STRING_SILENT_MARKER); + PrintLiteral(internal::kDebugStringSilentMarker); } Print(text_tail.data(), text_tail.size()); } diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h index c27ab3f78f..e10bef7ddf 100644 --- a/src/google/protobuf/text_format.h +++ b/src/google/protobuf/text_format.h @@ -60,6 +60,11 @@ namespace google { namespace protobuf { +namespace internal { +PROTOBUF_EXPORT extern const char kDebugStringSilentMarker[1]; +PROTOBUF_EXPORT extern const char kDebugStringSilentMarkerForDetection[3]; +} // namespace internal + namespace io { class ErrorCollector; // tokenizer.h } diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 9417b87419..126f2f3806 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -77,6 +77,8 @@ extern PROTOBUF_EXPORT std::atomic enable_debug_text_format_marker; // Can't use an anonymous namespace here due to brokenness of Tru64 compiler. namespace text_format_unittest { +using ::google::protobuf::internal::kDebugStringSilentMarker; + // A basic string with different escapable characters for testing. const std::string kEscapeTestString = "\"A string with ' characters \n and \r newlines and \t tabs and \001 " @@ -94,21 +96,21 @@ class TextFormatTest : public testing::Test { TestUtil::GetTestDataPath( "net/proto2/internal/" "testdata/text_format_unittest_data_oneof_implemented.txt"), - &static_proto_debug_string_, true)); - CleanStringLineEndings(&static_proto_debug_string_, false); + &static_proto_text_format_, true)); + CleanStringLineEndings(&static_proto_text_format_, false); } - TextFormatTest() : proto_debug_string_(static_proto_debug_string_) {} + TextFormatTest() : proto_text_format_(static_proto_text_format_) {} protected: - // Debug string read from text_format_unittest_data.txt. - const std::string proto_debug_string_; + // Text format read from text_format_unittest_data.txt. + const std::string proto_text_format_; unittest::TestAllTypes proto_; private: - static std::string static_proto_debug_string_; + static std::string static_proto_text_format_; }; -std::string TextFormatTest::static_proto_debug_string_; +std::string TextFormatTest::static_proto_text_format_; class TextFormatExtensionsTest : public testing::Test { public: @@ -116,31 +118,34 @@ class TextFormatExtensionsTest : public testing::Test { GOOGLE_CHECK_OK(File::GetContents( TestUtil::GetTestDataPath("net/proto2/internal/testdata/" "text_format_unittest_extensions_data.txt"), - &static_proto_debug_string_, true)); - CleanStringLineEndings(&static_proto_debug_string_, false); + &static_proto_text_format_, true)); + CleanStringLineEndings(&static_proto_text_format_, false); } - TextFormatExtensionsTest() - : proto_debug_string_(static_proto_debug_string_) {} + TextFormatExtensionsTest() : proto_text_format_(static_proto_text_format_) {} protected: // Debug string read from text_format_unittest_data.txt. - const std::string proto_debug_string_; + const std::string proto_text_format_; unittest::TestAllExtensions proto_; private: - static std::string static_proto_debug_string_; + static std::string static_proto_text_format_; }; -std::string TextFormatExtensionsTest::static_proto_debug_string_; +std::string TextFormatExtensionsTest::static_proto_text_format_; TEST_F(TextFormatTest, Basic) { TestUtil::SetAllFields(&proto_); - EXPECT_EQ(proto_debug_string_, proto_.DebugString()); + std::string actual_proto_text_format; + TextFormat::PrintToString(proto_, &actual_proto_text_format); + EXPECT_EQ(actual_proto_text_format, proto_text_format_); } TEST_F(TextFormatExtensionsTest, Extensions) { TestUtil::SetAllExtensions(&proto_); - EXPECT_EQ(proto_debug_string_, proto_.DebugString()); + std::string actual_proto_text_format; + TextFormat::PrintToString(proto_, &actual_proto_text_format); + EXPECT_EQ(actual_proto_text_format, proto_text_format_); } TEST_F(TextFormatTest, ShortDebugString) { @@ -149,11 +154,12 @@ TEST_F(TextFormatTest, ShortDebugString) { proto_.mutable_optional_nested_message()->set_bb(2); proto_.mutable_optional_foreign_message(); - EXPECT_EQ( - "optional_int32: 1 optional_string: \"hello\" " - "optional_nested_message { bb: 2 } " - "optional_foreign_message { }", - proto_.ShortDebugString()); + EXPECT_EQ(proto_.ShortDebugString(), + StrCat("optional_int32: ", kDebugStringSilentMarker, + "1 " + "optional_string: \"hello\" " + "optional_nested_message { bb: 2 } " + "optional_foreign_message { }")); } TEST_F(TextFormatTest, ShortPrimitiveRepeateds) { @@ -223,7 +229,8 @@ TEST_F(TextFormatTest, StringEscape) { // Hardcode a correct value to test against. std::string correct_string = - "optional_string: " + kEscapeTestStringEscaped + "\n"; + StrCat("optional_string: ", kDebugStringSilentMarker, + kEscapeTestStringEscaped, "\n"); // Compare. EXPECT_EQ(correct_string, debug_string); @@ -231,8 +238,8 @@ TEST_F(TextFormatTest, StringEscape) { // the protocol buffer contains no UTF-8 text. EXPECT_EQ(correct_string, utf8_debug_string); - std::string expected_short_debug_string = - "optional_string: " + kEscapeTestStringEscaped; + std::string expected_short_debug_string = StrCat( + "optional_string: ", kDebugStringSilentMarker, kEscapeTestStringEscaped); EXPECT_EQ(expected_short_debug_string, proto_.ShortDebugString()); } @@ -247,19 +254,13 @@ TEST_F(TextFormatTest, Utf8DebugString) { // Hardcode a correct value to test against. std::string correct_utf8_string = - "optional_string: " - "\"\350\260\267\346\255\214\"" - "\n" - "optional_bytes: " - "\"\\350\\260\\267\\346\\255\\214\"" - "\n"; + StrCat("optional_string: ", kDebugStringSilentMarker, + "\"\350\260\267\346\255\214\"\n" + "optional_bytes: \"\\350\\260\\267\\346\\255\\214\"\n"); std::string correct_string = - "optional_string: " - "\"\\350\\260\\267\\346\\255\\214\"" - "\n" - "optional_bytes: " - "\"\\350\\260\\267\\346\\255\\214\"" - "\n"; + StrCat("optional_string: ", kDebugStringSilentMarker, + "\"\\350\\260\\267\\346\\255\\214\"\n" + "optional_bytes: \"\\350\\260\\267\\346\\255\\214\"\n"); // Compare. EXPECT_EQ(correct_utf8_string, utf8_debug_string); @@ -282,18 +283,18 @@ TEST_F(TextFormatTest, PrintUnknownFields) { unknown_fields->AddVarint(8, 2); unknown_fields->AddVarint(8, 3); - EXPECT_EQ( - "5: 1\n" - "5: 0x00000002\n" - "5: 0x0000000000000003\n" - "5: \"4\"\n" - "5 {\n" - " 10: 5\n" - "}\n" - "8: 1\n" - "8: 2\n" - "8: 3\n", - message.DebugString()); + EXPECT_EQ(StrCat("5: ", kDebugStringSilentMarker, + "1\n" + "5: 0x00000002\n" + "5: 0x0000000000000003\n" + "5: \"4\"\n" + "5 {\n" + " 10: 5\n" + "}\n" + "8: 1\n" + "8: 2\n" + "8: 3\n"), + message.DebugString()); } TEST_F(TextFormatTest, PrintUnknownFieldsHidden) { @@ -800,15 +801,15 @@ TEST_F(TextFormatTest, CustomMessagePrinter) { } TEST_F(TextFormatTest, ParseBasic) { - io::ArrayInputStream input_stream(proto_debug_string_.data(), - proto_debug_string_.size()); + io::ArrayInputStream input_stream(proto_text_format_.data(), + proto_text_format_.size()); TextFormat::Parse(&input_stream, &proto_); TestUtil::ExpectAllFieldsSet(proto_); } TEST_F(TextFormatExtensionsTest, ParseExtensions) { - io::ArrayInputStream input_stream(proto_debug_string_.data(), - proto_debug_string_.size()); + io::ArrayInputStream input_stream(proto_text_format_.data(), + proto_text_format_.size()); TextFormat::Parse(&input_stream, &proto_); TestUtil::ExpectAllExtensionsSet(proto_); } @@ -844,12 +845,12 @@ TEST_F(TextFormatTest, PrintUnknownEnumFieldProto3) { proto.add_repeated_nested_enum( static_cast(-2147483648)); - EXPECT_EQ( - "repeated_nested_enum: 10\n" - "repeated_nested_enum: -10\n" - "repeated_nested_enum: 2147483647\n" - "repeated_nested_enum: -2147483648\n", - proto.DebugString()); + EXPECT_EQ(StrCat("repeated_nested_enum: ", kDebugStringSilentMarker, + "10\n" + "repeated_nested_enum: -10\n" + "repeated_nested_enum: 2147483647\n" + "repeated_nested_enum: -2147483648\n"), + proto.DebugString()); } TEST_F(TextFormatTest, ParseUnknownEnumFieldProto3) { @@ -1102,19 +1103,20 @@ TEST_F(TextFormatTest, PrintExotic) { // have this problem, so we switched to that instead. EXPECT_EQ( - "repeated_int64: -9223372036854775808\n" - "repeated_uint64: 18446744073709551615\n" - "repeated_double: 123.456\n" - "repeated_double: 1.23e+21\n" - "repeated_double: 1.23e-18\n" - "repeated_double: inf\n" - "repeated_double: -inf\n" - "repeated_double: nan\n" - "repeated_double: nan\n" - "repeated_double: nan\n" - "repeated_double: nan\n" - "repeated_string: " - "\"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\'\\\"\"\n", + StrCat("repeated_int64: ", kDebugStringSilentMarker, + "-9223372036854775808\n" + "repeated_uint64: 18446744073709551615\n" + "repeated_double: 123.456\n" + "repeated_double: 1.23e+21\n" + "repeated_double: 1.23e-18\n" + "repeated_double: inf\n" + "repeated_double: -inf\n" + "repeated_double: nan\n" + "repeated_double: nan\n" + "repeated_double: nan\n" + "repeated_double: nan\n" + "repeated_string: " + "\"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\'\\\"\"\n"), RemoveRedundantZeros(message.DebugString())); } @@ -1161,47 +1163,47 @@ TEST_F(TextFormatTest, PrintFloatPrecision) { message.add_repeated_double(1.2345678987654e100); message.add_repeated_double(1.23456789876543e100); - EXPECT_EQ( - "repeated_float: 1\n" - "repeated_float: 1.2\n" - "repeated_float: 1.23\n" - "repeated_float: 1.234\n" - "repeated_float: 1.2345\n" - "repeated_float: 1.23456\n" - "repeated_float: 1.2e+10\n" - "repeated_float: 1.23e+10\n" - "repeated_float: 1.234e+10\n" - "repeated_float: 1.2345e+10\n" - "repeated_float: 1.23456e+10\n" - "repeated_double: 1.2\n" - "repeated_double: 1.23\n" - "repeated_double: 1.234\n" - "repeated_double: 1.2345\n" - "repeated_double: 1.23456\n" - "repeated_double: 1.234567\n" - "repeated_double: 1.2345678\n" - "repeated_double: 1.23456789\n" - "repeated_double: 1.234567898\n" - "repeated_double: 1.2345678987\n" - "repeated_double: 1.23456789876\n" - "repeated_double: 1.234567898765\n" - "repeated_double: 1.2345678987654\n" - "repeated_double: 1.23456789876543\n" - "repeated_double: 1.2e+100\n" - "repeated_double: 1.23e+100\n" - "repeated_double: 1.234e+100\n" - "repeated_double: 1.2345e+100\n" - "repeated_double: 1.23456e+100\n" - "repeated_double: 1.234567e+100\n" - "repeated_double: 1.2345678e+100\n" - "repeated_double: 1.23456789e+100\n" - "repeated_double: 1.234567898e+100\n" - "repeated_double: 1.2345678987e+100\n" - "repeated_double: 1.23456789876e+100\n" - "repeated_double: 1.234567898765e+100\n" - "repeated_double: 1.2345678987654e+100\n" - "repeated_double: 1.23456789876543e+100\n", - RemoveRedundantZeros(message.DebugString())); + EXPECT_EQ(StrCat("repeated_float: ", kDebugStringSilentMarker, + "1\n" + "repeated_float: 1.2\n" + "repeated_float: 1.23\n" + "repeated_float: 1.234\n" + "repeated_float: 1.2345\n" + "repeated_float: 1.23456\n" + "repeated_float: 1.2e+10\n" + "repeated_float: 1.23e+10\n" + "repeated_float: 1.234e+10\n" + "repeated_float: 1.2345e+10\n" + "repeated_float: 1.23456e+10\n" + "repeated_double: 1.2\n" + "repeated_double: 1.23\n" + "repeated_double: 1.234\n" + "repeated_double: 1.2345\n" + "repeated_double: 1.23456\n" + "repeated_double: 1.234567\n" + "repeated_double: 1.2345678\n" + "repeated_double: 1.23456789\n" + "repeated_double: 1.234567898\n" + "repeated_double: 1.2345678987\n" + "repeated_double: 1.23456789876\n" + "repeated_double: 1.234567898765\n" + "repeated_double: 1.2345678987654\n" + "repeated_double: 1.23456789876543\n" + "repeated_double: 1.2e+100\n" + "repeated_double: 1.23e+100\n" + "repeated_double: 1.234e+100\n" + "repeated_double: 1.2345e+100\n" + "repeated_double: 1.23456e+100\n" + "repeated_double: 1.234567e+100\n" + "repeated_double: 1.2345678e+100\n" + "repeated_double: 1.23456789e+100\n" + "repeated_double: 1.234567898e+100\n" + "repeated_double: 1.2345678987e+100\n" + "repeated_double: 1.23456789876e+100\n" + "repeated_double: 1.234567898765e+100\n" + "repeated_double: 1.2345678987654e+100\n" + "repeated_double: 1.23456789876543e+100\n"), + RemoveRedundantZeros(message.DebugString())); } TEST_F(TextFormatTest, AllowPartial) { @@ -2064,9 +2066,9 @@ TEST_F(TextFormatParserTest, ParseSkippedFieldWithAdditionalWhiteSpaces) { class TextFormatMessageSetTest : public testing::Test { protected: - static const char proto_debug_string_[]; + static const char proto_text_format_[]; }; -const char TextFormatMessageSetTest::proto_debug_string_[] = +const char TextFormatMessageSetTest::proto_text_format_[] = "message_set {\n" " [protobuf_unittest.TestMessageSetExtension1] {\n" " i: 23\n" @@ -2086,12 +2088,14 @@ TEST_F(TextFormatMessageSetTest, Serialize) { proto.mutable_message_set()->MutableExtension( protobuf_unittest::TestMessageSetExtension2::message_set_extension); item_b->set_str("foo"); - EXPECT_EQ(proto_debug_string_, proto.DebugString()); + std::string actual_proto_text_format; + TextFormat::PrintToString(proto, &actual_proto_text_format); + EXPECT_EQ(proto_text_format_, actual_proto_text_format); } TEST_F(TextFormatMessageSetTest, Deserialize) { protobuf_unittest::TestMessageSetContainer proto; - ASSERT_TRUE(TextFormat::ParseFromString(proto_debug_string_, &proto)); + ASSERT_TRUE(TextFormat::ParseFromString(proto_text_format_, &proto)); EXPECT_EQ( 23, proto.message_set() @@ -2251,131 +2255,6 @@ TEST(TextFormatUnknownFieldTest, TestUnknownExtension) { EXPECT_FALSE(parser.ParseFromString("unknown_field: 1", &proto)); } -class TextFormatSilentMarkerTest : public testing::Test { - public: - void SetUp() override { - google::protobuf::internal::enable_debug_text_format_marker = true; - } - void TearDown() override { - google::protobuf::internal::enable_debug_text_format_marker = false; - } -}; - -TEST_F(TextFormatSilentMarkerTest, NonMessageFieldAsFirstField) { - protobuf_unittest::TestAllTypes proto; - proto.set_optional_int32(1); - proto.mutable_optional_nested_message()->set_bb(2); - - EXPECT_EQ( - "optional_int32: \t 1\n" - "optional_nested_message {\n" - " bb: 2\n" - "}\n", - proto.DebugString()); - - EXPECT_EQ( - "optional_int32: \t 1 " - "optional_nested_message { bb: 2 }", - proto.ShortDebugString()); -} - -TEST_F(TextFormatSilentMarkerTest, MessageFieldAsFirstField) { - protobuf_unittest::TestAllTypes proto; - proto.mutable_optional_nested_message()->set_bb(2); - proto.add_repeated_int32(3); - - EXPECT_EQ( - "optional_nested_message \t {\n" - " bb: 2\n" - "}\n" - "repeated_int32: 3\n", - proto.DebugString()); - - EXPECT_EQ( - "optional_nested_message \t { bb: 2 } " - "repeated_int32: 3", - proto.ShortDebugString()); -} - -TEST_F(TextFormatSilentMarkerTest, UnknownFieldAsFirstField) { - unittest::TestEmptyMessage message; - UnknownFieldSet* unknown_fields = message.mutable_unknown_fields(); - - unknown_fields->AddVarint(5, 1); - unknown_fields->AddGroup(5)->AddVarint(10, 5); - - EXPECT_EQ( - "5: \t 1\n" - "5 {\n" - " 10: 5\n" - "}\n", - message.DebugString()); - - EXPECT_EQ( - "5: \t 1 " - "5 { 10: 5 }", - message.ShortDebugString()); - - unknown_fields->Clear(); - unknown_fields->AddGroup(5)->AddVarint(10, 5); - unknown_fields->AddVarint(5, 1); - - EXPECT_EQ( - "5 \t {\n" - " 10: 5\n" - "}\n" - "5: 1\n", - message.DebugString()); - - EXPECT_EQ( - "5 \t { 10: 5 } " - "5: 1", - message.ShortDebugString()); -} - -TEST_F(TextFormatSilentMarkerTest, AnyFieldAsFirstField) { - protobuf_unittest::TestAllTypes proto; - proto.set_optional_string("teststr"); - proto.set_optional_int32(432); - Any any; - any.PackFrom(proto); - - EXPECT_EQ( - "[type.googleapis.com/protobuf_unittest.TestAllTypes] \t {\n" - " optional_int32: 432\n" - " optional_string: \"teststr\"\n" - "}\n", - any.DebugString()); - - EXPECT_EQ( - "[type.googleapis.com/protobuf_unittest.TestAllTypes]" - " \t { optional_int32: 432 optional_string: \"teststr\" }", - any.ShortDebugString()); -} - -TEST_F(TextFormatSilentMarkerTest, ExtensionFieldAsFirstField) { - unittest::TestAllExtensions proto; - proto.SetExtension(protobuf_unittest::optional_int32_extension, 101); - proto.SetExtension(protobuf_unittest::optional_int64_extension, 102); - - EXPECT_EQ( - "[protobuf_unittest.optional_int32_extension]: \t 101\n" - "[protobuf_unittest.optional_int64_extension]: 102\n", - proto.DebugString()); -} - -TEST_F(TextFormatSilentMarkerTest, MapFieldAsFirstField) { - unittest::TestMap proto; - (*proto.mutable_map_int32_int32())[0] = 1; - (*proto.mutable_map_int64_int64())[2] = 3; - - EXPECT_EQ( - "map_int32_int32 \t {\n key: 0\n value: 1\n}\n" - "map_int64_int64 {\n key: 2\n value: 3\n}\n", - proto.DebugString()); -} - - TEST(TextFormatFloatingPointTest, PreservesNegative0) { proto3_unittest::TestAllTypes in_message; in_message.set_optional_float(-0.0f); diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 6c8f3b2fdb..728a004389 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -97,6 +97,7 @@ Timestamp::Timestamp(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Timestamp::Timestamp(const Timestamp& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Timestamp* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.seconds_){} , decltype(_impl_.nanos_){} @@ -247,26 +248,22 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Timestamp::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Timestamp::GetClassData() const { return &_class_data_; } -void Timestamp::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Timestamp::MergeFrom(const Timestamp& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) - GOOGLE_DCHECK_NE(&from, this); +void Timestamp::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_seconds() != 0) { - _internal_set_seconds(from._internal_seconds()); + _this->_internal_set_seconds(from._internal_seconds()); } if (from._internal_nanos() != 0) { - _internal_set_nanos(from._internal_nanos()); + _this->_internal_set_nanos(from._internal_nanos()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Timestamp::CopyFrom(const Timestamp& from) { diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 4561e681fa..9f9afde588 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -136,9 +136,11 @@ class PROTOBUF_EXPORT Timestamp final : using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; void CopyFrom(const Timestamp& from); using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom(const Timestamp& from); + void MergeFrom( const Timestamp& from) { + Timestamp::MergeImpl(*this, from); + } private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from); + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); public: PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 618159b26e..e29bbb83a1 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -368,6 +368,7 @@ Type::Type(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Type::Type(const Type& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Type* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.fields_){from._impl_.fields_} , decltype(_impl_.oneofs_){from._impl_.oneofs_} @@ -383,13 +384,13 @@ Type::Type(const Type& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_source_context()) { - _impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_); + _this->_impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_); } - _impl_.syntax_ = from._impl_.syntax_; + _this->_impl_.syntax_ = from._impl_.syntax_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Type) } @@ -672,32 +673,29 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Type::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Type::GetClassData() const { return &_class_data_; } -void Type::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Type::MergeFrom(const Type& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) - GOOGLE_DCHECK_NE(&from, this); +void Type::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.fields_.MergeFrom(from._impl_.fields_); - _impl_.oneofs_.MergeFrom(from._impl_.oneofs_); - _impl_.options_.MergeFrom(from._impl_.options_); + _this->_impl_.fields_.MergeFrom(from._impl_.fields_); + _this->_impl_.oneofs_.MergeFrom(from._impl_.oneofs_); + _this->_impl_.options_.MergeFrom(from._impl_.options_); if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (from._internal_has_source_context()) { - _internal_mutable_source_context()->::PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context()); + _this->_internal_mutable_source_context()->::PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom( + from._internal_source_context()); } if (from._internal_syntax() != 0) { - _internal_set_syntax(from._internal_syntax()); + _this->_internal_set_syntax(from._internal_syntax()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Type::CopyFrom(const Type& from) { @@ -751,6 +749,7 @@ Field::Field(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Field::Field(const Field& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Field* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.options_){from._impl_.options_} , decltype(_impl_.name_){} @@ -770,32 +769,32 @@ Field::Field(const Field& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } _impl_.type_url_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.type_url_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_type_url().empty()) { - _impl_.type_url_.Set(from._internal_type_url(), - GetArenaForAllocation()); + _this->_impl_.type_url_.Set(from._internal_type_url(), + _this->GetArenaForAllocation()); } _impl_.json_name_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.json_name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_json_name().empty()) { - _impl_.json_name_.Set(from._internal_json_name(), - GetArenaForAllocation()); + _this->_impl_.json_name_.Set(from._internal_json_name(), + _this->GetArenaForAllocation()); } _impl_.default_value_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.default_value_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_default_value().empty()) { - _impl_.default_value_.Set(from._internal_default_value(), - GetArenaForAllocation()); + _this->_impl_.default_value_.Set(from._internal_default_value(), + _this->GetArenaForAllocation()); } ::memcpy(&_impl_.kind_, &from._impl_.kind_, static_cast(reinterpret_cast(&_impl_.packed_) - @@ -1174,48 +1173,44 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Field::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Field::GetClassData() const { return &_class_data_; } -void Field::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Field::MergeFrom(const Field& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) - GOOGLE_DCHECK_NE(&from, this); +void Field::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.options_.MergeFrom(from._impl_.options_); + _this->_impl_.options_.MergeFrom(from._impl_.options_); if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (!from._internal_type_url().empty()) { - _internal_set_type_url(from._internal_type_url()); + _this->_internal_set_type_url(from._internal_type_url()); } if (!from._internal_json_name().empty()) { - _internal_set_json_name(from._internal_json_name()); + _this->_internal_set_json_name(from._internal_json_name()); } if (!from._internal_default_value().empty()) { - _internal_set_default_value(from._internal_default_value()); + _this->_internal_set_default_value(from._internal_default_value()); } if (from._internal_kind() != 0) { - _internal_set_kind(from._internal_kind()); + _this->_internal_set_kind(from._internal_kind()); } if (from._internal_cardinality() != 0) { - _internal_set_cardinality(from._internal_cardinality()); + _this->_internal_set_cardinality(from._internal_cardinality()); } if (from._internal_number() != 0) { - _internal_set_number(from._internal_number()); + _this->_internal_set_number(from._internal_number()); } if (from._internal_oneof_index() != 0) { - _internal_set_oneof_index(from._internal_oneof_index()); + _this->_internal_set_oneof_index(from._internal_oneof_index()); } if (from._internal_packed() != 0) { - _internal_set_packed(from._internal_packed()); + _this->_internal_set_packed(from._internal_packed()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Field::CopyFrom(const Field& from) { @@ -1290,6 +1285,7 @@ Enum::Enum(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Enum::Enum(const Enum& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Enum* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.enumvalue_){from._impl_.enumvalue_} , decltype(_impl_.options_){from._impl_.options_} @@ -1304,13 +1300,13 @@ Enum::Enum(const Enum& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_source_context()) { - _impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_); + _this->_impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_); } - _impl_.syntax_ = from._impl_.syntax_; + _this->_impl_.syntax_ = from._impl_.syntax_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Enum) } @@ -1557,31 +1553,28 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Enum::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Enum::GetClassData() const { return &_class_data_; } -void Enum::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void Enum::MergeFrom(const Enum& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) - GOOGLE_DCHECK_NE(&from, this); +void Enum::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.enumvalue_.MergeFrom(from._impl_.enumvalue_); - _impl_.options_.MergeFrom(from._impl_.options_); + _this->_impl_.enumvalue_.MergeFrom(from._impl_.enumvalue_); + _this->_impl_.options_.MergeFrom(from._impl_.options_); if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (from._internal_has_source_context()) { - _internal_mutable_source_context()->::PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context()); + _this->_internal_mutable_source_context()->::PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom( + from._internal_source_context()); } if (from._internal_syntax() != 0) { - _internal_set_syntax(from._internal_syntax()); + _this->_internal_set_syntax(from._internal_syntax()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void Enum::CopyFrom(const Enum& from) { @@ -1634,6 +1627,7 @@ EnumValue::EnumValue(::PROTOBUF_NAMESPACE_ID::Arena* arena, } EnumValue::EnumValue(const EnumValue& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumValue* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.options_){from._impl_.options_} , decltype(_impl_.name_){} @@ -1646,10 +1640,10 @@ EnumValue::EnumValue(const EnumValue& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } - _impl_.number_ = from._impl_.number_; + _this->_impl_.number_ = from._impl_.number_; // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValue) } @@ -1834,27 +1828,23 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumValue::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValue::GetClassData() const { return &_class_data_; } -void EnumValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast(to)->MergeFrom( - static_cast(from)); -} - -void EnumValue::MergeFrom(const EnumValue& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) - GOOGLE_DCHECK_NE(&from, this); +void EnumValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) + GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; (void) cached_has_bits; - _impl_.options_.MergeFrom(from._impl_.options_); + _this->_impl_.options_.MergeFrom(from._impl_.options_); if (!from._internal_name().empty()) { - _internal_set_name(from._internal_name()); + _this->_internal_set_name(from._internal_name()); } if (from._internal_number() != 0) { - _internal_set_number(from._internal_number()); + _this->_internal_set_number(from._internal_number()); } - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); } void EnumValue::CopyFrom(const EnumValue& from) { @@ -1912,6 +1902,7 @@ Option::Option(::PROTOBUF_NAMESPACE_ID::Arena* arena, } Option::Option(const Option& from) : ::PROTOBUF_NAMESPACE_ID::Message() { + Option* const _this = this; (void)_this; new (&_impl_) Impl_{ decltype(_impl_.name_){} , decltype(_impl_.value_){nullptr} @@ -1923,11 +1914,11 @@ Option::Option(const Option& from) _impl_.name_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING if (!from._internal_name().empty()) { - _impl_.name_.Set(from._internal_name(), - GetArenaForAllocation()); + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); } if (from._internal_has_value()) { - _impl_.value_ = new ::PROTOBUF_NAMESPACE_ID::Any(*from._impl_.value_); + _this->_impl_.value_ = new ::PROTOBUF_NAMESPACE_ID::Any(*from._impl_.value_); } // @@protoc_insertion_point(copy_constructor:google.protobuf.Option) } @@ -2089,26 +2080,23 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Option::_class_data_ = { }; const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Option::GetClassData() const { return &_class_data_; } -void Option::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, - const ::PROTOBUF_NAMESPACE_ID::Message& from) { - static_cast