Breaking change: Upgrade return type of several string returning functions to `absl::string_view`.

This includes (but not limited to) `MessageLite::GetTypeName`, `UnknownField::length_delimited`, and
all the name functions in descriptors like `FieldDescriptor::full_name`.

Part of the changes announced in
https://protobuf.dev/news/2024-10-02/#descriptor-apis

PiperOrigin-RevId: 715013326
pull/19926/head
Protobuf Team Bot 4 months ago committed by Copybara-Service
parent 1355ef2766
commit d1990d968a
  1. 2
      src/google/protobuf/compiler/cpp/field_generators/cord_field.cc
  2. 4
      src/google/protobuf/compiler/cpp/service.h
  3. 2
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  4. 2
      src/google/protobuf/compiler/csharp/csharp_message.cc
  5. 2
      src/google/protobuf/compiler/java/doc_comment.cc
  6. 5
      src/google/protobuf/compiler/java/field_common.cc
  7. 9
      src/google/protobuf/compiler/java/file.cc
  8. 10
      src/google/protobuf/compiler/java/full/enum.cc
  9. 2
      src/google/protobuf/compiler/java/full/message.cc
  10. 10
      src/google/protobuf/compiler/java/lite/enum.cc
  11. 2
      src/google/protobuf/compiler/java/lite/message.cc
  12. 4
      src/google/protobuf/compiler/java/name_resolver.cc
  13. 6
      src/google/protobuf/compiler/java/names.cc
  14. 4
      src/google/protobuf/compiler/objectivec/field.cc
  15. 38
      src/google/protobuf/compiler/python/generator.cc
  16. 2
      src/google/protobuf/compiler/ruby/ruby_generator.cc
  17. 16
      src/google/protobuf/descriptor.cc
  18. 2
      src/google/protobuf/port_def.inc
  19. 2
      src/google/protobuf/port_undef.inc
  20. 10
      src/google/protobuf/reflection_ops.cc

@ -39,7 +39,7 @@ void SetCordVariables(
"\"", absl::CEscape(descriptor->default_value_string()), "\""); "\"", absl::CEscape(descriptor->default_value_string()), "\"");
(*variables)["default_length"] = (*variables)["default_length"] =
absl::StrCat(descriptor->default_value_string().length()); absl::StrCat(descriptor->default_value_string().length());
(*variables)["full_name"] = descriptor->full_name(); (*variables)["full_name"] = std::string(descriptor->full_name());
// For one of Cords // For one of Cords
(*variables)["default_variable_name"] = MakeDefaultName(descriptor); (*variables)["default_variable_name"] = MakeDefaultName(descriptor);
(*variables)["default_variable_field"] = MakeDefaultFieldName(descriptor); (*variables)["default_variable_field"] = MakeDefaultFieldName(descriptor);

@ -32,8 +32,8 @@ class ServiceGenerator {
const absl::flat_hash_map<absl::string_view, std::string>& vars, const absl::flat_hash_map<absl::string_view, std::string>& vars,
const Options& options) const Options& options)
: descriptor_(descriptor), options_(&options), vars_(vars) { : descriptor_(descriptor), options_(&options), vars_(vars) {
vars_["classname"] = descriptor_->name(); vars_["classname"] = std::string(descriptor_->name());
vars_["full_name"] = descriptor_->full_name(); vars_["full_name"] = std::string(descriptor_->full_name());
} }
ServiceGenerator(const ServiceGenerator&) = delete; ServiceGenerator(const ServiceGenerator&) = delete;

