PROTOBUF_SYNC_PIPER
pull/9482/head
Joshua Haberman 3 years ago
parent ab4585a695
commit dce403a8b3
  1. 7
      BUILD
  2. 72
      CHANGES.txt
  3. 5
      CONTRIBUTORS.txt
  4. 14
      conformance/conformance_test.cc
  5. 6
      conformance/conformance_test.h
  6. 6
      conformance/conformance_test_runner.cc
  7. 104
      conformance/failure_list_js.txt
  8. 23
      csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs
  9. 2
      java/core/BUILD
  10. 2
      java/core/generate-test-sources-build.xml
  11. 7
      java/core/src/main/java/com/google/protobuf/ArrayDecoders.java
  12. 2
      java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
  13. 4
      java/core/src/main/java/com/google/protobuf/Internal.java
  14. 8
      java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java
  15. 2
      java/core/src/main/java/com/google/protobuf/MessageReflection.java
  16. 2
      java/core/src/main/java/com/google/protobuf/MessageSetSchema.java
  17. 9
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  18. 42
      java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java
  19. 6
      java/core/src/main/java/com/google/protobuf/Utf8.java
  20. 7
      java/core/src/test/java/com/google/protobuf/TextFormatTest.java
  21. 45
      java/kotlin/src/main/kotlin/com/google/protobuf/Anies.kt
  22. 70
      java/kotlin/src/test/kotlin/com/google/protobuf/AniesTest.kt
  23. 1
      java/lite/generate-test-sources-build.xml
  24. 2
      java/lite/pom.xml
  25. 11
      kokoro/linux/dockerfile/test/java_stretch/Dockerfile
  26. 32
      kokoro/linux/dockerfile/test/php80/Dockerfile
  27. 18
      kokoro/linux/python36/build.sh
  28. 11
      kokoro/linux/python36/continuous.cfg
  29. 11
      kokoro/linux/python36/presubmit.cfg
  30. 18
      kokoro/linux/python36_cpp/build.sh
  31. 11
      kokoro/linux/python36_cpp/continuous.cfg
  32. 11
      kokoro/linux/python36_cpp/presubmit.cfg
  33. 10
      kokoro/release/python/windows/build_artifacts.bat
  34. 6
      kokoro/release/python/windows/build_single_artifact.bat
  35. 10
      objectivec/README.md
  36. 81
      php/ext/google/protobuf/array.c
  37. 78
      php/ext/google/protobuf/map.c
  38. 36
      php/ext/google/protobuf/protobuf.h
  39. 1
      php/src/Google/Protobuf/Internal/GPBUtil.php
  40. 2
      php/src/Google/Protobuf/Internal/GPBWire.php
  41. 11
      php/src/Google/Protobuf/Internal/MapField.php
  42. 10
      php/src/Google/Protobuf/Internal/MapFieldIter.php
  43. 10
      php/src/Google/Protobuf/Internal/RepeatedField.php
  44. 6
      php/src/Google/Protobuf/Internal/RepeatedFieldIter.php
  45. 2
      python/README.md
  46. 8
      python/google/protobuf/internal/descriptor_pool_test.py
  47. 12
      python/google/protobuf/json_format.py
  48. 2
      python/google/protobuf/pyext/message.cc
  49. 3
      python/google/protobuf/pyext/unknown_fields.cc
  50. 4
      python/tox.ini
  51. 4
      src/google/protobuf/any.cc
  52. 18
      src/google/protobuf/any.pb.cc
  53. 26
      src/google/protobuf/any.pb.h
  54. 6
      src/google/protobuf/any_lite.cc
  55. 63
      src/google/protobuf/api.pb.cc
  56. 94
      src/google/protobuf/api.pb.h
  57. 42
      src/google/protobuf/arena.h
  58. 12
      src/google/protobuf/arena_unittest.cc
  59. 114
      src/google/protobuf/arenastring.cc
  60. 296
      src/google/protobuf/arenastring.h
  61. 39
      src/google/protobuf/arenastring_unittest.cc
  62. 35
      src/google/protobuf/compiler/cpp/cpp_enum_field.cc
  63. 9
      src/google/protobuf/compiler/cpp/cpp_field.cc
  64. 8
      src/google/protobuf/compiler/cpp/cpp_generator.cc
  65. 6
      src/google/protobuf/compiler/cpp/cpp_message.cc
  66. 118
      src/google/protobuf/compiler/cpp/cpp_message_field.cc
  67. 51
      src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc
  68. 43
      src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
  69. 4
      src/google/protobuf/compiler/cpp/cpp_primitive_field.h
  70. 165
      src/google/protobuf/compiler/cpp/cpp_string_field.cc
  71. 4
      src/google/protobuf/compiler/cpp/cpp_string_field.h
  72. 14
      src/google/protobuf/compiler/objectivec/objectivec_generator.cc
  73. 17
      src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
  74. 4
      src/google/protobuf/compiler/objectivec/objectivec_helpers.h
  75. 4
      src/google/protobuf/compiler/parser_unittest.cc
  76. 54
      src/google/protobuf/compiler/plugin.pb.cc
  77. 95
      src/google/protobuf/compiler/plugin.pb.h
  78. 59
      src/google/protobuf/compiler/subprocess.cc
  79. 92
      src/google/protobuf/descriptor.cc
  80. 297
      src/google/protobuf/descriptor.pb.cc
  81. 515
      src/google/protobuf/descriptor.pb.h
  82. 22
      src/google/protobuf/descriptor_unittest.cc
  83. 22
      src/google/protobuf/dynamic_message.cc
  84. 126
      src/google/protobuf/generated_message_reflection.cc
  85. 100
      src/google/protobuf/generated_message_tctable_impl.h
  86. 181
      src/google/protobuf/generated_message_tctable_lite.cc
  87. 385
      src/google/protobuf/generated_message_tctable_lite_test.cc
  88. 3
      src/google/protobuf/generated_message_util.cc
  89. 28
      src/google/protobuf/inlined_string_field.cc
  90. 301
      src/google/protobuf/inlined_string_field.h
  91. 1
      src/google/protobuf/inlined_string_field_unittest.cc
  92. 6
      src/google/protobuf/map_type_handler.h
  93. 3
      src/google/protobuf/message_lite.cc
  94. 23
      src/google/protobuf/message_unittest.inc
  95. 11
      src/google/protobuf/parse_context.cc
  96. 12
      src/google/protobuf/reflection_ops.cc
  97. 9
      src/google/protobuf/source_context.pb.cc
  98. 13
      src/google/protobuf/source_context.pb.h
  99. 6
      src/google/protobuf/struct.pb.cc
  100. 11
      src/google/protobuf/struct.pb.h
  101. Some files were not shown because too many files have changed in this diff Show More

@ -28,9 +28,7 @@ ZLIB_DEPS = ["@zlib//:zlib"]
################################################################################ ################################################################################
MSVC_COPTS = [ MSVC_COPTS = [
"/wd4018", # -Wno-sign-compare
"/wd4065", # switch statement contains 'default' but no 'case' labels "/wd4065", # switch statement contains 'default' but no 'case' labels
"/wd4146", # unary minus operator applied to unsigned type, result still unsigned
"/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
"/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
"/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
@ -48,7 +46,6 @@ COPTS = select({
":msvc": MSVC_COPTS, ":msvc": MSVC_COPTS,
"//conditions:default": [ "//conditions:default": [
"-DHAVE_ZLIB", "-DHAVE_ZLIB",
"-Wmissing-field-initializers",
"-Woverloaded-virtual", "-Woverloaded-virtual",
"-Wno-sign-compare", "-Wno-sign-compare",
], ],
@ -163,7 +160,6 @@ cc_library(
"src/google/protobuf/arenastring.cc", "src/google/protobuf/arenastring.cc",
"src/google/protobuf/extension_set.cc", "src/google/protobuf/extension_set.cc",
"src/google/protobuf/generated_enum_util.cc", "src/google/protobuf/generated_enum_util.cc",
"src/google/protobuf/generated_message_table_driven_lite.cc",
"src/google/protobuf/generated_message_tctable_lite.cc", "src/google/protobuf/generated_message_tctable_lite.cc",
"src/google/protobuf/generated_message_util.cc", "src/google/protobuf/generated_message_util.cc",
"src/google/protobuf/implicit_weak_message.cc", "src/google/protobuf/implicit_weak_message.cc",
@ -225,7 +221,6 @@ cc_library(
"src/google/protobuf/field_mask.pb.cc", "src/google/protobuf/field_mask.pb.cc",
"src/google/protobuf/generated_message_bases.cc", "src/google/protobuf/generated_message_bases.cc",
"src/google/protobuf/generated_message_reflection.cc", "src/google/protobuf/generated_message_reflection.cc",
"src/google/protobuf/generated_message_table_driven.cc",
"src/google/protobuf/generated_message_tctable_full.cc", "src/google/protobuf/generated_message_tctable_full.cc",
"src/google/protobuf/io/gzip_stream.cc", "src/google/protobuf/io/gzip_stream.cc",
"src/google/protobuf/io/printer.cc", "src/google/protobuf/io/printer.cc",
@ -501,6 +496,8 @@ cc_library(
"src/google/protobuf/compiler/plugin.cc", "src/google/protobuf/compiler/plugin.cc",
"src/google/protobuf/compiler/plugin.pb.cc", "src/google/protobuf/compiler/plugin.pb.cc",
"src/google/protobuf/compiler/python/python_generator.cc", "src/google/protobuf/compiler/python/python_generator.cc",
"src/google/protobuf/compiler/python/python_helpers.cc",
"src/google/protobuf/compiler/python/python_pyi_generator.cc",
"src/google/protobuf/compiler/ruby/ruby_generator.cc", "src/google/protobuf/compiler/ruby/ruby_generator.cc",
"src/google/protobuf/compiler/subprocess.cc", "src/google/protobuf/compiler/subprocess.cc",
"src/google/protobuf/compiler/zip_writer.cc", "src/google/protobuf/compiler/zip_writer.cc",

@ -9,6 +9,78 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
* Unknown enums for proto2 protos now properly implement proto2's behavior of * Unknown enums for proto2 protos now properly implement proto2's behavior of
putting such values in unknown fields. putting such values in unknown fields.
Java
* Don't support map fields in DynamicMessage.Builder.{getFieldBuilder,getRepeatedFieldBuilder}
* Fix parseFrom to only throw InvalidProtocolBufferException
* InvalidProtocolBufferException now allows arbitrary wrapped Exception types.
* Fix bug in `FieldSet.Builder.mergeFrom`
* Flush CodedOutputStream also flushes underlying OutputStream
* When oneof case is the same and the field type is Message, merge the
subfield. (previously it was replaced.)’
* add @CheckReturnValue to some protobuf types
* Report original exceptions when parsing JSON
* Add more info to @deprecated javadoc for set/get/has methods
* Fix initialization bug in doc comment line numbers
Kotlin
* Add orNull extensions for optional message fields in Kotlin.
Python
* Fix type annotations of some Duration and Timestamp methods.
* Repeated field containers are now generic in field types and could be used
in type annotations.
* Protobuf python generated codes are simplified. Descriptors and message
classes' definitions are now dynamic created in internal/builder.py.
Insertion Points for messages classes are discarded.
* protoc is now able to generate python stub (.pyi) by --gen_pyi
* has_presence is added for FieldDescriptor in python
* Loosen indexing type requirements to allow valid __index__() implementations
rather than only PyLongObjects.
* Fix the deepcopy bug caused by not copying message_listener.
* Added python JSON parse recursion limit (default 100)
* path info is added for python JSON parse errors
* Pure python repeated scalar fields will not able to pickle. Convert to list
first.
* Timestamp.ToDatetime() now accepts an optional tzinfo parameter. If
specified, the function returns a timezone-aware datetime in the given time
zone. If omitted or None, the function returns a timezone-naive UTC datetime
(as previously).
* Adds client_streaming and server_streaming fields to MethodDescriptor.
Compiler
* Migrate IsDefault(const std::string*) and UnsafeSetDefault(const std::string*)
* Implement strong qualified tags for TaggedPtr
* Rework allocations to power-of-two byte sizes.
* Migrate IsDefault(const std::string*) and UnsafeSetDefault(const std::string*)
* Implement strong qualified tags for TaggedPtr
* Make TaggedPtr Set...() calls explicitly spell out the content type.
* Check for parsing error before verifying UTF8.
* Enforce a maximum message nesting limit of 32 in the descriptor builder to
guard against stack overflows
* Fixed bugs in operators for RepeatedPtrIterator
* Assert a maximum map alignment for allocated values
* Fix proto1 group extension protodb parsing error
* Do not log/report the same descriptor symbol multiple times if it contains
more than one invalid character.
* Add UnknownFieldSet::SerializeToString and SerializeToCodedStream.
Arenas
* Change Repeated*Field to reuse memory when using arenas.
* Implements pbarenaz for profiling proto arenas
* Introduce CreateString() and CreateArenaString() for cleaner semantics
* Fix unreferenced parameter for MSVC builds
* Add UnsafeSetAllocated to be used for one-of string fields.
* Make Arena::AllocateAligned() a public function.
* Determine if ArenaDtor related code generation is necessary in one place.
* Implement on demand register ArenaDtor for InlinedStringField
C++
* manually *struct Cord fields to work better with arenas.
* manually destruct map fields.
* Generate narrower code
* Fix https://github.com/protocolbuffers/protobuf/issues/9378 by removing
shadowed _cached_size_ field
2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) 2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
Python Python

@ -100,3 +100,8 @@ Patch contributors:
Andrew Paprocki <andrew@ishiboo.com> Andrew Paprocki <andrew@ishiboo.com>
* Fixed minor IBM xlC compiler build issues * Fixed minor IBM xlC compiler build issues
* Added atomicops for AIX (POWER) * Added atomicops for AIX (POWER)
Nipunn Koorapati <nipunn1313@gmail.com>
* Provide a type alias field ValueType on EnumTypeWrapper
* Match service argument names to abstract interface

@ -350,7 +350,17 @@ bool ConformanceTestSuite::CheckSetEmpty(
StringAppendF(&output_, "\n"); StringAppendF(&output_, "\n");
if (!write_to_file.empty()) { if (!write_to_file.empty()) {
std::ofstream os(write_to_file); std::string full_filename;
const std::string* filename = &write_to_file;
if (!output_dir_.empty()) {
full_filename = output_dir_;
if (*output_dir_.rbegin() != '/') {
full_filename.push_back('/');
}
full_filename += write_to_file;
filename = &full_filename;
}
std::ofstream os(*filename);
if (os) { if (os) {
for (std::set<string>::const_iterator iter = set_to_check.begin(); for (std::set<string>::const_iterator iter = set_to_check.begin();
iter != set_to_check.end(); ++iter) { iter != set_to_check.end(); ++iter) {
@ -358,7 +368,7 @@ bool ConformanceTestSuite::CheckSetEmpty(
} }
} else { } else {
StringAppendF(&output_, "Failed to open file: %s\n", StringAppendF(&output_, "Failed to open file: %s\n",
write_to_file.c_str()); filename->c_str());
} }
} }

@ -174,6 +174,11 @@ class ConformanceTestSuite {
failure_list_flag_name_ = failure_list_flag_name; failure_list_flag_name_ = failure_list_flag_name;
} }
// Sets the path of the output directory.
void SetOutputDir(const char* output_dir) {
output_dir_ = output_dir;
}
// Run all the conformance tests against the given test runner. // Run all the conformance tests against the given test runner.
// Test output will be stored in "output". // Test output will be stored in "output".
// //
@ -296,6 +301,7 @@ class ConformanceTestSuite {
bool verbose_; bool verbose_;
bool enforce_recommended_; bool enforce_recommended_;
std::string output_; std::string output_;
std::string output_dir_;
std::string failure_list_flag_name_; std::string failure_list_flag_name_;
std::string failure_list_filename_; std::string failure_list_filename_;

@ -141,6 +141,9 @@ void UsageError() {
" strictly conforming to protobuf\n"); " strictly conforming to protobuf\n");
fprintf(stderr, fprintf(stderr,
" spec.\n"); " spec.\n");
fprintf(stderr,
" --output_dir <dirname> Directory to write\n"
" output files.\n");
exit(1); exit(1);
} }
@ -208,6 +211,9 @@ int ForkPipeRunner::Run(
suite->SetVerbose(true); suite->SetVerbose(true);
} else if (strcmp(argv[arg], "--enforce_recommended") == 0) { } else if (strcmp(argv[arg], "--enforce_recommended") == 0) {
suite->SetEnforceRecommended(true); suite->SetEnforceRecommended(true);
} else if (strcmp(argv[arg], "--output_dir") == 0) {
if (++arg == argc) UsageError();
suite->SetOutputDir(argv[arg]);
} else if (argv[arg][0] == '-') { } else if (argv[arg][0] == '-') {
bool recognized_flag = false; bool recognized_flag = false;
for (ConformanceTestSuite* suite : suites) { for (ConformanceTestSuite* suite : suites) {

@ -0,0 +1,104 @@
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput
Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput
Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput
Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput
Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput

@ -138,6 +138,29 @@ namespace Google.Protobuf
Assert.AreEqual(message.ToByteArray(), otherEmptyMessage.ToByteArray()); Assert.AreEqual(message.ToByteArray(), otherEmptyMessage.ToByteArray());
} }
[Test]
public void TestClone_LengthDelimited()
{
var unknownVarintField = new UnknownField();
unknownVarintField.AddVarint(99);
var unknownLengthDelimitedField1 = new UnknownField();
unknownLengthDelimitedField1.AddLengthDelimited(ByteString.CopyFromUtf8("some data"));
var unknownLengthDelimitedField2 = new UnknownField();
unknownLengthDelimitedField2.AddLengthDelimited(ByteString.CopyFromUtf8("some more data"));
var destUnknownFieldSet = new UnknownFieldSet();
destUnknownFieldSet.AddOrReplaceField(997, unknownVarintField);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField1);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField2);
var clone = UnknownFieldSet.Clone(destUnknownFieldSet);
Assert.IsTrue(clone.HasField(997));
Assert.IsTrue(clone.HasField(999));
}
[Test] [Test]
[TestCaseSource(typeof(Data), "Messages")] [TestCaseSource(typeof(Data), "Messages")]
public void TestDiscardUnknownFields(IMessage message) public void TestDiscardUnknownFields(IMessage message)

@ -27,6 +27,7 @@ LITE_SRCS = [
"src/main/java/com/google/protobuf/CodedInputStreamReader.java", "src/main/java/com/google/protobuf/CodedInputStreamReader.java",
"src/main/java/com/google/protobuf/CodedOutputStream.java", "src/main/java/com/google/protobuf/CodedOutputStream.java",
"src/main/java/com/google/protobuf/CodedOutputStreamWriter.java", "src/main/java/com/google/protobuf/CodedOutputStreamWriter.java",
"src/main/java/com/google/protobuf/CompileTimeConstant.java",
"src/main/java/com/google/protobuf/DoubleArrayList.java", "src/main/java/com/google/protobuf/DoubleArrayList.java",
"src/main/java/com/google/protobuf/ExperimentalApi.java", "src/main/java/com/google/protobuf/ExperimentalApi.java",
"src/main/java/com/google/protobuf/ExtensionLite.java", "src/main/java/com/google/protobuf/ExtensionLite.java",
@ -41,6 +42,7 @@ LITE_SRCS = [
"src/main/java/com/google/protobuf/FloatArrayList.java", "src/main/java/com/google/protobuf/FloatArrayList.java",
"src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java", "src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java",
"src/main/java/com/google/protobuf/GeneratedMessageLite.java", "src/main/java/com/google/protobuf/GeneratedMessageLite.java",
"src/main/java/com/google/protobuf/InlineMe.java",
"src/main/java/com/google/protobuf/IntArrayList.java", "src/main/java/com/google/protobuf/IntArrayList.java",
"src/main/java/com/google/protobuf/Internal.java", "src/main/java/com/google/protobuf/Internal.java",
"src/main/java/com/google/protobuf/InvalidProtocolBufferException.java", "src/main/java/com/google/protobuf/InvalidProtocolBufferException.java",

@ -4,6 +4,7 @@
<arg value="--java_out=${generated.testsources.dir}"/> <arg value="--java_out=${generated.testsources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/> <arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="--proto_path=${test.proto.dir}"/> <arg value="--proto_path=${test.proto.dir}"/>
<arg value="${protobuf.source.dir}/google/protobuf/map_lite_unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_custom_options.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/unittest_custom_options.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_enormous_descriptor.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/unittest_enormous_descriptor.proto"/>
@ -22,6 +23,7 @@
<arg value="${test.proto.dir}/com/google/protobuf/any_test.proto"/> <arg value="${test.proto.dir}/com/google/protobuf/any_test.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/cached_field_size_test.proto"/> <arg value="${test.proto.dir}/com/google/protobuf/cached_field_size_test.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/deprecated_file.proto"/> <arg value="${test.proto.dir}/com/google/protobuf/deprecated_file.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/dynamic_message_test.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/field_presence_test.proto"/> <arg value="${test.proto.dir}/com/google/protobuf/field_presence_test.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/lazy_fields_lite.proto"/> <arg value="${test.proto.dir}/com/google/protobuf/lazy_fields_lite.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/lite_equals_and_hash.proto"/> <arg value="${test.proto.dir}/com/google/protobuf/lite_equals_and_hash.proto"/>

@ -45,14 +45,15 @@ import java.io.IOException;
*/ */
@CheckReturnValue @CheckReturnValue
final class ArrayDecoders { final class ArrayDecoders {
private ArrayDecoders() {
}
/** /**
* A helper used to return multiple values in a Java function. Java doesn't natively support * A helper used to return multiple values in a Java function. Java doesn't natively support
* returning multiple values in a function. Creating a new Object to hold the return values will * returning multiple values in a function. Creating a new Object to hold the return values will
* be too expensive. Instead, we pass a Registers instance to functions that want to return * be too expensive. Instead, we pass a Registers instance to functions that want to return
* multiple values and let the function set the return value in this Registers instance instead. * multiple values and let the function set the return value in this Registers instance instead.
*
* <p>TODO(xiaofeng): This could be merged into CodedInputStream or CodedInputStreamReader which
* is already being passed through all the parsing routines.
*/ */
static final class Registers { static final class Registers {
public int int1; public int int1;

@ -692,7 +692,7 @@ public abstract class GeneratedMessageLite<
// The wire format for MessageSet is: // The wire format for MessageSet is:
// message MessageSet { // message MessageSet {
// repeated group Item = 1 { // repeated group Item = 1 {
// required int32 typeId = 2; // required uint32 typeId = 2;
// required bytes message = 3; // required bytes message = 3;
// } // }
// } // }

@ -259,7 +259,9 @@ public final class Internal {
/** Helper method for implementing {@link Message#equals(Object)} for bytes field. */ /** Helper method for implementing {@link Message#equals(Object)} for bytes field. */
public static boolean equals(List<byte[]> a, List<byte[]> b) { public static boolean equals(List<byte[]> a, List<byte[]> b) {
if (a.size() != b.size()) return false; if (a.size() != b.size()) {
return false;
}
for (int i = 0; i < a.size(); ++i) { for (int i = 0; i < a.size(); ++i) {
if (!Arrays.equals(a.get(i), b.get(i))) { if (!Arrays.equals(a.get(i), b.get(i))) {
return false; return false;

@ -55,6 +55,14 @@ public class InvalidProtocolBufferException extends IOException {
super(description, e); super(description, e);
} }
public InvalidProtocolBufferException(IOException e) {
super(e.getMessage(), e);
}
public InvalidProtocolBufferException(String description, IOException e) {
super(description, e);
}
/** /**
* Attaches an unfinished message to the exception to support best-effort parsing in {@code * Attaches an unfinished message to the exception to support best-effort parsing in {@code
* Parser} interface. * Parser} interface.

@ -882,7 +882,7 @@ class MessageReflection {
// The wire format for MessageSet is: // The wire format for MessageSet is:
// message MessageSet { // message MessageSet {
// repeated group Item = 1 { // repeated group Item = 1 {
// required int32 typeId = 2; // required uint32 typeId = 2;
// required bytes message = 3; // required bytes message = 3;
// } // }
// } // }

@ -300,7 +300,7 @@ final class MessageSetSchema<T> implements Schema<T> {
// The wire format for MessageSet is: // The wire format for MessageSet is:
// message MessageSet { // message MessageSet {
// repeated group Item = 1 { // repeated group Item = 1 {
// required int32 typeId = 2; // required uint32 typeId = 2;
// required bytes message = 3; // required bytes message = 3;
// } // }
// } // }

@ -51,7 +51,7 @@ import java.util.regex.Pattern;
/** /**
* Provide text parsing and formatting support for proto2 instances. The implementation largely * Provide text parsing and formatting support for proto2 instances. The implementation largely
* follows google/protobuf/text_format.cc. * follows text_format.cc.
* *
* @author wenboz@google.com Wenbo Zhu * @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda * @author kenton@google.com Kenton Varda
@ -2309,7 +2309,7 @@ public final class TextFormat {
* Un-escape a byte sequence as escaped using {@link #escapeBytes(ByteString)}. Two-digit hex * Un-escape a byte sequence as escaped using {@link #escapeBytes(ByteString)}. Two-digit hex
* escapes (starting with "\x") are also recognized. * escapes (starting with "\x") are also recognized.
*/ */
public static ByteString unescapeBytes(final CharSequence charString) public static ByteString unescapeBytes(CharSequence charString)
throws InvalidEscapeSequenceException { throws InvalidEscapeSequenceException {
// First convert the Java character sequence to UTF-8 bytes. // First convert the Java character sequence to UTF-8 bytes.
ByteString input = ByteString.copyFromUtf8(charString.toString()); ByteString input = ByteString.copyFromUtf8(charString.toString());
@ -2445,9 +2445,10 @@ public final class TextFormat {
+ "' is not a valid code point value"); + "' is not a valid code point value");
} }
Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(codepoint); Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(codepoint);
if (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES) if (unicodeBlock != null
&& (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES)
|| unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES) || unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES)
|| unicodeBlock.equals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES)) { || unicodeBlock.equals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES))) {
throw new InvalidEscapeSequenceException( throw new InvalidEscapeSequenceException(
"Invalid escape sequence: '\\U" "Invalid escape sequence: '\\U"
+ input.substring(i, i + 8).toStringUtf8() + input.substring(i, i + 8).toStringUtf8()

@ -30,7 +30,24 @@
package com.google.protobuf; package com.google.protobuf;
/** Provide text format escaping support for proto2 instances. */ /**
* Provide text format escaping of proto instances. These ASCII characters are escaped:
*
* ASCII #7 (bell) --> \a
* ASCII #8 (backspace) --> \b
* ASCII #9 (horizontal tab) --> \t
* ASCII #10 (linefeed) --> \n
* ASCII #11 (vertical tab) --> \v
* ASCII #13 (carriage return) --> \r
* ASCII #12 (formfeed) --> \f
* ASCII #34 (apostrophe) --> \'
* ASCII #39 (straight double quote) --> \"
* ASCII #92 (backslash) --> \\
*
* Other printable ASCII characters between 32 and 127 inclusive are output as is, unescaped.
* Other ASCII characters less than 32 and all Unicode characters 128 or greater are
* first encoded as UTF-8, then each byte is escaped individually as a 3-digit octal escape.
*/
final class TextFormatEscaper { final class TextFormatEscaper {
private TextFormatEscaper() {} private TextFormatEscaper() {}
@ -41,17 +58,13 @@ final class TextFormatEscaper {
} }
/** /**
* Escapes bytes in the format used in protocol buffer text format, which is the same as the * Backslash escapes bytes in the format used in protocol buffer text format.
* format used for C string literals. All bytes that are not printable 7-bit ASCII characters are
* escaped, as well as backslash, single-quote, and double-quote characters. Characters for which
* no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences.
*/ */
static String escapeBytes(final ByteSequence input) { static String escapeBytes(ByteSequence input) {
final StringBuilder builder = new StringBuilder(input.size()); final StringBuilder builder = new StringBuilder(input.size());
for (int i = 0; i < input.size(); i++) { for (int i = 0; i < input.size(); i++) {
final byte b = input.byteAt(i); byte b = input.byteAt(i);
switch (b) { switch (b) {
// Java does not recognize \a or \v, apparently.
case 0x07: case 0x07:
builder.append("\\a"); builder.append("\\a");
break; break;
@ -100,10 +113,7 @@ final class TextFormatEscaper {
} }
/** /**
* Escapes bytes in the format used in protocol buffer text format, which is the same as the * Backslash escapes bytes in the format used in protocol buffer text format.
* format used for C string literals. All bytes that are not printable 7-bit ASCII characters are
* escaped, as well as backslash, single-quote, and double-quote characters. Characters for which
* no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences.
*/ */
static String escapeBytes(final ByteString input) { static String escapeBytes(final ByteString input) {
return escapeBytes( return escapeBytes(
@ -137,16 +147,14 @@ final class TextFormatEscaper {
} }
/** /**
* Like {@link #escapeBytes(ByteString)}, but escapes a text string. Non-ASCII characters are * Like {@link #escapeBytes(ByteString)}, but escapes a text string.
* first encoded as UTF-8, then each byte is escaped individually as a 3-digit octal escape. Yes,
* it's weird.
*/ */
static String escapeText(final String input) { static String escapeText(String input) {
return escapeBytes(ByteString.copyFromUtf8(input)); return escapeBytes(ByteString.copyFromUtf8(input));
} }
/** Escape double quotes and backslashes in a String for unicode output of a message. */ /** Escape double quotes and backslashes in a String for unicode output of a message. */
static String escapeDoubleQuotesAndBackslashes(final String input) { static String escapeDoubleQuotesAndBackslashes(String input) {
return input.replace("\\", "\\\\").replace("\"", "\\\""); return input.replace("\\", "\\\\").replace("\"", "\\\"");
} }
} }

@ -64,9 +64,9 @@ import java.nio.ByteBuffer;
* <em>Well Formed UTF-8 Byte Sequences</em>. * <em>Well Formed UTF-8 Byte Sequences</em>.
* *
* <p>This class supports decoding of partial byte sequences, so that the bytes in a complete UTF-8 * <p>This class supports decoding of partial byte sequences, so that the bytes in a complete UTF-8
* byte sequences can be stored in multiple segments. Methods typically return {@link #MALFORMED} if * byte sequence can be stored in multiple segments. Methods typically return {@link #MALFORMED} if
* the partial byte sequence is definitely not well-formed, {@link #COMPLETE} if it is well-formed * the partial byte sequence is definitely not well-formed; {@link #COMPLETE} if it is well-formed
* in the absence of additional input, or if the byte sequence apparently terminated in the middle * in the absence of additional input; or, if the byte sequence apparently terminated in the middle
* of a character, an opaque integer "state" value containing enough information to decode the * of a character, an opaque integer "state" value containing enough information to decode the
* character when passed to a subsequent invocation of a partial decoding method. * character when passed to a subsequent invocation of a partial decoding method.
* *

@ -170,6 +170,13 @@ public class TextFormatTest {
assertThat(javaText).isEqualTo(ALL_FIELDS_SET_TEXT); assertThat(javaText).isEqualTo(ALL_FIELDS_SET_TEXT);
} }
@Test
// https://github.com/protocolbuffers/protobuf/issues/9447
public void testCharacterNotInUnicodeBlock() throws TextFormat.InvalidEscapeSequenceException {
ByteString actual = TextFormat.unescapeBytes("\\U000358da");
assertThat(actual.size()).isEqualTo(4);
}
/** Print TestAllTypes as Builder and compare with golden file. */ /** Print TestAllTypes as Builder and compare with golden file. */
@Test @Test
public void testPrintMessageBuilder() throws Exception { public void testPrintMessageBuilder() throws Exception {

@ -0,0 +1,45 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf.kotlin
import com.google.protobuf.Any as ProtoAny
import com.google.protobuf.Message
/** Returns `true` if this [com.google.protobuf.Any] contains a message of type `T`. */
inline fun <reified T : Message> ProtoAny.isA(): Boolean = this.`is`(T::class.java)
/**
* Returns the message of type `T` encoded in this [com.google.protobuf.Any].
*
* @throws InvalidProtocolBufferException if this [com.google.protobuf.Any] does not contain a `T`
* message.
*/
inline fun <reified T : Message> ProtoAny.unpack(): T = unpack(T::class.java)

@ -0,0 +1,70 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf.kotlin
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.Any as ProtoAny
import com.google.protobuf.InvalidProtocolBufferException
import protobuf_unittest.UnittestProto.BoolMessage
import protobuf_unittest.UnittestProto.Int32Message
import protobuf_unittest.int32Message
import kotlin.test.assertFailsWith
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
/** Tests for extension methods on [ProtoAny]. */
@RunWith(JUnit4::class)
class AniesTest {
companion object {
val anAny = ProtoAny.pack(int32Message { data = 5 })
}
@Test
fun isA_Positive() {
assertThat(anAny.isA<Int32Message>()).isTrue()
}
@Test
fun isA_Negative() {
assertThat(anAny.isA<BoolMessage>()).isFalse()
}
@Test
fun unpackValid() {
assertThat(anAny.unpack<Int32Message>().data).isEqualTo(5)
}
@Test
fun unpackInvalid() {
assertFailsWith<InvalidProtocolBufferException> { anAny.unpack<BoolMessage>() }
}
}

@ -5,6 +5,7 @@
<arg value="--proto_path=${protobuf.source.dir}"/> <arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="--proto_path=${protobuf.basedir}/java/core/${test.proto.dir}"/> <arg value="--proto_path=${protobuf.basedir}/java/core/${test.proto.dir}"/>
<arg value="${protobuf.source.dir}/google/protobuf/descriptor.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/descriptor.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/map_lite_unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/unittest_import.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_lite.proto"/> <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_lite.proto"/>

@ -105,6 +105,7 @@
<include>CodedInputStreamReader.java</include> <include>CodedInputStreamReader.java</include>
<include>CodedOutputStream.java</include> <include>CodedOutputStream.java</include>
<include>CodedOutputStreamWriter.java</include> <include>CodedOutputStreamWriter.java</include>
<include>CompileTimeConstant.java</include>
<include>DoubleArrayList.java</include> <include>DoubleArrayList.java</include>
<include>ExperimentalApi.java</include> <include>ExperimentalApi.java</include>
<include>ExtensionLite.java</include> <include>ExtensionLite.java</include>
@ -119,6 +120,7 @@
<include>FloatArrayList.java</include> <include>FloatArrayList.java</include>
<include>GeneratedMessageInfoFactory.java</include> <include>GeneratedMessageInfoFactory.java</include>
<include>GeneratedMessageLite.java</include> <include>GeneratedMessageLite.java</include>
<include>InlineMe.java</include>
<include>IntArrayList.java</include> <include>IntArrayList.java</include>
<include>Internal.java</include> <include>Internal.java</include>
<include>InvalidProtocolBufferException.java</include> <include>InvalidProtocolBufferException.java</include>

@ -1,4 +1,7 @@
FROM debian:stretch # Despite the name of this image, we are no longer on stretch.
# We should consider renaming this image, and/or evaluating what
# software versions we actually need.
FROM debian:bullseye
# Install dependencies. We start with the basic ones required to build protoc # Install dependencies. We start with the basic ones required to build protoc
# and the C++ build # and the C++ build
@ -22,9 +25,11 @@ RUN apt-get update && apt-get install -y \
wget \ wget \
# Java dependencies # Java dependencies
maven \ maven \
openjdk-8-jdk \ openjdk-11-jdk \
# Required for the gtest build.
python2 \
# Python dependencies # Python dependencies
python3-setuptools \ python3-setuptools \
python3-pip \ python3-pip \
virtualenv \ python3-venv \
&& apt-get clean && apt-get clean

@ -1,4 +1,4 @@
FROM debian:jessie FROM debian:stretch
# Install dependencies. We start with the basic ones require to build protoc # Install dependencies. We start with the basic ones require to build protoc
# and the C++ build # and the C++ build
@ -29,7 +29,7 @@ RUN apt-get update && apt-get install -y \
# Install php dependencies # Install php dependencies
RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ RUN apt-get clean && apt-get update && apt-get install -y --force-yes \
php5 \ php \
libcurl4-openssl-dev \ libcurl4-openssl-dev \
libgmp-dev \ libgmp-dev \
libgmp3-dev \ libgmp3-dev \
@ -90,6 +90,34 @@ RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar \
&& cp phpunit /usr/local/php-8.0/bin \ && cp phpunit /usr/local/php-8.0/bin \
&& mv phpunit /usr/local/php-8.0-zts/bin && mv phpunit /usr/local/php-8.0-zts/bin
# php 8.1
RUN cd php-src \
&& git checkout php-8.1.2 \
&& ./buildconf --force
RUN cd php-src \
&& ./configure \
--enable-bcmath \
--enable-mbstring \
--with-gmp \
--with-openssl \
--with-zlib \
--prefix=/usr/local/php-8.1 \
&& make \
&& make install \
&& make clean
RUN cd php-src \
&& ./configure \
--enable-bcmath \
--enable-mbstring \
--enable-maintainer-zts \
--with-gmp \
--with-openssl \
--with-zlib \
--prefix=/usr/local/php-8.1-zts \
&& make \
&& make install \
&& make clean
# Install php dependencies # Install php dependencies
RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ RUN apt-get clean && apt-get update && apt-get install -y --force-yes \
valgrind \ valgrind \

@ -1,18 +0,0 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.
# Change to repo root
cd $(dirname $0)/../../..
export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="python36"
./kokoro/linux/build_and_run_docker.sh

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,18 +0,0 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.
# Change to repo root
cd $(dirname $0)/../../..
export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="python36_cpp"
./kokoro/linux/build_and_run_docker.sh

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36_cpp/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36_cpp/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -40,16 +40,6 @@ mkdir %ARTIFACT_DIR%
REM Build wheel REM Build wheel
SET PYTHON=C:\python36_32bit
SET PYTHON_VERSION=3.6
SET PYTHON_ARCH=32
CALL build_single_artifact.bat || goto :error
SET PYTHON=C:\python36
SET PYTHON_VERSION=3.6
SET PYTHON_ARCH=64
CALL build_single_artifact.bat || goto :error
SET PYTHON=C:\python37_32bit SET PYTHON=C:\python37_32bit
SET PYTHON_VERSION=3.7 SET PYTHON_VERSION=3.7
SET PYTHON_ARCH=32 SET PYTHON_ARCH=32

@ -1,11 +1,5 @@
setlocal setlocal
if %PYTHON%==C:\python36_32bit set generator=Visual Studio 14
if %PYTHON%==C:\python36_32bit set vcplatform=Win32
if %PYTHON%==C:\python36 set generator=Visual Studio 14 Win64
if %PYTHON%==C:\python36 set vcplatform=x64
if %PYTHON%==C:\python37_32bit set generator=Visual Studio 14 if %PYTHON%==C:\python37_32bit set generator=Visual Studio 14
if %PYTHON%==C:\python37_32bit set vcplatform=Win32 if %PYTHON%==C:\python37_32bit set vcplatform=Win32

@ -133,8 +133,8 @@ This options allow you to provide a custom prefix for all the symbols generated
from a proto file (classes (from message), enums, the Root for extension from a proto file (classes (from message), enums, the Root for extension
support). support).
If not set, the generation option `use_package_as_prefix` (documented below) If not set, the generation options `default_objc_class_prefix` and `use_package_as_prefix`
controls what is used instead. Since Objective C uses a global namespace for all (documented below) control what is used instead. Since Objective C uses a global namespace for all
of its classes, there can be collisions. `use_package_as_prefix=yes` should of its classes, there can be collisions. `use_package_as_prefix=yes` should
avoid collisions since proto package are used to scope/name things in other avoid collisions since proto package are used to scope/name things in other
languages, but this option can be used to get shorter names instead. Convention languages, but this option can be used to get shorter names instead. Convention
@ -182,6 +182,12 @@ supported keys are:
having to add the runtime directory to the header search path since the having to add the runtime directory to the header search path since the
generate `#import` will be more complete. generate `#import` will be more complete.
* `default_objc_class_prefix`: The default ObjC prefix value to use when
generating sources. The generator will use this if the `objc_class_prefix`
file option is not set. This option can be useful if multiple iOS apps
consume the same proto file but wish to use a different prefix for their
generated sources.
* `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The * `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The
`value` for `use_package_as_prefix` can be `yes` or `no`, and indicates `value` for `use_package_as_prefix` can be `yes` or `no`, and indicates
if a prefix should be derived from the proto package for all the symbols if a prefix should be derived from the proto package for all the symbols

@ -287,7 +287,7 @@ PHP_METHOD(RepeatedField, append) {
} }
/** /**
* RepeatedField::offsetExists() * RepeatedField::offsetExists(): bool
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -309,7 +309,7 @@ PHP_METHOD(RepeatedField, offsetExists) {
} }
/** /**
* RepeatedField::offsetGet() * RepeatedField::offsetGet(): mixed
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -341,7 +341,7 @@ PHP_METHOD(RepeatedField, offsetGet) {
} }
/** /**
* RepeatedField::offsetSet() * RepeatedField::offsetSet(): void
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -386,7 +386,7 @@ PHP_METHOD(RepeatedField, offsetSet) {
} }
/** /**
* RepeatedField::offsetUnset() * RepeatedField::offsetUnset(): void
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -416,7 +416,7 @@ PHP_METHOD(RepeatedField, offsetUnset) {
} }
/** /**
* RepeatedField::count() * RepeatedField::count(): int
* *
* Implements the Countable interface. Invoked when PHP code calls: * Implements the Countable interface. Invoked when PHP code calls:
* *
@ -436,7 +436,7 @@ PHP_METHOD(RepeatedField, count) {
} }
/** /**
* RepeatedField::getIterator() * RepeatedField::getIterator(): Traversable
* *
* Implements the IteratorAggregate interface. Invoked when PHP code calls: * Implements the IteratorAggregate interface. Invoked when PHP code calls:
* *
@ -459,24 +459,38 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1)
ZEND_ARG_INFO(0, newval) ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0)
ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval) ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0)
ZEND_END_ARG_INFO()
static zend_function_entry repeated_field_methods[] = { static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, count, arginfo_count, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC)
ZEND_FE_END ZEND_FE_END
}; };
@ -550,7 +564,7 @@ static void RepeatedFieldIter_make(zval *val, zval *repeated_field) {
*/ */
/** /**
* RepeatedFieldIter::rewind() * RepeatedFieldIter::rewind(): void
* *
* Implements the Iterator interface. Sets the iterator to the first element. * Implements the Iterator interface. Sets the iterator to the first element.
*/ */
@ -560,7 +574,7 @@ PHP_METHOD(RepeatedFieldIter, rewind) {
} }
/** /**
* RepeatedFieldIter::current() * RepeatedFieldIter::current(): mixed
* *
* Implements the Iterator interface. Returns the current value. * Implements the Iterator interface. Returns the current value.
*/ */
@ -583,7 +597,7 @@ PHP_METHOD(RepeatedFieldIter, current) {
} }
/** /**
* RepeatedFieldIter::key() * RepeatedFieldIter::key(): mixed
* *
* Implements the Iterator interface. Returns the current key. * Implements the Iterator interface. Returns the current key.
*/ */
@ -593,7 +607,7 @@ PHP_METHOD(RepeatedFieldIter, key) {
} }
/** /**
* RepeatedFieldIter::next() * RepeatedFieldIter::next(): void
* *
* Implements the Iterator interface. Advances to the next element. * Implements the Iterator interface. Advances to the next element.
*/ */
@ -603,7 +617,7 @@ PHP_METHOD(RepeatedFieldIter, next) {
} }
/** /**
* RepeatedFieldIter::valid() * RepeatedFieldIter::valid(): bool
* *
* Implements the Iterator interface. Returns true if this is a valid element. * Implements the Iterator interface. Returns true if this is a valid element.
*/ */
@ -613,12 +627,27 @@ PHP_METHOD(RepeatedFieldIter, valid) {
RETURN_BOOL(intern->position < upb_array_size(field->array)); RETURN_BOOL(intern->position < upb_array_size(field->array));
} }
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
static zend_function_entry repeated_field_iter_methods[] = { static zend_function_entry repeated_field_iter_methods[] = {
PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC)
ZEND_FE_END ZEND_FE_END
}; };

@ -305,7 +305,7 @@ PHP_METHOD(MapField, __construct) {
} }
/** /**
* MapField::offsetExists() * MapField::offsetExists(): bool
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -329,7 +329,7 @@ PHP_METHOD(MapField, offsetExists) {
} }
/** /**
* MapField::offsetGet() * MapField::offsetGet(): mixed
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -361,7 +361,7 @@ PHP_METHOD(MapField, offsetGet) {
} }
/** /**
* MapField::offsetSet() * MapField::offsetSet(): void
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -389,7 +389,7 @@ PHP_METHOD(MapField, offsetSet) {
} }
/** /**
* MapField::offsetUnset() * MapField::offsetUnset(): void
* *
* Implements the ArrayAccess interface. Invoked when PHP code calls: * Implements the ArrayAccess interface. Invoked when PHP code calls:
* *
@ -413,7 +413,7 @@ PHP_METHOD(MapField, offsetUnset) {
} }
/** /**
* MapField::count() * MapField::count(): int
* *
* Implements the Countable interface. Invoked when PHP code calls: * Implements the Countable interface. Invoked when PHP code calls:
* *
@ -433,7 +433,7 @@ PHP_METHOD(MapField, count) {
} }
/** /**
* MapField::getIterator() * MapField::getIterator(): Traversable
* *
* Implements the IteratorAggregate interface. Invoked when PHP code calls: * Implements the IteratorAggregate interface. Invoked when PHP code calls:
* *
@ -453,23 +453,38 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 2)
ZEND_ARG_INFO(0, value_class) ZEND_ARG_INFO(0, value_class)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1)
ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval) ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
static zend_function_entry MapField_methods[] = { static zend_function_entry MapField_methods[] = {
PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(MapField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(MapField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC)
PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapField, count, arginfo_count, ZEND_ACC_PUBLIC)
PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC)
ZEND_FE_END ZEND_FE_END
}; };
@ -547,7 +562,7 @@ static void MapFieldIter_make(zval *val, zval *map_field) {
*/ */
/** /**
* MapFieldIter::rewind() * MapFieldIter::rewind(): void
* *
* Implements the Iterator interface. Sets the iterator to the first element. * Implements the Iterator interface. Sets the iterator to the first element.
*/ */
@ -559,7 +574,7 @@ PHP_METHOD(MapFieldIter, rewind) {
} }
/** /**
* MapFieldIter::current() * MapFieldIter::current(): mixed
* *
* Implements the Iterator interface. Returns the current value. * Implements the Iterator interface. Returns the current value.
*/ */
@ -587,7 +602,7 @@ PHP_METHOD(MapFieldIter, key) {
} }
/** /**
* MapFieldIter::next() * MapFieldIter::next(): void
* *
* Implements the Iterator interface. Advances to the next element. * Implements the Iterator interface. Advances to the next element.
*/ */
@ -598,7 +613,7 @@ PHP_METHOD(MapFieldIter, next) {
} }
/** /**
* MapFieldIter::valid() * MapFieldIter::valid(): bool
* *
* Implements the Iterator interface. Returns true if this is a valid element. * Implements the Iterator interface. Returns true if this is a valid element.
*/ */
@ -609,12 +624,27 @@ PHP_METHOD(MapFieldIter, valid) {
RETURN_BOOL(!done); RETURN_BOOL(!done);
} }
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
static zend_function_entry map_field_iter_methods[] = { static zend_function_entry map_field_iter_methods[] = {
PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC)
ZEND_FE_END ZEND_FE_END
}; };

@ -82,6 +82,42 @@ const zval *get_generated_pool();
// PHP 7.2.0. // PHP 7.2.0.
#if PHP_VERSION_ID < 70200 #if PHP_VERSION_ID < 70200
#define zend_ce_countable spl_ce_Countable #define zend_ce_countable spl_ce_Countable
#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null)
#endif
// polyfill for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX, which changes between 7.1 and 7.2
#if PHP_VERSION_ID < 70200
#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, /*class_name*/ 0, allow_null)
#else
#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null)
#endif
// In PHP 8.1, mismatched tentative return types emit a deprecation notice.
// https://wiki.php.net/rfc/internal_method_return_types
//
// When compiling for earlier php versions, the return type is dropped.
#if PHP_VERSION_ID < 80100
#define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null)
#endif
#ifndef IS_VOID
#define IS_VOID 99
#endif
#ifndef IS_MIXED
#define IS_MIXED 99
#endif
#ifndef _IS_BOOL
#define _IS_BOOL 99
#endif
#ifndef IS_LONG
#define IS_LONG 99
#endif #endif
ZEND_BEGIN_ARG_INFO(arginfo_void, 0) ZEND_BEGIN_ARG_INFO(arginfo_void, 0)

@ -37,6 +37,7 @@ use Google\Protobuf\FieldMask;
use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\MapField; use Google\Protobuf\Internal\MapField;
use function bccomp;
function camel2underscore($input) { function camel2underscore($input) {
preg_match_all( preg_match_all(

@ -146,7 +146,7 @@ class GPBWire
return bcsub(bcmul(bcsub(0, $int64), 2), 1); return bcsub(bcmul(bcsub(0, $int64), 2), 1);
} }
} else { } else {
return ($int64 << 1) ^ ($int64 >> 63); return ((int)$int64 << 1) ^ ((int)$int64 >> 63);
} }
} }

@ -37,6 +37,8 @@
namespace Google\Protobuf\Internal; namespace Google\Protobuf\Internal;
use Traversable;
/** /**
* MapField is used by generated protocol message classes to manipulate map * MapField is used by generated protocol message classes to manipulate map
* fields. It can be used like native PHP array. * fields. It can be used like native PHP array.
@ -134,6 +136,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
* @throws \ErrorException Invalid type for index. * @throws \ErrorException Invalid type for index.
* @throws \ErrorException Non-existing index. * @throws \ErrorException Non-existing index.
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($key) public function offsetGet($key)
{ {
return $this->container[$key]; return $this->container[$key];
@ -151,6 +154,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
* @throws \ErrorException Invalid type for value. * @throws \ErrorException Invalid type for value.
* @throws \ErrorException Non-existing key. * @throws \ErrorException Non-existing key.
*/ */
#[\ReturnTypeWillChange]
public function offsetSet($key, $value) public function offsetSet($key, $value)
{ {
$this->checkKey($this->key_type, $key); $this->checkKey($this->key_type, $key);
@ -209,6 +213,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
* @return void * @return void
* @throws \ErrorException Invalid type for key. * @throws \ErrorException Invalid type for key.
*/ */
#[\ReturnTypeWillChange]
public function offsetUnset($key) public function offsetUnset($key)
{ {
$this->checkKey($this->key_type, $key); $this->checkKey($this->key_type, $key);
@ -224,7 +229,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
* @return bool True if the element at the given key exists. * @return bool True if the element at the given key exists.
* @throws \ErrorException Invalid type for key. * @throws \ErrorException Invalid type for key.
*/ */
public function offsetExists($key) public function offsetExists($key): bool
{ {
$this->checkKey($this->key_type, $key); $this->checkKey($this->key_type, $key);
return isset($this->container[$key]); return isset($this->container[$key]);
@ -233,7 +238,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
/** /**
* @ignore * @ignore
*/ */
public function getIterator() public function getIterator(): Traversable
{ {
return new MapFieldIter($this->container, $this->key_type); return new MapFieldIter($this->container, $this->key_type);
} }
@ -245,7 +250,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
* *
* @return integer The number of stored elements. * @return integer The number of stored elements.
*/ */
public function count() public function count(): int
{ {
return count($this->container); return count($this->container);
} }

@ -68,9 +68,10 @@ class MapFieldIter implements \Iterator
* *
* @return void * @return void
*/ */
#[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
return reset($this->container); reset($this->container);
} }
/** /**
@ -78,6 +79,7 @@ class MapFieldIter implements \Iterator
* *
* @return object The element at the current position. * @return object The element at the current position.
*/ */
#[\ReturnTypeWillChange]
public function current() public function current()
{ {
return current($this->container); return current($this->container);
@ -88,6 +90,7 @@ class MapFieldIter implements \Iterator
* *
* @return object The current key. * @return object The current key.
*/ */
#[\ReturnTypeWillChange]
public function key() public function key()
{ {
$key = key($this->container); $key = key($this->container);
@ -117,9 +120,10 @@ class MapFieldIter implements \Iterator
* *
* @return void * @return void
*/ */
#[\ReturnTypeWillChange]
public function next() public function next()
{ {
return next($this->container); next($this->container);
} }
/** /**
@ -127,7 +131,7 @@ class MapFieldIter implements \Iterator
* *
* @return bool True if there are more elements to iterate. * @return bool True if there are more elements to iterate.
*/ */
public function valid() public function valid(): bool
{ {
return key($this->container) !== null; return key($this->container) !== null;
} }

@ -39,6 +39,7 @@ namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBUtil; use Google\Protobuf\Internal\GPBUtil;
use Traversable;
/** /**
* RepeatedField is used by generated protocol message classes to manipulate * RepeatedField is used by generated protocol message classes to manipulate
@ -121,6 +122,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
* @throws \ErrorException Invalid type for index. * @throws \ErrorException Invalid type for index.
* @throws \ErrorException Non-existing index. * @throws \ErrorException Non-existing index.
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($offset) public function offsetGet($offset)
{ {
return $this->container[$offset]; return $this->container[$offset];
@ -138,6 +140,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
* @throws \ErrorException Non-existing index. * @throws \ErrorException Non-existing index.
* @throws \ErrorException Incorrect type of the element. * @throws \ErrorException Incorrect type of the element.
*/ */
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value) public function offsetSet($offset, $value)
{ {
switch ($this->type) { switch ($this->type) {
@ -209,6 +212,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
* @throws \ErrorException The element to be removed is not at the end of the * @throws \ErrorException The element to be removed is not at the end of the
* RepeatedField. * RepeatedField.
*/ */
#[\ReturnTypeWillChange]
public function offsetUnset($offset) public function offsetUnset($offset)
{ {
$count = count($this->container); $count = count($this->container);
@ -230,7 +234,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
* @return bool True if the element at the given offset exists. * @return bool True if the element at the given offset exists.
* @throws \ErrorException Invalid type for index. * @throws \ErrorException Invalid type for index.
*/ */
public function offsetExists($offset) public function offsetExists($offset): bool
{ {
return isset($this->container[$offset]); return isset($this->container[$offset]);
} }
@ -238,7 +242,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
/** /**
* @ignore * @ignore
*/ */
public function getIterator() public function getIterator(): Traversable
{ {
return new RepeatedFieldIter($this->container); return new RepeatedFieldIter($this->container);
} }
@ -250,7 +254,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
* *
* @return integer The number of stored elements. * @return integer The number of stored elements.
*/ */
public function count() public function count(): int
{ {
return count($this->container); return count($this->container);
} }

@ -71,6 +71,7 @@ class RepeatedFieldIter implements \Iterator
* *
* @return void * @return void
*/ */
#[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
$this->position = 0; $this->position = 0;
@ -81,6 +82,7 @@ class RepeatedFieldIter implements \Iterator
* *
* @return object The element at the current position. * @return object The element at the current position.
*/ */
#[\ReturnTypeWillChange]
public function current() public function current()
{ {
return $this->container[$this->position]; return $this->container[$this->position];
@ -91,6 +93,7 @@ class RepeatedFieldIter implements \Iterator
* *
* @return integer The current position. * @return integer The current position.
*/ */
#[\ReturnTypeWillChange]
public function key() public function key()
{ {
return $this->position; return $this->position;
@ -101,6 +104,7 @@ class RepeatedFieldIter implements \Iterator
* *
* @return void * @return void
*/ */
#[\ReturnTypeWillChange]
public function next() public function next()
{ {
++$this->position; ++$this->position;
@ -111,7 +115,7 @@ class RepeatedFieldIter implements \Iterator
* *
* @return bool True if there are more elements to iterate. * @return bool True if there are more elements to iterate.
*/ */
public function valid() public function valid(): bool
{ {
return isset($this->container[$this->position]); return isset($this->container[$this->position]);
} }

@ -26,7 +26,7 @@ use python c++ implementation.
Installation Installation
============ ============
1) Make sure you have Python 3.5 or newer. If in doubt, run: 1) Make sure you have Python 3.7 or newer. If in doubt, run:
$ python -V $ python -V

@ -541,7 +541,13 @@ class DescriptorPoolTestBase(object):
pool._AddExtensionDescriptor( pool._AddExtensionDescriptor(
file_descriptor.extensions_by_name['optional_int32_extension']) file_descriptor.extensions_by_name['optional_int32_extension'])
pool.Add(unittest_fd) pool.Add(unittest_fd)
pool.Add(conflict_fd) with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
pool.Add(conflict_fd)
self.assertTrue(len(w))
self.assertIs(w[0].category, RuntimeWarning)
self.assertIn('Conflict register for file "other_file": ',
str(w[0].message))
pool.FindFileByName(unittest_fd.name) pool.FindFileByName(unittest_fd.name)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pool.FindFileByName(conflict_fd.name) pool.FindFileByName(conflict_fd.name)

@ -95,7 +95,8 @@ def MessageToJson(
sort_keys=False, sort_keys=False,
use_integers_for_enums=False, use_integers_for_enums=False,
descriptor_pool=None, descriptor_pool=None,
float_precision=None): float_precision=None,
ensure_ascii=True):
"""Converts protobuf message to JSON format. """Converts protobuf message to JSON format.
Args: Args:
@ -114,6 +115,8 @@ def MessageToJson(
descriptor_pool: A Descriptor Pool for resolving types. If None use the descriptor_pool: A Descriptor Pool for resolving types. If None use the
default. default.
float_precision: If set, use this to specify float field valid digits. float_precision: If set, use this to specify float field valid digits.
ensure_ascii: If True, strings with non-ASCII characters are escaped.
If False, Unicode strings are returned unchanged.
Returns: Returns:
A string containing the JSON formatted protocol buffer message. A string containing the JSON formatted protocol buffer message.
@ -124,7 +127,7 @@ def MessageToJson(
use_integers_for_enums, use_integers_for_enums,
descriptor_pool, descriptor_pool,
float_precision=float_precision) float_precision=float_precision)
return printer.ToJsonString(message, indent, sort_keys) return printer.ToJsonString(message, indent, sort_keys, ensure_ascii)
def MessageToDict( def MessageToDict(
@ -190,9 +193,10 @@ class _Printer(object):
else: else:
self.float_format = None self.float_format = None
def ToJsonString(self, message, indent, sort_keys): def ToJsonString(self, message, indent, sort_keys, ensure_ascii):
js = self._MessageToJsonObject(message) js = self._MessageToJsonObject(message)
return json.dumps(js, indent=indent, sort_keys=sort_keys) return json.dumps(
js, indent=indent, sort_keys=sort_keys, ensure_ascii=ensure_ascii)
def _MessageToJsonObject(self, message): def _MessageToJsonObject(self, message):
"""Converts message to an object according to Proto3 JSON Specification.""" """Converts message to an object according to Proto3 JSON Specification."""

@ -1002,7 +1002,7 @@ int DeleteRepeatedField(
} }
} }
Arena* arena = Arena::InternalHelper<Message>::GetArenaForAllocation(message); Arena* arena = Arena::InternalGetArenaForAllocation(message);
GOOGLE_DCHECK_EQ(arena, nullptr) GOOGLE_DCHECK_EQ(arena, nullptr)
<< "python protobuf is expected to be allocated from heap"; << "python protobuf is expected to be allocated from heap";
// Remove items, starting from the end. // Remove items, starting from the end.

@ -137,8 +137,9 @@ static void Dealloc(PyObject* pself) {
reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr; reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr;
} }
Py_CLEAR(self->parent); Py_CLEAR(self->parent);
auto* py_type = Py_TYPE(pself);
self->~PyUnknownFields(); self->~PyUnknownFields();
Py_TYPE(pself)->tp_free(pself); py_type->tp_free(pself);
} }
static PySequenceMethods SqMethods = { static PySequenceMethods SqMethods = {

@ -1,6 +1,6 @@
[tox] [tox]
envlist = envlist =
py{35,36,37,38,39,310}-{cpp,python} py{37,38,39,310}-{cpp,python}
[testenv] [testenv]
usedevelop=true usedevelop=true
@ -14,7 +14,7 @@ setenv =
commands = commands =
python setup.py -q build_py python setup.py -q build_py
python: python setup.py -q build python: python setup.py -q build
py{35,36,37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension py{37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension
python: python setup.py -q test -q python: python setup.py -q test -q
cpp: python setup.py -q test -q --cpp_implementation cpp: python setup.py -q test -q --cpp_implementation
python: python setup.py -q test_conformance python: python setup.py -q test_conformance

@ -49,10 +49,8 @@ bool AnyMetadata::PackFrom(Arena* arena, const Message& message) {
bool AnyMetadata::PackFrom(Arena* arena, const Message& message, bool AnyMetadata::PackFrom(Arena* arena, const Message& message,
StringPiece type_url_prefix) { StringPiece type_url_prefix) {
type_url_->Set( type_url_->Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString(),
GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix), arena); GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix), arena);
return message.SerializeToString( return message.SerializeToString(value_->Mutable(arena));
value_->Mutable(ArenaStringPtr::EmptyDefault{}, arena));
} }
bool AnyMetadata::UnpackTo(Message* message) const { bool AnyMetadata::UnpackTo(Message* message) const {

@ -119,18 +119,18 @@ Any::Any(const Any& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
type_url_.InitDefault(); type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_type_url().empty()) { if (!from._internal_type_url().empty()) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_type_url(), type_url_.Set(from._internal_type_url(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
value_.InitDefault(); value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_value().empty()) { if (!from._internal_value().empty()) {
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_value(), value_.Set(from._internal_value(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any) // @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
@ -139,11 +139,11 @@ Any::Any(const Any& from)
inline void Any::SharedCtor() { inline void Any::SharedCtor() {
type_url_.InitDefault(); type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.InitDefault(); value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
@ -158,8 +158,8 @@ Any::~Any() {
inline void Any::SharedDtor() { inline void Any::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); type_url_.Destroy();
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); value_.Destroy();
} }
void Any::SetCachedSize(int size) const { void Any::SetCachedSize(int size) const {
@ -325,12 +325,10 @@ void Any::InternalSwap(Any* other) {
auto* rhs_arena = other->GetArenaForAllocation(); auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&type_url_, lhs_arena, &type_url_, lhs_arena,
&other->type_url_, rhs_arena &other->type_url_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&value_, lhs_arena, &value_, lhs_arena,
&other->value_, rhs_arena &other->value_, rhs_arena
); );

@ -275,7 +275,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Any::set_type_url(ArgT0&& arg0, ArgT... args) { void Any::set_type_url(ArgT0&& arg0, ArgT... args) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
} }
inline std::string* Any::mutable_type_url() { inline std::string* Any::mutable_type_url() {
@ -288,15 +288,15 @@ inline const std::string& Any::_internal_type_url() const {
} }
inline void Any::_internal_set_type_url(const std::string& value) { inline void Any::_internal_set_type_url(const std::string& value) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); type_url_.Set(value, GetArenaForAllocation());
} }
inline std::string* Any::_internal_mutable_type_url() { inline std::string* Any::_internal_mutable_type_url() {
return type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return type_url_.Mutable(GetArenaForAllocation());
} }
inline std::string* Any::release_type_url() { inline std::string* Any::release_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return type_url_.Release();
} }
inline void Any::set_allocated_type_url(std::string* type_url) { inline void Any::set_allocated_type_url(std::string* type_url) {
if (type_url != nullptr) { if (type_url != nullptr) {
@ -304,11 +304,10 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
} else { } else {
} }
type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url, type_url_.SetAllocated(type_url, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (type_url_.IsDefault()) { if (type_url_.IsDefault()) {
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); type_url_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
@ -326,7 +325,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Any::set_value(ArgT0&& arg0, ArgT... args) { void Any::set_value(ArgT0&& arg0, ArgT... args) {
value_.SetBytes(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); value_.SetBytes(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.value) // @@protoc_insertion_point(field_set:google.protobuf.Any.value)
} }
inline std::string* Any::mutable_value() { inline std::string* Any::mutable_value() {
@ -339,15 +338,15 @@ inline const std::string& Any::_internal_value() const {
} }
inline void Any::_internal_set_value(const std::string& value) { inline void Any::_internal_set_value(const std::string& value) {
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); value_.Set(value, GetArenaForAllocation());
} }
inline std::string* Any::_internal_mutable_value() { inline std::string* Any::_internal_mutable_value() {
return value_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return value_.Mutable(GetArenaForAllocation());
} }
inline std::string* Any::release_value() { inline std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value) // @@protoc_insertion_point(field_release:google.protobuf.Any.value)
return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return value_.Release();
} }
inline void Any::set_allocated_value(std::string* value) { inline void Any::set_allocated_value(std::string* value) {
if (value != nullptr) { if (value != nullptr) {
@ -355,11 +354,10 @@ inline void Any::set_allocated_value(std::string* value) {
} else { } else {
} }
value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, value_.SetAllocated(value, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (value_.IsDefault()) { if (value_.IsDefault()) {
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); value_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)

@ -55,10 +55,8 @@ const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";
bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message, bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message,
StringPiece type_url_prefix, StringPiece type_url_prefix,
StringPiece type_name) { StringPiece type_name) {
type_url_->Set(&::google::protobuf::internal::GetEmptyString(), type_url_->Set(GetTypeUrl(type_name, type_url_prefix), arena);
GetTypeUrl(type_name, type_url_prefix), arena); return message.SerializeToString(value_->Mutable(arena));
return message.SerializeToString(
value_->Mutable(ArenaStringPtr::EmptyDefault{}, arena));
} }
bool AnyMetadata::InternalUnpackTo(StringPiece type_name, bool AnyMetadata::InternalUnpackTo(StringPiece type_name,

@ -204,18 +204,18 @@ Api::Api(const Api& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) { if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
version_.InitDefault(); version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_version().empty()) { if (!from._internal_version().empty()) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_version(), version_.Set(from._internal_version(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_source_context()) { if (from._internal_has_source_context()) {
@ -230,11 +230,11 @@ Api::Api(const Api& from)
inline void Api::SharedCtor() { inline void Api::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.InitDefault(); version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&source_context_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&source_context_) - reinterpret_cast<char*>(this)),
@ -253,8 +253,8 @@ Api::~Api() {
inline void Api::SharedDtor() { inline void Api::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); version_.Destroy();
if (this != internal_default_instance()) delete source_context_; if (this != internal_default_instance()) delete source_context_;
} }
@ -574,12 +574,10 @@ void Api::InternalSwap(Api* other) {
options_.InternalSwap(&other->options_); options_.InternalSwap(&other->options_);
mixins_.InternalSwap(&other->mixins_); mixins_.InternalSwap(&other->mixins_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&version_, lhs_arena, &version_, lhs_arena,
&other->version_, rhs_arena &other->version_, rhs_arena
); );
@ -619,26 +617,26 @@ Method::Method(const Method& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) { if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
request_type_url_.InitDefault(); request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_request_type_url().empty()) { if (!from._internal_request_type_url().empty()) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_request_type_url(), request_type_url_.Set(from._internal_request_type_url(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
response_type_url_.InitDefault(); response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_response_type_url().empty()) { if (!from._internal_response_type_url().empty()) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_response_type_url(), response_type_url_.Set(from._internal_response_type_url(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
::memcpy(&request_streaming_, &from.request_streaming_, ::memcpy(&request_streaming_, &from.request_streaming_,
@ -650,15 +648,15 @@ Method::Method(const Method& from)
inline void Method::SharedCtor() { inline void Method::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.InitDefault(); request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.InitDefault(); response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&request_streaming_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&request_streaming_) - reinterpret_cast<char*>(this)),
@ -677,9 +675,9 @@ Method::~Method() {
inline void Method::SharedDtor() { inline void Method::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
request_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); request_type_url_.Destroy();
response_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); response_type_url_.Destroy();
} }
void Method::SetCachedSize(int size) const { void Method::SetCachedSize(int size) const {
@ -984,17 +982,14 @@ void Method::InternalSwap(Method* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
options_.InternalSwap(&other->options_); options_.InternalSwap(&other->options_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&request_type_url_, lhs_arena, &request_type_url_, lhs_arena,
&other->request_type_url_, rhs_arena &other->request_type_url_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&response_type_url_, lhs_arena, &response_type_url_, lhs_arena,
&other->response_type_url_, rhs_arena &other->response_type_url_, rhs_arena
); );
@ -1029,18 +1024,18 @@ Mixin::Mixin(const Mixin& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) { if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
root_.InitDefault(); root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_root().empty()) { if (!from._internal_root().empty()) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_root(), root_.Set(from._internal_root(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin) // @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
@ -1049,11 +1044,11 @@ Mixin::Mixin(const Mixin& from)
inline void Mixin::SharedCtor() { inline void Mixin::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.InitDefault(); root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
@ -1068,8 +1063,8 @@ Mixin::~Mixin() {
inline void Mixin::SharedDtor() { inline void Mixin::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); root_.Destroy();
} }
void Mixin::SetCachedSize(int size) const { void Mixin::SetCachedSize(int size) const {
@ -1240,12 +1235,10 @@ void Mixin::InternalSwap(Mixin* other) {
auto* rhs_arena = other->GetArenaForAllocation(); auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&root_, lhs_arena, &root_, lhs_arena,
&other->root_, rhs_arena &other->root_, rhs_arena
); );

@ -739,7 +739,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Api::set_name(ArgT0&& arg0, ArgT... args) { void Api::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.name) // @@protoc_insertion_point(field_set:google.protobuf.Api.name)
} }
inline std::string* Api::mutable_name() { inline std::string* Api::mutable_name() {
@ -752,15 +752,15 @@ inline const std::string& Api::_internal_name() const {
} }
inline void Api::_internal_set_name(const std::string& value) { inline void Api::_internal_set_name(const std::string& value) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); name_.Set(value, GetArenaForAllocation());
} }
inline std::string* Api::_internal_mutable_name() { inline std::string* Api::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return name_.Mutable(GetArenaForAllocation());
} }
inline std::string* Api::release_name() { inline std::string* Api::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.name) // @@protoc_insertion_point(field_release:google.protobuf.Api.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return name_.Release();
} }
inline void Api::set_allocated_name(std::string* name) { inline void Api::set_allocated_name(std::string* name) {
if (name != nullptr) { if (name != nullptr) {
@ -768,11 +768,10 @@ inline void Api::set_allocated_name(std::string* name) {
} else { } else {
} }
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, name_.SetAllocated(name, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) { if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
@ -867,7 +866,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Api::set_version(ArgT0&& arg0, ArgT... args) { void Api::set_version(ArgT0&& arg0, ArgT... args) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); version_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.version) // @@protoc_insertion_point(field_set:google.protobuf.Api.version)
} }
inline std::string* Api::mutable_version() { inline std::string* Api::mutable_version() {
@ -880,15 +879,15 @@ inline const std::string& Api::_internal_version() const {
} }
inline void Api::_internal_set_version(const std::string& value) { inline void Api::_internal_set_version(const std::string& value) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); version_.Set(value, GetArenaForAllocation());
} }
inline std::string* Api::_internal_mutable_version() { inline std::string* Api::_internal_mutable_version() {
return version_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return version_.Mutable(GetArenaForAllocation());
} }
inline std::string* Api::release_version() { inline std::string* Api::release_version() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.version) // @@protoc_insertion_point(field_release:google.protobuf.Api.version)
return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return version_.Release();
} }
inline void Api::set_allocated_version(std::string* version) { inline void Api::set_allocated_version(std::string* version) {
if (version != nullptr) { if (version != nullptr) {
@ -896,11 +895,10 @@ inline void Api::set_allocated_version(std::string* version) {
} else { } else {
} }
version_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version, version_.SetAllocated(version, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (version_.IsDefault()) { if (version_.IsDefault()) {
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); version_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
@ -977,8 +975,7 @@ inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCon
} }
if (source_context) { if (source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper< ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(
::PROTOBUF_NAMESPACE_ID::MessageLite>::GetOwningArena(
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context)); reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context));
if (message_arena != submessage_arena) { if (message_arena != submessage_arena) {
source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
@ -1068,7 +1065,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Method::set_name(ArgT0&& arg0, ArgT... args) { void Method::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.name) // @@protoc_insertion_point(field_set:google.protobuf.Method.name)
} }
inline std::string* Method::mutable_name() { inline std::string* Method::mutable_name() {
@ -1081,15 +1078,15 @@ inline const std::string& Method::_internal_name() const {
} }
inline void Method::_internal_set_name(const std::string& value) { inline void Method::_internal_set_name(const std::string& value) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); name_.Set(value, GetArenaForAllocation());
} }
inline std::string* Method::_internal_mutable_name() { inline std::string* Method::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return name_.Mutable(GetArenaForAllocation());
} }
inline std::string* Method::release_name() { inline std::string* Method::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.name) // @@protoc_insertion_point(field_release:google.protobuf.Method.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return name_.Release();
} }
inline void Method::set_allocated_name(std::string* name) { inline void Method::set_allocated_name(std::string* name) {
if (name != nullptr) { if (name != nullptr) {
@ -1097,11 +1094,10 @@ inline void Method::set_allocated_name(std::string* name) {
} else { } else {
} }
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, name_.SetAllocated(name, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) { if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
@ -1119,7 +1115,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Method::set_request_type_url(ArgT0&& arg0, ArgT... args) { void Method::set_request_type_url(ArgT0&& arg0, ArgT... args) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); request_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url)
} }
inline std::string* Method::mutable_request_type_url() { inline std::string* Method::mutable_request_type_url() {
@ -1132,15 +1128,15 @@ inline const std::string& Method::_internal_request_type_url() const {
} }
inline void Method::_internal_set_request_type_url(const std::string& value) { inline void Method::_internal_set_request_type_url(const std::string& value) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); request_type_url_.Set(value, GetArenaForAllocation());
} }
inline std::string* Method::_internal_mutable_request_type_url() { inline std::string* Method::_internal_mutable_request_type_url() {
return request_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return request_type_url_.Mutable(GetArenaForAllocation());
} }
inline std::string* Method::release_request_type_url() { inline std::string* Method::release_request_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url)
return request_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return request_type_url_.Release();
} }
inline void Method::set_allocated_request_type_url(std::string* request_type_url) { inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
if (request_type_url != nullptr) { if (request_type_url != nullptr) {
@ -1148,11 +1144,10 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
} else { } else {
} }
request_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url, request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (request_type_url_.IsDefault()) { if (request_type_url_.IsDefault()) {
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); request_type_url_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
@ -1190,7 +1185,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Method::set_response_type_url(ArgT0&& arg0, ArgT... args) { void Method::set_response_type_url(ArgT0&& arg0, ArgT... args) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); response_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url)
} }
inline std::string* Method::mutable_response_type_url() { inline std::string* Method::mutable_response_type_url() {
@ -1203,15 +1198,15 @@ inline const std::string& Method::_internal_response_type_url() const {
} }
inline void Method::_internal_set_response_type_url(const std::string& value) { inline void Method::_internal_set_response_type_url(const std::string& value) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); response_type_url_.Set(value, GetArenaForAllocation());
} }
inline std::string* Method::_internal_mutable_response_type_url() { inline std::string* Method::_internal_mutable_response_type_url() {
return response_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return response_type_url_.Mutable(GetArenaForAllocation());
} }
inline std::string* Method::release_response_type_url() { inline std::string* Method::release_response_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url)
return response_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return response_type_url_.Release();
} }
inline void Method::set_allocated_response_type_url(std::string* response_type_url) { inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
if (response_type_url != nullptr) { if (response_type_url != nullptr) {
@ -1219,11 +1214,10 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
} else { } else {
} }
response_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url, response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (response_type_url_.IsDefault()) { if (response_type_url_.IsDefault()) {
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); response_type_url_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
@ -1322,7 +1316,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Mixin::set_name(ArgT0&& arg0, ArgT... args) { void Mixin::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_set:google.protobuf.Mixin.name)
} }
inline std::string* Mixin::mutable_name() { inline std::string* Mixin::mutable_name() {
@ -1335,15 +1329,15 @@ inline const std::string& Mixin::_internal_name() const {
} }
inline void Mixin::_internal_set_name(const std::string& value) { inline void Mixin::_internal_set_name(const std::string& value) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); name_.Set(value, GetArenaForAllocation());
} }
inline std::string* Mixin::_internal_mutable_name() { inline std::string* Mixin::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return name_.Mutable(GetArenaForAllocation());
} }
inline std::string* Mixin::release_name() { inline std::string* Mixin::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return name_.Release();
} }
inline void Mixin::set_allocated_name(std::string* name) { inline void Mixin::set_allocated_name(std::string* name) {
if (name != nullptr) { if (name != nullptr) {
@ -1351,11 +1345,10 @@ inline void Mixin::set_allocated_name(std::string* name) {
} else { } else {
} }
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, name_.SetAllocated(name, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) { if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
@ -1373,7 +1366,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Mixin::set_root(ArgT0&& arg0, ArgT... args) { void Mixin::set_root(ArgT0&& arg0, ArgT... args) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); root_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_set:google.protobuf.Mixin.root)
} }
inline std::string* Mixin::mutable_root() { inline std::string* Mixin::mutable_root() {
@ -1386,15 +1379,15 @@ inline const std::string& Mixin::_internal_root() const {
} }
inline void Mixin::_internal_set_root(const std::string& value) { inline void Mixin::_internal_set_root(const std::string& value) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); root_.Set(value, GetArenaForAllocation());
} }
inline std::string* Mixin::_internal_mutable_root() { inline std::string* Mixin::_internal_mutable_root() {
return root_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return root_.Mutable(GetArenaForAllocation());
} }
inline std::string* Mixin::release_root() { inline std::string* Mixin::release_root() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return root_.Release();
} }
inline void Mixin::set_allocated_root(std::string* root) { inline void Mixin::set_allocated_root(std::string* root) {
if (root != nullptr) { if (root != nullptr) {
@ -1402,11 +1395,10 @@ inline void Mixin::set_allocated_root(std::string* root) {
} else { } else {
} }
root_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root, root_.SetAllocated(root, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (root_.IsDefault()) { if (root_.IsDefault()) {
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); root_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)

@ -413,27 +413,10 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template <typename T> template <typename T>
class InternalHelper { class InternalHelper {
public: private:
// Provides access to protected GetOwningArena to generated messages. // Provides access to protected GetOwningArena to generated messages.
static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); } static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); }
// Provides access to protected GetArenaForAllocation to generated messages.
static Arena* GetArenaForAllocation(const T* p) {
return GetArenaForAllocationInternal(
p, std::is_convertible<T*, MessageLite*>());
}
// Creates message-owned arena.
static Arena* CreateMessageOwnedArena() {
return new Arena(internal::MessageOwned{});
}
// Checks whether the given arena is message-owned.
static bool IsMessageOwnedArena(Arena* arena) {
return arena->IsMessageOwned();
}
private:
static Arena* GetArenaForAllocationInternal( static Arena* GetArenaForAllocationInternal(
const T* p, std::true_type /*is_derived_from<MessageLite>*/) { const T* p, std::true_type /*is_derived_from<MessageLite>*/) {
return p->GetArenaForAllocation(); return p->GetArenaForAllocation();
@ -516,6 +499,29 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
friend class TestUtil::ReflectionTester; friend class TestUtil::ReflectionTester;
}; };
// Provides access to protected GetOwningArena to generated messages. For
// internal use only.
template <typename T>
static Arena* InternalGetOwningArena(const T* p) {
return InternalHelper<T>::GetOwningArena(p);
}
// Provides access to protected GetArenaForAllocation to generated messages.
// For internal use only.
template <typename T>
static Arena* InternalGetArenaForAllocation(const T* p) {
return InternalHelper<T>::GetArenaForAllocationInternal(
p, std::is_convertible<T*, MessageLite*>());
}
// Creates message-owned arena. For internal use only.
static Arena* InternalCreateMessageOwnedArena() {
return new Arena(internal::MessageOwned{});
}
// Checks whether this arena is message-owned. For internal use only.
bool InternalIsMessageOwnedArena() { return IsMessageOwned(); }
// Helper typetraits that indicates support for arenas in a type T at compile // Helper typetraits that indicates support for arenas in a type T at compile
// time. This is public only to allow construction of higher-level templated // time. This is public only to allow construction of higher-level templated
// utilities. // utilities.

@ -547,13 +547,11 @@ TEST(ArenaTest, UnsafeArenaSwap) {
TEST(ArenaTest, GetOwningArena) { TEST(ArenaTest, GetOwningArena) {
Arena arena; Arena arena;
auto* m1 = Arena::CreateMessage<TestAllTypes>(&arena); auto* m1 = Arena::CreateMessage<TestAllTypes>(&arena);
EXPECT_EQ(Arena::InternalHelper<TestAllTypes>::GetOwningArena(m1), &arena); EXPECT_EQ(Arena::InternalGetOwningArena(m1), &arena);
EXPECT_EQ( EXPECT_EQ(&arena, Arena::InternalGetOwningArena(
&arena, m1->mutable_repeated_foreign_message()));
Arena::InternalHelper<RepeatedPtrField<ForeignMessage>>::GetOwningArena( EXPECT_EQ(&arena,
m1->mutable_repeated_foreign_message())); Arena::InternalGetOwningArena(m1->mutable_repeated_int32()));
EXPECT_EQ(&arena, Arena::InternalHelper<RepeatedField<int>>::GetOwningArena(
m1->mutable_repeated_int32()));
} }
TEST(ArenaTest, SwapBetweenArenasUsingReflection) { TEST(ArenaTest, SwapBetweenArenasUsingReflection) {

@ -30,6 +30,7 @@
#include <google/protobuf/arenastring.h> #include <google/protobuf/arenastring.h>
#include <cstddef>
#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/coded_stream.h>
@ -109,13 +110,7 @@ std::string* ArenaStringPtr::SetAndReturnNewString() {
return new_string; return new_string;
} }
void ArenaStringPtr::DestroyNoArenaSlowPath() { void ArenaStringPtr::Set(ConstStringParam value, Arena* arena) {
GOOGLE_DCHECK(tagged_ptr_.IsAllocated());
delete UnsafeMutablePointer();
}
void ArenaStringPtr::Set(const std::string*, ConstStringParam value,
::google::protobuf::Arena* arena) {
if (IsDefault()) { if (IsDefault()) {
// If we're not on an arena, skip straight to a true string to avoid // If we're not on an arena, skip straight to a true string to avoid
// possible copy cost later. // possible copy cost later.
@ -125,8 +120,8 @@ void ArenaStringPtr::Set(const std::string*, ConstStringParam value,
UnsafeMutablePointer()->assign(value.data(), value.length()); UnsafeMutablePointer()->assign(value.data(), value.length());
} }
} }
void ArenaStringPtr::Set(const std::string*, std::string&& value,
::google::protobuf::Arena* arena) { void ArenaStringPtr::Set(std::string&& value, Arena* arena) {
if (IsDefault()) { if (IsDefault()) {
NewString(arena, std::move(value)); NewString(arena, std::move(value));
} else if (IsFixedSizeArena()) { } else if (IsFixedSizeArena()) {
@ -139,47 +134,26 @@ void ArenaStringPtr::Set(const std::string*, std::string&& value,
} }
} }
void ArenaStringPtr::Set(EmptyDefault, ConstStringParam value, std::string* ArenaStringPtr::Mutable(Arena* arena) {
::google::protobuf::Arena* arena) { if (tagged_ptr_.IsMutable()) {
Set(&GetEmptyStringAlreadyInited(), value, arena); return tagged_ptr_.Get();
}
void ArenaStringPtr::Set(EmptyDefault, std::string&& value,
::google::protobuf::Arena* arena) {
Set(&GetEmptyStringAlreadyInited(), std::move(value), arena);
}
void ArenaStringPtr::Set(NonEmptyDefault, ConstStringParam value,
::google::protobuf::Arena* arena) {
Set(nullptr, value, arena);
}
void ArenaStringPtr::Set(NonEmptyDefault, std::string&& value,
::google::protobuf::Arena* arena) {
Set(nullptr, std::move(value), arena);
}
std::string* ArenaStringPtr::Mutable(EmptyDefault, ::google::protobuf::Arena* arena) {
if (!IsFixedSizeArena() && !IsDefault()) {
return UnsafeMutablePointer();
} else { } else {
return MutableSlow(arena); return MutableSlow(arena);
} }
} }
std::string* ArenaStringPtr::Mutable(const LazyString& default_value, std::string* ArenaStringPtr::Mutable(const LazyString& default_value,
::google::protobuf::Arena* arena) { Arena* arena) {
if (!IsFixedSizeArena() && !IsDefault()) { if (tagged_ptr_.IsMutable()) {
return UnsafeMutablePointer(); return tagged_ptr_.Get();
} else { } else {
return MutableSlow(arena, default_value); return MutableSlow(arena, default_value);
} }
} }
std::string* ArenaStringPtr::MutableNoCopy(const std::string*, std::string* ArenaStringPtr::MutableNoCopy(Arena* arena) {
::google::protobuf::Arena* arena) { if (tagged_ptr_.IsMutable()) {
if (!IsFixedSizeArena() && !IsDefault()) { return tagged_ptr_.Get();
return UnsafeMutablePointer();
} else { } else {
GOOGLE_DCHECK(IsDefault()); GOOGLE_DCHECK(IsDefault());
// Allocate empty. The contents are not relevant. // Allocate empty. The contents are not relevant.
@ -194,45 +168,24 @@ std::string* ArenaStringPtr::MutableSlow(::google::protobuf::Arena* arena,
return NewString(arena, lazy_default.get()...); return NewString(arena, lazy_default.get()...);
} }
std::string* ArenaStringPtr::Release(const std::string* default_value, std::string* ArenaStringPtr::Release() {
::google::protobuf::Arena* arena) { if (IsDefault()) return nullptr;
if (IsDefault()) {
return nullptr;
} else {
return ReleaseNonDefault(default_value, arena);
}
}
std::string* ArenaStringPtr::ReleaseNonDefault(const std::string* default_value, std::string* released = tagged_ptr_.Get();
::google::protobuf::Arena* arena) { if (!tagged_ptr_.IsAllocated()) {
GOOGLE_DCHECK(!IsDefault()); released = tagged_ptr_.IsMutable() ? new std::string(std::move(*released))
: new std::string(*released);
if (!IsFixedSizeArena()) {
std::string* released;
if (arena != nullptr) {
released = new std::string;
released->swap(*UnsafeMutablePointer());
} else {
released = UnsafeMutablePointer();
}
tagged_ptr_.SetDefault(default_value);
return released;
} else /* IsFixedSizeArena() */ {
GOOGLE_DCHECK(arena != nullptr);
std::string* released = new std::string(Get());
tagged_ptr_.SetDefault(default_value);
return released;
} }
InitDefault();
return released;
} }
void ArenaStringPtr::SetAllocated(const std::string* default_value, void ArenaStringPtr::SetAllocated(std::string* value, Arena* arena) {
std::string* value, ::google::protobuf::Arena* arena) {
// Release what we have first. // Release what we have first.
if (arena == nullptr && !IsDefault()) { Destroy();
delete UnsafeMutablePointer();
}
if (value == nullptr) { if (value == nullptr) {
tagged_ptr_.SetDefault(default_value); InitDefault();
} else { } else {
#ifndef NDEBUG #ifndef NDEBUG
// On debug builds, copy the string so the address differs. delete will // On debug builds, copy the string so the address differs. delete will
@ -246,23 +199,12 @@ void ArenaStringPtr::SetAllocated(const std::string* default_value,
} }
} }
void ArenaStringPtr::Destroy(const std::string*, ::google::protobuf::Arena* arena) { void ArenaStringPtr::Destroy() {
if (arena == nullptr) { if (tagged_ptr_.IsAllocated()) {
GOOGLE_DCHECK(!IsFixedSizeArena()); delete tagged_ptr_.Get();
if (!IsDefault()) {
delete UnsafeMutablePointer();
}
} }
} }
void ArenaStringPtr::Destroy(EmptyDefault, ::google::protobuf::Arena* arena) {
Destroy(&GetEmptyStringAlreadyInited(), arena);
}
void ArenaStringPtr::Destroy(NonEmptyDefault, ::google::protobuf::Arena* arena) {
Destroy(nullptr, arena);
}
void ArenaStringPtr::ClearToEmpty() { void ArenaStringPtr::ClearToEmpty() {
if (IsDefault()) { if (IsDefault()) {
// Already set to default -- do nothing. // Already set to default -- do nothing.

@ -187,7 +187,7 @@ class TaggedPtr {
} }
inline T* TagAs(Type type, T* p) { inline T* TagAs(Type type, T* p) {
GOOGLE_DCHECK(type == kDefault || p != nullptr); GOOGLE_DCHECK(p != nullptr);
assert_aligned(p); assert_aligned(p);
ptr_ = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(p) | type); ptr_ = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(p) | type);
return p; return p;
@ -232,84 +232,84 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
struct EmptyDefault {}; struct EmptyDefault {};
struct NonEmptyDefault {}; struct NonEmptyDefault {};
void Set(const std::string* default_value, ConstStringParam value, // Called from generated code / reflection runtime only. Resets value to point
::google::protobuf::Arena* arena); // to a default string pointer, with the semantics that this ArenaStringPtr
void Set(const std::string* default_value, std::string&& value, // does not own the pointed-to memory. Disregards initial value of ptr_ (so
::google::protobuf::Arena* arena); // this is the *ONLY* safe method to call after construction or when
void Set(EmptyDefault, ConstStringParam value, ::google::protobuf::Arena* arena); // reinitializing after becoming the active field in a oneof union).
void Set(EmptyDefault, std::string&& value, ::google::protobuf::Arena* arena); inline void InitDefault();
void Set(NonEmptyDefault, ConstStringParam value, ::google::protobuf::Arena* arena);
void Set(NonEmptyDefault, std::string&& value, ::google::protobuf::Arena* arena); // Similar to `InitDefault` except that it allows the default value to be
template <typename FirstParam> // initialized to an externally owned string. This method is called from
void Set(FirstParam p1, const char* str, ::google::protobuf::Arena* arena) { // parsing code. `str` must not be null and outlive this instance.
Set(p1, ConstStringParam(str), arena); inline void InitExternal(const std::string* str);
}
template <typename FirstParam> // Called from generated code / reflection runtime only. Resets the value of
void Set(FirstParam p1, const char* str, size_t size, // this instances to the heap allocated value in `str`. `str` must not be
::google::protobuf::Arena* arena) { // null. Invokes `arena->Own(str)` to transfer ownership into the arena if
ConstStringParam sp{str, size}; // for string_view and `const string &` // `arena` is not null, else, `str` will be owned by ArenaStringPtr. This
Set(p1, sp, arena); // function should only be used to initialize a ArenaStringPtr or on an
} // instance known to not carry any heap allocated value.
template <typename FirstParam, typename RefWrappedType> inline void InitAllocated(std::string* str, Arena* arena);
void Set(FirstParam p1,
std::reference_wrapper<RefWrappedType> const_string_ref, void Set(ConstStringParam value, Arena* arena);
void Set(std::string&& value, Arena* arena);
void Set(const char* s, Arena* arena);
void Set(const char* s, size_t n, Arena* arena);
void SetBytes(ConstStringParam value, Arena* arena);
void SetBytes(std::string&& value, Arena* arena);
void SetBytes(const char* s, Arena* arena);
void SetBytes(const void* p, size_t n, Arena* arena);
template <typename RefWrappedType>
void Set(std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena) { ::google::protobuf::Arena* arena) {
Set(p1, const_string_ref.get(), arena); Set(const_string_ref.get(), arena);
} }
template <typename FirstParam, typename SecondParam> // Returns a mutable std::string reference.
void SetBytes(FirstParam p1, SecondParam&& p2, ::google::protobuf::Arena* arena) { // The version accepting a `LazyString` value is used in the generated code to
Set(p1, static_cast<SecondParam&&>(p2), arena); // initialize mutable copies for fields with a non-empty default where the
} // default value is lazily initialized.
template <typename FirstParam> std::string* Mutable(Arena* arena);
void SetBytes(FirstParam p1, const void* str, size_t size, std::string* Mutable(const LazyString& default_value, Arena* arena);
::google::protobuf::Arena* arena) {
// must work whether ConstStringParam is string_view or `const string &` // Gets a mutable pointer with unspecified contents.
ConstStringParam sp{static_cast<const char*>(str), size}; // This function is identical to Mutable(), except it is optimized for the
Set(p1, sp, arena); // case where the caller is not interested in the current contents. For
} // example, if the current field is not mutable, it will re-initialize the
// value with an empty string rather than a (non-empty) default value.
// Likewise, if the current value is a fixed size arena string with contents,
// it will be initialized into an empty mutable arena string.
std::string* MutableNoCopy(Arena* arena);
// Basic accessors. // Basic accessors.
PROTOBUF_NDEBUG_INLINE const std::string& Get() const { PROTOBUF_NDEBUG_INLINE const std::string& Get() const {
// Unconditionally mask away the tag. // Unconditionally mask away the tag.
return *tagged_ptr_.Get(); return *tagged_ptr_.Get();
} }
PROTOBUF_NDEBUG_INLINE const std::string* GetPointer() const {
// Unconditionally mask away the tag. // Returns a pointer to the stored contents for this instance.
// This method is for internal debugging and tracking purposes only.
PROTOBUF_NDEBUG_INLINE const std::string* UnsafeGetPointer() const
PROTOBUF_RETURNS_NONNULL {
return tagged_ptr_.Get(); return tagged_ptr_.Get();
} }
// For fields with an empty default value.
std::string* Mutable(EmptyDefault, ::google::protobuf::Arena* arena);
// For fields with a non-empty default value.
std::string* Mutable(const LazyString& default_value, ::google::protobuf::Arena* arena);
// Release returns a std::string* instance that is heap-allocated and is not // Release returns a std::string* instance that is heap-allocated and is not
// Own()'d by any arena. If the field is not set, this returns nullptr. The // Own()'d by any arena. If the field is not set, this returns nullptr. The
// caller retains ownership. Clears this field back to nullptr state. Used to // caller retains ownership. Clears this field back to the default state.
// implement release_<field>() methods on generated classes. // Used to implement release_<field>() methods on generated classes.
PROTOBUF_NODISCARD std::string* Release(const std::string* default_value, PROTOBUF_NODISCARD std::string* Release();
::google::protobuf::Arena* arena);
PROTOBUF_NODISCARD std::string* ReleaseNonDefault(
const std::string* default_value, ::google::protobuf::Arena* arena);
// Takes a std::string that is heap-allocated, and takes ownership. The // Takes a std::string that is heap-allocated, and takes ownership. The
// std::string's destructor is registered with the arena. Used to implement // std::string's destructor is registered with the arena. Used to implement
// set_allocated_<field> in generated classes. // set_allocated_<field> in generated classes.
void SetAllocated(const std::string* default_value, std::string* value, void SetAllocated(std::string* value, Arena* arena);
::google::protobuf::Arena* arena);
// Swaps internal pointers. Arena-safety semantics: this is guarded by the
// logic in Swap()/UnsafeArenaSwap() at the message level, so this method is
// 'unsafe' if called directly.
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(
const std::string* default_value, ArenaStringPtr* rhs, Arena* rhs_arena,
ArenaStringPtr* lhs, Arena* lhs_arena);
// Frees storage (if not on an arena). // Frees storage (if not on an arena).
void Destroy(const std::string* default_value, ::google::protobuf::Arena* arena); void Destroy();
void Destroy(EmptyDefault, ::google::protobuf::Arena* arena);
void Destroy(NonEmptyDefault, ::google::protobuf::Arena* arena);
// Clears content, but keeps allocated std::string, to avoid the overhead of // Clears content, but keeps allocated std::string, to avoid the overhead of
// heap operations. After this returns, the content (as seen by the user) will // heap operations. After this returns, the content (as seen by the user) will
@ -326,37 +326,109 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// (as seen by the user) will always be equal to |default_value|. // (as seen by the user) will always be equal to |default_value|.
void ClearToDefault(const LazyString& default_value, ::google::protobuf::Arena* arena); void ClearToDefault(const LazyString& default_value, ::google::protobuf::Arena* arena);
// Called from generated code / reflection runtime only. Resets value to point // Swaps internal pointers. Arena-safety semantics: this is guarded by the
// to a default string pointer, with the semantics that this ArenaStringPtr // logic in Swap()/UnsafeArenaSwap() at the message level, so this method is
// does not own the pointed-to memory. Disregards initial value of ptr_ (so // 'unsafe' if called directly.
// this is the *ONLY* safe method to call after construction or when inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(ArenaStringPtr* rhs,
// reinitializing after becoming the active field in a oneof union). Arena* rhs_arena,
// This function allows an explicit default value other than the default ArenaStringPtr* lhs,
// global empty string. This is used in unit tests and by fields with Arena* lhs_arena);
// explicit non-empty default string values using null defaults.
inline void InitDefault(); // --------------------------------------------------------
inline void InitDefault(const std::string* str); // Below functions will be removed in subsequent code change
// --------------------------------------------------------
#ifdef DEPRECATED_METHODS_TO_BE_DELETED
PROTOBUF_NDEBUG_INLINE const std::string* GetPointer() const {
return UnsafeGetPointer();
}
// Called from generated code / reflection runtime only. Resets the value of template <typename DefaultArg>
// this instances to the heap allocated value in `str`. `str` must not be void Set(DefaultArg, ConstStringParam value, Arena* arena) {
// null. Invokes `arena->Own(str)` to transfer ownership into the arena if return Set(value, arena);
// `arena` is not null, else, `str` will be owned by ArenaStringPtr. This }
// function should only be used to initialize a ArenaStringPtr or on an template <typename DefaultArg>
// instance known to not carry any heap allocated value. void Set(DefaultArg, std::string&& value, Arena* arena) {
inline void InitAllocated(std::string* str, Arena* arena); return Set(std::move(value), arena);
}
template <typename DefaultArg>
void Set(DefaultArg, const char* s, Arena* arena) {
return Set(ConstStringParam{s}, arena);
}
template <typename DefaultArg>
void Set(DefaultArg, const char* s, size_t n, Arena* arena) {
return Set(ConstStringParam{s, n}, arena);
}
// Returns a mutable pointer, but doesn't initialize the string to the void SetBytes(EmptyDefault, ConstStringParam value, Arena* arena) {
// default value. return Set(value, arena);
std::string* MutableNoArenaNoDefault(const std::string* default_value); }
void SetBytes(NonEmptyDefault, ConstStringParam value, Arena* arena) {
return Set(value, arena);
}
void SetBytes(const std::string*, ConstStringParam value, Arena* arena) {
return Set(value, arena);
}
void SetBytes(EmptyDefault, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
void SetBytes(NonEmptyDefault, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
void SetBytes(const std::string*, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
void SetBytes(EmptyDefault, const char* s, Arena* arena) {
return Set(s, arena);
}
void SetBytes(NonEmptyDefault, const char* s, Arena* arena) {
return Set(s, arena);
}
void SetBytes(const std::string*, const char* s, Arena* arena) {
return Set(s, arena);
}
void SetBytes(EmptyDefault, const void* p, size_t n, Arena* arena) {
return SetBytes(p, n, arena);
}
void SetBytes(NonEmptyDefault, const void* p, size_t n, Arena* arena) {
return SetBytes(p, n, arena);
}
void SetBytes(const std::string*, const void* p, size_t n, Arena* arena) {
return SetBytes(p, n, arena);
}
std::string* Mutable(EmptyDefault, Arena* arena) { return Mutable(arena); }
std::string* MutableNoArenaNoDefault(const std::string*) {
return Mutable(nullptr);
}
std::string* MutableNoCopy(const std::string*, ::google::protobuf::Arena* arena) {
return MutableNoCopy(arena);
}
PROTOBUF_NODISCARD std::string* Release(const std::string*, Arena* arena) {
return Release();
}
PROTOBUF_NODISCARD std::string* ReleaseNonDefault(const std::string*,
Arena* arena) {
return Release();
}
// Get a mutable pointer with unspecified contents. void SetAllocated(const std::string*, std::string* value, Arena* arena) {
// Similar to `MutableNoArenaNoDefault`, but also handles the arena case. SetAllocated(value, arena);
// If the value was donated, the contents are discarded. }
std::string* MutableNoCopy(const std::string* default_value,
::google::protobuf::Arena* arena);
// Destroy the string. Assumes `arena == nullptr`. void Destroy(const std::string*, ::google::protobuf::Arena* arena) { Destroy(); }
void DestroyNoArena(const std::string* default_value); void Destroy(EmptyDefault, ::google::protobuf::Arena* arena) { Destroy(); }
void Destroy(NonEmptyDefault, ::google::protobuf::Arena* arena) { Destroy(); }
void DestroyNoArena(const std::string*) { Destroy(); }
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(const std::string*,
ArenaStringPtr* rhs,
Arena* rhs_arena,
ArenaStringPtr* lhs,
Arena* lhs_arena) {
InternalSwap(rhs, rhs_arena, lhs, lhs_arena);
}
#endif // DEPRECATED_METHODS_TO_BE_DELETED
// Internal setter used only at parse time to directly set a donated string // Internal setter used only at parse time to directly set a donated string
// value. // value.
@ -407,9 +479,6 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// Sets value to a newly allocated string and returns it // Sets value to a newly allocated string and returns it
std::string* SetAndReturnNewString(); std::string* SetAndReturnNewString();
// Destroys the non-default string value out-of-line
void DestroyNoArenaSlowPath();
friend class EpsCopyInputStream; friend class EpsCopyInputStream;
}; };
@ -417,7 +486,7 @@ inline void ArenaStringPtr::InitDefault() {
tagged_ptr_ = TaggedPtr<std::string>(&fixed_address_empty_string); tagged_ptr_ = TaggedPtr<std::string>(&fixed_address_empty_string);
} }
inline void ArenaStringPtr::InitDefault(const std::string* str) { inline void ArenaStringPtr::InitExternal(const std::string* str) {
tagged_ptr_.SetDefault(str); tagged_ptr_.SetDefault(str);
} }
@ -430,9 +499,32 @@ inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) {
} }
} }
inline void ArenaStringPtr::Set(const char* s, Arena* arena) {
Set(ConstStringParam{s}, arena);
}
inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) {
Set(ConstStringParam{s, n}, arena);
}
inline void ArenaStringPtr::SetBytes(ConstStringParam value, Arena* arena) {
Set(value, arena);
}
inline void ArenaStringPtr::SetBytes(std::string&& value, Arena* arena) {
Set(std::move(value), arena);
}
inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) {
Set(s, arena);
}
inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) {
Set(ConstStringParam{static_cast<const char*>(p), n}, arena);
}
// Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs. // Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs.
inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( // inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( //
const std::string*, //
ArenaStringPtr* rhs, Arena* rhs_arena, // ArenaStringPtr* rhs, Arena* rhs_arena, //
ArenaStringPtr* lhs, Arena* lhs_arena) { ArenaStringPtr* lhs, Arena* lhs_arena) {
// Silence unused variable warnings in release buildls. // Silence unused variable warnings in release buildls.
@ -466,28 +558,6 @@ inline void ArenaStringPtr::ClearNonDefaultToEmpty() {
tagged_ptr_.Get()->clear(); tagged_ptr_.Get()->clear();
} }
inline std::string* ArenaStringPtr::MutableNoArenaNoDefault(
const std::string* /* default_value */) {
// VERY IMPORTANT for performance and code size: this will reduce to a member
// variable load, a pointer check (against |default_value|, in practice a
// static global) and a branch to the slowpath (which calls operator new and
// the ctor). DO NOT add any tagged-pointer operations here.
GOOGLE_DCHECK(!tagged_ptr_.IsArena());
if (IsDefault()) {
return SetAndReturnNewString();
} else {
return UnsafeMutablePointer();
}
}
inline void ArenaStringPtr::DestroyNoArena(
const std::string* /* default_value */) {
GOOGLE_DCHECK(!tagged_ptr_.IsArena());
if (!IsDefault()) {
DestroyNoArenaSlowPath();
}
}
inline std::string* ArenaStringPtr::UnsafeMutablePointer() { inline std::string* ArenaStringPtr::UnsafeMutablePointer() {
GOOGLE_DCHECK(tagged_ptr_.IsMutable()); GOOGLE_DCHECK(tagged_ptr_.IsMutable());
GOOGLE_DCHECK(tagged_ptr_.Get() != nullptr); GOOGLE_DCHECK(tagged_ptr_.Get() != nullptr);

@ -34,6 +34,7 @@
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/logging.h>
@ -72,37 +73,36 @@ INSTANTIATE_TEST_SUITE_P(ArenaString, SingleArena, testing::Bool());
TEST_P(SingleArena, GetSet) { TEST_P(SingleArena, GetSet) {
auto arena = GetArena(); auto arena = GetArena();
ArenaStringPtr field; ArenaStringPtr field;
field.InitDefault(empty_default); field.InitDefault();
EXPECT_EQ("", field.Get()); EXPECT_EQ("", field.Get());
field.Set(empty_default, "Test short", arena.get()); field.Set("Test short", arena.get());
EXPECT_EQ("Test short", field.Get()); EXPECT_EQ("Test short", field.Get());
field.Set(empty_default, "Test long long long long value", arena.get()); field.Set("Test long long long long value", arena.get());
EXPECT_EQ("Test long long long long value", field.Get()); EXPECT_EQ("Test long long long long value", field.Get());
field.Set(empty_default, "", arena.get()); field.Set("", arena.get());
field.Destroy(empty_default, arena.get()); field.Destroy();
} }
TEST_P(SingleArena, MutableAccessor) { TEST_P(SingleArena, MutableAccessor) {
auto arena = GetArena(); auto arena = GetArena();
ArenaStringPtr field; ArenaStringPtr field;
const std::string* empty_default = &internal::GetEmptyString(); field.InitDefault();
field.InitDefault(empty_default);
std::string* mut = field.Mutable(EmptyDefault{}, arena.get()); std::string* mut = field.Mutable(arena.get());
EXPECT_EQ(mut, field.Mutable(EmptyDefault{}, arena.get())); EXPECT_EQ(mut, field.Mutable(arena.get()));
EXPECT_EQ(mut, &field.Get()); EXPECT_EQ(mut, &field.Get());
EXPECT_NE(empty_default, mut); EXPECT_NE(empty_default, mut);
EXPECT_EQ("", *mut); EXPECT_EQ("", *mut);
*mut = "Test long long long long value"; // ensure string allocates storage *mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ("Test long long long long value", field.Get()); EXPECT_EQ("Test long long long long value", field.Get());
field.Destroy(empty_default, arena.get()); field.Destroy();
} }
TEST_P(SingleArena, NullDefault) { TEST_P(SingleArena, NullDefault) {
auto arena = GetArena(); auto arena = GetArena();
ArenaStringPtr field; ArenaStringPtr field;
field.InitDefault(nullptr); field.InitDefault();
std::string* mut = field.Mutable(nonempty_default, arena.get()); std::string* mut = field.Mutable(nonempty_default, arena.get());
EXPECT_EQ(mut, field.Mutable(nonempty_default, arena.get())); EXPECT_EQ(mut, field.Mutable(nonempty_default, arena.get()));
EXPECT_EQ(mut, &field.Get()); EXPECT_EQ(mut, &field.Get());
@ -110,7 +110,7 @@ TEST_P(SingleArena, NullDefault) {
EXPECT_EQ("default", *mut); EXPECT_EQ("default", *mut);
*mut = "Test long long long long value"; // ensure string allocates storage *mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ("Test long long long long value", field.Get()); EXPECT_EQ("Test long long long long value", field.Get());
field.Destroy(nullptr, arena.get()); field.Destroy();
} }
class DualArena : public testing::TestWithParam<std::tuple<bool, bool>> { class DualArena : public testing::TestWithParam<std::tuple<bool, bool>> {
@ -131,23 +131,22 @@ INSTANTIATE_TEST_SUITE_P(ArenaString, DualArena,
TEST_P(DualArena, Swap) { TEST_P(DualArena, Swap) {
auto lhs_arena = GetLhsArena(); auto lhs_arena = GetLhsArena();
ArenaStringPtr lhs; ArenaStringPtr lhs;
lhs.InitDefault(empty_default); lhs.InitDefault();
ArenaStringPtr rhs; ArenaStringPtr rhs;
rhs.InitDefault(empty_default); rhs.InitDefault();
{ {
auto rhs_arena = GetRhsArena(); auto rhs_arena = GetRhsArena();
lhs.Set(empty_default, "lhs value that has some heft", lhs_arena.get()); lhs.Set("lhs value that has some heft", lhs_arena.get());
rhs.Set(empty_default, "rhs value that has some heft", rhs_arena.get()); rhs.Set("rhs value that has some heft", rhs_arena.get());
ArenaStringPtr::InternalSwap(empty_default, // ArenaStringPtr::InternalSwap(&lhs, lhs_arena.get(), //
&lhs, lhs_arena.get(), //
&rhs, rhs_arena.get()); &rhs, rhs_arena.get());
EXPECT_EQ("rhs value that has some heft", lhs.Get()); EXPECT_EQ("rhs value that has some heft", lhs.Get());
EXPECT_EQ("lhs value that has some heft", rhs.Get()); EXPECT_EQ("lhs value that has some heft", rhs.Get());
lhs.Destroy(empty_default, rhs_arena.get()); lhs.Destroy();
} }
EXPECT_EQ("lhs value that has some heft", rhs.Get()); EXPECT_EQ("lhs value that has some heft", rhs.Get());
rhs.Destroy(empty_default, lhs_arena.get()); rhs.Destroy();
} }

@ -91,7 +91,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"inline $type$ $classname$::_internal_$name$() const {\n" "inline $type$ $classname$::_internal_$name$() const {\n"
" return static_cast< $type$ >($name$_);\n" " return static_cast< $type$ >($field$);\n"
"}\n" "}\n"
"inline $type$ $classname$::$name$() const {\n" "inline $type$ $classname$::$name$() const {\n"
"$annotate_get$" "$annotate_get$"
@ -104,7 +104,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
} }
format( format(
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_ = value;\n" " $field$ = value;\n"
"}\n" "}\n"
"inline void $classname$::set_$name$($type$ value) {\n" "inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n" " _internal_set_$name$(value);\n"
@ -115,7 +115,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
void EnumFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void EnumFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_ = $default$;\n"); format("$field$ = $default$;\n");
} }
void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const { void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
@ -125,7 +125,7 @@ void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n"); format("swap($field$, other->$field$);\n");
} }
void EnumFieldGenerator::GenerateConstructorCode(io::Printer* printer) const { void EnumFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
@ -177,7 +177,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
format( format(
"inline $type$ $classname$::_internal_$name$() const {\n" "inline $type$ $classname$::_internal_$name$() const {\n"
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" return static_cast< $type$ >($field_member$);\n" " return static_cast< $type$ >($field$);\n"
" }\n" " }\n"
" return static_cast< $type$ >($default$);\n" " return static_cast< $type$ >($default$);\n"
"}\n" "}\n"
@ -195,7 +195,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" }\n" " }\n"
" $field_member$ = value;\n" " $field$ = value;\n"
"}\n" "}\n"
"inline void $classname$::set_$name$($type$ value) {\n" "inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n" " _internal_set_$name$(value);\n"
@ -206,7 +206,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void EnumOneofFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void EnumOneofFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$field_member$ = $default$;\n"); format("$field$ = $default$;\n");
} }
void EnumOneofFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void EnumOneofFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
@ -264,7 +264,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"inline $type$ $classname$::_internal_$name$(int index) const {\n" "inline $type$ $classname$::_internal_$name$(int index) const {\n"
" return static_cast< $type$ >($name$_.Get(index));\n" " return static_cast< $type$ >($field$.Get(index));\n"
"}\n" "}\n"
"inline $type$ $classname$::$name$(int index) const {\n" "inline $type$ $classname$::$name$(int index) const {\n"
"$annotate_get$" "$annotate_get$"
@ -276,7 +276,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
format(" assert($type$_IsValid(value));\n"); format(" assert($type$_IsValid(value));\n");
} }
format( format(
" $name$_.Set(index, value);\n" " $field$.Set(index, value);\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n" " // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n" "}\n"
@ -285,7 +285,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
format(" assert($type$_IsValid(value));\n"); format(" assert($type$_IsValid(value));\n");
} }
format( format(
" $name$_.Add(value);\n" " $field$.Add(value);\n"
"}\n" "}\n"
"inline void $classname$::add_$name$($type$ value) {\n" "inline void $classname$::add_$name$($type$ value) {\n"
" _internal_add_$name$(value);\n" " _internal_add_$name$(value);\n"
@ -296,11 +296,11 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
"$classname$::$name$() const {\n" "$classname$::$name$() const {\n"
"$annotate_list$" "$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n" " // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n" " return $field$;\n"
"}\n" "}\n"
"inline ::$proto_ns$::RepeatedField<int>*\n" "inline ::$proto_ns$::RepeatedField<int>*\n"
"$classname$::_internal_mutable_$name$() {\n" "$classname$::_internal_mutable_$name$() {\n"
" return &$name$_;\n" " return &$field$;\n"
"}\n" "}\n"
"inline ::$proto_ns$::RepeatedField<int>*\n" "inline ::$proto_ns$::RepeatedField<int>*\n"
"$classname$::mutable_$name$() {\n" "$classname$::mutable_$name$() {\n"
@ -313,19 +313,19 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
void RepeatedEnumFieldGenerator::GenerateClearingCode( void RepeatedEnumFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.Clear();\n"); format("$field$.Clear();\n");
} }
void RepeatedEnumFieldGenerator::GenerateMergingCode( void RepeatedEnumFieldGenerator::GenerateMergingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n"); format("$field$.MergeFrom(from.$field$);\n");
} }
void RepeatedEnumFieldGenerator::GenerateSwappingCode( void RepeatedEnumFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n"); format("$field$.InternalSwap(&other->$field$);\n");
} }
void RepeatedEnumFieldGenerator::GenerateConstructorCode( void RepeatedEnumFieldGenerator::GenerateConstructorCode(
@ -344,7 +344,7 @@ void RepeatedEnumFieldGenerator::GenerateSerializeWithCachedSizesToArray(
"_$name$_cached_byte_size_.load(std::memory_order_relaxed);\n" "_$name$_cached_byte_size_.load(std::memory_order_relaxed);\n"
" if (byte_size > 0) {\n" " if (byte_size > 0) {\n"
" target = stream->WriteEnumPacked(\n" " target = stream->WriteEnumPacked(\n"
" $number$, $name$_, byte_size, target);\n" " $number$, $field$, byte_size, target);\n"
" }\n" " }\n"
"}\n"); "}\n");
} else { } else {
@ -375,7 +375,8 @@ void RepeatedEnumFieldGenerator::GenerateByteSize(io::Printer* printer) const {
format( format(
"if (data_size > 0) {\n" "if (data_size > 0) {\n"
" total_size += $tag_size$ +\n" " total_size += $tag_size$ +\n"
" ::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n" " "
"::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n"
"}\n" "}\n"
"int cached_size = ::_pbi::ToCachedSize(data_size);\n" "int cached_size = ::_pbi::ToCachedSize(data_size);\n"
"_$name$_cached_byte_size_.store(cached_size,\n" "_$name$_cached_byte_size_.store(cached_size,\n"

@ -81,7 +81,7 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
std::string field_name = google::protobuf::compiler::cpp::FieldName(descriptor); std::string field_name = google::protobuf::compiler::cpp::FieldName(descriptor);
std::string field_pointer = std::string field_pointer =
descriptor->options().ctype() == google::protobuf::FieldOptions::STRING descriptor->options().ctype() == google::protobuf::FieldOptions::STRING
? "$0.GetPointer()" ? "$0.UnsafeGetPointer()"
: "$0"; : "$0";
if (descriptor->default_value_string().empty()) { if (descriptor->default_value_string().empty()) {
@ -114,7 +114,7 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor,
if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING) { if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING) {
return strings::Substitute( return strings::Substitute(
"$0.IsDefault() ? &$1.get() : $0.GetPointer()", field_member, "$0.IsDefault() ? &$1.get() : $0.UnsafeGetPointer()", field_member,
MakeDefaultName(descriptor)); MakeDefaultName(descriptor));
} }
@ -241,7 +241,12 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
(*variables)["number"] = StrCat(descriptor->number()); (*variables)["number"] = StrCat(descriptor->number());
(*variables)["classname"] = ClassName(FieldScope(descriptor), false); (*variables)["classname"] = ClassName(FieldScope(descriptor), false);
(*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type()); (*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type());
// TODO(b/218325252): convert all usages of "field_member" to "field" and
// remove this. The former may unnecessarily cause line breaks in protoc code.
// Note that the length of variables has no effect on the generated code. It
// only affects the readability of code template in protoc.
(*variables)["field_member"] = FieldMemberName(descriptor); (*variables)["field_member"] = FieldMemberName(descriptor);
(*variables)["field"] = FieldMemberName(descriptor);
(*variables)["tag_size"] = StrCat( (*variables)["tag_size"] = StrCat(
WireFormat::TagSize(descriptor->number(), descriptor->type())); WireFormat::TagSize(descriptor->number(), descriptor->type()));

@ -82,6 +82,12 @@ bool CppGenerator::Generate(const FileDescriptor* file,
// FOO_EXPORT is a macro which should expand to __declspec(dllexport) or // FOO_EXPORT is a macro which should expand to __declspec(dllexport) or
// __declspec(dllimport) depending on what is being compiled. // __declspec(dllimport) depending on what is being compiled.
// //
// If the proto_h option is passed to the compiler, we will generate all
// classes and enums so that they can be forward-declared from files that
// need them from imports.
//
// If the lite option is passed to the compiler, we will generate the
// current files and all transitive dependencies using the LITE runtime.
Options file_options; Options file_options;
file_options.opensource_runtime = opensource_runtime_; file_options.opensource_runtime = opensource_runtime_;
@ -111,6 +117,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.num_cc_files = file_options.num_cc_files =
strto32(options[i].second.c_str(), nullptr, 10); strto32(options[i].second.c_str(), nullptr, 10);
} }
} else if (options[i].first == "proto_h") {
file_options.proto_h = true;
} else if (options[i].first == "annotate_accessor") { } else if (options[i].first == "annotate_accessor") {
file_options.annotate_accessor = true; file_options.annotate_accessor = true;
} else if (options[i].first == "inject_field_listener_events") { } else if (options[i].first == "inject_field_listener_events") {

@ -1240,12 +1240,13 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) {
} else { } else {
format( format(
"inline int $classname$::_internal_$name$_size() const {\n" "inline int $classname$::_internal_$name$_size() const {\n"
" return $name$_$1$.size();\n" " return $1$$2$.size();\n"
"}\n" "}\n"
"inline int $classname$::$name$_size() const {\n" "inline int $classname$::$name$_size() const {\n"
"$annotate_size$" "$annotate_size$"
" return _internal_$name$_size();\n" " return _internal_$name$_size();\n"
"}\n", "}\n",
FieldMemberName(field),
IsImplicitWeakField(field, options_, scc_analyzer_) && IsImplicitWeakField(field, options_, scc_analyzer_) &&
field->message_type() field->message_type()
? ".weak" ? ".weak"
@ -1391,8 +1392,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
if (EnableMessageOwnedArena(descriptor_, options_)) { if (EnableMessageOwnedArena(descriptor_, options_)) {
format( format(
"inline $classname$() : $classname$(" "inline $classname$() : $classname$("
"::$proto_ns$::Arena::InternalHelper<$classname$>::\n" "::$proto_ns$::Arena::InternalCreateMessageOwnedArena(), true) {}\n");
" CreateMessageOwnedArena(), true) {}\n");
} else { } else {
format("inline $classname$() : $classname$(nullptr) {}\n"); format("inline $classname$() : $classname$(nullptr) {}\n");
} }

@ -182,14 +182,13 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
// If we're not on an arena, free whatever we were holding before. // If we're not on an arena, free whatever we were holding before.
// (If we are on arena, we can just forget the earlier pointer.) // (If we are on arena, we can just forget the earlier pointer.)
" if (GetArenaForAllocation() == nullptr) {\n" " if (GetArenaForAllocation() == nullptr) {\n"
" delete reinterpret_cast<::$proto_ns$::MessageLite*>($name$_);\n" " delete reinterpret_cast<::$proto_ns$::MessageLite*>($field$);\n"
" }\n"); " }\n");
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
" $name$_ = " " $field$ = reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
} else { } else {
format(" $name$_ = $name$;\n"); format(" $field$ = $name$;\n");
} }
format( format(
" if ($name$) {\n" " if ($name$) {\n"
@ -207,7 +206,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_release$" "$annotate_release$"
" $clear_hasbit$\n" " $clear_hasbit$\n"
" $type$* temp = $casted_member$;\n" " $type$* temp = $casted_member$;\n"
" $name$_ = nullptr;\n" " $field$ = nullptr;\n"
"#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE\n" "#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE\n"
" auto* old = reinterpret_cast<::$proto_ns$::MessageLite*>(temp);\n" " auto* old = reinterpret_cast<::$proto_ns$::MessageLite*>(temp);\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n" " temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
@ -225,7 +224,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$type_reference_function$" "$type_reference_function$"
" $clear_hasbit$\n" " $clear_hasbit$\n"
" $type$* temp = $casted_member$;\n" " $type$* temp = $casted_member$;\n"
" $name$_ = nullptr;\n" " $field$ = nullptr;\n"
" return temp;\n" " return temp;\n"
"}\n"); "}\n");
@ -233,12 +232,12 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"inline $type$* $classname$::_internal_mutable_$name$() {\n" "inline $type$* $classname$::_internal_mutable_$name$() {\n"
"$type_reference_function$" "$type_reference_function$"
" $set_hasbit$\n" " $set_hasbit$\n"
" if ($name$_ == nullptr) {\n" " if ($field$ == nullptr) {\n"
" auto* p = CreateMaybeMessage<$type$>(GetArenaForAllocation());\n"); " auto* p = CreateMaybeMessage<$type$>(GetArenaForAllocation());\n");
if (implicit_weak_field_) { if (implicit_weak_field_) {
format(" $name$_ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n"); format(" $field$ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n");
} else { } else {
format(" $name$_ = p;\n"); format(" $field$ = p;\n");
} }
format( format(
" }\n" " }\n"
@ -259,9 +258,9 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
format(" if (message_arena == nullptr) {\n"); format(" if (message_arena == nullptr) {\n");
if (IsCrossFileMessage(descriptor_)) { if (IsCrossFileMessage(descriptor_)) {
format( format(
" delete reinterpret_cast< ::$proto_ns$::MessageLite*>($name$_);\n"); " delete reinterpret_cast< ::$proto_ns$::MessageLite*>($field$);\n");
} else { } else {
format(" delete $name$_;\n"); format(" delete $field$;\n");
} }
format( format(
" }\n" " }\n"
@ -271,14 +270,13 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
// isn't defined in this file. // isn't defined in this file.
format( format(
" ::$proto_ns$::Arena* submessage_arena =\n" " ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<\n" " ::$proto_ns$::Arena::InternalGetOwningArena(\n"
" ::$proto_ns$::MessageLite>::GetOwningArena(\n"
" reinterpret_cast<::$proto_ns$::MessageLite*>(" " reinterpret_cast<::$proto_ns$::MessageLite*>("
"$name$));\n"); "$name$));\n");
} else { } else {
format( format(
" ::$proto_ns$::Arena* submessage_arena =\n" " ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<$type$>::GetOwningArena(" " ::$proto_ns$::Arena::InternalGetOwningArena("
"$name$);\n"); "$name$);\n");
} }
format( format(
@ -291,9 +289,9 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n" " $clear_hasbit$\n"
" }\n"); " }\n");
if (implicit_weak_field_) { if (implicit_weak_field_) {
format(" $name$_ = reinterpret_cast<MessageLite*>($name$);\n"); format(" $field$ = reinterpret_cast<MessageLite*>($name$);\n");
} else { } else {
format(" $name$_ = $name$;\n"); format(" $field$ = $name$;\n");
} }
format( format(
"$annotate_set$" "$annotate_set$"
@ -328,8 +326,8 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
format( format(
"const ::$proto_ns$::MessageLite& $classname$::_Internal::$name$(\n" "const ::$proto_ns$::MessageLite& $classname$::_Internal::$name$(\n"
" const $classname$* msg) {\n" " const $classname$* msg) {\n"
" if (msg->$field_member$ != nullptr) {\n" " if (msg->$field$ != nullptr) {\n"
" return *msg->$field_member$;\n" " return *msg->$field$;\n"
" } else {\n" " } else {\n"
" return *$type_default_instance_ptr$;\n" " return *$type_default_instance_ptr$;\n"
" }\n" " }\n"
@ -341,7 +339,7 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
format(" msg->$set_hasbit$\n"); format(" msg->$set_hasbit$\n");
} }
if (descriptor_->real_containing_oneof() == nullptr) { if (descriptor_->real_containing_oneof() == nullptr) {
format(" if (msg->$field_member$ == nullptr) {\n"); format(" if (msg->$field$ == nullptr) {\n");
} else { } else {
format( format(
" if (!msg->_internal_has_$name$()) {\n" " if (!msg->_internal_has_$name$()) {\n"
@ -349,10 +347,10 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
" msg->set_has_$name$();\n"); " msg->set_has_$name$();\n");
} }
format( format(
" msg->$field_member$ = $type_default_instance_ptr$->New(\n" " msg->$field$ = $type_default_instance_ptr$->New(\n"
" msg->GetArenaForAllocation());\n" " msg->GetArenaForAllocation());\n"
" }\n" " }\n"
" return msg->$field_member$;\n" " return msg->$field$;\n"
"}\n"); "}\n");
} else { } else {
// This inline accessor directly returns member field and is used in // This inline accessor directly returns member field and is used in
@ -361,7 +359,7 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
format( format(
"const $type$&\n" "const $type$&\n"
"$classname$::_Internal::$name$(const $classname$* msg) {\n" "$classname$::_Internal::$name$(const $classname$* msg) {\n"
" return *msg->$field_member$;\n" " return *msg->$field$;\n"
"}\n"); "}\n");
} }
} }
@ -374,12 +372,12 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
// If we don't have has-bits, message presence is indicated only by ptr != // If we don't have has-bits, message presence is indicated only by ptr !=
// nullptr. Thus on clear, we need to delete the object. // nullptr. Thus on clear, we need to delete the object.
format( format(
"if (GetArenaForAllocation() == nullptr && $name$_ != nullptr) {\n" "if (GetArenaForAllocation() == nullptr && $field$ != nullptr) {\n"
" delete $name$_;\n" " delete $field$;\n"
"}\n" "}\n"
"$name$_ = nullptr;\n"); "$field$ = nullptr;\n");
} else { } else {
format("if ($name$_ != nullptr) $name$_->Clear();\n"); format("if ($field$ != nullptr) $field$->Clear();\n");
} }
} }
@ -392,14 +390,14 @@ void MessageFieldGenerator::GenerateMessageClearingCode(
// If we don't have has-bits, message presence is indicated only by ptr != // If we don't have has-bits, message presence is indicated only by ptr !=
// nullptr. Thus on clear, we need to delete the object. // nullptr. Thus on clear, we need to delete the object.
format( format(
"if (GetArenaForAllocation() == nullptr && $name$_ != nullptr) {\n" "if (GetArenaForAllocation() == nullptr && $field$ != nullptr) {\n"
" delete $name$_;\n" " delete $field$;\n"
"}\n" "}\n"
"$name$_ = nullptr;\n"); "$field$ = nullptr;\n");
} else { } else {
format( format(
"$DCHK$($name$_ != nullptr);\n" "$DCHK$($field$ != nullptr);\n"
"$name$_->Clear();\n"); "$field$->Clear();\n");
} }
} }
@ -422,7 +420,7 @@ void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n"); format("swap($field$, other->$field$);\n");
} }
void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
@ -487,7 +485,7 @@ void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const {
format( format(
"total_size += $tag_size$ +\n" "total_size += $tag_size$ +\n"
" ::$proto_ns$::internal::WireFormatLite::$declared_type$Size(\n" " ::$proto_ns$::internal::WireFormatLite::$declared_type$Size(\n"
" *$field_member$);\n"); " *$field$);\n");
} }
void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const { void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
@ -498,7 +496,7 @@ void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"if (_internal_has_$name$()) {\n" "if (_internal_has_$name$()) {\n"
" if (!$name$_->IsInitialized()) return false;\n" " if (!$field$->IsInitialized()) return false;\n"
"}\n"); "}\n");
} }
@ -532,15 +530,13 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
// isn't defined in this file. // isn't defined in this file.
format( format(
" ::$proto_ns$::Arena* submessage_arena =\n" " ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<\n" " ::$proto_ns$::Arena::InternalGetOwningArena(\n"
" ::$proto_ns$::MessageLite>::GetOwningArena(\n"
" reinterpret_cast<::$proto_ns$::MessageLite*>(" " reinterpret_cast<::$proto_ns$::MessageLite*>("
"$name$));\n"); "$name$));\n");
} else { } else {
format( format(
" ::$proto_ns$::Arena* submessage_arena =\n" " ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<" " ::$proto_ns$::Arena::InternalGetOwningArena($name$);\n");
"$type$>::GetOwningArena($name$);\n");
} }
format( format(
" if (message_arena != submessage_arena) {\n" " if (message_arena != submessage_arena) {\n"
@ -548,7 +544,7 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
" message_arena, $name$, submessage_arena);\n" " message_arena, $name$, submessage_arena);\n"
" }\n" " }\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$ = $name$;\n" " $field$ = $name$;\n"
" }\n" " }\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
@ -569,7 +565,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (GetArenaForAllocation() != nullptr) {\n" " if (GetArenaForAllocation() != nullptr) {\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n" " temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
" }\n" " }\n"
" $field_member$ = nullptr;\n" " $field$ = nullptr;\n"
" return temp;\n" " return temp;\n"
" } else {\n" " } else {\n"
" return nullptr;\n" " return nullptr;\n"
@ -596,7 +592,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n" " clear_has_$oneof_name$();\n"
" $type$* temp = $casted_member$;\n" " $type$* temp = $casted_member$;\n"
" $field_member$ = nullptr;\n" " $field$ = nullptr;\n"
" return temp;\n" " return temp;\n"
" } else {\n" " } else {\n"
" return nullptr;\n" " return nullptr;\n"
@ -612,10 +608,10 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n"); " set_has_$name$();\n");
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
" $field_member$ = " " $field$ = "
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n"); "reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
} else { } else {
format(" $field_member$ = $name$;\n"); format(" $field$ = $name$;\n");
} }
format( format(
" }\n" " }\n"
@ -630,12 +626,12 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n"); " set_has_$name$();\n");
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
" $field_member$ = " " $field$ = "
"reinterpret_cast<::$proto_ns$::MessageLite*>(CreateMaybeMessage< " "reinterpret_cast<::$proto_ns$::MessageLite*>(CreateMaybeMessage< "
"$type$ >(GetArenaForAllocation()));\n"); "$type$ >(GetArenaForAllocation()));\n");
} else { } else {
format( format(
" $field_member$ = CreateMaybeMessage< $type$ " " $field$ = CreateMaybeMessage< $type$ "
">(GetArenaForAllocation());\n"); ">(GetArenaForAllocation());\n");
} }
format( format(
@ -657,7 +653,7 @@ void MessageOneofFieldGenerator::GenerateClearingCode(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"if (GetArenaForAllocation() == nullptr) {\n" "if (GetArenaForAllocation() == nullptr) {\n"
" delete $field_member$;\n" " delete $field$;\n"
"}\n"); "}\n");
} }
@ -690,7 +686,7 @@ void MessageOneofFieldGenerator::GenerateIsInitialized(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"if (_internal_has_$name$()) {\n" "if (_internal_has_$name$()) {\n"
" if (!$field_member$->IsInitialized()) return false;\n" " if (!$field$->IsInitialized()) return false;\n"
"}\n"); "}\n");
} }
@ -769,21 +765,21 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
// TODO(dlj): move insertion points // TODO(dlj): move insertion points
" // @@protoc_insertion_point(field_mutable:$full_name$)\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
"$type_reference_function$" "$type_reference_function$"
" return $name$_$weak$.Mutable(index);\n" " return $field$$weak$.Mutable(index);\n"
"}\n" "}\n"
"inline ::$proto_ns$::RepeatedPtrField< $type$ >*\n" "inline ::$proto_ns$::RepeatedPtrField< $type$ >*\n"
"$classname$::mutable_$name$() {\n" "$classname$::mutable_$name$() {\n"
"$annotate_mutable_list$" "$annotate_mutable_list$"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
"$type_reference_function$" "$type_reference_function$"
" return &$name$_$weak$;\n" " return &$field$$weak$;\n"
"}\n"); "}\n");
if (options_.safe_boundary_check) { if (options_.safe_boundary_check) {
format( format(
"inline const $type$& $classname$::_internal_$name$(int index) const " "inline const $type$& $classname$::_internal_$name$(int index) const "
"{\n" "{\n"
" return $name$_$weak$.InternalCheckedGet(index,\n" " return $field$$weak$.InternalCheckedGet(index,\n"
" reinterpret_cast<const $type$&>($type_default_instance$));\n" " reinterpret_cast<const $type$&>($type_default_instance$));\n"
"}\n"); "}\n");
} else { } else {
@ -791,7 +787,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
"inline const $type$& $classname$::_internal_$name$(int index) const " "inline const $type$& $classname$::_internal_$name$(int index) const "
"{\n" "{\n"
"$type_reference_function$" "$type_reference_function$"
" return $name$_$weak$.Get(index);\n" " return $field$$weak$.Get(index);\n"
"}\n"); "}\n");
} }
@ -802,7 +798,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
" return _internal_$name$(index);\n" " return _internal_$name$(index);\n"
"}\n" "}\n"
"inline $type$* $classname$::_internal_add_$name$() {\n" "inline $type$* $classname$::_internal_add_$name$() {\n"
" return $name$_$weak$.Add();\n" " return $field$$weak$.Add();\n"
"}\n" "}\n"
"inline $type$* $classname$::add_$name$() {\n" "inline $type$* $classname$::add_$name$() {\n"
" $type$* _add = _internal_add_$name$();\n" " $type$* _add = _internal_add_$name$();\n"
@ -817,7 +813,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_list$" "$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n" " // @@protoc_insertion_point(field_list:$full_name$)\n"
"$type_reference_function$" "$type_reference_function$"
" return $name$_$weak$;\n" " return $field$$weak$;\n"
"}\n"); "}\n");
} }
@ -826,7 +822,7 @@ void RepeatedMessageFieldGenerator::GenerateClearingCode(
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.Clear();\n"); format("$field$.Clear();\n");
} }
void RepeatedMessageFieldGenerator::GenerateMergingCode( void RepeatedMessageFieldGenerator::GenerateMergingCode(
@ -834,7 +830,7 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode(
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n"); format("$field$.MergeFrom(from.$field$);\n");
} }
void RepeatedMessageFieldGenerator::GenerateSwappingCode( void RepeatedMessageFieldGenerator::GenerateSwappingCode(
@ -842,7 +838,7 @@ void RepeatedMessageFieldGenerator::GenerateSwappingCode(
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n"); format("$field$.InternalSwap(&other->$field$);\n");
} }
void RepeatedMessageFieldGenerator::GenerateConstructorCode( void RepeatedMessageFieldGenerator::GenerateConstructorCode(
@ -857,8 +853,8 @@ void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
"for (auto it = this->$name$_.pointer_begin(),\n" "for (auto it = this->$field$.pointer_begin(),\n"
" end = this->$name$_.pointer_end(); it < end; ++it) {\n"); " end = this->$field$.pointer_end(); it < end; ++it) {\n");
if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) { if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) {
format( format(
" target = ::$proto_ns$::internal::WireFormatLite::\n" " target = ::$proto_ns$::internal::WireFormatLite::\n"
@ -902,7 +898,7 @@ void RepeatedMessageFieldGenerator::GenerateByteSize(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"total_size += $tag_size$UL * this->_internal_$name$_size();\n" "total_size += $tag_size$UL * this->_internal_$name$_size();\n"
"for (const auto& msg : this->$name$_) {\n" "for (const auto& msg : this->$field$) {\n"
" total_size +=\n" " total_size +=\n"
" ::$proto_ns$::internal::WireFormatLite::$declared_type$Size(msg);\n" " ::$proto_ns$::internal::WireFormatLite::$declared_type$Size(msg);\n"
"}\n"); "}\n");
@ -917,11 +913,11 @@ void RepeatedMessageFieldGenerator::GenerateIsInitialized(
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
"if (!::$proto_ns$::internal::AllAreInitializedWeak($name$_.weak))\n" "if (!::$proto_ns$::internal::AllAreInitializedWeak($field$.weak))\n"
" return false;\n"); " return false;\n");
} else { } else {
format( format(
"if (!::$proto_ns$::internal::AllAreInitialized($name$_))\n" "if (!::$proto_ns$::internal::AllAreInitialized($field$))\n"
" return false;\n"); " return false;\n");
} }
} }

@ -92,8 +92,7 @@ bool IsFieldEligibleForFastParsing(
return false; return false;
} }
switch (field->type()) { switch (field->type()) {
// Strings, enums, and groups are not handled on the fast path. // Groups are not handled on the fast path.
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_GROUP: case FieldDescriptor::TYPE_GROUP:
return false; return false;
@ -109,6 +108,7 @@ bool IsFieldEligibleForFastParsing(
break; break;
// Some bytes fields can be handled on fast path. // Some bytes fields can be handled on fast path.
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_BYTES:
if (field->options().ctype() != FieldOptions::STRING || if (field->options().ctype() != FieldOptions::STRING ||
!field->default_value_string().empty() || !field->default_value_string().empty() ||
@ -237,15 +237,15 @@ std::vector<const FieldDescriptor*> FilterMiniParsedFields(
} }
break; break;
// TODO(b/209516305): add TYPE_STRING once field names are available. case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING:
if (IsStringInlined(field, options)) { if (IsStringInlined(field, options)) {
// TODO(b/198211897): support InilnedStringField. // TODO(b/198211897): support InilnedStringField.
handled = false; handled = false;
} else { } else {
handled = true; handled = true;
} }
break; break;
case FieldDescriptor::TYPE_MESSAGE: case FieldDescriptor::TYPE_MESSAGE:
// TODO(b/210762816): support remaining field types. // TODO(b/210762816): support remaining field types.
@ -777,9 +777,9 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) {
} else { } else {
format( format(
"{$1$,\n" "{$1$,\n"
" {$2$, $3$, $4$, PROTOBUF_FIELD_OFFSET($classname$, $5$_)}},\n", " {$2$, $3$, $4$, PROTOBUF_FIELD_OFFSET($classname$, $5$)}},\n",
info.func_name, info.coded_tag, info.hasbit_idx, info.aux_idx, info.func_name, info.coded_tag, info.hasbit_idx, info.aux_idx,
FieldName(info.field)); FieldMemberName(info.field));
} }
} }
} }
@ -1003,7 +1003,7 @@ void ParseFunctionGenerator::GenerateArenaString(Formatter& format,
"::" + MakeDefaultName(field) + ".get()"; "::" + MakeDefaultName(field) + ".get()";
format( format(
"if (arena != nullptr) {\n" "if (arena != nullptr) {\n"
" ptr = ctx->ReadArenaString(ptr, &$msg$$name$_, arena"); " ptr = ctx->ReadArenaString(ptr, &$msg$$field$, arena");
if (IsStringInlined(field, options_)) { if (IsStringInlined(field, options_)) {
GOOGLE_DCHECK(!inlined_string_indices_.empty()); GOOGLE_DCHECK(!inlined_string_indices_.empty());
int inlined_string_index = inlined_string_indices_[field->index()]; int inlined_string_index = inlined_string_indices_[field->index()];
@ -1022,10 +1022,9 @@ void ParseFunctionGenerator::GenerateArenaString(Formatter& format,
");\n" ");\n"
"} else {\n" "} else {\n"
" ptr = ::_pbi::InlineGreedyStringParser(" " ptr = ::_pbi::InlineGreedyStringParser("
"$msg$$name$_.MutableNoArenaNoDefault(&$1$), ptr, ctx);\n" "$msg$$field$.MutableNoCopy(nullptr), ptr, ctx);\n"
"}\n" "}\n"
"const std::string* str = &$msg$$name$_.Get(); (void)str;\n", "const std::string* str = &$msg$$field$.Get(); (void)str;\n");
default_string);
} }
void ParseFunctionGenerator::GenerateStrings(Formatter& format, void ParseFunctionGenerator::GenerateStrings(Formatter& format,
@ -1134,13 +1133,13 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
format( format(
"auto object = " "auto object = "
"::$proto_ns$::internal::InitEnumParseWrapper<" "::$proto_ns$::internal::InitEnumParseWrapper<"
"$unknown_fields_type$>(&$msg$$name$_, $1$_IsValid, " "$unknown_fields_type$>(&$msg$$field$, $1$_IsValid, "
"$2$, &$msg$_internal_metadata_);\n" "$2$, &$msg$_internal_metadata_);\n"
"ptr = ctx->ParseMessage(&object, ptr);\n", "ptr = ctx->ParseMessage(&object, ptr);\n",
QualifiedClassName(val->enum_type(), options_), QualifiedClassName(val->enum_type(), options_),
field->number()); field->number());
} else { } else {
format("ptr = ctx->ParseMessage(&$msg$$name$_, ptr);\n"); format("ptr = ctx->ParseMessage(&$msg$$field$, ptr);\n");
} }
} else if (IsLazy(field, options_, scc_analyzer_)) { } else if (IsLazy(field, options_, scc_analyzer_)) {
bool eager_verify = bool eager_verify =
@ -1157,19 +1156,19 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
format( format(
"if (!$msg$_internal_has_$name$()) {\n" "if (!$msg$_internal_has_$name$()) {\n"
" $msg$clear_$1$();\n" " $msg$clear_$1$();\n"
" $msg$$1$_.$name$_ = ::$proto_ns$::Arena::CreateMessage<\n" " $msg$$field$ = ::$proto_ns$::Arena::CreateMessage<\n"
" ::$proto_ns$::internal::LazyField>(" " ::$proto_ns$::internal::LazyField>("
"$msg$GetArenaForAllocation());\n" "$msg$GetArenaForAllocation());\n"
" $msg$set_has_$name$();\n" " $msg$set_has_$name$();\n"
"}\n" "}\n"
"auto* lazy_field = $msg$$1$_.$name$_;\n", "auto* lazy_field = $msg$$field$;\n",
field->containing_oneof()->name()); field->containing_oneof()->name());
} else if (HasHasbit(field)) { } else if (HasHasbit(field)) {
format( format(
"_Internal::set_has_$name$(&$has_bits$);\n" "_Internal::set_has_$name$(&$has_bits$);\n"
"auto* lazy_field = &$msg$$name$_;\n"); "auto* lazy_field = &$msg$$field$;\n");
} else { } else {
format("auto* lazy_field = &$msg$$name$_;\n"); format("auto* lazy_field = &$msg$$field$;\n");
} }
format( format(
"::$proto_ns$::internal::LazyFieldParseHelper<\n" "::$proto_ns$::internal::LazyFieldParseHelper<\n"
@ -1192,7 +1191,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
"ptr);\n"); "ptr);\n");
} else { } else {
format( format(
"ptr = ctx->ParseMessage($msg$$name$_.AddWeak(" "ptr = ctx->ParseMessage($msg$$field$.AddWeak("
"reinterpret_cast<const ::$proto_ns$::MessageLite*>($1$ptr_)" "reinterpret_cast<const ::$proto_ns$::MessageLite*>($1$ptr_)"
"), ptr);\n", "), ptr);\n",
QualifiedDefaultInstanceName(field->message_type(), options_)); QualifiedDefaultInstanceName(field->message_type(), options_));
@ -1291,7 +1290,7 @@ void ParseFunctionGenerator::GenerateFieldBody(
format("_Internal::set_has_$name$(&$has_bits$);\n"); format("_Internal::set_has_$name$(&$has_bits$);\n");
} }
format( format(
"$msg$$name$_ = ::$proto_ns$::internal::ReadVarint$1$$2$(&ptr);\n" "$msg$$field$ = ::$proto_ns$::internal::ReadVarint$1$$2$(&ptr);\n"
"CHK_(ptr);\n", "CHK_(ptr);\n",
zigzag, size); zigzag, size);
} }
@ -1438,6 +1437,8 @@ void ParseFunctionGenerator::GenerateFieldSwitch(
format.Indent(); format.Indent();
for (const auto* field : fields) { for (const auto* field : fields) {
// Set abbreviated form instead of field_member.
format.Set("field", FieldMemberName(field));
PrintFieldComment(format, field); PrintFieldComment(format, field);
format("case $1$:\n", field->number()); format("case $1$:\n", field->number());
format.Indent(); format.Indent();

@ -150,7 +150,7 @@ void PrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"inline $type$ $classname$::_internal_$name$() const {\n" "inline $type$ $classname$::_internal_$name$() const {\n"
" return $name$_;\n" " return $field$;\n"
"}\n" "}\n"
"inline $type$ $classname$::$name$() const {\n" "inline $type$ $classname$::$name$() const {\n"
"$annotate_get$" "$annotate_get$"
@ -159,7 +159,7 @@ void PrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n" "}\n"
"inline void $classname$::_internal_set_$name$($type$ value) {\n" "inline void $classname$::_internal_set_$name$($type$ value) {\n"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_ = value;\n" " $field$ = value;\n"
"}\n" "}\n"
"inline void $classname$::set_$name$($type$ value) {\n" "inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n" " _internal_set_$name$(value);\n"
@ -170,7 +170,7 @@ void PrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
void PrimitiveFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void PrimitiveFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_ = $default$;\n"); format("$field$ = $default$;\n");
} }
void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) const { void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
@ -180,7 +180,7 @@ void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
void PrimitiveFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void PrimitiveFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n"); format("swap($field$, other->$field$);\n");
} }
void PrimitiveFieldGenerator::GenerateConstructorCode( void PrimitiveFieldGenerator::GenerateConstructorCode(
@ -249,7 +249,7 @@ void PrimitiveOneofFieldGenerator::GenerateInlineAccessorDefinitions(
format( format(
"inline $type$ $classname$::_internal_$name$() const {\n" "inline $type$ $classname$::_internal_$name$() const {\n"
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" return $field_member$;\n" " return $field$;\n"
" }\n" " }\n"
" return $default$;\n" " return $default$;\n"
"}\n" "}\n"
@ -258,7 +258,7 @@ void PrimitiveOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" }\n" " }\n"
" $field_member$ = value;\n" " $field$ = value;\n"
"}\n" "}\n"
"inline $type$ $classname$::$name$() const {\n" "inline $type$ $classname$::$name$() const {\n"
"$annotate_get$" "$annotate_get$"
@ -275,7 +275,7 @@ void PrimitiveOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void PrimitiveOneofFieldGenerator::GenerateClearingCode( void PrimitiveOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$field_member$ = $default$;\n"); format("$field$ = $default$;\n");
} }
void PrimitiveOneofFieldGenerator::GenerateSwappingCode( void PrimitiveOneofFieldGenerator::GenerateSwappingCode(
@ -344,7 +344,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"inline $type$ $classname$::_internal_$name$(int index) const {\n" "inline $type$ $classname$::_internal_$name$(int index) const {\n"
" return $name$_.Get(index);\n" " return $field$.Get(index);\n"
"}\n" "}\n"
"inline $type$ $classname$::$name$(int index) const {\n" "inline $type$ $classname$::$name$(int index) const {\n"
"$annotate_get$" "$annotate_get$"
@ -353,11 +353,11 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n" "}\n"
"inline void $classname$::set_$name$(int index, $type$ value) {\n" "inline void $classname$::set_$name$(int index, $type$ value) {\n"
"$annotate_set$" "$annotate_set$"
" $name$_.Set(index, value);\n" " $field$.Set(index, value);\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n" " // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::_internal_add_$name$($type$ value) {\n" "inline void $classname$::_internal_add_$name$($type$ value) {\n"
" $name$_.Add(value);\n" " $field$.Add(value);\n"
"}\n" "}\n"
"inline void $classname$::add_$name$($type$ value) {\n" "inline void $classname$::add_$name$($type$ value) {\n"
" _internal_add_$name$(value);\n" " _internal_add_$name$(value);\n"
@ -366,7 +366,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n" "}\n"
"inline const ::$proto_ns$::RepeatedField< $type$ >&\n" "inline const ::$proto_ns$::RepeatedField< $type$ >&\n"
"$classname$::_internal_$name$() const {\n" "$classname$::_internal_$name$() const {\n"
" return $name$_;\n" " return $field$;\n"
"}\n" "}\n"
"inline const ::$proto_ns$::RepeatedField< $type$ >&\n" "inline const ::$proto_ns$::RepeatedField< $type$ >&\n"
"$classname$::$name$() const {\n" "$classname$::$name$() const {\n"
@ -376,7 +376,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n" "}\n"
"inline ::$proto_ns$::RepeatedField< $type$ >*\n" "inline ::$proto_ns$::RepeatedField< $type$ >*\n"
"$classname$::_internal_mutable_$name$() {\n" "$classname$::_internal_mutable_$name$() {\n"
" return &$name$_;\n" " return &$field$;\n"
"}\n" "}\n"
"inline ::$proto_ns$::RepeatedField< $type$ >*\n" "inline ::$proto_ns$::RepeatedField< $type$ >*\n"
"$classname$::mutable_$name$() {\n" "$classname$::mutable_$name$() {\n"
@ -389,30 +389,19 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
void RepeatedPrimitiveFieldGenerator::GenerateClearingCode( void RepeatedPrimitiveFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.Clear();\n"); format("$field$.Clear();\n");
} }
void RepeatedPrimitiveFieldGenerator::GenerateMergingCode( void RepeatedPrimitiveFieldGenerator::GenerateMergingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n"); format("$field$.MergeFrom(from.$field$);\n");
} }
void RepeatedPrimitiveFieldGenerator::GenerateSwappingCode( void RepeatedPrimitiveFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n"); format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
// Not needed for repeated fields.
}
void RepeatedPrimitiveFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.CopyFrom(from.$name$_);\n");
} }
void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray(
@ -456,7 +445,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize(
if (fixed_size == -1) { if (fixed_size == -1) {
format( format(
"size_t data_size = ::_pbi::WireFormatLite::\n" "size_t data_size = ::_pbi::WireFormatLite::\n"
" $declared_type$Size(this->$name$_);\n"); " $declared_type$Size(this->$field$);\n");
} else { } else {
format( format(
"unsigned int count = static_cast<unsigned " "unsigned int count = static_cast<unsigned "

@ -98,8 +98,8 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override; void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override; void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override; void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override; void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateSerializeWithCachedSizesToArray( void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override; io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override; void GenerateByteSize(io::Printer* printer) const override;

@ -54,8 +54,6 @@ void SetStringVariables(const FieldDescriptor* descriptor,
const std::string kNS = "::" + (*variables)["proto_ns"] + "::internal::"; const std::string kNS = "::" + (*variables)["proto_ns"] + "::internal::";
const std::string kArenaStringPtr = kNS + "ArenaStringPtr"; const std::string kArenaStringPtr = kNS + "ArenaStringPtr";
const std::string kEmptyDefault = kArenaStringPtr + "::EmptyDefault{}";
const std::string kNonEmptyDefault = kArenaStringPtr + "::NonEmptyDefault{}";
(*variables)["default"] = DefaultValue(options, descriptor); (*variables)["default"] = DefaultValue(options, descriptor);
(*variables)["default_length"] = (*variables)["default_length"] =
@ -64,21 +62,17 @@ void SetStringVariables(const FieldDescriptor* descriptor,
(*variables)["default_variable_name"] = default_variable_string; (*variables)["default_variable_name"] = default_variable_string;
if (descriptor->default_value_string().empty()) { if (descriptor->default_value_string().empty()) {
(*variables)["init_value"] = "";
(*variables)["default_string"] = kNS + "GetEmptyStringAlreadyInited()"; (*variables)["default_string"] = kNS + "GetEmptyStringAlreadyInited()";
(*variables)["default_value"] = "&" + (*variables)["default_string"]; (*variables)["default_value"] = "&" + (*variables)["default_string"];
(*variables)["default_value_tag"] = kEmptyDefault; (*variables)["lazy_variable_args"] = "";
(*variables)["default_variable_or_tag"] = kEmptyDefault;
} else { } else {
(*variables)["lazy_variable"] = (*variables)["lazy_variable"] =
QualifiedClassName(descriptor->containing_type(), options) + QualifiedClassName(descriptor->containing_type(), options) +
"::" + default_variable_string; "::" + default_variable_string;
(*variables)["init_value"] = "nullptr";
(*variables)["default_string"] = (*variables)["lazy_variable"] + ".get()"; (*variables)["default_string"] = (*variables)["lazy_variable"] + ".get()";
(*variables)["default_value"] = "nullptr"; (*variables)["default_value"] = "nullptr";
(*variables)["default_value_tag"] = kNonEmptyDefault; (*variables)["lazy_variable_args"] = (*variables)["lazy_variable"] + ", ";
(*variables)["default_variable_or_tag"] = (*variables)["lazy_variable"];
} }
(*variables)["pointer_type"] = (*variables)["pointer_type"] =
@ -210,7 +204,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" // @@protoc_insertion_point(field_get:$full_name$)\n"); " // @@protoc_insertion_point(field_get:$full_name$)\n");
if (!descriptor_->default_value_string().empty()) { if (!descriptor_->default_value_string().empty()) {
format( format(
" if ($name$_.IsDefault()) return " " if ($field$.IsDefault()) return "
"$default_variable_name$.get();\n"); "$default_variable_name$.get();\n");
} }
format( format(
@ -222,7 +216,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline PROTOBUF_ALWAYS_INLINE\n" "inline PROTOBUF_ALWAYS_INLINE\n"
"void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n" "void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.$setter$($default_value_tag$, static_cast<ArgT0 &&>(arg0)," " $field$.$setter$(static_cast<ArgT0 &&>(arg0),"
" args..., GetArenaForAllocation());\n" " args..., GetArenaForAllocation());\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n" " // @@protoc_insertion_point(field_set:$full_name$)\n"
@ -233,7 +227,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline PROTOBUF_ALWAYS_INLINE\n" "inline PROTOBUF_ALWAYS_INLINE\n"
"void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n" "void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.$setter$(nullptr, static_cast<ArgT0 &&>(arg0)," " $field$.$setter$(static_cast<ArgT0 &&>(arg0),"
" args..., GetArenaForAllocation(), _internal_$name$_donated(), " " args..., GetArenaForAllocation(), _internal_$name$_donated(), "
"&$donating_states_word$, $mask_for_undonate$, this);\n" "&$donating_states_word$, $mask_for_undonate$, this);\n"
"$annotate_set$" "$annotate_set$"
@ -252,18 +246,18 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" return _s;\n" " return _s;\n"
"}\n" "}\n"
"inline const std::string& $classname$::_internal_$name$() const {\n" "inline const std::string& $classname$::_internal_$name$() const {\n"
" return $name$_.Get();\n" " return $field$.Get();\n"
"}\n" "}\n"
"inline void $classname$::_internal_set_$name$(const std::string& " "inline void $classname$::_internal_set_$name$(const std::string& "
"value) {\n" "value) {\n"
" $set_hasbit$\n"); " $set_hasbit$\n");
if (!inlined_) { if (!inlined_) {
format( format(
" $name$_.Set($default_value_tag$, value, GetArenaForAllocation());\n" " $field$.Set(value, GetArenaForAllocation());\n"
"}\n"); "}\n");
} else { } else {
format( format(
" $name$_.Set(nullptr, value, GetArenaForAllocation(),\n" " $field$.Set(value, GetArenaForAllocation(),\n"
" _internal_$name$_donated(), &$donating_states_word$, " " _internal_$name$_donated(), &$donating_states_word$, "
"$mask_for_undonate$, this);\n" "$mask_for_undonate$, this);\n"
"}\n"); "}\n");
@ -273,12 +267,12 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $set_hasbit$\n"); " $set_hasbit$\n");
if (!inlined_) { if (!inlined_) {
format( format(
" return $name$_.Mutable($default_variable_or_tag$, " " return $field$.Mutable($lazy_variable_args$"
"GetArenaForAllocation());\n" "GetArenaForAllocation());\n"
"}\n"); "}\n");
} else { } else {
format( format(
" return $name$_.Mutable($default_variable_or_tag$, " " return $field$.Mutable($lazy_variable_args$"
"GetArenaForAllocation(), _internal_$name$_donated(), " "GetArenaForAllocation(), _internal_$name$_donated(), "
"&$donating_states_word$, $mask_for_undonate$, this);\n" "&$donating_states_word$, $mask_for_undonate$, this);\n"
"}\n"); "}\n");
@ -295,26 +289,23 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" }\n" " }\n"
" $clear_hasbit$\n"); " $clear_hasbit$\n");
if (!inlined_) { if (!inlined_) {
format( format(" auto* p = $field$.Release();\n");
" auto* p = $name$_.ReleaseNonDefault($default_value$, "
"GetArenaForAllocation());\n");
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
format( format(
"#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n" "#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"
" if ($name$_.IsDefault()) {\n" " if ($field$.IsDefault()) {\n"
" $name$_.Set($default_value$, \"\", GetArenaForAllocation());\n" " $field$.Set(\"\", GetArenaForAllocation());\n"
" }\n" " }\n"
"#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"); "#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n");
} }
format(" return p;\n"); format(" return p;\n");
} else { } else {
format( format(
" return $name$_.Release(nullptr, GetArenaForAllocation(), " " return $field$.Release(GetArenaForAllocation(), "
"_internal_$name$_donated());\n"); "_internal_$name$_donated());\n");
} }
} else { } else {
format( format(" return $field$.Release();\n");
" return $name$_.Release($default_value$, GetArenaForAllocation());\n");
} }
format( format(
@ -326,21 +317,19 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n" " $clear_hasbit$\n"
" }\n"); " }\n");
if (!inlined_) { if (!inlined_) {
format( format(" $field$.SetAllocated($name$, GetArenaForAllocation());\n");
" $name$_.SetAllocated($default_value$, $name$,\n"
" GetArenaForAllocation());\n");
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
format( format(
"#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n" "#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"
" if ($name$_.IsDefault()) {\n" " if ($field$.IsDefault()) {\n"
" $name$_.Set($default_value$, \"\", GetArenaForAllocation());\n" " $field$.Set(\"\", GetArenaForAllocation());\n"
" }\n" " }\n"
"#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"); "#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n");
} }
} else { } else {
// Currently, string fields with default value can't be inlined. // Currently, string fields with default value can't be inlined.
format( format(
" $name$_.SetAllocated(nullptr, $name$, GetArenaForAllocation(), " " $field$.SetAllocated(nullptr, $name$, GetArenaForAllocation(), "
"_internal_$name$_donated(), &$donating_states_word$, " "_internal_$name$_donated(), &$donating_states_word$, "
"$mask_for_undonate$, this);\n"); "$mask_for_undonate$, this);\n");
} }
@ -364,11 +353,11 @@ void StringFieldGenerator::GenerateNonInlineAccessorDefinitions(
void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
format("$name$_.ClearToEmpty();\n"); format("$field$.ClearToEmpty();\n");
} else { } else {
GOOGLE_DCHECK(!inlined_); GOOGLE_DCHECK(!inlined_);
format( format(
"$name$_.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n"); "$field$.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n");
} }
} }
@ -394,20 +383,20 @@ void StringFieldGenerator::GenerateMessageClearingCode(
// //
// For non-inlined strings, we distinguish from non-default by comparing // For non-inlined strings, we distinguish from non-default by comparing
// instances, rather than contents. // instances, rather than contents.
format("$DCHK$(!$name$_.IsDefault());\n"); format("$DCHK$(!$field$.IsDefault());\n");
} }
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
if (must_be_present) { if (must_be_present) {
format("$name$_.ClearNonDefaultToEmpty();\n"); format("$field$.ClearNonDefaultToEmpty();\n");
} else { } else {
format("$name$_.ClearToEmpty();\n"); format("$field$.ClearToEmpty();\n");
} }
} else { } else {
// Clear to a non-empty default is more involved, as we try to use the // Clear to a non-empty default is more involved, as we try to use the
// Arena if one is present and may need to reallocate the string. // Arena if one is present and may need to reallocate the string.
format( format(
"$name$_.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n "); "$field$.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n ");
} }
} }
@ -422,16 +411,15 @@ void StringFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
if (!inlined_) { if (!inlined_) {
format( format(
"::$proto_ns$::internal::ArenaStringPtr::InternalSwap(\n" "::$proto_ns$::internal::ArenaStringPtr::InternalSwap(\n"
" $default_value$,\n" " &$field$, lhs_arena,\n"
" &$name$_, lhs_arena,\n" " &other->$field$, rhs_arena\n"
" &other->$name$_, rhs_arena\n"
");\n"); ");\n");
} else { } else {
format( format(
"::$proto_ns$::internal::InlinedStringField::InternalSwap(\n" "::$proto_ns$::internal::InlinedStringField::InternalSwap(\n"
" &$name$_, lhs_arena, " " &$field$, lhs_arena, "
"(_inlined_string_donated_[0] & 0x1u) == 0, this,\n" "(_inlined_string_donated_[0] & 0x1u) == 0, this,\n"
" &other->$name$_, rhs_arena, " " &other->$field$, rhs_arena, "
"(other->_inlined_string_donated_[0] & 0x1u) == 0, other);\n"); "(other->_inlined_string_donated_[0] & 0x1u) == 0, other);\n");
} }
} }
@ -442,12 +430,12 @@ void StringFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
return; return;
} }
GOOGLE_DCHECK(!inlined_); GOOGLE_DCHECK(!inlined_);
format("$name$_.InitDefault($init_value$);\n"); format("$name$_.InitDefault();\n");
if (IsString(descriptor_, options_) && if (IsString(descriptor_, options_) &&
descriptor_->default_value_string().empty()) { descriptor_->default_value_string().empty()) {
format( format(
"#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n" "#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"
" $name$_.Set($default_value$, \"\", GetArenaForAllocation());\n" " $name$_.Set(\"\", GetArenaForAllocation());\n"
"#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"); "#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n");
} }
} }
@ -470,11 +458,11 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
if (!inlined_) { if (!inlined_) {
format( format(
"$name$_.Set($default_value_tag$, from._internal_$name$(), \n" "$field$.Set(from._internal_$name$(), \n"
" GetArenaForAllocation());\n"); " GetArenaForAllocation());\n");
} else { } else {
format( format(
"$name$_.Set(nullptr, from._internal_$name$(),\n" "$field$.Set(from._internal_$name$(),\n"
" GetArenaForAllocation(), _internal_$name$_donated(), " " GetArenaForAllocation(), _internal_$name$_donated(), "
"&$donating_states_word$, $mask_for_undonate$, this);\n"); "&$donating_states_word$, $mask_for_undonate$, this);\n");
} }
@ -486,14 +474,14 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
void StringFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { void StringFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!inlined_) { if (!inlined_) {
format("$name$_.DestroyNoArena($default_value$);\n"); format("$field$.Destroy();\n");
return; return;
} }
// Explicitly calls ~InlinedStringField as its automatic call is disabled. // Explicitly calls ~InlinedStringField as its automatic call is disabled.
// Destructor has been implicitly skipped as a union, and even the // Destructor has been implicitly skipped as a union, and even the
// message-owned arena is enabled, arena could still be missing for // message-owned arena is enabled, arena could still be missing for
// Arena::CreateMessage(nullptr). // Arena::CreateMessage(nullptr).
format("$name$_.~InlinedStringField();\n"); format("$field$.~InlinedStringField();\n");
} }
ArenaDtorNeeds StringFieldGenerator::NeedsArenaDestructor() const { ArenaDtorNeeds StringFieldGenerator::NeedsArenaDestructor() const {
@ -507,7 +495,7 @@ void StringFieldGenerator::GenerateArenaDestructorCode(
// _this is the object being destructed (we are inside a static method here). // _this is the object being destructed (we are inside a static method here).
format( format(
"if (!_this->_internal_$name$_donated()) {\n" "if (!_this->_internal_$name$_donated()) {\n"
" _this->$name$_.~InlinedStringField();\n" " _this->$field$.~InlinedStringField();\n"
"}\n"); "}\n");
} }
@ -575,9 +563,9 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (!_internal_has_$name$()) {\n" " if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.InitDefault($init_value$);\n" " $field$.InitDefault();\n"
" }\n" " }\n"
" $field_member$.$setter$($default_value_tag$," " $field$.$setter$("
" static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());\n" " static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n" " // @@protoc_insertion_point(field_set:$full_name$)\n"
@ -590,7 +578,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n" "}\n"
"inline const std::string& $classname$::_internal_$name$() const {\n" "inline const std::string& $classname$::_internal_$name$() const {\n"
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" return $field_member$.Get();\n" " return $field$.Get();\n"
" }\n" " }\n"
" return $default_string$;\n" " return $default_string$;\n"
"}\n" "}\n"
@ -599,28 +587,26 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (!_internal_has_$name$()) {\n" " if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.InitDefault($init_value$);\n" " $field$.InitDefault();\n"
" }\n" " }\n"
" $field_member$.Set($default_value_tag$, value, " " $field$.Set(value, GetArenaForAllocation());\n"
"GetArenaForAllocation());\n"
"}\n"); "}\n");
format( format(
"inline std::string* $classname$::_internal_mutable_$name$() {\n" "inline std::string* $classname$::_internal_mutable_$name$() {\n"
" if (!_internal_has_$name$()) {\n" " if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.InitDefault($init_value$);\n" " $field$.InitDefault();\n"
" }\n" " }\n"
" return $field_member$.Mutable(\n" " return $field$.Mutable($lazy_variable_args$"
" $default_variable_or_tag$, GetArenaForAllocation());\n" " GetArenaForAllocation());\n"
"}\n" "}\n"
"inline std::string* $classname$::$release_name$() {\n" "inline std::string* $classname$::$release_name$() {\n"
"$annotate_release$" "$annotate_release$"
" // @@protoc_insertion_point(field_release:$full_name$)\n" " // @@protoc_insertion_point(field_release:$full_name$)\n"
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n" " clear_has_$oneof_name$();\n"
" return $field_member$.ReleaseNonDefault($default_value$, " " return $field$.Release();\n"
"GetArenaForAllocation());\n"
" } else {\n" " } else {\n"
" return nullptr;\n" " return nullptr;\n"
" }\n" " }\n"
@ -631,7 +617,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" }\n" " }\n"
" if ($name$ != nullptr) {\n" " if ($name$ != nullptr) {\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.InitAllocated($name$, GetArenaForAllocation());\n" " $field$.InitAllocated($name$, GetArenaForAllocation());\n"
" }\n" " }\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
@ -641,9 +627,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void StringOneofFieldGenerator::GenerateClearingCode( void StringOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format("$field$.Destroy();\n");
"$field_member$.Destroy($default_value_tag$, "
"GetArenaForAllocation());\n");
} }
void StringOneofFieldGenerator::GenerateMessageClearingCode( void StringOneofFieldGenerator::GenerateMessageClearingCode(
@ -758,14 +742,14 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
format( format(
"inline const std::string& $classname$::_internal_$name$(int index) " "inline const std::string& $classname$::_internal_$name$(int index) "
"const {\n" "const {\n"
" return $name$_.InternalCheckedGet(\n" " return $field$.InternalCheckedGet(\n"
" index, ::$proto_ns$::internal::GetEmptyStringAlreadyInited());\n" " index, ::$proto_ns$::internal::GetEmptyStringAlreadyInited());\n"
"}\n"); "}\n");
} else { } else {
format( format(
"inline const std::string& $classname$::_internal_$name$(int index) " "inline const std::string& $classname$::_internal_$name$(int index) "
"const {\n" "const {\n"
" return $name$_.Get(index);\n" " return $field$.Get(index);\n"
"}\n"); "}\n");
} }
format( format(
@ -777,23 +761,23 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline std::string* $classname$::mutable_$name$(int index) {\n" "inline std::string* $classname$::mutable_$name$(int index) {\n"
"$annotate_mutable$" "$annotate_mutable$"
" // @@protoc_insertion_point(field_mutable:$full_name$)\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
" return $name$_.Mutable(index);\n" " return $field$.Mutable(index);\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(int index, const std::string& " "inline void $classname$::set_$name$(int index, const std::string& "
"value) " "value) "
"{\n" "{\n"
" $name$_.Mutable(index)->assign(value);\n" " $field$.Mutable(index)->assign(value);\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n" " // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(int index, std::string&& value) {\n" "inline void $classname$::set_$name$(int index, std::string&& value) {\n"
" $name$_.Mutable(index)->assign(std::move(value));\n" " $field$.Mutable(index)->assign(std::move(value));\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n" " // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(int index, const char* value) {\n" "inline void $classname$::set_$name$(int index, const char* value) {\n"
" $null_check$" " $null_check$"
" $name$_.Mutable(index)->assign(value);\n" " $field$.Mutable(index)->assign(value);\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
"}\n"); "}\n");
@ -801,7 +785,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
format( format(
"inline void " "inline void "
"$classname$::set_$name$(int index, StringPiece value) {\n" "$classname$::set_$name$(int index, StringPiece value) {\n"
" $name$_.Mutable(index)->assign(value.data(), value.size());\n" " $field$.Mutable(index)->assign(value.data(), value.size());\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n" " // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
"}\n"); "}\n");
@ -810,34 +794,34 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline void " "inline void "
"$classname$::set_$name$" "$classname$::set_$name$"
"(int index, const $pointer_type$* value, size_t size) {\n" "(int index, const $pointer_type$* value, size_t size) {\n"
" $name$_.Mutable(index)->assign(\n" " $field$.Mutable(index)->assign(\n"
" reinterpret_cast<const char*>(value), size);\n" " reinterpret_cast<const char*>(value), size);\n"
"$annotate_set$" "$annotate_set$"
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
"}\n" "}\n"
"inline std::string* $classname$::_internal_add_$name$() {\n" "inline std::string* $classname$::_internal_add_$name$() {\n"
" return $name$_.Add();\n" " return $field$.Add();\n"
"}\n" "}\n"
"inline void $classname$::add_$name$(const std::string& value) {\n" "inline void $classname$::add_$name$(const std::string& value) {\n"
" $name$_.Add()->assign(value);\n" " $field$.Add()->assign(value);\n"
"$annotate_add$" "$annotate_add$"
" // @@protoc_insertion_point(field_add:$full_name$)\n" " // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::add_$name$(std::string&& value) {\n" "inline void $classname$::add_$name$(std::string&& value) {\n"
" $name$_.Add(std::move(value));\n" " $field$.Add(std::move(value));\n"
"$annotate_add$" "$annotate_add$"
" // @@protoc_insertion_point(field_add:$full_name$)\n" " // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::add_$name$(const char* value) {\n" "inline void $classname$::add_$name$(const char* value) {\n"
" $null_check$" " $null_check$"
" $name$_.Add()->assign(value);\n" " $field$.Add()->assign(value);\n"
"$annotate_add$" "$annotate_add$"
" // @@protoc_insertion_point(field_add_char:$full_name$)\n" " // @@protoc_insertion_point(field_add_char:$full_name$)\n"
"}\n"); "}\n");
if (!options_.opensource_runtime) { if (!options_.opensource_runtime) {
format( format(
"inline void $classname$::add_$name$(StringPiece value) {\n" "inline void $classname$::add_$name$(StringPiece value) {\n"
" $name$_.Add()->assign(value.data(), value.size());\n" " $field$.Add()->assign(value.data(), value.size());\n"
"$annotate_add$" "$annotate_add$"
" // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n" " // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n"
"}\n"); "}\n");
@ -845,7 +829,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
format( format(
"inline void " "inline void "
"$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n" "$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n"
" $name$_.Add()->assign(reinterpret_cast<const char*>(value), size);\n" " $field$.Add()->assign(reinterpret_cast<const char*>(value), size);\n"
"$annotate_add$" "$annotate_add$"
" // @@protoc_insertion_point(field_add_pointer:$full_name$)\n" " // @@protoc_insertion_point(field_add_pointer:$full_name$)\n"
"}\n" "}\n"
@ -853,43 +837,32 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"$classname$::$name$() const {\n" "$classname$::$name$() const {\n"
"$annotate_list$" "$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n" " // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n" " return $field$;\n"
"}\n" "}\n"
"inline ::$proto_ns$::RepeatedPtrField<std::string>*\n" "inline ::$proto_ns$::RepeatedPtrField<std::string>*\n"
"$classname$::mutable_$name$() {\n" "$classname$::mutable_$name$() {\n"
"$annotate_mutable_list$" "$annotate_mutable_list$"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
" return &$name$_;\n" " return &$field$;\n"
"}\n"); "}\n");
} }
void RepeatedStringFieldGenerator::GenerateClearingCode( void RepeatedStringFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.Clear();\n"); format("$field$.Clear();\n");
} }
void RepeatedStringFieldGenerator::GenerateMergingCode( void RepeatedStringFieldGenerator::GenerateMergingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n"); format("$field$.MergeFrom(from.$field$);\n");
} }
void RepeatedStringFieldGenerator::GenerateSwappingCode( void RepeatedStringFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n"); format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedStringFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
// Not needed for repeated fields.
}
void RepeatedStringFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.CopyFrom(from.$name$_);");
} }
void RepeatedStringFieldGenerator::GenerateSerializeWithCachedSizesToArray( void RepeatedStringFieldGenerator::GenerateSerializeWithCachedSizesToArray(
@ -916,11 +889,11 @@ void RepeatedStringFieldGenerator::GenerateByteSize(
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"total_size += $tag_size$ *\n" "total_size += $tag_size$ *\n"
" ::$proto_ns$::internal::FromIntSize($name$_.size());\n" " ::$proto_ns$::internal::FromIntSize($field$.size());\n"
"for (int i = 0, n = $name$_.size(); i < n; i++) {\n" "for (int i = 0, n = $field$.size(); i < n; i++) {\n"
" total_size += " " total_size += "
"::$proto_ns$::internal::WireFormatLite::$declared_type$Size(\n" "::$proto_ns$::internal::WireFormatLite::$declared_type$Size(\n"
" $name$_.Get(i));\n" " $field$.Get(i));\n"
"}\n"); "}\n");
} }

@ -111,8 +111,8 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override; void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override; void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override; void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override; void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateSerializeWithCachedSizesToArray( void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override; io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override; void GenerateByteSize(io::Printer* printer) const override;

@ -190,10 +190,20 @@ bool ObjectiveCGenerator::GenerateAll(
// header search path since the generate #import will be more complete. // header search path since the generate #import will be more complete.
generation_options.runtime_import_prefix = generation_options.runtime_import_prefix =
StripSuffixString(options[i].second, "/"); StripSuffixString(options[i].second, "/");
} else if (options[i].first == "default_objc_class_prefix") {
// The default objc class prefix to use if specified by the command line
// invocation. The file option is always honored first if one is present.
std::string value = options[i].second;
if (value.empty()) {
*error = "error: default_objc_class_prefix cannot be empty.";
return false;
}
SetDefaultObjcClassPrefix(value);
} else if (options[i].first == "use_package_as_prefix") { } else if (options[i].first == "use_package_as_prefix") {
// Controls how the symbols should be prefixed to avoid symbols // Controls how the symbols should be prefixed to avoid symbols
// collisions. The objc_class_prefix file option is always honored, this // collisions. The objc_class_prefix file option is always honored first
// is just what to do if that isn't set. The available options are: // followed by the default_objc_class_prefix generator option. This is is just
// what to do if either of these options are not set. The available options are:
// "no": Not prefixed (the existing mode). // "no": Not prefixed (the existing mode).
// "yes": Make a prefix out of the proto package. // "yes": Make a prefix out of the proto package.
bool value = false; bool value = false;

@ -99,6 +99,9 @@ class PrefixModeStorage {
public: public:
PrefixModeStorage(); PrefixModeStorage();
const std::string default_objc_class_prefix() const { return default_objc_class_prefix_; }
void set_default_objc_class_prefix(const std::string& default_objc_class_prefix) { default_objc_class_prefix_ = default_objc_class_prefix; }
bool use_package_name() const { return use_package_name_; } bool use_package_name() const { return use_package_name_; }
void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; } void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; }
@ -116,13 +119,14 @@ class PrefixModeStorage {
private: private:
bool use_package_name_; bool use_package_name_;
std::string default_objc_class_prefix_;
std::string exception_path_; std::string exception_path_;
std::string forced_prefix_; std::string forced_prefix_;
std::unordered_set<std::string> exceptions_; std::unordered_set<std::string> exceptions_;
}; };
PrefixModeStorage::PrefixModeStorage() { PrefixModeStorage::PrefixModeStorage() {
// Even thought there are generation options, have an env back door since some // Even though there are generation options, have an env back door since some
// of these helpers could be used in other plugins. // of these helpers could be used in other plugins.
use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false); use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false);
@ -169,6 +173,10 @@ PrefixModeStorage g_prefix_mode;
} // namespace } // namespace
void SetDefaultObjcClassPrefix(const std::string& default_objc_class_prefix) {
g_prefix_mode.set_default_objc_class_prefix(default_objc_class_prefix);
}
bool UseProtoPackageAsDefaultPrefix() { bool UseProtoPackageAsDefaultPrefix() {
return g_prefix_mode.use_package_name(); return g_prefix_mode.use_package_name();
} }
@ -526,11 +534,16 @@ std::string BaseFileName(const FileDescriptor* file) {
} }
std::string FileClassPrefix(const FileDescriptor* file) { std::string FileClassPrefix(const FileDescriptor* file) {
// Always honor the file option. // Always honor the file option first.
if (file->options().has_objc_class_prefix()) { if (file->options().has_objc_class_prefix()) {
return file->options().objc_class_prefix(); return file->options().objc_class_prefix();
} }
// If a default prefix is passed through objc_opt then accept it.
if (!g_prefix_mode.default_objc_class_prefix().empty()) {
return g_prefix_mode.default_objc_class_prefix();
}
// If package prefix isn't enabled, done. // If package prefix isn't enabled, done.
if (!g_prefix_mode.use_package_name()) { if (!g_prefix_mode.use_package_name()) {
return ""; return "";

@ -47,6 +47,9 @@ namespace protobuf {
namespace compiler { namespace compiler {
namespace objectivec { namespace objectivec {
// Set the default objc class prefix that should be used. This method is used only
// when default_objc_class_prefix is passed through objc_opt.
void PROTOC_EXPORT SetDefaultObjcClassPrefix(const std::string& objc_class_prefix);
// Get/Set if the proto package should be used to make the default prefix for // Get/Set if the proto package should be used to make the default prefix for
// symbols. This will then impact most of the type naming apis below. It is done // symbols. This will then impact most of the type naming apis below. It is done
// as a global to not break any other generator reusing the methods since they // as a global to not break any other generator reusing the methods since they
@ -68,6 +71,7 @@ struct Options {
std::string generate_for_named_framework; std::string generate_for_named_framework;
std::string named_framework_to_proto_path_mappings_path; std::string named_framework_to_proto_path_mappings_path;
std::string runtime_import_prefix; std::string runtime_import_prefix;
std::string default_objc_class_prefix;
bool prefixes_must_be_registered; bool prefixes_must_be_registered;
bool require_prefixes; bool require_prefixes;
}; };

@ -2466,7 +2466,9 @@ TEST_F(ParseDescriptorDebugTest, TestMaps) {
// *output_field to the descriptor of the field, and *output_index to -1. // *output_field to the descriptor of the field, and *output_index to -1.
// Returns true if the path was valid, false otherwise. A gTest failure is // Returns true if the path was valid, false otherwise. A gTest failure is
// recorded before returning false. // recorded before returning false.
bool FollowPath(const Message& root, const int* path_begin, const int* path_end, bool FollowPath(const Message& root,
RepeatedField<int>::const_iterator path_begin,
RepeatedField<int>::const_iterator path_end,
const Message** output_message, const Message** output_message,
const FieldDescriptor** output_field, int* output_index) { const FieldDescriptor** output_field, int* output_index) {
if (path_begin == path_end) { if (path_begin == path_end) {

@ -252,10 +252,10 @@ Version::Version(const Version& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
suffix_.InitDefault(); suffix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); suffix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_suffix()) { if (from._internal_has_suffix()) {
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_suffix(), suffix_.Set(from._internal_suffix(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
::memcpy(&major_, &from.major_, ::memcpy(&major_, &from.major_,
@ -267,7 +267,7 @@ Version::Version(const Version& from)
inline void Version::SharedCtor() { inline void Version::SharedCtor() {
suffix_.InitDefault(); suffix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); suffix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&major_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&major_) - reinterpret_cast<char*>(this)),
@ -286,7 +286,7 @@ Version::~Version() {
inline void Version::SharedDtor() { inline void Version::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
suffix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); suffix_.Destroy();
} }
void Version::SetCachedSize(int size) const { void Version::SetCachedSize(int size) const {
@ -517,7 +517,6 @@ void Version::InternalSwap(Version* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&suffix_, lhs_arena, &suffix_, lhs_arena,
&other->suffix_, rhs_arena &other->suffix_, rhs_arena
); );
@ -572,10 +571,10 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
parameter_.InitDefault(); parameter_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); parameter_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_parameter()) { if (from._internal_has_parameter()) {
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_parameter(), parameter_.Set(from._internal_parameter(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_compiler_version()) { if (from._internal_has_compiler_version()) {
@ -589,7 +588,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
inline void CodeGeneratorRequest::SharedCtor() { inline void CodeGeneratorRequest::SharedCtor() {
parameter_.InitDefault(); parameter_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); parameter_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
compiler_version_ = nullptr; compiler_version_ = nullptr;
} }
@ -605,7 +604,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
inline void CodeGeneratorRequest::SharedDtor() { inline void CodeGeneratorRequest::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
parameter_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); parameter_.Destroy();
if (this != internal_default_instance()) delete compiler_version_; if (this != internal_default_instance()) delete compiler_version_;
} }
@ -864,7 +863,6 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
file_to_generate_.InternalSwap(&other->file_to_generate_); file_to_generate_.InternalSwap(&other->file_to_generate_);
proto_file_.InternalSwap(&other->proto_file_); proto_file_.InternalSwap(&other->proto_file_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&parameter_, lhs_arena, &parameter_, lhs_arena,
&other->parameter_, rhs_arena &other->parameter_, rhs_arena
); );
@ -917,26 +915,26 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
insertion_point_.InitDefault(); insertion_point_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); insertion_point_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_insertion_point()) { if (from._internal_has_insertion_point()) {
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_insertion_point(), insertion_point_.Set(from._internal_insertion_point(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
content_.InitDefault(); content_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); content_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_content()) { if (from._internal_has_content()) {
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_content(), content_.Set(from._internal_content(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_generated_code_info()) { if (from._internal_has_generated_code_info()) {
@ -950,15 +948,15 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
inline void CodeGeneratorResponse_File::SharedCtor() { inline void CodeGeneratorResponse_File::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
insertion_point_.InitDefault(); insertion_point_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); insertion_point_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
content_.InitDefault(); content_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); content_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
generated_code_info_ = nullptr; generated_code_info_ = nullptr;
} }
@ -974,9 +972,9 @@ CodeGeneratorResponse_File::~CodeGeneratorResponse_File() {
inline void CodeGeneratorResponse_File::SharedDtor() { inline void CodeGeneratorResponse_File::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
insertion_point_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); insertion_point_.Destroy();
content_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); content_.Destroy();
if (this != internal_default_instance()) delete generated_code_info_; if (this != internal_default_instance()) delete generated_code_info_;
} }
@ -1234,17 +1232,14 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other)
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&insertion_point_, lhs_arena, &insertion_point_, lhs_arena,
&other->insertion_point_, rhs_arena &other->insertion_point_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&content_, lhs_arena, &content_, lhs_arena,
&other->content_, rhs_arena &other->content_, rhs_arena
); );
@ -1284,10 +1279,10 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
error_.InitDefault(); error_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); error_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_error()) { if (from._internal_has_error()) {
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_error(), error_.Set(from._internal_error(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
supported_features_ = from.supported_features_; supported_features_ = from.supported_features_;
@ -1297,7 +1292,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
inline void CodeGeneratorResponse::SharedCtor() { inline void CodeGeneratorResponse::SharedCtor() {
error_.InitDefault(); error_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); error_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
supported_features_ = uint64_t{0u}; supported_features_ = uint64_t{0u};
} }
@ -1313,7 +1308,7 @@ CodeGeneratorResponse::~CodeGeneratorResponse() {
inline void CodeGeneratorResponse::SharedDtor() { inline void CodeGeneratorResponse::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
error_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); error_.Destroy();
} }
void CodeGeneratorResponse::SetCachedSize(int size) const { void CodeGeneratorResponse::SetCachedSize(int size) const {
@ -1525,7 +1520,6 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) {
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
file_.InternalSwap(&other->file_); file_.InternalSwap(&other->file_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&error_, lhs_arena, &error_, lhs_arena,
&other->error_, rhs_arena &other->error_, rhs_arena
); );

@ -1093,7 +1093,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void Version::set_suffix(ArgT0&& arg0, ArgT... args) { void Version::set_suffix(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); suffix_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix) // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix)
} }
inline std::string* Version::mutable_suffix() { inline std::string* Version::mutable_suffix() {
@ -1106,11 +1106,11 @@ inline const std::string& Version::_internal_suffix() const {
} }
inline void Version::_internal_set_suffix(const std::string& value) { inline void Version::_internal_set_suffix(const std::string& value) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); suffix_.Set(value, GetArenaForAllocation());
} }
inline std::string* Version::_internal_mutable_suffix() { inline std::string* Version::_internal_mutable_suffix() {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
return suffix_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return suffix_.Mutable(GetArenaForAllocation());
} }
inline std::string* Version::release_suffix() { inline std::string* Version::release_suffix() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix) // @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix)
@ -1118,10 +1118,10 @@ inline std::string* Version::release_suffix() {
return nullptr; return nullptr;
} }
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
auto* p = suffix_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); auto* p = suffix_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (suffix_.IsDefault()) { if (suffix_.IsDefault()) {
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); suffix_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p; return p;
@ -1132,11 +1132,10 @@ inline void Version::set_allocated_suffix(std::string* suffix) {
} else { } else {
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
} }
suffix_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), suffix, suffix_.SetAllocated(suffix, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (suffix_.IsDefault()) { if (suffix_.IsDefault()) {
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); suffix_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix) // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix)
@ -1241,7 +1240,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorRequest::set_parameter(ArgT0&& arg0, ArgT... args) { void CodeGeneratorRequest::set_parameter(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); parameter_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.parameter) // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.parameter)
} }
inline std::string* CodeGeneratorRequest::mutable_parameter() { inline std::string* CodeGeneratorRequest::mutable_parameter() {
@ -1254,11 +1253,11 @@ inline const std::string& CodeGeneratorRequest::_internal_parameter() const {
} }
inline void CodeGeneratorRequest::_internal_set_parameter(const std::string& value) { inline void CodeGeneratorRequest::_internal_set_parameter(const std::string& value) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); parameter_.Set(value, GetArenaForAllocation());
} }
inline std::string* CodeGeneratorRequest::_internal_mutable_parameter() { inline std::string* CodeGeneratorRequest::_internal_mutable_parameter() {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
return parameter_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return parameter_.Mutable(GetArenaForAllocation());
} }
inline std::string* CodeGeneratorRequest::release_parameter() { inline std::string* CodeGeneratorRequest::release_parameter() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter) // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter)
@ -1266,10 +1265,10 @@ inline std::string* CodeGeneratorRequest::release_parameter() {
return nullptr; return nullptr;
} }
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
auto* p = parameter_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); auto* p = parameter_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (parameter_.IsDefault()) { if (parameter_.IsDefault()) {
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); parameter_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p; return p;
@ -1280,11 +1279,10 @@ inline void CodeGeneratorRequest::set_allocated_parameter(std::string* parameter
} else { } else {
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
} }
parameter_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), parameter, parameter_.SetAllocated(parameter, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (parameter_.IsDefault()) { if (parameter_.IsDefault()) {
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); parameter_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.parameter) // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.parameter)
@ -1404,7 +1402,7 @@ inline void CodeGeneratorRequest::set_allocated_compiler_version(::PROTOBUF_NAME
} }
if (compiler_version) { if (compiler_version) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::PROTOBUF_NAMESPACE_ID::compiler::Version>::GetOwningArena(compiler_version); ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(compiler_version);
if (message_arena != submessage_arena) { if (message_arena != submessage_arena) {
compiler_version = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( compiler_version = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, compiler_version, submessage_arena); message_arena, compiler_version, submessage_arena);
@ -1441,7 +1439,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse_File::set_name(ArgT0&& arg0, ArgT... args) { void CodeGeneratorResponse_File::set_name(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.name) // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.name)
} }
inline std::string* CodeGeneratorResponse_File::mutable_name() { inline std::string* CodeGeneratorResponse_File::mutable_name() {
@ -1454,11 +1452,11 @@ inline const std::string& CodeGeneratorResponse_File::_internal_name() const {
} }
inline void CodeGeneratorResponse_File::_internal_set_name(const std::string& value) { inline void CodeGeneratorResponse_File::_internal_set_name(const std::string& value) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); name_.Set(value, GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse_File::_internal_mutable_name() { inline std::string* CodeGeneratorResponse_File::_internal_mutable_name() {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return name_.Mutable(GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse_File::release_name() { inline std::string* CodeGeneratorResponse_File::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name) // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name)
@ -1466,10 +1464,10 @@ inline std::string* CodeGeneratorResponse_File::release_name() {
return nullptr; return nullptr;
} }
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
auto* p = name_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); auto* p = name_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) { if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p; return p;
@ -1480,11 +1478,10 @@ inline void CodeGeneratorResponse_File::set_allocated_name(std::string* name) {
} else { } else {
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
} }
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, name_.SetAllocated(name, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) { if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name)
@ -1510,7 +1507,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse_File::set_insertion_point(ArgT0&& arg0, ArgT... args) { void CodeGeneratorResponse_File::set_insertion_point(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000002u; _has_bits_[0] |= 0x00000002u;
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); insertion_point_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
} }
inline std::string* CodeGeneratorResponse_File::mutable_insertion_point() { inline std::string* CodeGeneratorResponse_File::mutable_insertion_point() {
@ -1523,11 +1520,11 @@ inline const std::string& CodeGeneratorResponse_File::_internal_insertion_point(
} }
inline void CodeGeneratorResponse_File::_internal_set_insertion_point(const std::string& value) { inline void CodeGeneratorResponse_File::_internal_set_insertion_point(const std::string& value) {
_has_bits_[0] |= 0x00000002u; _has_bits_[0] |= 0x00000002u;
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); insertion_point_.Set(value, GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse_File::_internal_mutable_insertion_point() { inline std::string* CodeGeneratorResponse_File::_internal_mutable_insertion_point() {
_has_bits_[0] |= 0x00000002u; _has_bits_[0] |= 0x00000002u;
return insertion_point_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return insertion_point_.Mutable(GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse_File::release_insertion_point() { inline std::string* CodeGeneratorResponse_File::release_insertion_point() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
@ -1535,10 +1532,10 @@ inline std::string* CodeGeneratorResponse_File::release_insertion_point() {
return nullptr; return nullptr;
} }
_has_bits_[0] &= ~0x00000002u; _has_bits_[0] &= ~0x00000002u;
auto* p = insertion_point_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); auto* p = insertion_point_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (insertion_point_.IsDefault()) { if (insertion_point_.IsDefault()) {
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); insertion_point_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p; return p;
@ -1549,11 +1546,10 @@ inline void CodeGeneratorResponse_File::set_allocated_insertion_point(std::strin
} else { } else {
_has_bits_[0] &= ~0x00000002u; _has_bits_[0] &= ~0x00000002u;
} }
insertion_point_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), insertion_point, insertion_point_.SetAllocated(insertion_point, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (insertion_point_.IsDefault()) { if (insertion_point_.IsDefault()) {
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); insertion_point_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
@ -1579,7 +1575,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse_File::set_content(ArgT0&& arg0, ArgT... args) { void CodeGeneratorResponse_File::set_content(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000004u; _has_bits_[0] |= 0x00000004u;
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); content_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.content) // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.content)
} }
inline std::string* CodeGeneratorResponse_File::mutable_content() { inline std::string* CodeGeneratorResponse_File::mutable_content() {
@ -1592,11 +1588,11 @@ inline const std::string& CodeGeneratorResponse_File::_internal_content() const
} }
inline void CodeGeneratorResponse_File::_internal_set_content(const std::string& value) { inline void CodeGeneratorResponse_File::_internal_set_content(const std::string& value) {
_has_bits_[0] |= 0x00000004u; _has_bits_[0] |= 0x00000004u;
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); content_.Set(value, GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse_File::_internal_mutable_content() { inline std::string* CodeGeneratorResponse_File::_internal_mutable_content() {
_has_bits_[0] |= 0x00000004u; _has_bits_[0] |= 0x00000004u;
return content_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return content_.Mutable(GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse_File::release_content() { inline std::string* CodeGeneratorResponse_File::release_content() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content) // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content)
@ -1604,10 +1600,10 @@ inline std::string* CodeGeneratorResponse_File::release_content() {
return nullptr; return nullptr;
} }
_has_bits_[0] &= ~0x00000004u; _has_bits_[0] &= ~0x00000004u;
auto* p = content_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); auto* p = content_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (content_.IsDefault()) { if (content_.IsDefault()) {
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); content_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p; return p;
@ -1618,11 +1614,10 @@ inline void CodeGeneratorResponse_File::set_allocated_content(std::string* conte
} else { } else {
_has_bits_[0] &= ~0x00000004u; _has_bits_[0] &= ~0x00000004u;
} }
content_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), content, content_.SetAllocated(content, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (content_.IsDefault()) { if (content_.IsDefault()) {
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); content_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content) // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content)
@ -1701,8 +1696,7 @@ inline void CodeGeneratorResponse_File::set_allocated_generated_code_info(::PROT
} }
if (generated_code_info) { if (generated_code_info) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper< ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(
::PROTOBUF_NAMESPACE_ID::MessageLite>::GetOwningArena(
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(generated_code_info)); reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(generated_code_info));
if (message_arena != submessage_arena) { if (message_arena != submessage_arena) {
generated_code_info = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( generated_code_info = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
@ -1740,7 +1734,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse::set_error(ArgT0&& arg0, ArgT... args) { void CodeGeneratorResponse::set_error(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); error_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.error) // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.error)
} }
inline std::string* CodeGeneratorResponse::mutable_error() { inline std::string* CodeGeneratorResponse::mutable_error() {
@ -1753,11 +1747,11 @@ inline const std::string& CodeGeneratorResponse::_internal_error() const {
} }
inline void CodeGeneratorResponse::_internal_set_error(const std::string& value) { inline void CodeGeneratorResponse::_internal_set_error(const std::string& value) {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); error_.Set(value, GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse::_internal_mutable_error() { inline std::string* CodeGeneratorResponse::_internal_mutable_error() {
_has_bits_[0] |= 0x00000001u; _has_bits_[0] |= 0x00000001u;
return error_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return error_.Mutable(GetArenaForAllocation());
} }
inline std::string* CodeGeneratorResponse::release_error() { inline std::string* CodeGeneratorResponse::release_error() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error) // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error)
@ -1765,10 +1759,10 @@ inline std::string* CodeGeneratorResponse::release_error() {
return nullptr; return nullptr;
} }
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
auto* p = error_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); auto* p = error_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (error_.IsDefault()) { if (error_.IsDefault()) {
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); error_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p; return p;
@ -1779,11 +1773,10 @@ inline void CodeGeneratorResponse::set_allocated_error(std::string* error) {
} else { } else {
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
} }
error_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error, error_.SetAllocated(error, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (error_.IsDefault()) { if (error_.IsDefault()) {
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); error_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.error) // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.error)

@ -73,15 +73,15 @@ static void CloseHandleOrDie(HANDLE handle) {
Subprocess::Subprocess() Subprocess::Subprocess()
: process_start_error_(ERROR_SUCCESS), : process_start_error_(ERROR_SUCCESS),
child_handle_(NULL), child_handle_(nullptr),
child_stdin_(NULL), child_stdin_(nullptr),
child_stdout_(NULL) {} child_stdout_(nullptr) {}
Subprocess::~Subprocess() { Subprocess::~Subprocess() {
if (child_stdin_ != NULL) { if (child_stdin_ != nullptr) {
CloseHandleOrDie(child_stdin_); CloseHandleOrDie(child_stdin_);
} }
if (child_stdout_ != NULL) { if (child_stdout_ != nullptr) {
CloseHandleOrDie(child_stdout_); CloseHandleOrDie(child_stdout_);
} }
} }
@ -93,10 +93,10 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) {
HANDLE stdout_pipe_read; HANDLE stdout_pipe_read;
HANDLE stdout_pipe_write; HANDLE stdout_pipe_write;
if (!CreatePipe(&stdin_pipe_read, &stdin_pipe_write, NULL, 0)) { if (!CreatePipe(&stdin_pipe_read, &stdin_pipe_write, nullptr, 0)) {
GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError()); GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError());
} }
if (!CreatePipe(&stdout_pipe_read, &stdout_pipe_write, NULL, 0)) { if (!CreatePipe(&stdout_pipe_read, &stdout_pipe_write, nullptr, 0)) {
GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError()); GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError());
} }
@ -134,14 +134,14 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) {
// Create the process. // Create the process.
PROCESS_INFORMATION process_info; PROCESS_INFORMATION process_info;
if (CreateProcessA((search_mode == SEARCH_PATH) ? NULL : program.c_str(), if (CreateProcessA((search_mode == SEARCH_PATH) ? nullptr : program.c_str(),
(search_mode == SEARCH_PATH) ? command_line : NULL, (search_mode == SEARCH_PATH) ? command_line : nullptr,
NULL, // process security attributes nullptr, // process security attributes
NULL, // thread security attributes nullptr, // thread security attributes
TRUE, // inherit handles? TRUE, // inherit handles?
0, // obscure creation flags 0, // obscure creation flags
NULL, // environment (inherit from parent) nullptr, // environment (inherit from parent)
NULL, // current directory (inherit from parent) nullptr, // current directory (inherit from parent)
&startup_info, &process_info)) { &startup_info, &process_info)) {
child_handle_ = process_info.hProcess; child_handle_ = process_info.hProcess;
CloseHandleOrDie(process_info.hThread); CloseHandleOrDie(process_info.hThread);
@ -165,28 +165,28 @@ bool Subprocess::Communicate(const Message& input, Message* output,
return false; return false;
} }
GOOGLE_CHECK(child_handle_ != NULL) << "Must call Start() first."; GOOGLE_CHECK(child_handle_ != nullptr) << "Must call Start() first.";
std::string input_data = input.SerializeAsString(); std::string input_data = input.SerializeAsString();
std::string output_data; std::string output_data;
int input_pos = 0; int input_pos = 0;
while (child_stdout_ != NULL) { while (child_stdout_ != nullptr) {
HANDLE handles[2]; HANDLE handles[2];
int handle_count = 0; int handle_count = 0;
if (child_stdin_ != NULL) { if (child_stdin_ != nullptr) {
handles[handle_count++] = child_stdin_; handles[handle_count++] = child_stdin_;
} }
if (child_stdout_ != NULL) { if (child_stdout_ != nullptr) {
handles[handle_count++] = child_stdout_; handles[handle_count++] = child_stdout_;
} }
DWORD wait_result = DWORD wait_result =
WaitForMultipleObjects(handle_count, handles, FALSE, INFINITE); WaitForMultipleObjects(handle_count, handles, FALSE, INFINITE);
HANDLE signaled_handle = NULL; HANDLE signaled_handle = nullptr;
if (wait_result >= WAIT_OBJECT_0 && if (wait_result >= WAIT_OBJECT_0 &&
wait_result < WAIT_OBJECT_0 + handle_count) { wait_result < WAIT_OBJECT_0 + handle_count) {
signaled_handle = handles[wait_result - WAIT_OBJECT_0]; signaled_handle = handles[wait_result - WAIT_OBJECT_0];
@ -201,7 +201,7 @@ bool Subprocess::Communicate(const Message& input, Message* output,
if (signaled_handle == child_stdin_) { if (signaled_handle == child_stdin_) {
DWORD n; DWORD n;
if (!WriteFile(child_stdin_, input_data.data() + input_pos, if (!WriteFile(child_stdin_, input_data.data() + input_pos,
input_data.size() - input_pos, &n, NULL)) { input_data.size() - input_pos, &n, nullptr)) {
// Child closed pipe. Presumably it will report an error later. // Child closed pipe. Presumably it will report an error later.
// Pretend we're done for now. // Pretend we're done for now.
input_pos = input_data.size(); input_pos = input_data.size();
@ -212,27 +212,27 @@ bool Subprocess::Communicate(const Message& input, Message* output,
if (input_pos == input_data.size()) { if (input_pos == input_data.size()) {
// We're done writing. Close. // We're done writing. Close.
CloseHandleOrDie(child_stdin_); CloseHandleOrDie(child_stdin_);
child_stdin_ = NULL; child_stdin_ = nullptr;
} }
} else if (signaled_handle == child_stdout_) { } else if (signaled_handle == child_stdout_) {
char buffer[4096]; char buffer[4096];
DWORD n; DWORD n;
if (!ReadFile(child_stdout_, buffer, sizeof(buffer), &n, NULL)) { if (!ReadFile(child_stdout_, buffer, sizeof(buffer), &n, nullptr)) {
// We're done reading. Close. // We're done reading. Close.
CloseHandleOrDie(child_stdout_); CloseHandleOrDie(child_stdout_);
child_stdout_ = NULL; child_stdout_ = nullptr;
} else { } else {
output_data.append(buffer, n); output_data.append(buffer, n);
} }
} }
} }
if (child_stdin_ != NULL) { if (child_stdin_ != nullptr) {
// Child did not finish reading input before it closed the output. // Child did not finish reading input before it closed the output.
// Presumably it exited with an error. // Presumably it exited with an error.
CloseHandleOrDie(child_stdin_); CloseHandleOrDie(child_stdin_);
child_stdin_ = NULL; child_stdin_ = nullptr;
} }
DWORD wait_result = WaitForSingleObject(child_handle_, INFINITE); DWORD wait_result = WaitForSingleObject(child_handle_, INFINITE);
@ -252,7 +252,7 @@ bool Subprocess::Communicate(const Message& input, Message* output,
} }
CloseHandleOrDie(child_handle_); CloseHandleOrDie(child_handle_);
child_handle_ = NULL; child_handle_ = nullptr;
if (exit_code != 0) { if (exit_code != 0) {
*error = strings::Substitute("Plugin failed with status code $0.", exit_code); *error = strings::Substitute("Plugin failed with status code $0.", exit_code);
@ -273,9 +273,10 @@ std::string Subprocess::Win32ErrorMessage(DWORD error_code) {
// WTF? // WTF?
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), nullptr, error_code,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPSTR)&message, // NOT A BUG! (LPSTR)&message, // NOT A BUG!
0, NULL); 0, nullptr);
std::string result = message; std::string result = message;
LocalFree(message); LocalFree(message);

@ -49,7 +49,6 @@
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/once.h> #include <google/protobuf/stubs/once.h>
#include <google/protobuf/any.h> #include <google/protobuf/any.h>
@ -58,6 +57,7 @@
#include <google/protobuf/io/tokenizer.h> #include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/casts.h> #include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h> #include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/descriptor_database.h> #include <google/protobuf/descriptor_database.h>
#include <google/protobuf/dynamic_message.h> #include <google/protobuf/dynamic_message.h>
@ -256,7 +256,8 @@ class FlatAllocation {
template <typename U> template <typename U>
bool Init() { bool Init() {
if (std::is_trivially_constructible<U>::value) return true; // Skip for the `char` block. No need to zero initialize it.
if (std::is_same<U, char>::value) return true;
for (int i = 0, size = Size<U>(); i < size; ++i) { for (int i = 0, size = Size<U>(); i < size; ++i) {
::new (data() + BeginOffset<U>() + sizeof(U) * i) U{}; ::new (data() + BeginOffset<U>() + sizeof(U) * i) U{};
} }
@ -1299,10 +1300,6 @@ class FileDescriptorTables {
bool AddFieldByNumber(FieldDescriptor* field); bool AddFieldByNumber(FieldDescriptor* field);
bool AddEnumValueByNumber(EnumValueDescriptor* value); bool AddEnumValueByNumber(EnumValueDescriptor* value);
// Adds the field to the lowercase_name and camelcase_name maps. Never
// fails because we allow duplicates; the first field by the name wins.
void AddFieldByStylizedNames(const FieldDescriptor* field);
// Populates p->first->locations_by_path_ from p->second. // Populates p->first->locations_by_path_ from p->second.
// Unusual signature dictated by internal::call_once. // Unusual signature dictated by internal::call_once.
static void BuildLocationsByPath( static void BuildLocationsByPath(
@ -1329,12 +1326,13 @@ class FileDescriptorTables {
void FieldsByCamelcaseNamesLazyInitInternal() const; void FieldsByCamelcaseNamesLazyInitInternal() const;
SymbolsByParentSet symbols_by_parent_; SymbolsByParentSet symbols_by_parent_;
mutable FieldsByNameMap fields_by_lowercase_name_;
std::unique_ptr<FieldsByNameMap> fields_by_lowercase_name_tmp_;
mutable internal::once_flag fields_by_lowercase_name_once_; mutable internal::once_flag fields_by_lowercase_name_once_;
mutable FieldsByNameMap fields_by_camelcase_name_;
std::unique_ptr<FieldsByNameMap> fields_by_camelcase_name_tmp_;
mutable internal::once_flag fields_by_camelcase_name_once_; mutable internal::once_flag fields_by_camelcase_name_once_;
// Make these fields atomic to avoid race conditions with
// GetEstimatedOwnedMemoryBytesSize. Once the pointer is set the map won't
// change anymore.
mutable std::atomic<const FieldsByNameMap*> fields_by_lowercase_name_{};
mutable std::atomic<const FieldsByNameMap*> fields_by_camelcase_name_{};
FieldsByNumberSet fields_by_number_; // Not including extensions. FieldsByNumberSet fields_by_number_; // Not including extensions.
EnumValuesByNumberSet enum_values_by_number_; EnumValuesByNumberSet enum_values_by_number_;
mutable EnumValuesByNumberSet unknown_enum_values_by_number_ mutable EnumValuesByNumberSet unknown_enum_values_by_number_
@ -1372,11 +1370,12 @@ DescriptorPool::Tables::Tables() {
DescriptorPool::Tables::~Tables() { GOOGLE_DCHECK(checkpoints_.empty()); } DescriptorPool::Tables::~Tables() { GOOGLE_DCHECK(checkpoints_.empty()); }
FileDescriptorTables::FileDescriptorTables() FileDescriptorTables::FileDescriptorTables() {}
: fields_by_lowercase_name_tmp_(new FieldsByNameMap()),
fields_by_camelcase_name_tmp_(new FieldsByNameMap()) {}
FileDescriptorTables::~FileDescriptorTables() {} FileDescriptorTables::~FileDescriptorTables() {
delete fields_by_lowercase_name_.load(std::memory_order_acquire);
delete fields_by_camelcase_name_.load(std::memory_order_acquire);
}
inline const FileDescriptorTables& FileDescriptorTables::GetEmptyInstance() { inline const FileDescriptorTables& FileDescriptorTables::GetEmptyInstance() {
static auto file_descriptor_tables = static auto file_descriptor_tables =
@ -1519,13 +1518,14 @@ void FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic(
} }
void FileDescriptorTables::FieldsByLowercaseNamesLazyInitInternal() const { void FileDescriptorTables::FieldsByLowercaseNamesLazyInitInternal() const {
auto* map = new FieldsByNameMap;
for (Symbol symbol : symbols_by_parent_) { for (Symbol symbol : symbols_by_parent_) {
const FieldDescriptor* field = symbol.field_descriptor(); const FieldDescriptor* field = symbol.field_descriptor();
if (!field) continue; if (!field) continue;
PointerStringPair lowercase_key(FindParentForFieldsByMap(field), (*map)[{FindParentForFieldsByMap(field), field->lowercase_name().c_str()}] =
field->lowercase_name().c_str()); field;
InsertIfNotPresent(&fields_by_lowercase_name_, lowercase_key, field);
} }
fields_by_lowercase_name_.store(map, std::memory_order_release);
} }
inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName( inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName(
@ -1533,8 +1533,9 @@ inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName(
internal::call_once( internal::call_once(
fields_by_lowercase_name_once_, fields_by_lowercase_name_once_,
&FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, this); &FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, this);
return FindPtrOrNull(fields_by_lowercase_name_, return FindPtrOrNull(
PointerStringPair(parent, lowercase_name)); *fields_by_lowercase_name_.load(std::memory_order_acquire),
PointerStringPair(parent, lowercase_name));
} }
void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic( void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic(
@ -1543,13 +1544,14 @@ void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic(
} }
void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitInternal() const { void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitInternal() const {
auto* map = new FieldsByNameMap;
for (Symbol symbol : symbols_by_parent_) { for (Symbol symbol : symbols_by_parent_) {
const FieldDescriptor* field = symbol.field_descriptor(); const FieldDescriptor* field = symbol.field_descriptor();
if (!field) continue; if (!field) continue;
PointerStringPair camelcase_key(FindParentForFieldsByMap(field), (*map)[{FindParentForFieldsByMap(field), field->camelcase_name().c_str()}] =
field->camelcase_name().c_str()); field;
InsertIfNotPresent(&fields_by_camelcase_name_, camelcase_key, field);
} }
fields_by_camelcase_name_.store(map, std::memory_order_release);
} }
inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName( inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName(
@ -1557,8 +1559,9 @@ inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName(
internal::call_once( internal::call_once(
fields_by_camelcase_name_once_, fields_by_camelcase_name_once_,
FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, this); FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, this);
return FindPtrOrNull(fields_by_camelcase_name_, return FindPtrOrNull(
PointerStringPair(parent, camelcase_name)); *fields_by_camelcase_name_.load(std::memory_order_acquire),
PointerStringPair(parent, camelcase_name));
} }
inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber( inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber(
@ -1618,8 +1621,8 @@ FileDescriptorTables::FindEnumValueByNumberCreatingIfUnknown(
// EnumDescriptor (it's not a part of the enum as originally defined), but // EnumDescriptor (it's not a part of the enum as originally defined), but
// we do insert it into the table so that we can return the same pointer // we do insert it into the table so that we can return the same pointer
// later. // later.
std::string enum_value_name = StringPrintf("UNKNOWN_ENUM_VALUE_%s_%d", std::string enum_value_name = StringPrintf(
parent->name().c_str(), number); "UNKNOWN_ENUM_VALUE_%s_%d", parent->name().c_str(), number);
auto* pool = DescriptorPool::generated_pool(); auto* pool = DescriptorPool::generated_pool();
auto* tables = const_cast<DescriptorPool::Tables*>(pool->tables_.get()); auto* tables = const_cast<DescriptorPool::Tables*>(pool->tables_.get());
internal::FlatAllocator alloc; internal::FlatAllocator alloc;
@ -1688,39 +1691,7 @@ bool DescriptorPool::Tables::AddFile(const FileDescriptor* file) {
} }
} }
void FileDescriptorTables::FinalizeTables() { void FileDescriptorTables::FinalizeTables() {}
// Clean up the temporary maps used by AddFieldByStylizedNames().
fields_by_lowercase_name_tmp_ = nullptr;
fields_by_camelcase_name_tmp_ = nullptr;
}
void FileDescriptorTables::AddFieldByStylizedNames(
const FieldDescriptor* field) {
const void* parent = FindParentForFieldsByMap(field);
// We want fields_by_{lower,camel}case_name_ to be lazily built, but
// cross-link order determines which entry will be present in the case of a
// conflict. So we use the temporary maps that get destroyed after
// BuildFileImpl() to detect the conflicts, and only store the conflicts in
// the map that will persist. We will then lazily populate the rest of the
// entries from fields_by_number_.
PointerStringPair lowercase_key(parent, field->lowercase_name().c_str());
if (!InsertIfNotPresent(fields_by_lowercase_name_tmp_.get(),
lowercase_key, field)) {
InsertIfNotPresent(
&fields_by_lowercase_name_, lowercase_key,
FindPtrOrNull(*fields_by_lowercase_name_tmp_, lowercase_key));
}
PointerStringPair camelcase_key(parent, field->camelcase_name().c_str());
if (!InsertIfNotPresent(fields_by_camelcase_name_tmp_.get(),
camelcase_key, field)) {
InsertIfNotPresent(
&fields_by_camelcase_name_, camelcase_key,
FindPtrOrNull(*fields_by_camelcase_name_tmp_, camelcase_key));
}
}
bool FileDescriptorTables::AddFieldByNumber(FieldDescriptor* field) { bool FileDescriptorTables::AddFieldByNumber(FieldDescriptor* field) {
// Skip fields that are at the start of the sequence. // Skip fields that are at the start of the sequence.
@ -6270,9 +6241,6 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field,
field->options_ = &FieldOptions::default_instance(); field->options_ = &FieldOptions::default_instance();
} }
// Add the field to the lowercase-name and camelcase-name tables.
file_tables_->AddFieldByStylizedNames(field);
if (proto.has_extendee()) { if (proto.has_extendee()) {
Symbol extendee = Symbol extendee =
LookupSymbol(proto.extendee(), field->full_name(), LookupSymbol(proto.extendee(), field->full_name(),

@ -1506,26 +1506,26 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
package_.InitDefault(); package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_package()) { if (from._internal_has_package()) {
package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_package(), package_.Set(from._internal_package(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
syntax_.InitDefault(); syntax_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
syntax_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); syntax_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_syntax()) { if (from._internal_has_syntax()) {
syntax_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_syntax(), syntax_.Set(from._internal_syntax(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -1544,15 +1544,15 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from)
inline void FileDescriptorProto::SharedCtor() { inline void FileDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
package_.InitDefault(); package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
syntax_.InitDefault(); syntax_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
syntax_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); syntax_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -1571,9 +1571,9 @@ FileDescriptorProto::~FileDescriptorProto() {
inline void FileDescriptorProto::SharedDtor() { inline void FileDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); package_.Destroy();
syntax_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); syntax_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
if (this != internal_default_instance()) delete source_code_info_; if (this != internal_default_instance()) delete source_code_info_;
} }
@ -2102,17 +2102,14 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) {
public_dependency_.InternalSwap(&other->public_dependency_); public_dependency_.InternalSwap(&other->public_dependency_);
weak_dependency_.InternalSwap(&other->weak_dependency_); weak_dependency_.InternalSwap(&other->weak_dependency_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&package_, lhs_arena, &package_, lhs_arena,
&other->package_, rhs_arena &other->package_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&syntax_, lhs_arena, &syntax_, lhs_arena,
&other->syntax_, rhs_arena &other->syntax_, rhs_arena
); );
@ -2682,10 +2679,10 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -2699,7 +2696,7 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from)
inline void DescriptorProto::SharedCtor() { inline void DescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr; options_ = nullptr;
} }
@ -2715,7 +2712,7 @@ DescriptorProto::~DescriptorProto() {
inline void DescriptorProto::SharedDtor() { inline void DescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -3173,7 +3170,6 @@ void DescriptorProto::InternalSwap(DescriptorProto* other) {
reserved_range_.InternalSwap(&other->reserved_range_); reserved_range_.InternalSwap(&other->reserved_range_);
reserved_name_.InternalSwap(&other->reserved_name_); reserved_name_.InternalSwap(&other->reserved_name_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
@ -3443,42 +3439,42 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
extendee_.InitDefault(); extendee_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
extendee_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); extendee_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_extendee()) { if (from._internal_has_extendee()) {
extendee_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_extendee(), extendee_.Set(from._internal_extendee(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
type_name_.InitDefault(); type_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); type_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_type_name()) { if (from._internal_has_type_name()) {
type_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_type_name(), type_name_.Set(from._internal_type_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
default_value_.InitDefault(); default_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
default_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); default_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_default_value()) { if (from._internal_has_default_value()) {
default_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_default_value(), default_value_.Set(from._internal_default_value(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
json_name_.InitDefault(); json_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
json_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); json_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_json_name()) { if (from._internal_has_json_name()) {
json_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_json_name(), json_name_.Set(from._internal_json_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -3495,23 +3491,23 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
inline void FieldDescriptorProto::SharedCtor() { inline void FieldDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
extendee_.InitDefault(); extendee_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
extendee_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); extendee_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_name_.InitDefault(); type_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); type_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
default_value_.InitDefault(); default_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
default_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); default_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
json_name_.InitDefault(); json_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
json_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); json_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -3532,11 +3528,11 @@ FieldDescriptorProto::~FieldDescriptorProto() {
inline void FieldDescriptorProto::SharedDtor() { inline void FieldDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
extendee_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); extendee_.Destroy();
type_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); type_name_.Destroy();
default_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); default_value_.Destroy();
json_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); json_name_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -4010,27 +4006,22 @@ void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&extendee_, lhs_arena, &extendee_, lhs_arena,
&other->extendee_, rhs_arena &other->extendee_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&type_name_, lhs_arena, &type_name_, lhs_arena,
&other->type_name_, rhs_arena &other->type_name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&default_value_, lhs_arena, &default_value_, lhs_arena,
&other->default_value_, rhs_arena &other->default_value_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&json_name_, lhs_arena, &json_name_, lhs_arena,
&other->json_name_, rhs_arena &other->json_name_, rhs_arena
); );
@ -4080,10 +4071,10 @@ OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -4097,7 +4088,7 @@ OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from)
inline void OneofDescriptorProto::SharedCtor() { inline void OneofDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr; options_ = nullptr;
} }
@ -4113,7 +4104,7 @@ OneofDescriptorProto::~OneofDescriptorProto() {
inline void OneofDescriptorProto::SharedDtor() { inline void OneofDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -4304,7 +4295,6 @@ void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
@ -4583,10 +4573,10 @@ EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -4600,7 +4590,7 @@ EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from)
inline void EnumDescriptorProto::SharedCtor() { inline void EnumDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr; options_ = nullptr;
} }
@ -4616,7 +4606,7 @@ EnumDescriptorProto::~EnumDescriptorProto() {
inline void EnumDescriptorProto::SharedDtor() { inline void EnumDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -4909,7 +4899,6 @@ void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) {
reserved_range_.InternalSwap(&other->reserved_range_); reserved_range_.InternalSwap(&other->reserved_range_);
reserved_name_.InternalSwap(&other->reserved_name_); reserved_name_.InternalSwap(&other->reserved_name_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
@ -4955,10 +4944,10 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProt
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -4973,7 +4962,7 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProt
inline void EnumValueDescriptorProto::SharedCtor() { inline void EnumValueDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -4992,7 +4981,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() {
inline void EnumValueDescriptorProto::SharedDtor() { inline void EnumValueDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -5208,7 +5197,6 @@ void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
@ -5258,10 +5246,10 @@ ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& fro
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -5275,7 +5263,7 @@ ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& fro
inline void ServiceDescriptorProto::SharedCtor() { inline void ServiceDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr; options_ = nullptr;
} }
@ -5291,7 +5279,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() {
inline void ServiceDescriptorProto::SharedDtor() { inline void ServiceDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -5515,7 +5503,6 @@ void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) {
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
method_.InternalSwap(&other->method_); method_.InternalSwap(&other->method_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
@ -5570,26 +5557,26 @@ MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) { if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), name_.Set(from._internal_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
input_type_.InitDefault(); input_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
input_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); input_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_input_type()) { if (from._internal_has_input_type()) {
input_type_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_input_type(), input_type_.Set(from._internal_input_type(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
output_type_.InitDefault(); output_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
output_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); output_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_output_type()) { if (from._internal_has_output_type()) {
output_type_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_output_type(), output_type_.Set(from._internal_output_type(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
if (from._internal_has_options()) { if (from._internal_has_options()) {
@ -5606,15 +5593,15 @@ MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from)
inline void MethodDescriptorProto::SharedCtor() { inline void MethodDescriptorProto::SharedCtor() {
name_.InitDefault(); name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
input_type_.InitDefault(); input_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
input_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); input_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
output_type_.InitDefault(); output_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
output_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); output_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -5633,9 +5620,9 @@ MethodDescriptorProto::~MethodDescriptorProto() {
inline void MethodDescriptorProto::SharedDtor() { inline void MethodDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.Destroy();
input_type_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); input_type_.Destroy();
output_type_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); output_type_.Destroy();
if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete options_;
} }
@ -5946,17 +5933,14 @@ void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena, &name_, lhs_arena,
&other->name_, rhs_arena &other->name_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&input_type_, lhs_arena, &input_type_, lhs_arena,
&other->input_type_, rhs_arena &other->input_type_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&output_type_, lhs_arena, &output_type_, lhs_arena,
&other->output_type_, rhs_arena &other->output_type_, rhs_arena
); );
@ -6057,82 +6041,82 @@ FileOptions::FileOptions(const FileOptions& from)
_extensions_.MergeFrom(internal_default_instance(), from._extensions_); _extensions_.MergeFrom(internal_default_instance(), from._extensions_);
java_package_.InitDefault(); java_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); java_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_java_package()) { if (from._internal_has_java_package()) {
java_package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_java_package(), java_package_.Set(from._internal_java_package(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
java_outer_classname_.InitDefault(); java_outer_classname_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_outer_classname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); java_outer_classname_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_java_outer_classname()) { if (from._internal_has_java_outer_classname()) {
java_outer_classname_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_java_outer_classname(), java_outer_classname_.Set(from._internal_java_outer_classname(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
go_package_.InitDefault(); go_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
go_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); go_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_go_package()) { if (from._internal_has_go_package()) {
go_package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_go_package(), go_package_.Set(from._internal_go_package(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
objc_class_prefix_.InitDefault(); objc_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
objc_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); objc_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_objc_class_prefix()) { if (from._internal_has_objc_class_prefix()) {
objc_class_prefix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_objc_class_prefix(), objc_class_prefix_.Set(from._internal_objc_class_prefix(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
csharp_namespace_.InitDefault(); csharp_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
csharp_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); csharp_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_csharp_namespace()) { if (from._internal_has_csharp_namespace()) {
csharp_namespace_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_csharp_namespace(), csharp_namespace_.Set(from._internal_csharp_namespace(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
swift_prefix_.InitDefault(); swift_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
swift_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); swift_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_swift_prefix()) { if (from._internal_has_swift_prefix()) {
swift_prefix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_swift_prefix(), swift_prefix_.Set(from._internal_swift_prefix(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
php_class_prefix_.InitDefault(); php_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); php_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_php_class_prefix()) { if (from._internal_has_php_class_prefix()) {
php_class_prefix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_php_class_prefix(), php_class_prefix_.Set(from._internal_php_class_prefix(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
php_namespace_.InitDefault(); php_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); php_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_php_namespace()) { if (from._internal_has_php_namespace()) {
php_namespace_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_php_namespace(), php_namespace_.Set(from._internal_php_namespace(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
php_metadata_namespace_.InitDefault(); php_metadata_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_metadata_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); php_metadata_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_php_metadata_namespace()) { if (from._internal_has_php_metadata_namespace()) {
php_metadata_namespace_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_php_metadata_namespace(), php_metadata_namespace_.Set(from._internal_php_metadata_namespace(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
ruby_package_.InitDefault(); ruby_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
ruby_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); ruby_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_ruby_package()) { if (from._internal_has_ruby_package()) {
ruby_package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_ruby_package(), ruby_package_.Set(from._internal_ruby_package(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
::memcpy(&java_multiple_files_, &from.java_multiple_files_, ::memcpy(&java_multiple_files_, &from.java_multiple_files_,
@ -6144,43 +6128,43 @@ FileOptions::FileOptions(const FileOptions& from)
inline void FileOptions::SharedCtor() { inline void FileOptions::SharedCtor() {
java_package_.InitDefault(); java_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); java_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_outer_classname_.InitDefault(); java_outer_classname_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_outer_classname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); java_outer_classname_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
go_package_.InitDefault(); go_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
go_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); go_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
objc_class_prefix_.InitDefault(); objc_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
objc_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); objc_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
csharp_namespace_.InitDefault(); csharp_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
csharp_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); csharp_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
swift_prefix_.InitDefault(); swift_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
swift_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); swift_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_class_prefix_.InitDefault(); php_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); php_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_namespace_.InitDefault(); php_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); php_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_metadata_namespace_.InitDefault(); php_metadata_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_metadata_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); php_metadata_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
ruby_package_.InitDefault(); ruby_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
ruby_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); ruby_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&java_multiple_files_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&java_multiple_files_) - reinterpret_cast<char*>(this)),
@ -6201,16 +6185,16 @@ FileOptions::~FileOptions() {
inline void FileOptions::SharedDtor() { inline void FileOptions::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
java_package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); java_package_.Destroy();
java_outer_classname_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); java_outer_classname_.Destroy();
go_package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); go_package_.Destroy();
objc_class_prefix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); objc_class_prefix_.Destroy();
csharp_namespace_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); csharp_namespace_.Destroy();
swift_prefix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); swift_prefix_.Destroy();
php_class_prefix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); php_class_prefix_.Destroy();
php_namespace_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); php_namespace_.Destroy();
php_metadata_namespace_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); php_metadata_namespace_.Destroy();
ruby_package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); ruby_package_.Destroy();
} }
void FileOptions::SetCachedSize(int size) const { void FileOptions::SetCachedSize(int size) const {
@ -6994,52 +6978,42 @@ void FileOptions::InternalSwap(FileOptions* other) {
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); uninterpreted_option_.InternalSwap(&other->uninterpreted_option_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&java_package_, lhs_arena, &java_package_, lhs_arena,
&other->java_package_, rhs_arena &other->java_package_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&java_outer_classname_, lhs_arena, &java_outer_classname_, lhs_arena,
&other->java_outer_classname_, rhs_arena &other->java_outer_classname_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&go_package_, lhs_arena, &go_package_, lhs_arena,
&other->go_package_, rhs_arena &other->go_package_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&objc_class_prefix_, lhs_arena, &objc_class_prefix_, lhs_arena,
&other->objc_class_prefix_, rhs_arena &other->objc_class_prefix_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&csharp_namespace_, lhs_arena, &csharp_namespace_, lhs_arena,
&other->csharp_namespace_, rhs_arena &other->csharp_namespace_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&swift_prefix_, lhs_arena, &swift_prefix_, lhs_arena,
&other->swift_prefix_, rhs_arena &other->swift_prefix_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&php_class_prefix_, lhs_arena, &php_class_prefix_, lhs_arena,
&other->php_class_prefix_, rhs_arena &other->php_class_prefix_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&php_namespace_, lhs_arena, &php_namespace_, lhs_arena,
&other->php_namespace_, rhs_arena &other->php_namespace_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&php_metadata_namespace_, lhs_arena, &php_metadata_namespace_, lhs_arena,
&other->php_metadata_namespace_, rhs_arena &other->php_metadata_namespace_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&ruby_package_, lhs_arena, &ruby_package_, lhs_arena,
&other->ruby_package_, rhs_arena &other->ruby_package_, rhs_arena
); );
@ -9097,10 +9071,10 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_part_.InitDefault(); name_part_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_part_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_part_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name_part()) { if (from._internal_has_name_part()) {
name_part_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name_part(), name_part_.Set(from._internal_name_part(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
is_extension_ = from.is_extension_; is_extension_ = from.is_extension_;
@ -9110,7 +9084,7 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp
inline void UninterpretedOption_NamePart::SharedCtor() { inline void UninterpretedOption_NamePart::SharedCtor() {
name_part_.InitDefault(); name_part_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_part_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); name_part_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
is_extension_ = false; is_extension_ = false;
} }
@ -9126,7 +9100,7 @@ UninterpretedOption_NamePart::~UninterpretedOption_NamePart() {
inline void UninterpretedOption_NamePart::SharedDtor() { inline void UninterpretedOption_NamePart::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_part_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_part_.Destroy();
} }
void UninterpretedOption_NamePart::SetCachedSize(int size) const { void UninterpretedOption_NamePart::SetCachedSize(int size) const {
@ -9323,7 +9297,6 @@ void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* ot
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_part_, lhs_arena, &name_part_, lhs_arena,
&other->name_part_, rhs_arena &other->name_part_, rhs_arena
); );
@ -9375,26 +9348,26 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
identifier_value_.InitDefault(); identifier_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
identifier_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); identifier_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_identifier_value()) { if (from._internal_has_identifier_value()) {
identifier_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_identifier_value(), identifier_value_.Set(from._internal_identifier_value(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
string_value_.InitDefault(); string_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
string_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); string_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_string_value()) { if (from._internal_has_string_value()) {
string_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_string_value(), string_value_.Set(from._internal_string_value(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
aggregate_value_.InitDefault(); aggregate_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
aggregate_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); aggregate_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_aggregate_value()) { if (from._internal_has_aggregate_value()) {
aggregate_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_aggregate_value(), aggregate_value_.Set(from._internal_aggregate_value(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
::memcpy(&positive_int_value_, &from.positive_int_value_, ::memcpy(&positive_int_value_, &from.positive_int_value_,
@ -9406,15 +9379,15 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from)
inline void UninterpretedOption::SharedCtor() { inline void UninterpretedOption::SharedCtor() {
identifier_value_.InitDefault(); identifier_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
identifier_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); identifier_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
string_value_.InitDefault(); string_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
string_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); string_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
aggregate_value_.InitDefault(); aggregate_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
aggregate_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); aggregate_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&positive_int_value_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&positive_int_value_) - reinterpret_cast<char*>(this)),
@ -9433,9 +9406,9 @@ UninterpretedOption::~UninterpretedOption() {
inline void UninterpretedOption::SharedDtor() { inline void UninterpretedOption::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
identifier_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); identifier_value_.Destroy();
string_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); string_value_.Destroy();
aggregate_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); aggregate_value_.Destroy();
} }
void UninterpretedOption::SetCachedSize(int size) const { void UninterpretedOption::SetCachedSize(int size) const {
@ -9764,17 +9737,14 @@ void UninterpretedOption::InternalSwap(UninterpretedOption* other) {
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
name_.InternalSwap(&other->name_); name_.InternalSwap(&other->name_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&identifier_value_, lhs_arena, &identifier_value_, lhs_arena,
&other->identifier_value_, rhs_arena &other->identifier_value_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&string_value_, lhs_arena, &string_value_, lhs_arena,
&other->string_value_, rhs_arena &other->string_value_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&aggregate_value_, lhs_arena, &aggregate_value_, lhs_arena,
&other->aggregate_value_, rhs_arena &other->aggregate_value_, rhs_arena
); );
@ -9823,18 +9793,18 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location&
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
leading_comments_.InitDefault(); leading_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
leading_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); leading_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_leading_comments()) { if (from._internal_has_leading_comments()) {
leading_comments_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_leading_comments(), leading_comments_.Set(from._internal_leading_comments(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
trailing_comments_.InitDefault(); trailing_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
trailing_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); trailing_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_trailing_comments()) { if (from._internal_has_trailing_comments()) {
trailing_comments_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_trailing_comments(), trailing_comments_.Set(from._internal_trailing_comments(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo.Location) // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo.Location)
@ -9843,11 +9813,11 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location&
inline void SourceCodeInfo_Location::SharedCtor() { inline void SourceCodeInfo_Location::SharedCtor() {
leading_comments_.InitDefault(); leading_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
leading_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); leading_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
trailing_comments_.InitDefault(); trailing_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
trailing_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); trailing_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
@ -9862,8 +9832,8 @@ SourceCodeInfo_Location::~SourceCodeInfo_Location() {
inline void SourceCodeInfo_Location::SharedDtor() { inline void SourceCodeInfo_Location::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
leading_comments_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); leading_comments_.Destroy();
trailing_comments_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); trailing_comments_.Destroy();
} }
void SourceCodeInfo_Location::SetCachedSize(int size) const { void SourceCodeInfo_Location::SetCachedSize(int size) const {
@ -10168,12 +10138,10 @@ void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) {
span_.InternalSwap(&other->span_); span_.InternalSwap(&other->span_);
leading_detached_comments_.InternalSwap(&other->leading_detached_comments_); leading_detached_comments_.InternalSwap(&other->leading_detached_comments_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&leading_comments_, lhs_arena, &leading_comments_, lhs_arena,
&other->leading_comments_, rhs_arena &other->leading_comments_, rhs_arena
); );
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&trailing_comments_, lhs_arena, &trailing_comments_, lhs_arena,
&other->trailing_comments_, rhs_arena &other->trailing_comments_, rhs_arena
); );
@ -10393,10 +10361,10 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
source_file_.InitDefault(); source_file_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
source_file_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); source_file_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_source_file()) { if (from._internal_has_source_file()) {
source_file_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_source_file(), source_file_.Set(from._internal_source_file(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
::memcpy(&begin_, &from.begin_, ::memcpy(&begin_, &from.begin_,
@ -10408,7 +10376,7 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn
inline void GeneratedCodeInfo_Annotation::SharedCtor() { inline void GeneratedCodeInfo_Annotation::SharedCtor() {
source_file_.InitDefault(); source_file_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
source_file_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); source_file_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>( ::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&begin_) - reinterpret_cast<char*>(this)), reinterpret_cast<char*>(&begin_) - reinterpret_cast<char*>(this)),
@ -10427,7 +10395,7 @@ GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() {
inline void GeneratedCodeInfo_Annotation::SharedDtor() { inline void GeneratedCodeInfo_Annotation::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
source_file_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); source_file_.Destroy();
} }
void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const { void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const {
@ -10672,7 +10640,6 @@ void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* ot
swap(_has_bits_[0], other->_has_bits_[0]); swap(_has_bits_[0], other->_has_bits_[0]);
path_.InternalSwap(&other->path_); path_.InternalSwap(&other->path_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&source_file_, lhs_arena, &source_file_, lhs_arena,
&other->source_file_, rhs_arena &other->source_file_, rhs_arena
); );

File diff suppressed because it is too large Load Diff

@ -66,6 +66,8 @@
// Must be included last. // Must be included last.
#include <google/protobuf/port_def.inc> #include <google/protobuf/port_def.inc>
using ::testing::AnyOf;
namespace google { namespace google {
namespace protobuf { namespace protobuf {
@ -1307,7 +1309,8 @@ TEST_F(StylizedFieldNamesTest, CamelcaseName) {
TEST_F(StylizedFieldNamesTest, FindByLowercaseName) { TEST_F(StylizedFieldNamesTest, FindByLowercaseName) {
EXPECT_EQ(message_->field(0), message_->FindFieldByLowercaseName("foo_foo")); EXPECT_EQ(message_->field(0), message_->FindFieldByLowercaseName("foo_foo"));
EXPECT_EQ(message_->field(1), message_->FindFieldByLowercaseName("foobar")); EXPECT_THAT(message_->FindFieldByLowercaseName("foobar"),
AnyOf(message_->field(1), message_->field(4)));
EXPECT_EQ(message_->field(2), message_->FindFieldByLowercaseName("foobaz")); EXPECT_EQ(message_->field(2), message_->FindFieldByLowercaseName("foobaz"));
EXPECT_TRUE(message_->FindFieldByLowercaseName("FooBar") == nullptr); EXPECT_TRUE(message_->FindFieldByLowercaseName("FooBar") == nullptr);
EXPECT_TRUE(message_->FindFieldByLowercaseName("fooBaz") == nullptr); EXPECT_TRUE(message_->FindFieldByLowercaseName("fooBaz") == nullptr);
@ -1316,8 +1319,8 @@ TEST_F(StylizedFieldNamesTest, FindByLowercaseName) {
EXPECT_EQ(message_->extension(0), EXPECT_EQ(message_->extension(0),
message_->FindExtensionByLowercaseName("bar_foo")); message_->FindExtensionByLowercaseName("bar_foo"));
EXPECT_EQ(message_->extension(1), EXPECT_THAT(message_->FindExtensionByLowercaseName("barbar"),
message_->FindExtensionByLowercaseName("barbar")); AnyOf(message_->extension(1), message_->extension(4)));
EXPECT_EQ(message_->extension(2), EXPECT_EQ(message_->extension(2),
message_->FindExtensionByLowercaseName("barbaz")); message_->FindExtensionByLowercaseName("barbaz"));
EXPECT_TRUE(message_->FindExtensionByLowercaseName("BarBar") == nullptr); EXPECT_TRUE(message_->FindExtensionByLowercaseName("BarBar") == nullptr);
@ -1327,7 +1330,8 @@ TEST_F(StylizedFieldNamesTest, FindByLowercaseName) {
EXPECT_EQ(file_->extension(0), EXPECT_EQ(file_->extension(0),
file_->FindExtensionByLowercaseName("baz_foo")); file_->FindExtensionByLowercaseName("baz_foo"));
EXPECT_EQ(file_->extension(1), file_->FindExtensionByLowercaseName("bazbar")); EXPECT_THAT(file_->FindExtensionByLowercaseName("bazbar"),
AnyOf(file_->extension(1), file_->extension(4)));
EXPECT_EQ(file_->extension(2), file_->FindExtensionByLowercaseName("bazbaz")); EXPECT_EQ(file_->extension(2), file_->FindExtensionByLowercaseName("bazbaz"));
EXPECT_TRUE(file_->FindExtensionByLowercaseName("BazBar") == nullptr); EXPECT_TRUE(file_->FindExtensionByLowercaseName("BazBar") == nullptr);
EXPECT_TRUE(file_->FindExtensionByLowercaseName("bazBaz") == nullptr); EXPECT_TRUE(file_->FindExtensionByLowercaseName("bazBaz") == nullptr);
@ -1335,7 +1339,8 @@ TEST_F(StylizedFieldNamesTest, FindByLowercaseName) {
} }
TEST_F(StylizedFieldNamesTest, FindByCamelcaseName) { TEST_F(StylizedFieldNamesTest, FindByCamelcaseName) {
EXPECT_EQ(message_->field(0), message_->FindFieldByCamelcaseName("fooFoo")); EXPECT_THAT(message_->FindFieldByCamelcaseName("fooFoo"),
AnyOf(message_->field(0), message_->field(3)));
EXPECT_EQ(message_->field(1), message_->FindFieldByCamelcaseName("fooBar")); EXPECT_EQ(message_->field(1), message_->FindFieldByCamelcaseName("fooBar"));
EXPECT_EQ(message_->field(2), message_->FindFieldByCamelcaseName("fooBaz")); EXPECT_EQ(message_->field(2), message_->FindFieldByCamelcaseName("fooBaz"));
EXPECT_TRUE(message_->FindFieldByCamelcaseName("foo_foo") == nullptr); EXPECT_TRUE(message_->FindFieldByCamelcaseName("foo_foo") == nullptr);
@ -1343,8 +1348,8 @@ TEST_F(StylizedFieldNamesTest, FindByCamelcaseName) {
EXPECT_TRUE(message_->FindFieldByCamelcaseName("barFoo") == nullptr); EXPECT_TRUE(message_->FindFieldByCamelcaseName("barFoo") == nullptr);
EXPECT_TRUE(message_->FindFieldByCamelcaseName("nosuchfield") == nullptr); EXPECT_TRUE(message_->FindFieldByCamelcaseName("nosuchfield") == nullptr);
EXPECT_EQ(message_->extension(0), EXPECT_THAT(message_->FindExtensionByCamelcaseName("barFoo"),
message_->FindExtensionByCamelcaseName("barFoo")); AnyOf(message_->extension(0), message_->extension(3)));
EXPECT_EQ(message_->extension(1), EXPECT_EQ(message_->extension(1),
message_->FindExtensionByCamelcaseName("barBar")); message_->FindExtensionByCamelcaseName("barBar"));
EXPECT_EQ(message_->extension(2), EXPECT_EQ(message_->extension(2),
@ -1354,7 +1359,8 @@ TEST_F(StylizedFieldNamesTest, FindByCamelcaseName) {
EXPECT_TRUE(message_->FindExtensionByCamelcaseName("fooFoo") == nullptr); EXPECT_TRUE(message_->FindExtensionByCamelcaseName("fooFoo") == nullptr);
EXPECT_TRUE(message_->FindExtensionByCamelcaseName("nosuchfield") == nullptr); EXPECT_TRUE(message_->FindExtensionByCamelcaseName("nosuchfield") == nullptr);
EXPECT_EQ(file_->extension(0), file_->FindExtensionByCamelcaseName("bazFoo")); EXPECT_THAT(file_->FindExtensionByCamelcaseName("bazFoo"),
AnyOf(file_->extension(0), file_->extension(3)));
EXPECT_EQ(file_->extension(1), file_->FindExtensionByCamelcaseName("bazBar")); EXPECT_EQ(file_->extension(1), file_->FindExtensionByCamelcaseName("bazBar"));
EXPECT_EQ(file_->extension(2), file_->FindExtensionByCamelcaseName("bazBaz")); EXPECT_EQ(file_->extension(2), file_->FindExtensionByCamelcaseName("bazBaz"));
EXPECT_TRUE(file_->FindExtensionByCamelcaseName("baz_foo") == nullptr); EXPECT_TRUE(file_->FindExtensionByCamelcaseName("baz_foo") == nullptr);

@ -417,11 +417,7 @@ void DynamicMessage::SharedCtor(bool lock_factory) {
case FieldOptions::STRING: case FieldOptions::STRING:
if (!field->is_repeated()) { if (!field->is_repeated()) {
ArenaStringPtr* asp = new (field_ptr) ArenaStringPtr(); ArenaStringPtr* asp = new (field_ptr) ArenaStringPtr();
if (field->default_value_string().empty()) { asp->InitDefault();
asp->InitDefault();
} else {
asp->InitDefault(nullptr);
}
} else { } else {
new (field_ptr) new (field_ptr)
RepeatedPtrField<std::string>(GetArenaForAllocation()); RepeatedPtrField<std::string>(GetArenaForAllocation());
@ -522,13 +518,7 @@ DynamicMessage::~DynamicMessage() {
switch (field->options().ctype()) { switch (field->options().ctype()) {
default: default:
case FieldOptions::STRING: { case FieldOptions::STRING: {
// Oneof string fields are never set as a default instance. reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy();
// We just need to pass some arbitrary default string to make it
// work. This allows us to not have the real default accessible
// from reflection.
const std::string* default_value = nullptr;
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, nullptr);
break; break;
} }
} }
@ -582,13 +572,7 @@ DynamicMessage::~DynamicMessage() {
switch (field->options().ctype()) { switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps. default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: { case FieldOptions::STRING: {
const std::string* default_value = reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy();
reinterpret_cast<const ArenaStringPtr*>(
type_info_->prototype->OffsetToPointer(
type_info_->offsets[i]))
->GetPointer();
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(default_value,
nullptr);
break; break;
} }
} }

@ -280,10 +280,9 @@ size_t Reflection::SpaceUsedLong(const Message& message) const {
total_size += GetUnknownFields(message).SpaceUsedExcludingSelfLong(); total_size += GetUnknownFields(message).SpaceUsedExcludingSelfLong();
// If this message owns an arena, add any unused space that's been allocated. // If this message owns an arena, add any unused space that's been allocated.
auto* arena = Arena::InternalHelper<Message>::GetArenaForAllocation(&message); auto* arena = Arena::InternalGetArenaForAllocation(&message);
if (arena != nullptr && if (arena != nullptr && Arena::InternalGetOwningArena(&message) == nullptr &&
Arena::InternalHelper<Message>::GetOwningArena(&message) == nullptr && arena->InternalIsMessageOwnedArena()) {
Arena::InternalHelper<Message>::IsMessageOwnedArena(arena)) {
total_size += arena->SpaceAllocated() - arena->SpaceUsed(); total_size += arena->SpaceAllocated() - arena->SpaceUsed();
} }
@ -354,31 +353,26 @@ size_t Reflection::SpaceUsedLong(const Message& message) const {
case FieldDescriptor::CPPTYPE_STRING: { case FieldDescriptor::CPPTYPE_STRING: {
switch (field->options().ctype()) { switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps. default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: { case FieldOptions::STRING:
if (IsInlined(field)) { if (IsInlined(field)) {
const std::string* ptr = const std::string* ptr =
&GetField<InlinedStringField>(message, field).GetNoArena(); &GetField<InlinedStringField>(message, field).GetNoArena();
total_size += StringSpaceUsedExcludingSelfLong(*ptr); total_size += StringSpaceUsedExcludingSelfLong(*ptr);
break; } else {
} // Initially, the string points to the default value stored
// in the prototype. Only count the string if it has been
const std::string* ptr = // changed from the default value.
GetField<ArenaStringPtr>(message, field).GetPointer(); // Except oneof fields, those never point to a default instance,
// and there is no default instance to point to.
// Initially, the string points to the default value stored const auto& str = GetField<ArenaStringPtr>(message, field);
// in the prototype. Only count the string if it has been if (!str.IsDefault() || schema_.InRealOneof(field)) {
// changed from the default value. // string fields are represented by just a pointer, so also
// Except oneof fields, those never point to a default instance, // include sizeof(string) as well.
// and there is no default instance to point to. total_size += sizeof(std::string) +
if (schema_.InRealOneof(field) || StringSpaceUsedExcludingSelfLong(str.Get());
ptr != DefaultRaw<ArenaStringPtr>(field).GetPointer()) { }
// string fields are represented by just a pointer, so also
// include sizeof(string) as well.
total_size +=
sizeof(*ptr) + StringSpaceUsedExcludingSelfLong(*ptr);
} }
break; break;
}
} }
break; break;
} }
@ -486,8 +480,7 @@ class SwapFieldHelper {
static void SwapStringField(const Reflection* r, Message* lhs, Message* rhs, static void SwapStringField(const Reflection* r, Message* lhs, Message* rhs,
const FieldDescriptor* field); const FieldDescriptor* field);
static void SwapArenaStringPtr(const std::string* default_ptr, static void SwapArenaStringPtr(ArenaStringPtr* lhs, Arena* lhs_arena,
ArenaStringPtr* lhs, Arena* lhs_arena,
ArenaStringPtr* rhs, Arena* rhs_arena); ArenaStringPtr* rhs, Arena* rhs_arena);
template <bool unsafe_shallow_swap> template <bool unsafe_shallow_swap>
@ -551,12 +544,11 @@ void SwapFieldHelper::SwapInlinedStrings(const Reflection* r, Message* lhs,
rhs_arena, rhs_arena_dtor_registered, rhs); rhs_arena, rhs_arena_dtor_registered, rhs);
} else { } else {
const std::string temp = lhs_string->Get(); const std::string temp = lhs_string->Get();
lhs_string->Set(nullptr, rhs_string->Get(), lhs_arena, lhs_string->Set(rhs_string->Get(), lhs_arena,
r->IsInlinedStringDonated(*lhs, field), lhs_state, mask, r->IsInlinedStringDonated(*lhs, field), lhs_state, mask,
lhs); lhs);
rhs_string->Set(nullptr, temp, rhs_arena, rhs_string->Set(temp, rhs_arena, r->IsInlinedStringDonated(*rhs, field),
r->IsInlinedStringDonated(*rhs, field), rhs_state, mask, rhs_state, mask, rhs);
rhs);
} }
} }
@ -570,8 +562,7 @@ void SwapFieldHelper::SwapNonInlinedStrings(const Reflection* r, Message* lhs,
ArenaStringPtr::UnsafeShallowSwap(lhs_string, rhs_string); ArenaStringPtr::UnsafeShallowSwap(lhs_string, rhs_string);
} else { } else {
SwapFieldHelper::SwapArenaStringPtr( SwapFieldHelper::SwapArenaStringPtr(
r->DefaultRaw<ArenaStringPtr>(field).GetPointer(), // lhs_string, lhs->GetArenaForAllocation(), //
lhs_string, lhs->GetArenaForAllocation(), //
rhs_string, rhs->GetArenaForAllocation()); rhs_string, rhs->GetArenaForAllocation());
} }
} }
@ -595,28 +586,27 @@ void SwapFieldHelper::SwapStringField(const Reflection* r, Message* lhs,
} }
} }
void SwapFieldHelper::SwapArenaStringPtr(const std::string* default_ptr, void SwapFieldHelper::SwapArenaStringPtr(ArenaStringPtr* lhs, Arena* lhs_arena,
ArenaStringPtr* lhs, Arena* lhs_arena,
ArenaStringPtr* rhs, ArenaStringPtr* rhs,
Arena* rhs_arena) { Arena* rhs_arena) {
if (lhs_arena == rhs_arena) { if (lhs_arena == rhs_arena) {
ArenaStringPtr::InternalSwap(default_ptr, lhs, lhs_arena, rhs, rhs_arena); ArenaStringPtr::InternalSwap(lhs, lhs_arena, rhs, rhs_arena);
} else if (lhs->IsDefault() && rhs->IsDefault()) { } else if (lhs->IsDefault() && rhs->IsDefault()) {
// Nothing to do. // Nothing to do.
} else if (lhs->IsDefault()) { } else if (lhs->IsDefault()) {
lhs->Set(default_ptr, rhs->Get(), lhs_arena); lhs->Set(rhs->Get(), lhs_arena);
// rhs needs to be destroyed before overwritten. // rhs needs to be destroyed before overwritten.
rhs->Destroy(default_ptr, rhs_arena); rhs->Destroy();
rhs->InitDefault(default_ptr); rhs->InitDefault();
} else if (rhs->IsDefault()) { } else if (rhs->IsDefault()) {
rhs->Set(default_ptr, lhs->Get(), rhs_arena); rhs->Set(lhs->Get(), rhs_arena);
// lhs needs to be destroyed before overwritten. // lhs needs to be destroyed before overwritten.
lhs->Destroy(default_ptr, lhs_arena); lhs->Destroy();
lhs->InitDefault(default_ptr); lhs->InitDefault();
} else { } else {
std::string temp = lhs->Get(); std::string temp = lhs->Get();
lhs->Set(default_ptr, rhs->Get(), lhs_arena); lhs->Set(rhs->Get(), lhs_arena);
rhs->Set(default_ptr, std::move(temp), rhs_arena); rhs->Set(std::move(temp), rhs_arena);
} }
} }
@ -1266,20 +1256,17 @@ void Reflection::ClearField(Message* message,
case FieldDescriptor::CPPTYPE_STRING: { case FieldDescriptor::CPPTYPE_STRING: {
switch (field->options().ctype()) { switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps. default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: { case FieldOptions::STRING:
if (IsInlined(field)) { if (IsInlined(field)) {
// Currently, string with default value can't be inlined. So we // Currently, string with default value can't be inlined. So we
// don't have to handle default value here. // don't have to handle default value here.
MutableRaw<InlinedStringField>(message, field)->ClearToEmpty(); MutableRaw<InlinedStringField>(message, field)->ClearToEmpty();
break; } else {
auto* str = MutableRaw<ArenaStringPtr>(message, field);
str->Destroy();
str->InitDefault();
} }
const std::string* default_ptr =
DefaultRaw<ArenaStringPtr>(field).GetPointer();
MutableRaw<ArenaStringPtr>(message, field)
->SetAllocated(default_ptr, nullptr,
message->GetArenaForAllocation());
break; break;
}
} }
break; break;
} }
@ -1658,17 +1645,13 @@ std::string Reflection::GetString(const Message& message,
} }
switch (field->options().ctype()) { switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps. default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: { case FieldOptions::STRING:
if (IsInlined(field)) { if (IsInlined(field)) {
return GetField<InlinedStringField>(message, field).GetNoArena(); return GetField<InlinedStringField>(message, field).GetNoArena();
} else {
const auto& str = GetField<ArenaStringPtr>(message, field);
return str.IsDefault() ? field->default_value_string() : str.Get();
} }
if (auto* value =
GetField<ArenaStringPtr>(message, field).GetPointer()) {
return *value;
}
return field->default_value_string();
}
} }
} }
} }
@ -1687,17 +1670,13 @@ const std::string& Reflection::GetStringReference(const Message& message,
} }
switch (field->options().ctype()) { switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps. default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: { case FieldOptions::STRING:
if (IsInlined(field)) { if (IsInlined(field)) {
return GetField<InlinedStringField>(message, field).GetNoArena(); return GetField<InlinedStringField>(message, field).GetNoArena();
} else {
const auto& str = GetField<ArenaStringPtr>(message, field);
return str.IsDefault() ? field->default_value_string() : str.Get();
} }
if (auto* value =
GetField<ArenaStringPtr>(message, field).GetPointer()) {
return *value;
}
return field->default_value_string();
}
} }
} }
} }
@ -1720,7 +1699,7 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
&MutableInlinedStringDonatedArray(message)[index / 32]; &MutableInlinedStringDonatedArray(message)[index / 32];
uint32_t mask = ~(static_cast<uint32_t>(1) << (index % 32)); uint32_t mask = ~(static_cast<uint32_t>(1) << (index % 32));
MutableField<InlinedStringField>(message, field) MutableField<InlinedStringField>(message, field)
->Set(nullptr, value, message->GetArenaForAllocation(), ->Set(value, message->GetArenaForAllocation(),
IsInlinedStringDonated(*message, field), states, mask, IsInlinedStringDonated(*message, field), states, mask,
message); message);
break; break;
@ -1730,18 +1709,12 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
// We just need to pass some arbitrary default string to make it work. // We just need to pass some arbitrary default string to make it work.
// This allows us to not have the real default accessible from // This allows us to not have the real default accessible from
// reflection. // reflection.
const std::string* default_ptr =
schema_.InRealOneof(field)
? nullptr
: DefaultRaw<ArenaStringPtr>(field).GetPointer();
if (schema_.InRealOneof(field) && !HasOneofField(*message, field)) { if (schema_.InRealOneof(field) && !HasOneofField(*message, field)) {
ClearOneof(message, field->containing_oneof()); ClearOneof(message, field->containing_oneof());
MutableField<ArenaStringPtr>(message, field) MutableField<ArenaStringPtr>(message, field)->InitDefault();
->InitDefault(default_ptr);
} }
MutableField<ArenaStringPtr>(message, field) MutableField<ArenaStringPtr>(message, field)
->Set(default_ptr, std::move(value), ->Set(std::move(value), message->GetArenaForAllocation());
message->GetArenaForAllocation());
break; break;
} }
} }
@ -2721,8 +2694,7 @@ void Reflection::ClearOneof(Message* message,
// We just need to pass some arbitrary default string to make it // We just need to pass some arbitrary default string to make it
// work. This allows us to not have the real default accessible // work. This allows us to not have the real default accessible
// from reflection. // from reflection.
MutableField<ArenaStringPtr>(message, field) MutableField<ArenaStringPtr>(message, field)->Destroy();
->Destroy(nullptr, message->GetArenaForAllocation());
break; break;
} }
} }

@ -265,45 +265,9 @@ class PROTOBUF_EXPORT TcParser final {
static const char* GenericFallback(PROTOBUF_TC_PARAM_DECL); static const char* GenericFallback(PROTOBUF_TC_PARAM_DECL);
static const char* GenericFallbackLite(PROTOBUF_TC_PARAM_DECL); static const char* GenericFallbackLite(PROTOBUF_TC_PARAM_DECL);
// Dispatch to the designated parse function static const char* ParseLoop(MessageLite* msg, const char* ptr,
inline PROTOBUF_ALWAYS_INLINE static const char* TagDispatch( ParseContext* ctx,
PROTOBUF_TC_PARAM_DECL) { const TcParseTableBase* table);
const auto coded_tag = UnalignedLoad<uint16_t>(ptr);
const size_t idx = coded_tag & table->fast_idx_mask;
PROTOBUF_ASSUME((idx & 7) == 0);
auto* fast_entry = table->fast_entry(idx >> 3);
data = fast_entry->bits;
data.data ^= coded_tag;
PROTOBUF_MUSTTAIL return fast_entry->target(PROTOBUF_TC_PARAM_PASS);
}
// We can only safely call from field to next field if the call is optimized
// to a proper tail call. Otherwise we blow through stack. Clang and gcc
// reliably do this optimization in opt mode, but do not perform this in debug
// mode. Luckily the structure of the algorithm is such that it's always
// possible to just return and use the enclosing parse loop as a trampoline.
static const char* ToTagDispatch(PROTOBUF_TC_PARAM_DECL) {
constexpr bool always_return = !PROTOBUF_TAILCALL;
if (always_return || !ctx->DataAvailable(ptr)) {
PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS);
}
PROTOBUF_MUSTTAIL return TagDispatch(PROTOBUF_TC_PARAM_PASS);
}
PROTOBUF_NOINLINE static const char* ParseLoop(
MessageLite* msg, const char* ptr, ParseContext* ctx,
const TcParseTableBase* table) {
ScopedArenaSwap saved(msg, ctx);
const uint32_t has_bits_offset = table->has_bits_offset;
while (!ctx->Done(&ptr)) {
uint64_t hasbits = 0;
if (has_bits_offset) hasbits = RefAt<uint32_t>(msg, has_bits_offset);
ptr = TagDispatch(msg, ptr, ctx, table, hasbits, {});
if (ptr == nullptr) break;
if (ctx->LastTag() != 1) break; // Ended on terminating tag
}
return ptr;
}
// Functions referenced by generated fast tables (numeric types): // Functions referenced by generated fast tables (numeric types):
// F: fixed V: varint Z: zigzag // F: fixed V: varint Z: zigzag
@ -424,16 +388,6 @@ class PROTOBUF_EXPORT TcParser final {
return *target; return *target;
} }
static inline PROTOBUF_ALWAYS_INLINE void SyncHasbits(
MessageLite* msg, uint64_t hasbits, const TcParseTableBase* table) {
const uint32_t has_bits_offset = table->has_bits_offset;
if (has_bits_offset) {
// Only the first 32 has-bits are updated. Nothing above those is stored,
// but e.g. messages without has-bits update the upper bits.
RefAt<uint32_t>(msg, has_bits_offset) = static_cast<uint32_t>(hasbits);
}
}
// Mini parsing: // Mini parsing:
// //
// This function parses a field from incoming data based on metadata stored in // This function parses a field from incoming data based on metadata stored in
@ -453,38 +407,24 @@ class PROTOBUF_EXPORT TcParser final {
template <typename TagType> template <typename TagType>
static inline const char* RepeatedParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL); static inline const char* RepeatedParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL);
static inline PROTOBUF_ALWAYS_INLINE const char* ToParseLoop( static inline PROTOBUF_ALWAYS_INLINE void SyncHasbits(
PROTOBUF_TC_PARAM_DECL) { MessageLite* msg, uint64_t hasbits, const TcParseTableBase* table) {
(void)data; const uint32_t has_bits_offset = table->has_bits_offset;
(void)ctx; if (has_bits_offset) {
SyncHasbits(msg, hasbits, table); // Only the first 32 has-bits are updated. Nothing above those is stored,
return ptr; // but e.g. messages without has-bits update the upper bits.
RefAt<uint32_t>(msg, has_bits_offset) = static_cast<uint32_t>(hasbits);
}
} }
static inline PROTOBUF_ALWAYS_INLINE const char* Error( static const char* TagDispatch(PROTOBUF_TC_PARAM_DECL);
PROTOBUF_TC_PARAM_DECL) { static const char* ToTagDispatch(PROTOBUF_TC_PARAM_DECL);
(void)data; static const char* ToParseLoop(PROTOBUF_TC_PARAM_DECL);
(void)ctx; static const char* Error(PROTOBUF_TC_PARAM_DECL);
(void)ptr;
SyncHasbits(msg, hasbits, table);
return nullptr;
}
static const char* FastUnknownEnumFallback(PROTOBUF_TC_PARAM_DECL); static const char* FastUnknownEnumFallback(PROTOBUF_TC_PARAM_DECL);
class ScopedArenaSwap final { class ScopedArenaSwap;
public:
ScopedArenaSwap(MessageLite* msg, ParseContext* ctx)
: ctx_(ctx), saved_(ctx->data().arena) {
ctx_->data().arena = msg->GetArenaForAllocation();
}
ScopedArenaSwap(const ScopedArenaSwap&) = delete;
~ScopedArenaSwap() { ctx_->data().arena = saved_; }
private:
ParseContext* const ctx_;
Arena* const saved_;
};
template <class MessageBaseT, class UnknownFieldsT> template <class MessageBaseT, class UnknownFieldsT>
static const char* GenericFallbackImpl(PROTOBUF_TC_PARAM_DECL) { static const char* GenericFallbackImpl(PROTOBUF_TC_PARAM_DECL) {
@ -555,6 +495,14 @@ class PROTOBUF_EXPORT TcParser final {
uint32_t field_num, ParseContext* ctx, uint32_t field_num, ParseContext* ctx,
MessageLite* msg); MessageLite* msg);
// UTF-8 validation:
static void ReportFastUtf8Error(uint16_t coded_tag,
const TcParseTableBase* table);
static bool MpVerifyUtf8(StringPiece wire_bytes,
const TcParseTableBase* table,
const TcParseTableBase::FieldEntry& entry,
uint16_t xform_val);
// For FindFieldEntry tests: // For FindFieldEntry tests:
friend class FindFieldEntryTest; friend class FindFieldEntryTest;
static constexpr const uint32_t kMtSmallScanSize = 4; static constexpr const uint32_t kMtSmallScanSize = 4;

@ -46,19 +46,103 @@ namespace google {
namespace protobuf { namespace protobuf {
namespace internal { namespace internal {
const uint32_t TcParser::kMtSmallScanSize;
using FieldEntry = TcParseTableBase::FieldEntry; using FieldEntry = TcParseTableBase::FieldEntry;
//////////////////////////////////////////////////////////////////////////////
// Template instantiations:
//////////////////////////////////////////////////////////////////////////////
#ifndef NDEBUG #ifndef NDEBUG
template void AlignFail<4>(uintptr_t); template void AlignFail<4>(uintptr_t);
template void AlignFail<8>(uintptr_t); template void AlignFail<8>(uintptr_t);
#endif #endif
const uint32_t TcParser::kMtSmallScanSize;
const char* TcParser::GenericFallbackLite(PROTOBUF_TC_PARAM_DECL) { const char* TcParser::GenericFallbackLite(PROTOBUF_TC_PARAM_DECL) {
return GenericFallbackImpl<MessageLite, std::string>(PROTOBUF_TC_PARAM_PASS); return GenericFallbackImpl<MessageLite, std::string>(PROTOBUF_TC_PARAM_PASS);
} }
//////////////////////////////////////////////////////////////////////////////
// Core fast parsing implementation:
//////////////////////////////////////////////////////////////////////////////
class TcParser::ScopedArenaSwap final {
public:
ScopedArenaSwap(MessageLite* msg, ParseContext* ctx)
: ctx_(ctx), saved_(ctx->data().arena) {
ctx_->data().arena = msg->GetArenaForAllocation();
}
ScopedArenaSwap(const ScopedArenaSwap&) = delete;
~ScopedArenaSwap() { ctx_->data().arena = saved_; }
private:
ParseContext* const ctx_;
Arena* const saved_;
};
PROTOBUF_NOINLINE const char* TcParser::ParseLoop(
MessageLite* msg, const char* ptr, ParseContext* ctx,
const TcParseTableBase* table) {
ScopedArenaSwap saved(msg, ctx);
const uint32_t has_bits_offset = table->has_bits_offset;
while (!ctx->Done(&ptr)) {
uint64_t hasbits = 0;
if (has_bits_offset) hasbits = RefAt<uint32_t>(msg, has_bits_offset);
ptr = TagDispatch(msg, ptr, ctx, table, hasbits, {});
if (ptr == nullptr) break;
if (ctx->LastTag() != 1) break; // Ended on terminating tag
}
return ptr;
}
// Dispatch to the designated parse function
inline PROTOBUF_ALWAYS_INLINE const char* TcParser::TagDispatch(
PROTOBUF_TC_PARAM_DECL) {
const auto coded_tag = UnalignedLoad<uint16_t>(ptr);
const size_t idx = coded_tag & table->fast_idx_mask;
PROTOBUF_ASSUME((idx & 7) == 0);
auto* fast_entry = table->fast_entry(idx >> 3);
data = fast_entry->bits;
data.data ^= coded_tag;
PROTOBUF_MUSTTAIL return fast_entry->target(PROTOBUF_TC_PARAM_PASS);
}
// We can only safely call from field to next field if the call is optimized
// to a proper tail call. Otherwise we blow through stack. Clang and gcc
// reliably do this optimization in opt mode, but do not perform this in debug
// mode. Luckily the structure of the algorithm is such that it's always
// possible to just return and use the enclosing parse loop as a trampoline.
inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToTagDispatch(
PROTOBUF_TC_PARAM_DECL) {
constexpr bool always_return = !PROTOBUF_TAILCALL;
if (always_return || !ctx->DataAvailable(ptr)) {
PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS);
}
PROTOBUF_MUSTTAIL return TagDispatch(PROTOBUF_TC_PARAM_PASS);
}
inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToParseLoop(
PROTOBUF_TC_PARAM_DECL) {
(void)data;
(void)ctx;
SyncHasbits(msg, hasbits, table);
return ptr;
}
inline PROTOBUF_ALWAYS_INLINE const char* TcParser::Error(
PROTOBUF_TC_PARAM_DECL) {
(void)data;
(void)ctx;
(void)ptr;
SyncHasbits(msg, hasbits, table);
return nullptr;
}
//////////////////////////////////////////////////////////////////////////////
// Core mini parsing implementation:
//////////////////////////////////////////////////////////////////////////////
// Returns the address of the field for `tag` in the table's field entries. // Returns the address of the field for `tag` in the table's field entries.
// Returns nullptr if the field was not found. // Returns nullptr if the field was not found.
const TcParseTableBase::FieldEntry* TcParser::FindFieldEntry( const TcParseTableBase::FieldEntry* TcParser::FindFieldEntry(
@ -888,6 +972,17 @@ void PrintUTF8ErrorLog(StringPiece message_name,
StringPiece field_name, const char* operation_str, StringPiece field_name, const char* operation_str,
bool emit_stacktrace); bool emit_stacktrace);
void TcParser::ReportFastUtf8Error(uint16_t coded_tag,
const TcParseTableBase* table) {
if (coded_tag > 127) {
coded_tag = (coded_tag & 0x7f) + ((coded_tag & 0xff00) >> 1);
}
uint32_t field_num = coded_tag >> 3;
const auto* entry = FindFieldEntry(table, field_num);
PrintUTF8ErrorLog(MessageName(table), FieldName(table, entry), "parsing",
false);
}
namespace { namespace {
PROTOBUF_NOINLINE PROTOBUF_NOINLINE
@ -895,8 +990,7 @@ const char* SingularStringParserFallback(ArenaStringPtr* s, const char* ptr,
EpsCopyInputStream* stream) { EpsCopyInputStream* stream) {
int size = ReadSize(&ptr); int size = ReadSize(&ptr);
if (!ptr) return nullptr; if (!ptr) return nullptr;
return stream->ReadString( return stream->ReadString(ptr, size, s->MutableNoCopy(nullptr));
ptr, size, s->MutableNoArenaNoDefault(&GetEmptyStringAlreadyInited()));
} }
} // namespace } // namespace
@ -907,6 +1001,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularString(
if (PROTOBUF_PREDICT_FALSE(data.coded_tag<TagType>() != 0)) { if (PROTOBUF_PREDICT_FALSE(data.coded_tag<TagType>() != 0)) {
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS);
} }
auto saved_tag = UnalignedLoad<TagType>(ptr);
ptr += sizeof(TagType); ptr += sizeof(TagType);
hasbits |= (uint64_t{1} << data.hasbit_idx()); hasbits |= (uint64_t{1} << data.hasbit_idx());
auto& field = RefAt<ArenaStringPtr>(msg, data.offset()); auto& field = RefAt<ArenaStringPtr>(msg, data.offset());
@ -927,7 +1022,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularString(
if (PROTOBUF_PREDICT_TRUE(IsStructurallyValidUTF8(field.Get()))) { if (PROTOBUF_PREDICT_TRUE(IsStructurallyValidUTF8(field.Get()))) {
return ToParseLoop(PROTOBUF_TC_PARAM_PASS); return ToParseLoop(PROTOBUF_TC_PARAM_PASS);
} }
PrintUTF8ErrorLog("", "unknown", "parsing", false); ReportFastUtf8Error(saved_tag, table);
return utf8 == kUtf8 ? Error(PROTOBUF_TC_PARAM_PASS) return utf8 == kUtf8 ? Error(PROTOBUF_TC_PARAM_PASS)
: ToParseLoop(PROTOBUF_TC_PARAM_PASS); : ToParseLoop(PROTOBUF_TC_PARAM_PASS);
} }
@ -973,11 +1068,19 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedString(
if (ptr == nullptr) { if (ptr == nullptr) {
return Error(PROTOBUF_TC_PARAM_PASS); return Error(PROTOBUF_TC_PARAM_PASS);
} }
if (utf8 != kNoUtf8) { switch (utf8) {
if (PROTOBUF_PREDICT_FALSE(!IsStructurallyValidUTF8(*str))) { case kNoUtf8:
PrintUTF8ErrorLog("", "unknown", "parsing", false); #ifdef NDEBUG
case kUtf8ValidateOnly:
#endif
break;
default:
if (PROTOBUF_PREDICT_TRUE(IsStructurallyValidUTF8(*str))) {
break;
}
ReportFastUtf8Error(expected_tag, table);
if (utf8 == kUtf8) return Error(PROTOBUF_TC_PARAM_PASS); if (utf8 == kUtf8) return Error(PROTOBUF_TC_PARAM_PASS);
} break;
} }
if (!ctx->DataAvailable(ptr)) break; if (!ctx->DataAvailable(ptr)) break;
} while (UnalignedLoad<TagType>(ptr) == expected_tag); } while (UnalignedLoad<TagType>(ptr) == expected_tag);
@ -1060,11 +1163,10 @@ bool TcParser::ChangeOneof(const TcParseTableBase* table,
uint16_t current_kind = current_entry->type_card & field_layout::kFkMask; uint16_t current_kind = current_entry->type_card & field_layout::kFkMask;
uint16_t current_rep = current_entry->type_card & field_layout::kRepMask; uint16_t current_rep = current_entry->type_card & field_layout::kRepMask;
if (current_kind == field_layout::kFkString) { if (current_kind == field_layout::kFkString) {
Arena* arena = ctx->data().arena;
switch (current_rep) { switch (current_rep) {
case field_layout::kRepAString: { case field_layout::kRepAString: {
auto& field = RefAt<ArenaStringPtr>(msg, current_entry->offset); auto& field = RefAt<ArenaStringPtr>(msg, current_entry->offset);
field.Destroy(ArenaStringPtr::EmptyDefault{}, arena); field.Destroy();
break; break;
} }
case field_layout::kRepSString: case field_layout::kRepSString:
@ -1385,23 +1487,28 @@ const char* TcParser::MpPackedVarint(PROTOBUF_TC_PARAM_DECL) {
return Error(PROTOBUF_TC_PARAM_PASS); return Error(PROTOBUF_TC_PARAM_PASS);
} }
namespace { bool TcParser::MpVerifyUtf8(StringPiece wire_bytes,
const TcParseTableBase* table,
inline bool MpVerifyUtf8(StringPiece wire_bytes, const FieldEntry& entry, const FieldEntry& entry, uint16_t xform_val) {
uint16_t xform_val) {
if (xform_val == field_layout::kTvUtf8) { if (xform_val == field_layout::kTvUtf8) {
return VerifyUTF8(wire_bytes, "unknown"); if (!IsStructurallyValidUTF8(wire_bytes)) {
PrintUTF8ErrorLog(MessageName(table), FieldName(table, &entry), "parsing",
false);
return false;
}
return true;
} }
#ifndef NDEBUG #ifndef NDEBUG
if (xform_val == field_layout::kTvUtf8Debug) { if (xform_val == field_layout::kTvUtf8Debug) {
VerifyUTF8(wire_bytes, "unknown"); if (!IsStructurallyValidUTF8(wire_bytes)) {
PrintUTF8ErrorLog(MessageName(table), FieldName(table, &entry), "parsing",
false);
}
} }
#endif // NDEBUG #endif // NDEBUG
return true; return true;
} }
} // namespace
const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) { const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) {
const auto& entry = RefAt<FieldEntry>(table, data.entry_offset()); const auto& entry = RefAt<FieldEntry>(table, data.entry_offset());
const uint16_t type_card = entry.type_card; const uint16_t type_card = entry.type_card;
@ -1415,18 +1522,6 @@ const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) {
PROTOBUF_MUSTTAIL return MpRepeatedString(PROTOBUF_TC_PARAM_PASS); PROTOBUF_MUSTTAIL return MpRepeatedString(PROTOBUF_TC_PARAM_PASS);
} }
const uint16_t xform_val = type_card & field_layout::kTvMask; const uint16_t xform_val = type_card & field_layout::kTvMask;
// TODO(b/209516305): handle UTF-8 fields once field names are available.
if (
#ifdef NDEBUG
xform_val == field_layout::kTvUtf8
#else
xform_val != 0
#endif
) {
PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS);
}
const uint16_t rep = type_card & field_layout::kRepMask; const uint16_t rep = type_card & field_layout::kRepMask;
if (rep == field_layout::kRepIString) { if (rep == field_layout::kRepIString) {
// TODO(b/198211897): support InilnedStringField. // TODO(b/198211897): support InilnedStringField.
@ -1446,19 +1541,16 @@ const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) {
Arena* arena = ctx->data().arena; Arena* arena = ctx->data().arena;
switch (rep) { switch (rep) {
case field_layout::kRepAString: { case field_layout::kRepAString: {
const std::string* default_value =
RefAt<ArenaStringPtr>(table->default_instance, entry.offset)
.tagged_ptr_.Get();
auto& field = RefAt<ArenaStringPtr>(msg, entry.offset); auto& field = RefAt<ArenaStringPtr>(msg, entry.offset);
if (need_init) field.InitDefault(); if (need_init) field.InitDefault();
if (arena) { if (arena) {
ptr = ctx->ReadArenaString(ptr, &field, arena); ptr = ctx->ReadArenaString(ptr, &field, arena);
} else { } else {
std::string* str = field.MutableNoCopy(default_value, nullptr); std::string* str = field.MutableNoCopy(nullptr);
ptr = InlineGreedyStringParser(str, ptr, ctx); ptr = InlineGreedyStringParser(str, ptr, ctx);
} }
if (!ptr) break; if (!ptr) break;
is_valid = MpVerifyUtf8(field.Get(), entry, xform_val); is_valid = MpVerifyUtf8(field.Get(), table, entry, xform_val);
break; break;
} }
@ -1484,18 +1576,6 @@ const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) {
const uint16_t rep = type_card & field_layout::kRepMask; const uint16_t rep = type_card & field_layout::kRepMask;
const uint16_t xform_val = type_card & field_layout::kTvMask; const uint16_t xform_val = type_card & field_layout::kTvMask;
// TODO(b/209516305): handle UTF-8 fields once field names are available.
if (
#ifdef NDEBUG
xform_val == field_layout::kTvUtf8
#else
xform_val != 0
#endif
) {
PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS);
}
switch (rep) { switch (rep) {
case field_layout::kRepSString: { case field_layout::kRepSString: {
auto& field = RefAt<RepeatedPtrField<std::string>>(msg, entry.offset); auto& field = RefAt<RepeatedPtrField<std::string>>(msg, entry.offset);
@ -1505,8 +1585,9 @@ const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) {
ptr = ptr2; ptr = ptr2;
std::string* str = field.Add(); std::string* str = field.Add();
ptr = InlineGreedyStringParser(str, ptr, ctx); ptr = InlineGreedyStringParser(str, ptr, ctx);
if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || if (PROTOBUF_PREDICT_FALSE(
!MpVerifyUtf8(*str, entry, xform_val))) { ptr == nullptr ||
!MpVerifyUtf8(*str, table, entry, xform_val))) {
return Error(PROTOBUF_TC_PARAM_PASS); return Error(PROTOBUF_TC_PARAM_PASS);
} }
if (!ctx->DataAvailable(ptr)) break; if (!ctx->DataAvailable(ptr)) break;

@ -88,11 +88,11 @@ TEST(IsEntryForFieldNumTest, Matcher) {
} // namespace } // namespace
class FindFieldEntryTest : public ::testing::Test { class FindFieldEntryTest : public ::testing::Test {
protected: public:
// Calls the private `FindFieldEntry` function. // Calls the private `FindFieldEntry` function.
template <size_t kFastTableSizeLog2, size_t kNumEntries, size_t kNumFieldAux, template <size_t kFastTableSizeLog2, size_t kNumEntries, size_t kNumFieldAux,
size_t kNameTableSize> size_t kNameTableSize>
const TcParseTableBase::FieldEntry* FindFieldEntry( static const TcParseTableBase::FieldEntry* FindFieldEntry(
const TcParseTable<kFastTableSizeLog2, kNumEntries, kNumFieldAux, const TcParseTable<kFastTableSizeLog2, kNumEntries, kNumFieldAux,
kNameTableSize>& table, kNameTableSize>& table,
uint32_t tag) { uint32_t tag) {
@ -102,7 +102,7 @@ class FindFieldEntryTest : public ::testing::Test {
// Calls the private `FieldName` function. // Calls the private `FieldName` function.
template <size_t kFastTableSizeLog2, size_t kNumEntries, size_t kNumFieldAux, template <size_t kFastTableSizeLog2, size_t kNumEntries, size_t kNumFieldAux,
size_t kNameTableSize> size_t kNameTableSize>
StringPiece FieldName( static StringPiece FieldName(
const TcParseTable<kFastTableSizeLog2, kNumEntries, kNumFieldAux, const TcParseTable<kFastTableSizeLog2, kNumEntries, kNumFieldAux,
kNameTableSize>& table, kNameTableSize>& table,
const TcParseTableBase::FieldEntry* entry) { const TcParseTableBase::FieldEntry* entry) {
@ -112,7 +112,7 @@ class FindFieldEntryTest : public ::testing::Test {
// Calls the private `MessageName` function. // Calls the private `MessageName` function.
template <size_t kFastTableSizeLog2, size_t kNumEntries, size_t kNumFieldAux, template <size_t kFastTableSizeLog2, size_t kNumEntries, size_t kNumFieldAux,
size_t kNameTableSize> size_t kNameTableSize>
StringPiece MessageName( static StringPiece MessageName(
const TcParseTable<kFastTableSizeLog2, kNumEntries, kNumFieldAux, const TcParseTable<kFastTableSizeLog2, kNumEntries, kNumFieldAux,
kNameTableSize>& table) { kNameTableSize>& table) {
return TcParser::MessageName(&table.header); return TcParser::MessageName(&table.header);
@ -293,196 +293,197 @@ TEST_F(FindFieldEntryTest, EmptyMessage) {
EXPECT_THAT(MessageName(table), Eq("MessageName")); EXPECT_THAT(MessageName(table), Eq("MessageName"));
} }
TEST_F(FindFieldEntryTest, BigMessage) { // Make a monster with lots of field numbers
// Make a monster with lots of field numbers // clang-format off
// clang-format off const TcParseTable<5, 134, 5, 2176> test_all_types_table = {
const TcParseTable<5, 134, 5, 2176> test_all_types_table = { // header:
// header: {
{ 0, 0, 0, 0, // has_bits_offset, extensions
0, 0, 0, 0, // has_bits_offset, extensions 418, 248, // max_field_number, fast_idx_mask
418, 248, // max_field_number, fast_idx_mask 14, 1, // num_sequential_fields, sequential_fields_start
14, 1, // num_sequential_fields, sequential_fields_start 135, // num_field_entries
135, // num_field_entries 5, // num_aux_entries
5, // num_aux_entries offsetof(decltype(test_all_types_table), aux_entries),
offsetof(decltype(test_all_types_table), aux_entries), nullptr, // default instance
nullptr, // default instance nullptr, // fallback function
nullptr, // fallback function },
},
{{
// tail-call table
}},
{{// field numbers
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 18, 19, 21, 22, 24,
25, 27, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 48, 49, 51,
52, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
111, 112, 113, 114, 115, 116, 117, 118, 119, 201,
241, 242, 243, 244, 245, 246, 247, 248, 249, 250,
251, 252, 253, 254, 255, 321, 322, 401, 402, 403,
404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
414, 415, 416, 417}},
{{ {{
// "mini" table // tail-call table
}},
{{ // auxiliary entries (not used in this test)
{-1, 4},
{-1, 4},
{-1, 4},
{-1, 4},
{-1, 4},
}}, {{ // name lengths
"\1" // message name
"\16\16\17\17\17\17\20\20\21\21\16\17\15\17\16\27\30\24\25\25"
"\15\21\16\16\17\17\17\17\20\20\21\21\16\17\15\17\16\27\30\24"
"\25\25\15\17\17\21\21\21\21\23\23\25\25\17\20\15\21\20\31\32"
"\26\27\14\14\15\15\15\15\16\16\17\17\14\15\13\22\16\16\17\17"
"\17\17\20\20\21\21\16\17\15\24\14\24\14\13\12\14\13\14\12\4"
"\15\15\16\16\16\16\17\17\20\20\15\16\14\16\15\25\25\12\13\14"
"\15\13\15\12\12\13\14\14\14\16\16\15\15\16\0"
// names
"M"
"optional_int32"
"optional_int64"
"optional_uint32"
"optional_uint64"
"optional_sint32"
"optional_sint64"
"optional_fixed32"
"optional_fixed64"
"optional_sfixed32"
"optional_sfixed64"
"optional_float"
"optional_double"
"optional_bool"
"optional_string"
"optional_bytes"
"optional_nested_message"
"optional_foreign_message"
"optional_nested_enum"
"optional_foreign_enum"
"optional_string_piece"
"optional_cord"
"recursive_message"
"repeated_int32"
"repeated_int64"
"repeated_uint32"
"repeated_uint64"
"repeated_sint32"
"repeated_sint64"
"repeated_fixed32"
"repeated_fixed64"
"repeated_sfixed32"
"repeated_sfixed64"
"repeated_float"
"repeated_double"
"repeated_bool"
"repeated_string"
"repeated_bytes"
"repeated_nested_message"
"repeated_foreign_message"
"repeated_nested_enum"
"repeated_foreign_enum"
"repeated_string_piece"
"repeated_cord"
"map_int32_int32"
"map_int64_int64"
"map_uint32_uint32"
"map_uint64_uint64"
"map_sint32_sint32"
"map_sint64_sint64"
"map_fixed32_fixed32"
"map_fixed64_fixed64"
"map_sfixed32_sfixed32"
"map_sfixed64_sfixed64"
"map_int32_float"
"map_int32_double"
"map_bool_bool"
"map_string_string"
"map_string_bytes"
"map_string_nested_message"
"map_string_foreign_message"
"map_string_nested_enum"
"map_string_foreign_enum"
"packed_int32"
"packed_int64"
"packed_uint32"
"packed_uint64"
"packed_sint32"
"packed_sint64"
"packed_fixed32"
"packed_fixed64"
"packed_sfixed32"
"packed_sfixed64"
"packed_float"
"packed_double"
"packed_bool"
"packed_nested_enum"
"unpacked_int32"
"unpacked_int64"
"unpacked_uint32"
"unpacked_uint64"
"unpacked_sint32"
"unpacked_sint64"
"unpacked_fixed32"
"unpacked_fixed64"
"unpacked_sfixed32"
"unpacked_sfixed64"
"unpacked_float"
"unpacked_double"
"unpacked_bool"
"unpacked_nested_enum"
"oneof_uint32"
"oneof_nested_message"
"oneof_string"
"oneof_bytes"
"oneof_bool"
"oneof_uint64"
"oneof_float"
"oneof_double"
"oneof_enum"
"data"
"default_int32"
"default_int64"
"default_uint32"
"default_uint64"
"default_sint32"
"default_sint64"
"default_fixed32"
"default_fixed64"
"default_sfixed32"
"default_sfixed64"
"default_float"
"default_double"
"default_bool"
"default_string"
"default_bytes"
"optional_lazy_message"
"repeated_lazy_message"
"fieldname1"
"field_name2"
"_field_name3"
"field__name4_"
"field0name5"
"field_0_name6"
"fieldName7"
"FieldName8"
"field_Name9"
"Field_Name10"
"FIELD_NAME11"
"FIELD_name12"
"__field_name13"
"__Field_name14"
"field__name15"
"field__Name16"
"field_name17__"
}}, }},
}; {{// field numbers
// clang-format on 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 18, 19, 21, 22, 24,
25, 27, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 48, 49, 51,
52, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
111, 112, 113, 114, 115, 116, 117, 118, 119, 201,
241, 242, 243, 244, 245, 246, 247, 248, 249, 250,
251, 252, 253, 254, 255, 321, 322, 401, 402, 403,
404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
414, 415, 416, 417}},
{{
// "mini" table
}},
{{ // auxiliary entries (not used in this test)
{-1, 4},
{-1, 4},
{-1, 4},
{-1, 4},
{-1, 4},
}}, {{ // name lengths
"\1" // message name
"\16\16\17\17\17\17\20\20\21\21\16\17\15\17\16\27\30\24\25\25"
"\15\21\16\16\17\17\17\17\20\20\21\21\16\17\15\17\16\27\30\24"
"\25\25\15\17\17\21\21\21\21\23\23\25\25\17\20\15\21\20\31\32"
"\26\27\14\14\15\15\15\15\16\16\17\17\14\15\13\22\16\16\17\17"
"\17\17\20\20\21\21\16\17\15\24\14\24\14\13\12\14\13\14\12\4"
"\15\15\16\16\16\16\17\17\20\20\15\16\14\16\15\25\25\12\13\14"
"\15\13\15\12\12\13\14\14\14\16\16\15\15\16\0"
// names
"M"
"optional_int32"
"optional_int64"
"optional_uint32"
"optional_uint64"
"optional_sint32"
"optional_sint64"
"optional_fixed32"
"optional_fixed64"
"optional_sfixed32"
"optional_sfixed64"
"optional_float"
"optional_double"
"optional_bool"
"optional_string"
"optional_bytes"
"optional_nested_message"
"optional_foreign_message"
"optional_nested_enum"
"optional_foreign_enum"
"optional_string_piece"
"optional_cord"
"recursive_message"
"repeated_int32"
"repeated_int64"
"repeated_uint32"
"repeated_uint64"
"repeated_sint32"
"repeated_sint64"
"repeated_fixed32"
"repeated_fixed64"
"repeated_sfixed32"
"repeated_sfixed64"
"repeated_float"
"repeated_double"
"repeated_bool"
"repeated_string"
"repeated_bytes"
"repeated_nested_message"
"repeated_foreign_message"
"repeated_nested_enum"
"repeated_foreign_enum"
"repeated_string_piece"
"repeated_cord"
"map_int32_int32"
"map_int64_int64"
"map_uint32_uint32"
"map_uint64_uint64"
"map_sint32_sint32"
"map_sint64_sint64"
"map_fixed32_fixed32"
"map_fixed64_fixed64"
"map_sfixed32_sfixed32"
"map_sfixed64_sfixed64"
"map_int32_float"
"map_int32_double"
"map_bool_bool"
"map_string_string"
"map_string_bytes"
"map_string_nested_message"
"map_string_foreign_message"
"map_string_nested_enum"
"map_string_foreign_enum"
"packed_int32"
"packed_int64"
"packed_uint32"
"packed_uint64"
"packed_sint32"
"packed_sint64"
"packed_fixed32"
"packed_fixed64"
"packed_sfixed32"
"packed_sfixed64"
"packed_float"
"packed_double"
"packed_bool"
"packed_nested_enum"
"unpacked_int32"
"unpacked_int64"
"unpacked_uint32"
"unpacked_uint64"
"unpacked_sint32"
"unpacked_sint64"
"unpacked_fixed32"
"unpacked_fixed64"
"unpacked_sfixed32"
"unpacked_sfixed64"
"unpacked_float"
"unpacked_double"
"unpacked_bool"
"unpacked_nested_enum"
"oneof_uint32"
"oneof_nested_message"
"oneof_string"
"oneof_bytes"
"oneof_bool"
"oneof_uint64"
"oneof_float"
"oneof_double"
"oneof_enum"
"data"
"default_int32"
"default_int64"
"default_uint32"
"default_uint64"
"default_sint32"
"default_sint64"
"default_fixed32"
"default_fixed64"
"default_sfixed32"
"default_sfixed64"
"default_float"
"default_double"
"default_bool"
"default_string"
"default_bytes"
"optional_lazy_message"
"repeated_lazy_message"
"fieldname1"
"field_name2"
"_field_name3"
"field__name4_"
"field0name5"
"field_0_name6"
"fieldName7"
"FieldName8"
"field_Name9"
"Field_Name10"
"FIELD_NAME11"
"FIELD_name12"
"__field_name13"
"__Field_name14"
"field__name15"
"field__Name16"
"field_name17__"
}},
};
// clang-format on
TEST_F(FindFieldEntryTest, BigMessage) {
EXPECT_THAT(MessageName(test_all_types_table), Eq("M")); EXPECT_THAT(MessageName(test_all_types_table), Eq("M"));
for (int field_num : for (int field_num :
{1, 12, 31, 42, 57, 68, 79, 90, 101, 119, 249, 402, 412}) { {1, 12, 31, 42, 57, 68, 79, 90, 101, 119, 249, 402, 412}) {

@ -389,8 +389,7 @@ void GenericSwap(MessageLite* m1, MessageLite* m2) {
MessageLite* GetOwnedMessageInternal(Arena* message_arena, MessageLite* GetOwnedMessageInternal(Arena* message_arena,
MessageLite* submessage, MessageLite* submessage,
Arena* submessage_arena) { Arena* submessage_arena) {
GOOGLE_DCHECK(Arena::InternalHelper<MessageLite>::GetOwningArena(submessage) == GOOGLE_DCHECK(Arena::InternalGetOwningArena(submessage) == submessage_arena);
submessage_arena);
GOOGLE_DCHECK(message_arena != submessage_arena); GOOGLE_DCHECK(message_arena != submessage_arena);
GOOGLE_DCHECK_EQ(submessage_arena, nullptr); GOOGLE_DCHECK_EQ(submessage_arena, nullptr);
if (message_arena != nullptr && submessage_arena == nullptr) { if (message_arena != nullptr && submessage_arena == nullptr) {

@ -55,8 +55,7 @@ std::string* InlinedStringField::Mutable(const LazyString& /*default_value*/,
return MutableSlow(arena, donated, donating_states, mask, msg); return MutableSlow(arena, donated, donating_states, mask, msg);
} }
std::string* InlinedStringField::Mutable(ArenaStringPtr::EmptyDefault, std::string* InlinedStringField::Mutable(Arena* arena, bool donated,
Arena* arena, bool donated,
uint32_t* donating_states, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) { uint32_t mask, MessageLite* msg) {
if (arena == nullptr || !donated) { if (arena == nullptr || !donated) {
@ -83,27 +82,28 @@ void InlinedStringField::SetAllocated(const std::string* default_value,
SetAllocatedNoArena(default_value, value); SetAllocatedNoArena(default_value, value);
} }
void InlinedStringField::Set(const std::string* default_value, void InlinedStringField::Set(std::string&& value, Arena* arena, bool donated,
std::string&& value, Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) { MessageLite* msg) {
(void)donating_states; (void)donating_states;
(void)mask; (void)mask;
(void)msg; (void)msg;
SetNoArena(default_value, std::move(value)); SetNoArena(std::move(value));
} }
std::string* InlinedStringField::Release(const std::string* default_value, std::string* InlinedStringField::Release() {
Arena* arena, bool donated) { auto* released = new std::string(std::move(*get_mutable()));
if (arena == nullptr && !donated) { get_mutable()->clear();
return ReleaseNonDefaultNoArena(default_value); return released;
}
return ReleaseNonDefault(default_value, arena);
} }
std::string* InlinedStringField::ReleaseNonDefault( std::string* InlinedStringField::Release(Arena* arena, bool donated) {
const std::string* default_value, Arena* arena) { // We can not steal donated arena strings.
return ReleaseNonDefaultNoArena(default_value); std::string* released = (arena != nullptr && donated)
? new std::string(*get_mutable())
: new std::string(std::move(*get_mutable()));
get_mutable()->clear();
return released;
} }
void InlinedStringField::ClearToDefault(const LazyString& default_value, void InlinedStringField::ClearToDefault(const LazyString& default_value,

@ -130,63 +130,45 @@ class PROTOBUF_EXPORT InlinedStringField {
// `donated == ((donating_states & ~mask) != 0)` // `donated == ((donating_states & ~mask) != 0)`
// //
// This method never changes the `donating_states`. // This method never changes the `donating_states`.
void Set(const std::string* default_value, ConstStringParam value, void Set(ConstStringParam value, Arena* arena, bool donated,
Arena* arena, bool donated, uint32_t* /*donating_states*/, uint32_t* donating_states, uint32_t mask, MessageLite* msg);
uint32_t /*mask*/, MessageLite* /*msg*/) {
(void)arena;
(void)donated;
SetNoArena(default_value, value);
}
// Rvalue Set. If this field is donated, this method will undonate this field // Rvalue Set. If this field is donated, this method will undonate this field
// by mutating the `donating_states` according to `mask`. // by mutating the `donating_states` according to `mask`.
void Set(const std::string* default_value, std::string&& value, Arena* arena, void Set(std::string&& value, Arena* arena, bool donated,
bool donated, uint32_t* donating_states, uint32_t mask, uint32_t* donating_states, uint32_t mask, MessageLite* msg);
MessageLite* msg);
template <typename FirstParam> void Set(const char* str, ::google::protobuf::Arena* arena, bool donated,
void Set(FirstParam p1, const char* str, ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg);
uint32_t* donating_states, uint32_t mask, MessageLite* msg) {
Set(p1, ConstStringParam(str), arena, donated, donating_states, mask, msg);
}
template <typename FirstParam> void Set(const char* str, size_t size, ::google::protobuf::Arena* arena, bool donated,
void Set(FirstParam p1, const char* str, size_t size, ::google::protobuf::Arena* arena, uint32_t* donating_states, uint32_t mask, MessageLite* msg);
bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
ConstStringParam sp{str, size}; // for string_view and `const string &`
Set(p1, sp, arena, donated, donating_states, mask, msg);
}
template <typename FirstParam, typename RefWrappedType> template <typename RefWrappedType>
void Set(FirstParam p1, void Set(std::reference_wrapper<RefWrappedType> const_string_ref,
std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) { uint32_t mask, MessageLite* msg);
Set(p1, const_string_ref.get(), arena, donated, donating_states, mask, msg);
} void SetBytes(ConstStringParam value, Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask, MessageLite* msg);
template <typename FirstParam, typename SecondParam> void SetBytes(std::string&& value, Arena* arena, bool donated,
void SetBytes(FirstParam p1, SecondParam&& p2, ::google::protobuf::Arena* arena, uint32_t* donating_states, uint32_t mask, MessageLite* msg);
void SetBytes(const char* str, ::google::protobuf::Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask, MessageLite* msg);
void SetBytes(const void* p, size_t size, ::google::protobuf::Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask, bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) { MessageLite* msg);
Set(p1, static_cast<SecondParam&&>(p2), arena, donated, donating_states,
mask, msg);
}
template <typename FirstParam> template <typename RefWrappedType>
void SetBytes(FirstParam p1, const void* str, size_t size, void SetBytes(std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) { uint32_t mask, MessageLite* msg);
// Must work whether ConstStringParam is string_view or `const string &`
ConstStringParam sp{static_cast<const char*>(str), size};
Set(p1, sp, arena, donated, donating_states, mask, msg);
}
PROTOBUF_NDEBUG_INLINE void SetNoArena(const std::string* default_value, PROTOBUF_NDEBUG_INLINE void SetNoArena(StringPiece value);
StringPiece value); PROTOBUF_NDEBUG_INLINE void SetNoArena(std::string&& value);
PROTOBUF_NDEBUG_INLINE void SetNoArena(const std::string* default_value,
std::string&& value);
// Basic accessors. // Basic accessors.
PROTOBUF_NDEBUG_INLINE const std::string& Get() const { return GetNoArena(); } PROTOBUF_NDEBUG_INLINE const std::string& Get() const { return GetNoArena(); }
@ -196,22 +178,17 @@ class PROTOBUF_EXPORT InlinedStringField {
// field is donated, this method undonates this field by mutating the // field is donated, this method undonates this field by mutating the
// `donating_states` according to `mask`, and copies the content of the // `donating_states` according to `mask`, and copies the content of the
// original string to the returning string. // original string to the returning string.
std::string* Mutable(Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg);
std::string* Mutable(const LazyString& default_value, Arena* arena, std::string* Mutable(const LazyString& default_value, Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask, bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg); MessageLite* msg);
std::string* Mutable(ArenaStringPtr::EmptyDefault, Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask,
MessageLite* msg);
// Release returns a std::string* instance that is heap-allocated and is not // Mutable(nullptr_t) is an overload to explicitly support Mutable(nullptr)
// Own()'d by any arena. If the field is not set, this returns nullptr. The // calls used by the internal parser logic. This provides API equivalence with
// caller retains ownership. Clears this field back to nullptr state. Used to // ArenaStringPtr, while still protecting against calls with arena pointers.
// implement release_<field>() methods on generated classes. std::string* Mutable(std::nullptr_t);
PROTOBUF_NODISCARD std::string* Release(const std::string* default_value, std::string* MutableNoCopy(std::nullptr_t);
Arena* arena, bool donated);
PROTOBUF_NODISCARD std::string* ReleaseNonDefault(
const std::string* default_value, Arena* arena);
std::string* ReleaseNonDefaultNoArena(const std::string* default_value);
// Takes a std::string that is heap-allocated, and takes ownership. The // Takes a std::string that is heap-allocated, and takes ownership. The
// std::string's destructor is registered with the arena. Used to implement // std::string's destructor is registered with the arena. Used to implement
@ -226,6 +203,120 @@ class PROTOBUF_EXPORT InlinedStringField {
void SetAllocatedNoArena(const std::string* default_value, void SetAllocatedNoArena(const std::string* default_value,
std::string* value); std::string* value);
// Release returns a std::string* instance that is heap-allocated and is not
// Own()'d by any arena. If the field is not set, this returns nullptr. The
// caller retains ownership. Clears this field back to nullptr state. Used to
// implement release_<field>() methods on generated classes.
PROTOBUF_NODISCARD std::string* Release(Arena* arena, bool donated);
PROTOBUF_NODISCARD std::string* Release();
// --------------------------------------------------------
// Below functions will be removed in subsequent code change
// --------------------------------------------------------
#ifdef DEPRECATED_METHODS_TO_BE_DELETED
PROTOBUF_NODISCARD std::string* Release(const std::string*, Arena* arena,
bool donated) {
return Release(arena, donated);
}
PROTOBUF_NODISCARD std::string* ReleaseNonDefault(const std::string*,
Arena* arena) {
return Release();
}
std::string* ReleaseNonDefaultNoArena(const std::string* default_value) {
return Release();
}
void Set(const std::string*, ConstStringParam value, Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
Set(value, arena, donated, donating_states, mask, msg);
}
void Set(const std::string*, std::string&& value, Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask, MessageLite* msg) {
Set(std::move(value), arena, donated, donating_states, mask, msg);
}
template <typename FirstParam>
void Set(FirstParam, const char* str, ::google::protobuf::Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask, MessageLite* msg) {
Set(str, arena, donated, donating_states, mask, msg);
}
template <typename FirstParam>
void Set(FirstParam p1, const char* str, size_t size, ::google::protobuf::Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
Set(str, size, arena, donated, donating_states, mask, msg);
}
template <typename FirstParam, typename RefWrappedType>
void Set(FirstParam p1,
std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(const_string_ref, arena, donated, donating_states, mask, msg);
}
void SetBytes(const std::string*, ConstStringParam value, Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
Set(value, arena, donated, donating_states, mask, msg);
}
void SetBytes(const std::string*, std::string&& value, Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
Set(std::move(value), arena, donated, donating_states, mask, msg);
}
template <typename FirstParam>
void SetBytes(FirstParam p1, const char* str, ::google::protobuf::Arena* arena,
bool donated, uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
SetBytes(str, arena, donated, donating_states, mask, msg);
}
template <typename FirstParam>
void SetBytes(FirstParam p1, const void* p, size_t size,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
SetBytes(p, size, arena, donated, donating_states, mask, msg);
}
template <typename FirstParam, typename RefWrappedType>
void SetBytes(FirstParam p1,
std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
SetBytes(const_string_ref.get(), arena, donated, donating_states, mask,
msg);
}
void SetNoArena(const std::string*, StringPiece value) {
SetNoArena(value);
}
void SetNoArena(const std::string*, std::string&& value) {
SetNoArena(std::move(value));
}
std::string* Mutable(ArenaStringPtr::EmptyDefault, Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
return Mutable(arena, donated, donating_states, mask, msg);
}
PROTOBUF_NDEBUG_INLINE std::string* MutableNoArenaNoDefault(
const std::string* /*default_value*/) {
return MutableNoCopy(nullptr);
}
#endif // DEPRECATED_METHODS_TO_BE_DELETED
// Arena-safety semantics: this is guarded by the logic in // Arena-safety semantics: this is guarded by the logic in
// Swap()/UnsafeArenaSwap() at the message level, so this method is // Swap()/UnsafeArenaSwap() at the message level, so this method is
// 'unsafe' if called directly. // 'unsafe' if called directly.
@ -258,17 +349,12 @@ class PROTOBUF_EXPORT InlinedStringField {
void ClearToDefault(const LazyString& default_value, Arena* arena, void ClearToDefault(const LazyString& default_value, Arena* arena,
bool donated); bool donated);
// Returns a mutable pointer, but doesn't initialize the string to the
// default value.
PROTOBUF_NDEBUG_INLINE std::string* MutableNoArenaNoDefault(
const std::string* /*default_value*/);
// Generated code / reflection only! Returns a mutable pointer to the string. // Generated code / reflection only! Returns a mutable pointer to the string.
PROTOBUF_NDEBUG_INLINE std::string* UnsafeMutablePointer(); PROTOBUF_NDEBUG_INLINE std::string* UnsafeMutablePointer();
// InlinedStringField doesn't have things like the `default_value` pointer in // InlinedStringField doesn't have things like the `default_value` pointer in
// ArenaStringPtr. // ArenaStringPtr.
static constexpr bool IsDefault() { return false; } static constexpr bool IsDefault() { return false; }
static constexpr bool IsDefault(const std::string*) { return false; } static constexpr bool IsDefault(const std::string*) { return false; }
private: private:
@ -327,21 +413,11 @@ inline void InlinedStringField::DestroyNoArena(const std::string*) {
this->~InlinedStringField(); this->~InlinedStringField();
} }
inline std::string* InlinedStringField::ReleaseNonDefaultNoArena( inline void InlinedStringField::SetNoArena(StringPiece value) {
const std::string* /*default_value*/) {
// Currently, inlined string field can't have non empty default.
auto* released = new std::string();
get_mutable()->swap(*released);
return released;
}
inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
StringPiece value) {
get_mutable()->assign(value.data(), value.length()); get_mutable()->assign(value.data(), value.length());
} }
inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/, inline void InlinedStringField::SetNoArena(std::string&& value) {
std::string&& value) {
get_mutable()->assign(std::move(value)); get_mutable()->assign(std::move(value));
} }
@ -369,15 +445,84 @@ inline PROTOBUF_NDEBUG_INLINE void InlinedStringField::InternalSwap(
#endif #endif
} }
inline std::string* InlinedStringField::MutableNoArenaNoDefault( inline void InlinedStringField::Set(ConstStringParam value, Arena* arena,
const std::string*) { bool donated, uint32_t* /*donating_states*/,
return get_mutable(); uint32_t /*mask*/, MessageLite* /*msg*/) {
(void)arena;
(void)donated;
SetNoArena(value);
}
inline void InlinedStringField::Set(const char* str, ::google::protobuf::Arena* arena,
bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(ConstStringParam(str), arena, donated, donating_states, mask, msg);
}
inline void InlinedStringField::Set(const char* str, size_t size,
::google::protobuf::Arena* arena, bool donated,
uint32_t* donating_states, uint32_t mask,
MessageLite* msg) {
Set(ConstStringParam{str, size}, arena, donated, donating_states, mask, msg);
}
inline void InlinedStringField::SetBytes(ConstStringParam value, Arena* arena,
bool donated,
uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(value, arena, donated, donating_states, mask, msg);
}
inline void InlinedStringField::SetBytes(std::string&& value, Arena* arena,
bool donated,
uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(std::move(value), arena, donated, donating_states, mask, msg);
}
inline void InlinedStringField::SetBytes(const char* str,
::google::protobuf::Arena* arena, bool donated,
uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(str, arena, donated, donating_states, mask, msg);
}
inline void InlinedStringField::SetBytes(const void* p, size_t size,
::google::protobuf::Arena* arena, bool donated,
uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(static_cast<const char*>(p), size, arena, donated, donating_states, mask,
msg);
}
template <typename RefWrappedType>
inline void InlinedStringField::Set(
std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(const_string_ref.get(), arena, donated, donating_states, mask, msg);
}
template <typename RefWrappedType>
inline void InlinedStringField::SetBytes(
std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
uint32_t mask, MessageLite* msg) {
Set(const_string_ref.get(), arena, donated, donating_states, mask, msg);
} }
inline std::string* InlinedStringField::UnsafeMutablePointer() { inline std::string* InlinedStringField::UnsafeMutablePointer() {
return get_mutable(); return get_mutable();
} }
inline std::string* InlinedStringField::Mutable(std::nullptr_t) {
return get_mutable();
}
inline std::string* InlinedStringField::MutableNoCopy(std::nullptr_t) {
return get_mutable();
}
} // namespace internal } // namespace internal
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google

@ -35,6 +35,7 @@
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/logging.h>

@ -580,12 +580,12 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::IsInitialized(
template <typename Type> \ template <typename Type> \
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \
const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \
to->Set(&internal::GetEmptyStringAlreadyInited(), from, arena); \ to->Set(from, arena); \
} \ } \
template <typename Type> \ template <typename Type> \
void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \ void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \
TypeOnMemory& value) { \ TypeOnMemory& value) { \
value.DestroyNoArena(&internal::GetEmptyStringAlreadyInited()); \ value.Destroy(); \
} \ } \
template <typename Type> \ template <typename Type> \
constexpr auto \ constexpr auto \
@ -598,7 +598,7 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::IsInitialized(
Type>::MapEntryAccessorType* \ Type>::MapEntryAccessorType* \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \
TypeOnMemory* value, Arena* arena) { \ TypeOnMemory* value, Arena* arena) { \
return value->Mutable(ArenaStringPtr::EmptyDefault{}, arena); \ return value->Mutable(arena); \
} \ } \
template <typename Type> \ template <typename Type> \
inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \

@ -41,7 +41,6 @@
#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/parse_context.h> #include <google/protobuf/parse_context.h>
#include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream.h>
@ -230,7 +229,7 @@ bool MessageLite::MergeFromImpl(io::CodedInputStream* input,
if (PROTOBUF_PREDICT_FALSE(!ptr)) return false; if (PROTOBUF_PREDICT_FALSE(!ptr)) return false;
ctx.BackUp(ptr); ctx.BackUp(ptr);
if (!ctx.EndedAtEndOfStream()) { if (!ctx.EndedAtEndOfStream()) {
GOOGLE_DCHECK(ctx.LastTag() != 1); // We can't end on a pushed limit. GOOGLE_DCHECK_NE(ctx.LastTag(), 1); // We can't end on a pushed limit.
if (ctx.IsExceedingLimit(ptr)) return false; if (ctx.IsExceedingLimit(ptr)) return false;
input->SetLastTag(ctx.LastTag()); input->SetLastTag(ctx.LastTag());
} else { } else {

@ -419,6 +419,29 @@ TEST(MESSAGE_TEST_NAME, ParseStrictlyBoundedStream) {
TestUtil::ExpectAllFieldsSet(p.child().payload()); TestUtil::ExpectAllFieldsSet(p.child().payload());
} }
TEST(MESSAGE_TEST_NAME, AllSetMethodsOnStringField) {
UNITTEST::TestAllTypes msg;
msg.set_optional_string("Asciiz");
EXPECT_EQ(msg.optional_string(), "Asciiz");
msg.set_optional_string("Length delimited", 6);
EXPECT_EQ(msg.optional_string(), "Length");
std::string value = "std::string value 1";
msg.set_optional_string(value);
EXPECT_EQ(msg.optional_string(), "std::string value 1");
value = "std::string value 2";
msg.set_optional_string(std::cref(value));
EXPECT_EQ(msg.optional_string(), "std::string value 2");
value = "std::string value 3";
msg.set_optional_string(std::move(value));
EXPECT_EQ(msg.optional_string(), "std::string value 3");
}
TEST(MESSAGE_TEST_NAME, SuccessAfterParsingFailure) { TEST(MESSAGE_TEST_NAME, SuccessAfterParsingFailure) {
UNITTEST::NestedTestAllTypes o, p, q; UNITTEST::NestedTestAllTypes o, p, q;
constexpr int kDepth = 5; constexpr int kDepth = 5;

@ -30,7 +30,6 @@
#include <google/protobuf/parse_context.h> #include <google/protobuf/parse_context.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/arenastring.h> #include <google/protobuf/arenastring.h>
@ -51,8 +50,8 @@ namespace {
// Only call if at start of tag. // Only call if at start of tag.
bool ParseEndsInSlopRegion(const char* begin, int overrun, int depth) { bool ParseEndsInSlopRegion(const char* begin, int overrun, int depth) {
constexpr int kSlopBytes = EpsCopyInputStream::kSlopBytes; constexpr int kSlopBytes = EpsCopyInputStream::kSlopBytes;
GOOGLE_DCHECK(overrun >= 0); GOOGLE_DCHECK_GE(overrun, 0);
GOOGLE_DCHECK(overrun <= kSlopBytes); GOOGLE_DCHECK_LE(overrun, kSlopBytes);
auto ptr = begin + overrun; auto ptr = begin + overrun;
auto end = begin + kSlopBytes; auto end = begin + kSlopBytes;
while (ptr < end) { while (ptr < end) {
@ -181,17 +180,17 @@ std::pair<const char*, bool> EpsCopyInputStream::DoneFallback(int overrun,
// if (ptr < limit_end_) return {ptr, false}; // if (ptr < limit_end_) return {ptr, false};
GOOGLE_DCHECK(limit_end_ == buffer_end_ + (std::min)(0, limit_)); GOOGLE_DCHECK(limit_end_ == buffer_end_ + (std::min)(0, limit_));
// At this point we know the following assertion holds. // At this point we know the following assertion holds.
GOOGLE_DCHECK(limit_ > 0); GOOGLE_DCHECK_GT(limit_, 0);
GOOGLE_DCHECK(limit_end_ == buffer_end_); // because limit_ > 0 GOOGLE_DCHECK(limit_end_ == buffer_end_); // because limit_ > 0
const char* p; const char* p;
do { do {
// We are past the end of buffer_end_, in the slop region. // We are past the end of buffer_end_, in the slop region.
GOOGLE_DCHECK(overrun >= 0); GOOGLE_DCHECK_GE(overrun, 0);
p = NextBuffer(overrun, depth); p = NextBuffer(overrun, depth);
if (p == nullptr) { if (p == nullptr) {
// We are at the end of the stream // We are at the end of the stream
if (PROTOBUF_PREDICT_FALSE(overrun != 0)) return {nullptr, true}; if (PROTOBUF_PREDICT_FALSE(overrun != 0)) return {nullptr, true};
GOOGLE_DCHECK(limit_ > 0); GOOGLE_DCHECK_GT(limit_, 0);
limit_end_ = buffer_end_; limit_end_ = buffer_end_;
// Distinguish ending on a pushed limit or ending on end-of-stream. // Distinguish ending on a pushed limit or ending on end-of-stream.
SetEndOfStream(); SetEndOfStream();

@ -423,16 +423,16 @@ void ReflectionOps::FindInitializationErrors(const Message& message,
void GenericSwap(Message* lhs, Message* rhs) { void GenericSwap(Message* lhs, Message* rhs) {
#ifndef PROTOBUF_FORCE_COPY_IN_SWAP #ifndef PROTOBUF_FORCE_COPY_IN_SWAP
GOOGLE_DCHECK(Arena::InternalHelper<Message>::GetOwningArena(lhs) != GOOGLE_DCHECK(Arena::InternalGetOwningArena(lhs) !=
Arena::InternalHelper<Message>::GetOwningArena(rhs)); Arena::InternalGetOwningArena(rhs));
GOOGLE_DCHECK(Arena::InternalHelper<Message>::GetOwningArena(lhs) != nullptr || GOOGLE_DCHECK(Arena::InternalGetOwningArena(lhs) != nullptr ||
Arena::InternalHelper<Message>::GetOwningArena(rhs) != nullptr); Arena::InternalGetOwningArena(rhs) != nullptr);
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP #endif // !PROTOBUF_FORCE_COPY_IN_SWAP
// At least one of these must have an arena, so make `rhs` point to it. // At least one of these must have an arena, so make `rhs` point to it.
Arena* arena = Arena::InternalHelper<Message>::GetOwningArena(rhs); Arena* arena = Arena::InternalGetOwningArena(rhs);
if (arena == nullptr) { if (arena == nullptr) {
std::swap(lhs, rhs); std::swap(lhs, rhs);
arena = Arena::InternalHelper<Message>::GetOwningArena(rhs); arena = Arena::InternalGetOwningArena(rhs);
} }
// Improve efficiency by placing the temporary on an arena so that messages // Improve efficiency by placing the temporary on an arena so that messages

@ -97,10 +97,10 @@ SourceContext::SourceContext(const SourceContext& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
file_name_.InitDefault(); file_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
file_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); file_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_file_name().empty()) { if (!from._internal_file_name().empty()) {
file_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_file_name(), file_name_.Set(from._internal_file_name(),
GetArenaForAllocation()); GetArenaForAllocation());
} }
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext) // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext)
@ -109,7 +109,7 @@ SourceContext::SourceContext(const SourceContext& from)
inline void SourceContext::SharedCtor() { inline void SourceContext::SharedCtor() {
file_name_.InitDefault(); file_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
file_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); file_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
@ -124,7 +124,7 @@ SourceContext::~SourceContext() {
inline void SourceContext::SharedDtor() { inline void SourceContext::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
file_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); file_name_.Destroy();
} }
void SourceContext::SetCachedSize(int size) const { void SourceContext::SetCachedSize(int size) const {
@ -264,7 +264,6 @@ void SourceContext::InternalSwap(SourceContext* other) {
auto* rhs_arena = other->GetArenaForAllocation(); auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_); _internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&file_name_, lhs_arena, &file_name_, lhs_arena,
&other->file_name_, rhs_arena &other->file_name_, rhs_arena
); );

@ -225,7 +225,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE inline PROTOBUF_ALWAYS_INLINE
void SourceContext::set_file_name(ArgT0&& arg0, ArgT... args) { void SourceContext::set_file_name(ArgT0&& arg0, ArgT... args) {
file_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); file_name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name) // @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name)
} }
inline std::string* SourceContext::mutable_file_name() { inline std::string* SourceContext::mutable_file_name() {
@ -238,15 +238,15 @@ inline const std::string& SourceContext::_internal_file_name() const {
} }
inline void SourceContext::_internal_set_file_name(const std::string& value) { inline void SourceContext::_internal_set_file_name(const std::string& value) {
file_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); file_name_.Set(value, GetArenaForAllocation());
} }
inline std::string* SourceContext::_internal_mutable_file_name() { inline std::string* SourceContext::_internal_mutable_file_name() {
return file_name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); return file_name_.Mutable(GetArenaForAllocation());
} }
inline std::string* SourceContext::release_file_name() { inline std::string* SourceContext::release_file_name() {
// @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name) // @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name)
return file_name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return file_name_.Release();
} }
inline void SourceContext::set_allocated_file_name(std::string* file_name) { inline void SourceContext::set_allocated_file_name(std::string* file_name) {
if (file_name != nullptr) { if (file_name != nullptr) {
@ -254,11 +254,10 @@ inline void SourceContext::set_allocated_file_name(std::string* file_name) {
} else { } else {
} }
file_name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), file_name, file_name_.SetAllocated(file_name, GetArenaForAllocation());
GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (file_name_.IsDefault()) { if (file_name_.IsDefault()) {
file_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation()); file_name_.Set("", GetArenaForAllocation());
} }
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name)

@ -416,7 +416,7 @@ void Value::set_allocated_struct_value(::PROTOBUF_NAMESPACE_ID::Struct* struct_v
clear_kind(); clear_kind();
if (struct_value) { if (struct_value) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::PROTOBUF_NAMESPACE_ID::Struct>::GetOwningArena(struct_value); ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(struct_value);
if (message_arena != submessage_arena) { if (message_arena != submessage_arena) {
struct_value = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( struct_value = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, struct_value, submessage_arena); message_arena, struct_value, submessage_arena);
@ -431,7 +431,7 @@ void Value::set_allocated_list_value(::PROTOBUF_NAMESPACE_ID::ListValue* list_va
clear_kind(); clear_kind();
if (list_value) { if (list_value) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::PROTOBUF_NAMESPACE_ID::ListValue>::GetOwningArena(list_value); ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(list_value);
if (message_arena != submessage_arena) { if (message_arena != submessage_arena) {
list_value = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( list_value = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, list_value, submessage_arena); message_arena, list_value, submessage_arena);
@ -519,7 +519,7 @@ void Value::clear_kind() {
break; break;
} }
case kStringValue: { case kStringValue: {
kind_.string_value_.Destroy(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); kind_.string_value_.Destroy();
break; break;
} }
case kBoolValue: { case kBoolValue: {

@ -828,7 +828,7 @@ inline void Value::set_has_string_value() {
} }
inline void Value::clear_string_value() { inline void Value::clear_string_value() {
if (_internal_has_string_value()) { if (_internal_has_string_value()) {
kind_.string_value_.Destroy(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation()); kind_.string_value_.Destroy();
clear_has_kind(); clear_has_kind();
} }
} }
@ -843,7 +843,7 @@ inline void Value::set_string_value(ArgT0&& arg0, ArgT... args) {
set_has_string_value(); set_has_string_value();
kind_.string_value_.InitDefault(); kind_.string_value_.InitDefault();
} }
kind_.string_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation()); kind_.string_value_.Set( static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value)
} }
inline std::string* Value::mutable_string_value() { inline std::string* Value::mutable_string_value() {
@ -863,7 +863,7 @@ inline void Value::_internal_set_string_value(const std::string& value) {
set_has_string_value(); set_has_string_value();
kind_.string_value_.InitDefault(); kind_.string_value_.InitDefault();
} }
kind_.string_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation()); kind_.string_value_.Set(value, GetArenaForAllocation());
} }
inline std::string* Value::_internal_mutable_string_value() { inline std::string* Value::_internal_mutable_string_value() {
if (!_internal_has_string_value()) { if (!_internal_has_string_value()) {
@ -871,14 +871,13 @@ inline std::string* Value::_internal_mutable_string_value() {
set_has_string_value(); set_has_string_value();
kind_.string_value_.InitDefault(); kind_.string_value_.InitDefault();
} }
return kind_.string_value_.Mutable( return kind_.string_value_.Mutable( GetArenaForAllocation());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
} }
inline std::string* Value::release_string_value() { inline std::string* Value::release_string_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Value.string_value) // @@protoc_insertion_point(field_release:google.protobuf.Value.string_value)
if (_internal_has_string_value()) { if (_internal_has_string_value()) {
clear_has_kind(); clear_has_kind();
return kind_.string_value_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation()); return kind_.string_value_.Release();
} else { } else {
return nullptr; return nullptr;
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save