aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_string_field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_string_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 664a2779..7a849e2e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -36,6 +36,7 @@
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
+
#include <google/protobuf/stubs/strutil.h>
namespace google {
@@ -61,6 +62,7 @@ void SetStringVariables(const FieldDescriptor* descriptor,
".get()";
(*variables)["pointer_type"] =
descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char";
+ (*variables)["null_check"] = "GOOGLE_DCHECK(value != NULL);\n";
// NOTE: Escaped here to unblock proto1->proto2 migration.
// TODO(liujisi): Extend this to apply for other conflicting methods.
(*variables)["release_name"] =
@@ -190,6 +192,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
+ " $null_check$"
" $set_hasbit$\n"
" $name$_.Set($default_variable$, $string_piece$(value),\n"
" GetArenaNoVirtual());\n"
@@ -267,6 +270,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n"
"#endif\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
+ " $null_check$"
" $set_hasbit$\n"
" $name$_.SetNoArena($default_variable$, $string_piece$(value));\n"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
@@ -548,6 +552,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
+ " $null_check$"
" if (!has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
@@ -664,6 +669,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n"
"#endif\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
+ " $null_check$"
" if (!has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
@@ -882,6 +888,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n"
"#endif\n"
"$inline$void $classname$::set_$name$(int index, const char* value) {\n"
+ " $null_check$"
" $name$_.Mutable(index)->assign(value);\n"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
"}\n"
@@ -902,11 +909,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n"
"#if LANG_CXX11\n"
"$inline$void $classname$::add_$name$(::std::string&& value) {\n"
- " $name$_.Add()->assign(std::move(value));\n"
+ " $name$_.Add(std::move(value));\n"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n"
"#endif\n"
"$inline$void $classname$::add_$name$(const char* value) {\n"
+ " $null_check$"
" $name$_.Add()->assign(value);\n"
" // @@protoc_insertion_point(field_add_char:$full_name$)\n"
"}\n"
@@ -939,7 +947,7 @@ GenerateMergingCode(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateSwappingCode(io::Printer* printer) const {
- printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n");
+ printer->Print(variables_, "$name$_.InternalSwap(&other->$name$_);\n");
}
void RepeatedStringFieldGenerator::
@@ -969,7 +977,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
printer->Print(variables_,
- "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(