@ -72,7 +72,7 @@ void FieldGeneratorBase::SetCommonFieldVariables(
(*variables)["type_name"] = type_name(); (*variables)["type_name"] = type_name();
(*variables)["extended_type"] = GetClassName(descriptor_->containing_type()); (*variables)["extended_type"] = GetClassName(descriptor_->containing_type());
(*variables)["name"] = name(); (*variables)["name"] = name();
(*variables)["descriptor_name"] = descriptor_->name(); (*variables)["descriptor_name"] = std::string(descriptor_->name());
(*variables)["default_value"] = default_value(); (*variables)["default_value"] = default_value();
(*variables)["capitalized_type_name"] = capitalized_type_name(); (*variables)["capitalized_type_name"] = capitalized_type_name();
(*variables)["number"] = number(); (*variables)["number"] = number();

@ -212,7 +212,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
const OneofDescriptor* oneof = descriptor_->oneof_decl(i); const OneofDescriptor* oneof = descriptor_->oneof_decl(i);
vars["name"] = UnderscoresToCamelCase(oneof->name(), false); vars["name"] = UnderscoresToCamelCase(oneof->name(), false);
vars["property_name"] = UnderscoresToCamelCase(oneof->name(), true); vars["property_name"] = UnderscoresToCamelCase(oneof->name(), true);
vars["original_name"] = oneof->name(); vars["original_name"] = std::string(oneof->name());
printer->Print(vars, printer->Print(vars,
"private object $name$_;\n" "private object $name$_;\n"
"/// <summary>Enum of possible cases for the " "/// <summary>Enum of possible cases for the "

@ -210,7 +210,7 @@ static void WriteDebugString(io::Printer* printer, const FieldDescriptor* field,
const Options options, const bool kdoc) { const Options options, const bool kdoc) {
std::string field_comment = FirstLineOf(field->DebugString()); std::string field_comment = FirstLineOf(field->DebugString());
if (options.strip_nonfunctional_codegen) { if (options.strip_nonfunctional_codegen) {
field_comment = field->name(); field_comment = std::string(field->name());
} }
if (kdoc) { if (kdoc) {
printer->Print(" * `$def$`\n", "def", EscapeKdoc(field_comment)); printer->Print(" * `$def$`\n", "def", EscapeKdoc(field_comment));

@ -16,9 +16,10 @@ namespace java {
void SetCommonFieldVariables( void SetCommonFieldVariables(
const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, const FieldDescriptor* descriptor, const FieldGeneratorInfo* info,
absl::flat_hash_map<absl::string_view, std::string>* variables) { absl::flat_hash_map<absl::string_view, std::string>* variables) {
(*variables)["field_name"] = descriptor->name(); (*variables)["field_name"] = std::string(descriptor->name());
(*variables)["name"] = info->name; (*variables)["name"] = info->name;
(*variables)["classname"] = descriptor->containing_type()->name(); (*variables)["classname"] =
std::string(descriptor->containing_type()->name());
(*variables)["capitalized_name"] = info->capitalized_name; (*variables)["capitalized_name"] = info->capitalized_name;
(*variables)["disambiguated_reason"] = info->disambiguated_reason; (*variables)["disambiguated_reason"] = info->disambiguated_reason;
(*variables)["constant_name"] = FieldConstantName(descriptor); (*variables)["constant_name"] = FieldConstantName(descriptor);

@ -205,12 +205,11 @@ bool FileGenerator::Validate(std::string* error) {
// end up overwriting the outer class with one of the inner ones. // end up overwriting the outer class with one of the inner ones.
if (name_resolver_->HasConflictingClassName(file_, classname_, if (name_resolver_->HasConflictingClassName(file_, classname_,
NameEquality::EXACT_EQUAL)) { NameEquality::EXACT_EQUAL)) {
error->assign(file_->name()); *error = absl::StrCat(
error->append( file_->name(),
": Cannot generate Java output because the file's outer class name, " ": Cannot generate Java output because the file's outer class name, "
"\""); "\"",
error->append(classname_); classname_,
error->append(
"\", matches the name of one of the types declared inside it. " "\", matches the name of one of the types declared inside it. "
"Please either rename the type or use the java_outer_classname " "Please either rename the type or use the java_outer_classname "
"option to specify a different outer class name for the .proto file."); "option to specify a different outer class name for the .proto file.");

@ -85,7 +85,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {
for (const EnumValueDescriptor* value : canonical_values_) { for (const EnumValueDescriptor* value : canonical_values_) {
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
vars["name"] = value->name(); vars["name"] = std::string(value->name());
vars["index"] = absl::StrCat(value->index()); vars["index"] = absl::StrCat(value->index());
vars["number"] = absl::StrCat(value->number()); vars["number"] = absl::StrCat(value->number());
WriteEnumValueDocComment(printer, value, context_->options()); WriteEnumValueDocComment(printer, value, context_->options());
@ -124,9 +124,9 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {
for (const Alias& alias : aliases_) { for (const Alias& alias : aliases_) {
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
vars["classname"] = descriptor_->name(); vars["classname"] = std::string(descriptor_->name());
vars["name"] = alias.value->name(); vars["name"] = std::string(alias.value->name());
vars["canonical_name"] = alias.canonical_value->name(); vars["canonical_name"] = std::string(alias.canonical_value->name());
WriteEnumValueDocComment(printer, alias.value, context_->options()); WriteEnumValueDocComment(printer, alias.value, context_->options());
printer->Print( printer->Print(
vars, "public static final $classname$ $name$ = $canonical_name$;\n"); vars, "public static final $classname$ $name$ = $canonical_name$;\n");
@ -135,7 +135,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->value_count(); i++) { for (int i = 0; i < descriptor_->value_count(); i++) {
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
vars["name"] = descriptor_->value(i)->name(); vars["name"] = std::string(descriptor_->value(i)->name());
vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["number"] = absl::StrCat(descriptor_->value(i)->number());
vars["{"] = ""; vars["{"] = "";
vars["}"] = ""; vars["}"] = "";

@ -294,7 +294,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
absl::flat_hash_map<absl::string_view, std::string> variables; absl::flat_hash_map<absl::string_view, std::string> variables;
variables["static"] = is_own_file ? "" : "static "; variables["static"] = is_own_file ? "" : "static ";
variables["classname"] = descriptor_->name(); variables["classname"] = std::string(descriptor_->name());
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["deprecation"] = variables["deprecation"] =
descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "";

@ -71,7 +71,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (const EnumValueDescriptor* value : canonical_values_) { for (const EnumValueDescriptor* value : canonical_values_) {
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
vars["name"] = value->name(); vars["name"] = std::string(value->name());
vars["number"] = absl::StrCat(value->number()); vars["number"] = absl::StrCat(value->number());
WriteEnumValueDocComment(printer, value, context_->options()); WriteEnumValueDocComment(printer, value, context_->options());
if (value->options().deprecated()) { if (value->options().deprecated()) {
@ -94,9 +94,9 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (const Alias& alias : aliases_) { for (const Alias& alias : aliases_) {
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
vars["classname"] = descriptor_->name(); vars["classname"] = std::string(descriptor_->name());
vars["name"] = alias.value->name(); vars["name"] = std::string(alias.value->name());
vars["canonical_name"] = alias.canonical_value->name(); vars["canonical_name"] = std::string(alias.canonical_value->name());
WriteEnumValueDocComment(printer, alias.value, context_->options()); WriteEnumValueDocComment(printer, alias.value, context_->options());
printer->Print( printer->Print(
vars, "public static final $classname$ $name$ = $canonical_name$;\n"); vars, "public static final $classname$ $name$ = $canonical_name$;\n");
@ -105,7 +105,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->value_count(); i++) { for (int i = 0; i < descriptor_->value_count(); i++) {
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
vars["name"] = descriptor_->value(i)->name(); vars["name"] = std::string(descriptor_->value(i)->name());
vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["number"] = absl::StrCat(descriptor_->value(i)->number());
vars["{"] = ""; vars["{"] = "";
vars["}"] = ""; vars["}"] = "";

@ -149,7 +149,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
absl::flat_hash_map<absl::string_view, std::string> variables = {{"{", ""}, absl::flat_hash_map<absl::string_view, std::string> variables = {{"{", ""},
{"}", ""}}; {"}", ""}};
variables["static"] = is_own_file ? " " : " static "; variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name(); variables["classname"] = std::string(descriptor_->name());
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["deprecation"] = variables["deprecation"] =
descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "";

@ -142,9 +142,9 @@ std::string ClassNameResolver::GetFileDefaultImmutableClassName(
std::string basename; std::string basename;
std::string::size_type last_slash = file->name().find_last_of('/'); std::string::size_type last_slash = file->name().find_last_of('/');
if (last_slash == std::string::npos) { if (last_slash == std::string::npos) {
basename = file->name(); basename = std::string(file->name());
} else { } else {
basename = file->name().substr(last_slash + 1); basename = std::string(file->name().substr(last_slash + 1));
} }
// foo_bar_baz.proto -> FooBarBaz // foo_bar_baz.proto -> FooBarBaz
std::string ret = UnderscoresToCamelCase(StripProto(basename), true); std::string ret = UnderscoresToCamelCase(StripProto(basename), true);

@ -86,9 +86,9 @@ std::string FieldName(const FieldDescriptor* field) {
// of the group type. In Java, though, we would like to retain the original // of the group type. In Java, though, we would like to retain the original
// capitalization of the type name. // capitalization of the type name.
if (internal::cpp::IsGroupLike(*field)) { if (internal::cpp::IsGroupLike(*field)) {
field_name = field->message_type()->name(); field_name = std::string(field->message_type()->name());
} else { } else {
field_name = field->name(); field_name = std::string(field->name());
} }
if (IsForbidden(field_name)) { if (IsForbidden(field_name)) {
// Append a trailing "#" to indicate that the name should be decorated to // Append a trailing "#" to indicate that the name should be decorated to
@ -130,7 +130,7 @@ std::string FileJavaPackage(const FileDescriptor* file, bool immutable,
result = DefaultPackage(options); result = DefaultPackage(options);
if (!file->package().empty()) { if (!file->package().empty()) {
if (!result.empty()) result += '.'; if (!result.empty()) result += '.';
result += file->package(); absl::StrAppend(&result, file->package());
} }
} }

@ -41,9 +41,9 @@ void SetCommonFieldVariables(
std::string camel_case_name = FieldName(descriptor); std::string camel_case_name = FieldName(descriptor);
std::string raw_field_name; std::string raw_field_name;
if (internal::cpp::IsGroupLike(*descriptor)) { if (internal::cpp::IsGroupLike(*descriptor)) {
raw_field_name = descriptor->message_type()->name(); raw_field_name = std::string(descriptor->message_type()->name());
} else { } else {
raw_field_name = descriptor->name(); raw_field_name = std::string(descriptor->name());
} }
// The logic here has to match -[GGPBFieldDescriptor textFormatName]. // The logic here has to match -[GGPBFieldDescriptor textFormatName].
const std::string un_camel_case_name( const std::string un_camel_case_name(

@ -562,8 +562,8 @@ void Generator::PrintResolvedFeatures() const {
void Generator::PrintFileDescriptor() const { void Generator::PrintFileDescriptor() const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["name"] = file_->name(); m["name"] = std::string(file_->name());
m["package"] = file_->package(); m["package"] = std::string(file_->package());
m["syntax"] = GetLegacySyntaxName(GetEdition(*file_)); m["syntax"] = GetLegacySyntaxName(GetEdition(*file_));
m["edition"] = Edition_Name(GetEdition(*file_)); m["edition"] = Edition_Name(GetEdition(*file_));
m["options"] = OptionsValue(proto_.options().SerializeAsString()); m["options"] = OptionsValue(proto_.options().SerializeAsString());
@ -645,8 +645,8 @@ void Generator::PrintEnum(const EnumDescriptor& enum_descriptor,
std::string module_level_descriptor_name = std::string module_level_descriptor_name =
ModuleLevelDescriptorName(enum_descriptor); ModuleLevelDescriptorName(enum_descriptor);
m["descriptor_name"] = module_level_descriptor_name; m["descriptor_name"] = module_level_descriptor_name;
m["name"] = enum_descriptor.name(); m["name"] = std::string(enum_descriptor.name());
m["full_name"] = enum_descriptor.full_name(); m["full_name"] = std::string(enum_descriptor.full_name());
m["file"] = kDescriptorKey; m["file"] = kDescriptorKey;
const char enum_descriptor_template[] = const char enum_descriptor_template[] =
"$descriptor_name$ = _descriptor.EnumDescriptor(\n" "$descriptor_name$ = _descriptor.EnumDescriptor(\n"
@ -720,7 +720,7 @@ void Generator::PrintServiceDescriptor(
const ServiceDescriptor& descriptor) const { const ServiceDescriptor& descriptor) const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["service_name"] = ModuleLevelServiceDescriptorName(descriptor); m["service_name"] = ModuleLevelServiceDescriptorName(descriptor);
m["name"] = descriptor.name(); m["name"] = std::string(descriptor.name());
m["file"] = kDescriptorKey; m["file"] = kDescriptorKey;
printer_->Print(m, "$service_name$ = $file$.services_by_name['$name$']\n"); printer_->Print(m, "$service_name$ = $file$.services_by_name['$name$']\n");
} }
@ -770,8 +770,8 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const {
void Generator::PrintDescriptor(const Descriptor& message_descriptor, void Generator::PrintDescriptor(const Descriptor& message_descriptor,
const DescriptorProto& proto) const { const DescriptorProto& proto) const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["name"] = message_descriptor.name(); m["name"] = std::string(message_descriptor.name());
m["full_name"] = message_descriptor.full_name(); m["full_name"] = std::string(message_descriptor.full_name());
m["file"] = kDescriptorKey; m["file"] = kDescriptorKey;
PrintNestedDescriptors(message_descriptor, proto); PrintNestedDescriptors(message_descriptor, proto);
@ -836,8 +836,8 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor,
for (int i = 0; i < message_descriptor.oneof_decl_count(); ++i) { for (int i = 0; i < message_descriptor.oneof_decl_count(); ++i) {
const OneofDescriptor* desc = message_descriptor.oneof_decl(i); const OneofDescriptor* desc = message_descriptor.oneof_decl(i);
m.clear(); m.clear();
m["name"] = desc->name(); m["name"] = std::string(desc->name());
m["full_name"] = desc->full_name(); m["full_name"] = std::string(desc->full_name());
m["index"] = absl::StrCat(desc->index()); m["index"] = absl::StrCat(desc->index());
options_string = options_string =
OptionsValue(proto.oneof_decl(i).options().SerializeAsString()); OptionsValue(proto.oneof_decl(i).options().SerializeAsString());
@ -980,9 +980,9 @@ void Generator::FixForeignFieldsInDescriptor(
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
const OneofDescriptor* oneof = descriptor.oneof_decl(i); const OneofDescriptor* oneof = descriptor.oneof_decl(i);
m["descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["descriptor_name"] = ModuleLevelDescriptorName(descriptor);
m["oneof_name"] = oneof->name(); m["oneof_name"] = std::string(oneof->name());
for (int j = 0; j < oneof->field_count(); ++j) { for (int j = 0; j < oneof->field_count(); ++j) {
m["field_name"] = oneof->field(j)->name(); m["field_name"] = std::string(oneof->field(j)->name());
printer_->Print( printer_->Print(
m, m,
"$descriptor_name$.oneofs_by_name['$oneof_name$'].fields.append(\n" "$descriptor_name$.oneofs_by_name['$oneof_name$'].fields.append(\n"
@ -998,7 +998,7 @@ void Generator::FixForeignFieldsInDescriptor(
void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["message_name"] = descriptor.name(); m["message_name"] = std::string(descriptor.name());
m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
const char file_descriptor_template[] = const char file_descriptor_template[] =
"$descriptor_name$.message_types_by_name['$message_name$'] = " "$descriptor_name$.message_types_by_name['$message_name$'] = "
@ -1010,7 +1010,7 @@ void Generator::AddServiceToFileDescriptor(
const ServiceDescriptor& descriptor) const { const ServiceDescriptor& descriptor) const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["service_name"] = descriptor.name(); m["service_name"] = std::string(descriptor.name());
m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor); m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor);
const char file_descriptor_template[] = const char file_descriptor_template[] =
"$descriptor_name$.services_by_name['$service_name$'] = " "$descriptor_name$.services_by_name['$service_name$'] = "
@ -1022,7 +1022,7 @@ void Generator::AddEnumToFileDescriptor(
const EnumDescriptor& descriptor) const { const EnumDescriptor& descriptor) const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["enum_name"] = descriptor.name(); m["enum_name"] = std::string(descriptor.name());
m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
const char file_descriptor_template[] = const char file_descriptor_template[] =
"$descriptor_name$.enum_types_by_name['$enum_name$'] = " "$descriptor_name$.enum_types_by_name['$enum_name$'] = "
@ -1034,7 +1034,7 @@ void Generator::AddExtensionToFileDescriptor(
const FieldDescriptor& descriptor) const { const FieldDescriptor& descriptor) const {
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["field_name"] = descriptor.name(); m["field_name"] = std::string(descriptor.name());
m["resolved_name"] = ResolveKeyword(descriptor.name()); m["resolved_name"] = ResolveKeyword(descriptor.name());
const char file_descriptor_template[] = const char file_descriptor_template[] =
"$descriptor_name$.extensions_by_name['$field_name$'] = " "$descriptor_name$.extensions_by_name['$field_name$'] = "
@ -1143,7 +1143,7 @@ void Generator::PrintEnumValueDescriptor(
std::string options_string; std::string options_string;
proto.options().SerializeToString(&options_string); proto.options().SerializeToString(&options_string);
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["name"] = descriptor.name(); m["name"] = std::string(descriptor.name());
m["index"] = absl::StrCat(descriptor.index()); m["index"] = absl::StrCat(descriptor.index());
m["number"] = absl::StrCat(descriptor.number()); m["number"] = absl::StrCat(descriptor.number());
m["options"] = OptionsValue(options_string); m["options"] = OptionsValue(options_string);
@ -1161,8 +1161,8 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field,
std::string options_string; std::string options_string;
proto.options().SerializeToString(&options_string); proto.options().SerializeToString(&options_string);
absl::flat_hash_map<absl::string_view, std::string> m; absl::flat_hash_map<absl::string_view, std::string> m;
m["name"] = field.name(); m["name"] = std::string(field.name());
m["full_name"] = field.full_name(); m["full_name"] = std::string(field.full_name());
m["index"] = absl::StrCat(field.index()); m["index"] = absl::StrCat(field.index());
m["number"] = absl::StrCat(field.number()); m["number"] = absl::StrCat(field.number());
m["type"] = absl::StrCat(field.type()); m["type"] = absl::StrCat(field.type());
@ -1456,7 +1456,7 @@ void Generator::FixOptionsForField(const FieldDescriptor& field,
if (field.is_extension()) { if (field.is_extension()) {
if (field.extension_scope() == nullptr) { if (field.extension_scope() == nullptr) {
// Top level extensions. // Top level extensions.
field_name = field.name(); field_name = std::string(field.name());
} else { } else {
field_name = FieldReferencingExpression(field.extension_scope(), field, field_name = FieldReferencingExpression(field.extension_scope(), field,
"extensions_by_name"); "extensions_by_name");

@ -170,7 +170,7 @@ int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) {
<< " 'A::B::C' and not 'A.B.C'"; << " 'A::B::C' and not 'A.B.C'";
} }
} else { } else {
package_name = file->package(); package_name = std::string(file->package());
} }
// Use the appropriate delimiter // Use the appropriate delimiter

@ -3050,7 +3050,7 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const {
if (!containing_type()->is_unqualified_placeholder_) { if (!containing_type()->is_unqualified_placeholder_) {
proto->set_extendee("."); proto->set_extendee(".");
} }
proto->mutable_extendee()->append(containing_type()->full_name()); absl::StrAppend(proto->mutable_extendee(), containing_type()->full_name());
} }
if (cpp_type() == CPPTYPE_MESSAGE) { if (cpp_type() == CPPTYPE_MESSAGE) {
@ -3063,12 +3063,12 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const {
if (!message_type()->is_unqualified_placeholder_) { if (!message_type()->is_unqualified_placeholder_) {
proto->set_type_name("."); proto->set_type_name(".");
} }
proto->mutable_type_name()->append(message_type()->full_name()); absl::StrAppend(proto->mutable_type_name(), message_type()->full_name());
} else if (cpp_type() == CPPTYPE_ENUM) { } else if (cpp_type() == CPPTYPE_ENUM) {
if (!enum_type()->is_unqualified_placeholder_) { if (!enum_type()->is_unqualified_placeholder_) {
proto->set_type_name("."); proto->set_type_name(".");
} }
proto->mutable_type_name()->append(enum_type()->full_name()); absl::StrAppend(proto->mutable_type_name(), enum_type()->full_name());
} }
if (has_default_value()) { if (has_default_value()) {
@ -3152,12 +3152,12 @@ void MethodDescriptor::CopyTo(MethodDescriptorProto* proto) const {
if (!input_type()->is_unqualified_placeholder_) { if (!input_type()->is_unqualified_placeholder_) {
proto->set_input_type("."); proto->set_input_type(".");
} }
proto->mutable_input_type()->append(input_type()->full_name()); absl::StrAppend(proto->mutable_input_type(), input_type()->full_name());
if (!output_type()->is_unqualified_placeholder_) { if (!output_type()->is_unqualified_placeholder_) {
proto->set_output_type("."); proto->set_output_type(".");
} }
proto->mutable_output_type()->append(output_type()->full_name()); absl::StrAppend(proto->mutable_output_type(), output_type()->full_name());
if (&options() != &MethodOptions::default_instance()) { if (&options() != &MethodOptions::default_instance()) {
*proto->mutable_options() = options(); *proto->mutable_options() = options();
@ -3223,7 +3223,7 @@ bool RetrieveOptionsAssumingRightPool(
if (field->is_extension()) { if (field->is_extension()) {
name = absl::StrCat("(.", field->full_name(), ")"); name = absl::StrCat("(.", field->full_name(), ")");
} else { } else {
name = field->name(); name = std::string(field->name());
} }
option_entries->push_back(absl::StrCat(name, " = ", fieldval)); option_entries->push_back(absl::StrCat(name, " = ", fieldval));
} }
@ -7170,9 +7170,9 @@ void DescriptorBuilder::BuildEnumValue(const EnumValueDescriptorProto& proto,
// scope. Let's print an additional error to explain this. // scope. Let's print an additional error to explain this.
std::string outer_scope; std::string outer_scope;
if (parent->containing_type() == nullptr) { if (parent->containing_type() == nullptr) {
outer_scope = file_->package(); outer_scope = std::string(file_->package());
} else { } else {
outer_scope = parent->containing_type()->full_name(); outer_scope = std::string(parent->containing_type()->full_name());
} }
if (outer_scope.empty()) { if (outer_scope.empty()) {

@ -153,9 +153,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#ifdef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE #ifdef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE
#error PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE was previously defined #error PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE was previously defined
#endif #endif
#if defined(PROTOBUF_TEMPORARY_ENABLE_STRING_VIEW_RETURN_TYPE)
#define PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE 1 #define PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE 1
#endif
#ifdef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE_TYPENAME #ifdef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE_TYPENAME
#error PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE_TYPENAME was previously defined #error PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE_TYPENAME was previously defined

@ -69,10 +69,10 @@
#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES #ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
#undef PROTOBUF_FUTURE_BREAKING_CHANGES #undef PROTOBUF_FUTURE_BREAKING_CHANGES
#undef PROTOBUF_FUTURE_DESCRIPTOR_EXTENSION_DECL #undef PROTOBUF_FUTURE_DESCRIPTOR_EXTENSION_DECL
#undef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE
#undef PROTOBUF_FUTURE_REMOVE_CREATEMESSAGE #undef PROTOBUF_FUTURE_REMOVE_CREATEMESSAGE
#endif #endif
#undef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE
#undef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE_TYPENAME #undef PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE_TYPENAME
// Restore macros that may have been #undef'd in port_def.inc. // Restore macros that may have been #undef'd in port_def.inc.

@ -365,16 +365,12 @@ static std::string SubMessagePrefix(const std::string& prefix,
const FieldDescriptor* field, int index) { const FieldDescriptor* field, int index) {
std::string result(prefix); std::string result(prefix);
if (field->is_extension()) { if (field->is_extension()) {
result.append("("); absl::StrAppend(&result, "(", field->full_name(), ")");
result.append(field->full_name());
result.append(")");
} else { } else {
result.append(field->name()); absl::StrAppend(&result, field->name());
} }
if (index != -1) { if (index != -1) {
result.append("["); absl::StrAppend(&result, "[", index, "]");
result.append(absl::StrCat(index));
result.append("]");
} }
result.append("."); result.append(".");
return result; return result;

Loading…
Cancel
Save