Integrate from Piper for C++, Java, and Python (#10455)

* Sync from Piper @469587494

PROTOBUF_SYNC_PIPER

* Fixing github SOT protoc builds

* Fixing typos from google

* Remove leaked util/hash reference

* Fixing bad python merge

* Fixing python C++ library order
pull/10457/head
Mike Kruskal 3 years ago committed by GitHub
parent 6e8a7cdcb0
commit a3c8e2deb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .bazelrc
  2. 3
      cmake/abseil-cpp.cmake
  3. 3
      conformance/BUILD.bazel
  4. 72
      conformance/binary_json_conformance_suite.cc
  5. 4
      conformance/conformance.proto
  6. 53
      conformance/conformance_cpp.cc
  7. 4
      conformance/conformance_test.cc
  8. 78
      conformance/text_format_conformance_suite.cc
  9. 2
      java/core/src/test/java/com/google/protobuf/TextFormatTest.java
  10. 5
      python/google/protobuf/pyext/descriptor.cc
  11. 3
      python/google/protobuf/pyext/descriptor.h
  12. 45
      python/google/protobuf/pyext/descriptor_containers.cc
  13. 20
      python/google/protobuf/pyext/descriptor_pool.cc
  14. 5
      python/google/protobuf/pyext/extension_dict.cc
  15. 17
      python/google/protobuf/pyext/message.cc
  16. 4
      python/setup.py
  17. 29
      src/file_lists.cmake
  18. 8
      src/google/protobuf/BUILD.bazel
  19. 2
      src/google/protobuf/any.cc
  20. 20
      src/google/protobuf/any.h
  21. 4
      src/google/protobuf/any.pb.cc
  22. 8
      src/google/protobuf/any.pb.h
  23. 23
      src/google/protobuf/any_lite.cc
  24. 1
      src/google/protobuf/any_test.cc
  25. 2
      src/google/protobuf/api.pb.cc
  26. 6
      src/google/protobuf/api.pb.h
  27. 105
      src/google/protobuf/arena.cc
  28. 72
      src/google/protobuf/arena.h
  29. 67
      src/google/protobuf/arena_impl.h
  30. 2
      src/google/protobuf/arena_unittest.cc
  31. 8
      src/google/protobuf/arenastring.cc
  32. 13
      src/google/protobuf/arenastring.h
  33. 2
      src/google/protobuf/arenastring_unittest.cc
  34. 4
      src/google/protobuf/arenaz_sampler_test.cc
  35. 35
      src/google/protobuf/compiler/command_line_interface.cc
  36. 8
      src/google/protobuf/compiler/command_line_interface.h
  37. 42
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  38. 18
      src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
  39. 8
      src/google/protobuf/compiler/cpp/enum.cc
  40. 3
      src/google/protobuf/compiler/cpp/enum.h
  41. 16
      src/google/protobuf/compiler/cpp/enum_field.h
  42. 7
      src/google/protobuf/compiler/cpp/extension.cc
  43. 4
      src/google/protobuf/compiler/cpp/extension.h
  44. 68
      src/google/protobuf/compiler/cpp/field.cc
  45. 9
      src/google/protobuf/compiler/cpp/field.h
  46. 12
      src/google/protobuf/compiler/cpp/file.cc
  47. 4
      src/google/protobuf/compiler/cpp/file.h
  48. 3
      src/google/protobuf/compiler/cpp/generator.cc
  49. 3
      src/google/protobuf/compiler/cpp/generator.h
  50. 60
      src/google/protobuf/compiler/cpp/helpers.cc
  51. 13
      src/google/protobuf/compiler/cpp/helpers.h
  52. 5
      src/google/protobuf/compiler/cpp/map_field.cc
  53. 4
      src/google/protobuf/compiler/cpp/map_field.h
  54. 89
      src/google/protobuf/compiler/cpp/message.cc
  55. 3
      src/google/protobuf/compiler/cpp/message.h
  56. 16
      src/google/protobuf/compiler/cpp/message_field.h
  57. 23
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  58. 5
      src/google/protobuf/compiler/cpp/primitive_field.cc
  59. 18
      src/google/protobuf/compiler/cpp/primitive_field.h
  60. 10
      src/google/protobuf/compiler/cpp/service.cc
  61. 3
      src/google/protobuf/compiler/cpp/service.h
  62. 17
      src/google/protobuf/compiler/cpp/string_field.cc
  63. 15
      src/google/protobuf/compiler/cpp/string_field.h
  64. 8
      src/google/protobuf/compiler/cpp/unittest.inc
  65. 2
      src/google/protobuf/compiler/csharp/BUILD.bazel
  66. 4
      src/google/protobuf/compiler/csharp/csharp_enum.cc
  67. 46
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  68. 26
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  69. 21
      src/google/protobuf/compiler/csharp/csharp_message.cc
  70. 2
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  71. 10
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  72. 3
      src/google/protobuf/compiler/importer.cc
  73. 18
      src/google/protobuf/compiler/importer_unittest.cc
  74. 20
      src/google/protobuf/compiler/java/context.cc
  75. 6
      src/google/protobuf/compiler/java/context.h
  76. 13
      src/google/protobuf/compiler/java/enum.cc
  77. 7
      src/google/protobuf/compiler/java/enum_field.cc
  78. 11
      src/google/protobuf/compiler/java/enum_field_lite.cc
  79. 8
      src/google/protobuf/compiler/java/enum_lite.cc
  80. 7
      src/google/protobuf/compiler/java/extension.cc
  81. 9
      src/google/protobuf/compiler/java/field.cc
  82. 9
      src/google/protobuf/compiler/java/file.cc
  83. 28
      src/google/protobuf/compiler/java/helpers.cc
  84. 24
      src/google/protobuf/compiler/java/message.cc
  85. 8
      src/google/protobuf/compiler/java/message_builder.cc
  86. 3
      src/google/protobuf/compiler/java/message_builder_lite.cc
  87. 1
      src/google/protobuf/compiler/java/message_field_lite.cc
  88. 10
      src/google/protobuf/compiler/java/message_lite.cc
  89. 3
      src/google/protobuf/compiler/java/message_serialization.cc
  90. 9
      src/google/protobuf/compiler/java/message_serialization_unittest.cc
  91. 7
      src/google/protobuf/compiler/java/primitive_field.cc
  92. 8
      src/google/protobuf/compiler/java/primitive_field_lite.cc
  93. 13
      src/google/protobuf/compiler/java/service.cc
  94. 4
      src/google/protobuf/compiler/java/shared_code_generator.cc
  95. 5
      src/google/protobuf/compiler/java/string_field.cc
  96. 9
      src/google/protobuf/compiler/java/string_field_lite.cc
  97. 2
      src/google/protobuf/compiler/mock_code_generator.cc
  98. 1
      src/google/protobuf/compiler/objectivec/BUILD.bazel
  99. 10
      src/google/protobuf/compiler/objectivec/objectivec_enum.cc
  100. 2
      src/google/protobuf/compiler/objectivec/objectivec_extension.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1 +1 @@
build --cxxopt=-std=c++14
build --cxxopt=-std=c++14

@ -34,7 +34,10 @@ set(protobuf_ABSL_USED_TARGETS
absl::base
absl::bind_front
absl::cleanup
absl::cord
absl::core_headers
absl::debugging
absl::dynamic_annotations
absl::flags
absl::flat_hash_map
absl::flat_hash_set

@ -155,6 +155,7 @@ cc_library(
":jsoncpp",
":test_messages_proto2_proto_cc",
":test_messages_proto3_proto_cc",
"@com_google_absl//absl/status",
],
)
@ -190,6 +191,8 @@ cc_binary(
"//:protobuf",
"//:test_messages_proto2_cc_proto",
"//:test_messages_proto3_cc_proto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
],
)

@ -34,11 +34,11 @@
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h>
#include "absl/status/status.h"
#include "third_party/jsoncpp/json.h"
#include "conformance_test.h"
#include <google/protobuf/test_messages_proto2.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/stubs/status.h>
namespace proto2_messages = protobuf_test_messages::proto2;
@ -354,7 +354,7 @@ bool BinaryAndJsonConformanceSuite::ParseJsonResponse(
const ConformanceResponse& response,
Message* test_message) {
string binary_protobuf;
util::Status status =
absl::Status status =
JsonToBinaryString(type_resolver_.get(), type_url_,
response.json_payload(), &binary_protobuf);
@ -384,7 +384,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse(
case ConformanceResponse::kProtobufPayload: {
if (requested_output != conformance::PROTOBUF) {
ReportFailure(test_name, level, request, response,
StrCat("Test was asked for ",
absl::StrCat("Test was asked for ",
WireFormatToString(requested_output),
" output but provided PROTOBUF instead.")
.c_str());
@ -403,7 +403,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse(
case ConformanceResponse::kJsonPayload: {
if (requested_output != conformance::JSON) {
ReportFailure(test_name, level, request, response,
StrCat("Test was asked for ",
absl::StrCat("Test was asked for ",
WireFormatToString(requested_output),
" output but provided JSON instead.")
.c_str());
@ -440,7 +440,7 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForProtoWithProtoVersion (
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name = StrCat(
string effective_test_name = absl::StrCat(
setting.ConformanceLevelToString(level),
(is_proto3 ? ".Proto3" : ".Proto2"), ".ProtobufInput.", test_name);
@ -571,7 +571,7 @@ void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator(
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name =
StrCat(setting.ConformanceLevelToString(level),
absl::StrCat(setting.ConformanceLevelToString(level),
is_proto3 ? ".Proto3.JsonInput." : ".Proto2.JsonInput.",
test_name, ".Validator");
@ -615,7 +615,7 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForJson(
prototype, test_name, input_json);
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name = StrCat(
string effective_test_name = absl::StrCat(
setting.ConformanceLevelToString(level), ".Proto3.JsonInput.", test_name);
RunTest(effective_test_name, request, &response);
@ -642,7 +642,7 @@ void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson(
prototype, test_name, payload_message.SerializeAsString());
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name = StrCat(
string effective_test_name = absl::StrCat(
setting.ConformanceLevelToString(level), ".", test_name, ".JsonOutput");
RunTest(effective_test_name, request, &response);
@ -768,10 +768,10 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType(
string text = test_message->DebugString();
RunValidProtobufTest(
StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED,
absl::StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED,
proto, text, is_proto3);
RunValidBinaryProtobufTest(
StrCat("ValidDataScalarBinary", type_name, "[", i, "]"),
absl::StrCat("ValidDataScalarBinary", type_name, "[", i, "]"),
RECOMMENDED, proto, expected_proto, is_proto3);
}
@ -852,10 +852,10 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType(
// Ensures both packed and unpacked data can be parsed.
RunValidProtobufTest(
StrCat("ValidDataRepeated", type_name, ".UnpackedInput"),
absl::StrCat("ValidDataRepeated", type_name, ".UnpackedInput"),
REQUIRED, default_proto_unpacked, text, is_proto3);
RunValidProtobufTest(
StrCat("ValidDataRepeated", type_name, ".PackedInput"),
absl::StrCat("ValidDataRepeated", type_name, ".PackedInput"),
REQUIRED, default_proto_packed, text, is_proto3);
// proto2 should encode as unpacked by default and proto3 should encode as
@ -863,27 +863,27 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType(
string expected_proto = rep_field->is_packed()
? default_proto_packed_expected
: default_proto_unpacked_expected;
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name,
".UnpackedInput.DefaultOutput"),
RECOMMENDED, default_proto_unpacked,
expected_proto, is_proto3);
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name,
".PackedInput.DefaultOutput"),
RECOMMENDED, default_proto_packed,
expected_proto, is_proto3);
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name,
".UnpackedInput.PackedOutput"),
RECOMMENDED, packed_proto_unpacked,
packed_proto_expected, is_proto3);
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name,
".PackedInput.PackedOutput"),
RECOMMENDED, packed_proto_packed,
packed_proto_expected, is_proto3);
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name,
".UnpackedInput.UnpackedOutput"),
RECOMMENDED, unpacked_proto_unpacked,
unpacked_proto_expected, is_proto3);
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name,
".PackedInput.UnpackedOutput"),
RECOMMENDED, unpacked_proto_packed,
unpacked_proto_expected, is_proto3);
@ -899,7 +899,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType(
test_message->MergeFromString(expected_proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataRepeated", type_name),
RunValidProtobufTest(absl::StrCat("ValidDataRepeated", type_name),
REQUIRED, proto, text, is_proto3);
}
}
@ -975,7 +975,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name,
RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name,
value_type_name, ".Default"),
REQUIRED, proto, text, is_proto3);
}
@ -988,7 +988,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name,
RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name,
value_type_name, ".MissingDefault"),
REQUIRED, proto, text, is_proto3);
}
@ -1001,7 +1001,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name,
RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name,
value_type_name, ".NonDefault"),
REQUIRED, proto, text, is_proto3);
}
@ -1014,7 +1014,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name,
RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name,
value_type_name, ".Unordered"),
REQUIRED, proto, text, is_proto3);
}
@ -1031,7 +1031,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(proto2);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name,
RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name,
value_type_name, ".DuplicateKey"),
REQUIRED, proto, text, is_proto3);
}
@ -1045,7 +1045,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
test_message->MergeFromString(proto);
string text = test_message->DebugString();
RunValidProtobufTest(
StrCat("ValidDataMap", key_type_name, value_type_name,
absl::StrCat("ValidDataMap", key_type_name, value_type_name,
".DuplicateKeyInMapEntry"),
REQUIRED, proto, text, is_proto3);
}
@ -1059,7 +1059,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType(
test_message->MergeFromString(proto);
string text = test_message->DebugString();
RunValidProtobufTest(
StrCat("ValidDataMap", key_type_name, value_type_name,
absl::StrCat("ValidDataMap", key_type_name, value_type_name,
".DuplicateValueInMapEntry"),
REQUIRED, proto, text, is_proto3);
}
@ -1125,10 +1125,10 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType(
string text = test_message->DebugString();
RunValidProtobufTest(
StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED,
absl::StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED,
proto, text, is_proto3);
RunValidBinaryProtobufTest(
StrCat("ValidDataOneofBinary", type_name, ".DefaultValue"),
absl::StrCat("ValidDataOneofBinary", type_name, ".DefaultValue"),
RECOMMENDED, proto, proto, is_proto3);
}
@ -1140,25 +1140,25 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType(
string text = test_message->DebugString();
RunValidProtobufTest(
StrCat("ValidDataOneof", type_name, ".NonDefaultValue"),
absl::StrCat("ValidDataOneof", type_name, ".NonDefaultValue"),
REQUIRED, proto, text, is_proto3);
RunValidBinaryProtobufTest(
StrCat("ValidDataOneofBinary", type_name, ".NonDefaultValue"),
absl::StrCat("ValidDataOneofBinary", type_name, ".NonDefaultValue"),
RECOMMENDED, proto, proto, is_proto3);
}
{
// Tests oneof with multiple values of the same field.
const string proto = StrCat(default_value, non_default_value);
const string proto = absl::StrCat(default_value, non_default_value);
const string expected_proto = non_default_value;
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(expected_proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataOneof", type_name,
RunValidProtobufTest(absl::StrCat("ValidDataOneof", type_name,
".MultipleValuesForSameField"),
REQUIRED, proto, text, is_proto3);
RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name,
RunValidBinaryProtobufTest(absl::StrCat("ValidDataOneofBinary", type_name,
".MultipleValuesForSameField"),
RECOMMENDED, proto, expected_proto, is_proto3);
}
@ -1175,17 +1175,17 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType(
cat(tag(other_field->number(), other_wire_type),
GetDefaultValue(other_type));
const string proto = StrCat(other_value, non_default_value);
const string proto = absl::StrCat(other_value, non_default_value);
const string expected_proto = non_default_value;
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
test_message->MergeFromString(expected_proto);
string text = test_message->DebugString();
RunValidProtobufTest(StrCat("ValidDataOneof", type_name,
RunValidProtobufTest(absl::StrCat("ValidDataOneof", type_name,
".MultipleValuesForDifferentField"),
REQUIRED, proto, text, is_proto3);
RunValidBinaryProtobufTest(
StrCat("ValidDataOneofBinary", type_name,
absl::StrCat("ValidDataOneofBinary", type_name,
".MultipleValuesForDifferentField"),
RECOMMENDED, proto, expected_proto, is_proto3);
}

@ -92,10 +92,6 @@ message ConformanceRequest {
// The payload (whether protobuf of JSON) is always for a
// protobuf_test_messages.proto3.TestAllTypes proto (as defined in
// src/google/protobuf/proto3_test_messages.proto).
//
// TODO(haberman): if/when we expand the conformance tests to support proto2,
// we will want to include a field that lets the payload/response be a
// protobuf_test_messages.google.protobuf.TestAllTypes message instead.
oneof payload {
bytes protobuf_payload = 1;
string json_payload = 2;

@ -42,15 +42,14 @@
#include <google/protobuf/text_format.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h>
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/statusor.h>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "conformance/conformance.pb.h"
#include "conformance/conformance.pb.h"
#include <google/protobuf/test_messages_proto2.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/util/type_resolver.h>
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/status_macros.h>
// Must be included last.
@ -69,29 +68,29 @@ using ::google::protobuf::util::TypeResolver;
using ::protobuf_test_messages::proto2::TestAllTypesProto2;
using ::protobuf_test_messages::proto3::TestAllTypesProto3;
util::Status ReadFd(int fd, char* buf, size_t len) {
absl::Status ReadFd(int fd, char* buf, size_t len) {
while (len > 0) {
ssize_t bytes_read = read(fd, buf, len);
if (bytes_read == 0) {
return util::DataLossError("unexpected EOF");
return absl::DataLossError("unexpected EOF");
}
if (bytes_read < 0) {
return util::ErrnoToStatus(errno, "error reading from test runner");
return absl::ErrnoToStatus(errno, "error reading from test runner");
}
len -= bytes_read;
buf += bytes_read;
}
return util::OkStatus();
return absl::OkStatus();
}
util::Status WriteFd(int fd, const void* buf, size_t len) {
absl::Status WriteFd(int fd, const void* buf, size_t len) {
if (write(fd, buf, len) != len) {
return util::ErrnoToStatus(errno, "error reading to test runner");
return absl::ErrnoToStatus(errno, "error reading to test runner");
}
return util::OkStatus();
return absl::OkStatus();
}
class Harness {
@ -102,15 +101,15 @@ class Harness {
resolver_.reset(NewTypeResolverForDescriptorPool(
"type.googleapis.com", DescriptorPool::generated_pool()));
type_url_ = StrCat("type.googleapis.com/",
type_url_ = absl::StrCat("type.googleapis.com/",
TestAllTypesProto3::GetDescriptor()->full_name());
}
util::StatusOr<ConformanceResponse> RunTest(
absl::StatusOr<ConformanceResponse> RunTest(
const ConformanceRequest& request);
// Returns Ok(true) if we're done processing requests.
util::StatusOr<bool> ServeConformanceRequest();
absl::StatusOr<bool> ServeConformanceRequest();
private:
bool verbose_ = false;
@ -118,14 +117,14 @@ class Harness {
std::string type_url_;
};
util::StatusOr<ConformanceResponse> Harness::RunTest(
absl::StatusOr<ConformanceResponse> Harness::RunTest(
const ConformanceRequest& request) {
const Descriptor* descriptor =
DescriptorPool::generated_pool()->FindMessageTypeByName(
request.message_type());
if (descriptor == nullptr) {
return util::NotFoundError(
StrCat("No such message type: ", request.message_type()));
return absl::NotFoundError(
absl::StrCat("No such message type: ", request.message_type()));
}
std::unique_ptr<Message> test_message(
@ -148,12 +147,12 @@ util::StatusOr<ConformanceResponse> Harness::RunTest(
conformance::JSON_IGNORE_UNKNOWN_PARSING_TEST);
std::string proto_binary;
util::Status status =
absl::Status status =
JsonToBinaryString(resolver_.get(), type_url_, request.json_payload(),
&proto_binary, options);
if (!status.ok()) {
response.set_parse_error(
StrCat("parse error: ", status.message()));
absl::StrCat("parse error: ", status.message()));
return response;
}
@ -176,16 +175,16 @@ util::StatusOr<ConformanceResponse> Harness::RunTest(
}
case ConformanceRequest::PAYLOAD_NOT_SET:
return util::InvalidArgumentError("request didn't have payload");
return absl::InvalidArgumentError("request didn't have payload");
default:
return util::InvalidArgumentError(
StrCat("unknown payload type", request.payload_case()));
return absl::InvalidArgumentError(
absl::StrCat("unknown payload type", request.payload_case()));
}
switch (request.requested_output_format()) {
case conformance::UNSPECIFIED:
return util::InvalidArgumentError("unspecified output format");
return absl::InvalidArgumentError("unspecified output format");
case conformance::PROTOBUF: {
GOOGLE_CHECK(
@ -196,11 +195,11 @@ util::StatusOr<ConformanceResponse> Harness::RunTest(
case conformance::JSON: {
std::string proto_binary;
GOOGLE_CHECK(test_message->SerializeToString(&proto_binary));
util::Status status =
absl::Status status =
BinaryToJsonString(resolver_.get(), type_url_, proto_binary,
response.mutable_json_payload());
if (!status.ok()) {
response.set_serialize_error(StrCat(
response.set_serialize_error(absl::StrCat(
"failed to serialize JSON output: ", status.message()));
}
break;
@ -215,14 +214,14 @@ util::StatusOr<ConformanceResponse> Harness::RunTest(
}
default:
return util::InvalidArgumentError(StrCat(
return absl::InvalidArgumentError(absl::StrCat(
"unknown output format", request.requested_output_format()));
}
return response;
}
util::StatusOr<bool> Harness::ServeConformanceRequest() {
absl::StatusOr<bool> Harness::ServeConformanceRequest() {
uint32_t in_len;
if (!ReadFd(STDIN_FILENO, reinterpret_cast<char*>(&in_len), sizeof(in_len))
.ok()) {
@ -237,7 +236,7 @@ util::StatusOr<bool> Harness::ServeConformanceRequest() {
ConformanceRequest request;
GOOGLE_CHECK(request.ParseFromString(serialized_input));
util::StatusOr<ConformanceResponse> response = RunTest(request);
absl::StatusOr<ConformanceResponse> response = RunTest(request);
RETURN_IF_ERROR(response.status());
std::string serialized_output;

@ -129,7 +129,7 @@ string ConformanceTestSuite::ConformanceRequestSetting::
prototype_message_.GetDescriptor()->file()->syntax() ==
FileDescriptor::SYNTAX_PROTO3 ? "Proto3" : "Proto2";
return StrCat(ConformanceLevelToString(level_), ".", rname, ".",
return absl::StrCat(ConformanceLevelToString(level_), ".", rname, ".",
InputFormatString(input_format_), ".", test_name_, ".",
OutputFormatString(output_format_));
}
@ -290,7 +290,7 @@ void ConformanceTestSuite::VerifyResponse(
GOOGLE_DCHECK_EQ(response.result_case(), ConformanceResponse::kProtobufPayload);
const string& protobuf_payload = response.protobuf_payload();
check = equivalent_wire_format == protobuf_payload;
differences = StrCat("Expect: ", ToOctString(equivalent_wire_format),
differences = absl::StrCat("Expect: ", ToOctString(equivalent_wire_format),
", but got: ", ToOctString(protobuf_payload));
} else {
check = differencer.Compare(*reference_message, *test_message);

@ -85,7 +85,7 @@ bool TextFormatConformanceTestSuite::ParseResponse(
case ConformanceResponse::kProtobufPayload: {
if (requested_output != conformance::PROTOBUF) {
ReportFailure(test_name, level, request, response,
StrCat("Test was asked for ",
absl::StrCat("Test was asked for ",
WireFormatToString(requested_output),
" output but provided PROTOBUF instead.")
.c_str());
@ -104,7 +104,7 @@ bool TextFormatConformanceTestSuite::ParseResponse(
case ConformanceResponse::kTextPayload: {
if (requested_output != conformance::TEXT_FORMAT) {
ReportFailure(test_name, level, request, response,
StrCat("Test was asked for ",
absl::StrCat("Test was asked for ",
WireFormatToString(requested_output),
" output but provided TEXT_FORMAT instead.")
.c_str());
@ -141,7 +141,7 @@ void TextFormatConformanceTestSuite::ExpectParseFailure(const string& test_name,
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name =
StrCat(setting.ConformanceLevelToString(level),
absl::StrCat(setting.ConformanceLevelToString(level),
".Proto3.TextFormatInput.", test_name);
RunTest(effective_test_name, request, &response);
@ -263,64 +263,64 @@ void TextFormatConformanceTestSuite::RunSuiteImpl() {
const std::string field_name =
field_type == "String" ? "optional_string" : "optional_bytes";
RunValidTextFormatTest(
StrCat("StringLiteralConcat", field_type), REQUIRED,
StrCat(field_name, ": 'first' \"second\"\n'third'"));
absl::StrCat("StringLiteralConcat", field_type), REQUIRED,
absl::StrCat(field_name, ": 'first' \"second\"\n'third'"));
RunValidTextFormatTest(
StrCat("StringLiteralBasicEscapes", field_type), REQUIRED,
StrCat(field_name, ": '\\a\\b\\f\\n\\r\\t\\v\\?\\\\\\'\\\"'"));
absl::StrCat("StringLiteralBasicEscapes", field_type), REQUIRED,
absl::StrCat(field_name, ": '\\a\\b\\f\\n\\r\\t\\v\\?\\\\\\'\\\"'"));
RunValidTextFormatTest(
StrCat("StringLiteralOctalEscapes", field_type), REQUIRED,
StrCat(field_name, ": '\\341\\210\\264'"));
RunValidTextFormatTest(StrCat("StringLiteralHexEscapes", field_type),
absl::StrCat("StringLiteralOctalEscapes", field_type), REQUIRED,
absl::StrCat(field_name, ": '\\341\\210\\264'"));
RunValidTextFormatTest(absl::StrCat("StringLiteralHexEscapes", field_type),
REQUIRED,
StrCat(field_name, ": '\\xe1\\x88\\xb4'"));
absl::StrCat(field_name, ": '\\xe1\\x88\\xb4'"));
RunValidTextFormatTest(
StrCat("StringLiteralShortUnicodeEscape", field_type),
RECOMMENDED, StrCat(field_name, ": '\\u1234'"));
absl::StrCat("StringLiteralShortUnicodeEscape", field_type),
RECOMMENDED, absl::StrCat(field_name, ": '\\u1234'"));
RunValidTextFormatTest(
StrCat("StringLiteralLongUnicodeEscapes", field_type),
RECOMMENDED, StrCat(field_name, ": '\\U00001234\\U00010437'"));
absl::StrCat("StringLiteralLongUnicodeEscapes", field_type),
RECOMMENDED, absl::StrCat(field_name, ": '\\U00001234\\U00010437'"));
// String literals don't include line feeds.
ExpectParseFailure(StrCat("StringLiteralIncludesLF", field_type),
ExpectParseFailure(absl::StrCat("StringLiteralIncludesLF", field_type),
REQUIRED,
StrCat(field_name, ": 'first line\nsecond line'"));
absl::StrCat(field_name, ": 'first line\nsecond line'"));
// Unicode escapes don't include code points that lie beyond the planes
// (> 0x10ffff).
ExpectParseFailure(
StrCat("StringLiteralLongUnicodeEscapeTooLarge", field_type),
REQUIRED, StrCat(field_name, ": '\\U00110000'"));
absl::StrCat("StringLiteralLongUnicodeEscapeTooLarge", field_type),
REQUIRED, absl::StrCat(field_name, ": '\\U00110000'"));
// Unicode escapes don't include surrogates.
ExpectParseFailure(
StrCat("StringLiteralShortUnicodeEscapeSurrogatePair",
absl::StrCat("StringLiteralShortUnicodeEscapeSurrogatePair",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\ud801\\udc37'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\ud801\\udc37'"));
ExpectParseFailure(
StrCat("StringLiteralShortUnicodeEscapeSurrogateFirstOnly",
absl::StrCat("StringLiteralShortUnicodeEscapeSurrogateFirstOnly",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\ud800'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\ud800'"));
ExpectParseFailure(
StrCat("StringLiteralShortUnicodeEscapeSurrogateSecondOnly",
absl::StrCat("StringLiteralShortUnicodeEscapeSurrogateSecondOnly",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\udc00'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\udc00'"));
ExpectParseFailure(
StrCat("StringLiteralLongUnicodeEscapeSurrogateFirstOnly",
absl::StrCat("StringLiteralLongUnicodeEscapeSurrogateFirstOnly",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\U0000d800'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\U0000d800'"));
ExpectParseFailure(
StrCat("StringLiteralLongUnicodeEscapeSurrogateSecondOnly",
absl::StrCat("StringLiteralLongUnicodeEscapeSurrogateSecondOnly",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\U0000dc00'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\U0000dc00'"));
ExpectParseFailure(
StrCat("StringLiteralLongUnicodeEscapeSurrogatePair", field_type),
RECOMMENDED, StrCat(field_name, ": '\\U0000d801\\U00000dc37'"));
absl::StrCat("StringLiteralLongUnicodeEscapeSurrogatePair", field_type),
RECOMMENDED, absl::StrCat(field_name, ": '\\U0000d801\\U00000dc37'"));
ExpectParseFailure(
StrCat("StringLiteralUnicodeEscapeSurrogatePairLongShort",
absl::StrCat("StringLiteralUnicodeEscapeSurrogatePairLongShort",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\U0000d801\\udc37'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\U0000d801\\udc37'"));
ExpectParseFailure(
StrCat("StringLiteralUnicodeEscapeSurrogatePairShortLong",
absl::StrCat("StringLiteralUnicodeEscapeSurrogatePairShortLong",
field_type),
RECOMMENDED, StrCat(field_name, ": '\\ud801\\U0000dc37'"));
RECOMMENDED, absl::StrCat(field_name, ": '\\ud801\\U0000dc37'"));
// The following method depend on the type of field, as strings have extra
// validation.
@ -330,10 +330,10 @@ void TextFormatConformanceTestSuite::RunSuiteImpl() {
: &TextFormatConformanceTestSuite::RunValidTextFormatTest;
// String fields reject invalid UTF-8 byte sequences; bytes fields don't.
(this->*test_method)(StrCat(field_type, "FieldBadUTF8Octal"),
REQUIRED, StrCat(field_name, ": '\\300'"));
(this->*test_method)(StrCat(field_type, "FieldBadUTF8Hex"), REQUIRED,
StrCat(field_name, ": '\\xc0'"));
(this->*test_method)(absl::StrCat(field_type, "FieldBadUTF8Octal"),
REQUIRED, absl::StrCat(field_name, ": '\\300'"));
(this->*test_method)(absl::StrCat(field_type, "FieldBadUTF8Hex"), REQUIRED,
absl::StrCat(field_name, ": '\\xc0'"));
}
// Group fields

@ -1773,6 +1773,7 @@ public class TextFormatTest {
}
}
@SuppressWarnings("LenientFormatStringValidation")
private void assertLocation(
TextFormatParseInfoTree tree,
final Descriptor descriptor,
@ -1786,6 +1787,7 @@ public class TextFormatTest {
TextFormatParseLocation expected = TextFormatParseLocation.create(line, column);
assertThat(location).isEqualTo(expected);
} else if (line != -1 && column != -1) {
// Expected 0 args, but got 3.
assertWithMessage(
"Tree/descriptor/fieldname did not contain index %d, line %d column %d expected",
index, line, column)

@ -47,8 +47,8 @@
#include <google/protobuf/pyext/message.h>
#include <google/protobuf/pyext/message_factory.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#include "absl/strings/string_view.h"
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/stubs/hash.h>
#define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob) \
@ -1747,7 +1747,8 @@ static PyObject* FindMethodByName(PyBaseDescriptor *self, PyObject* arg) {
}
const MethodDescriptor* method_descriptor =
_GetDescriptor(self)->FindMethodByName(StringParam(name, name_size));
_GetDescriptor(self)->FindMethodByName(
absl::string_view(name, name_size));
if (method_descriptor == nullptr) {
PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name);
return nullptr;

@ -42,9 +42,6 @@ namespace google {
namespace protobuf {
namespace python {
// Should match the type of ConstStringParam.
using StringParam = std::string;
extern PyTypeObject PyMessageDescriptor_Type;
extern PyTypeObject PyFieldDescriptor_Type;
extern PyTypeObject PyEnumDescriptor_Type;

@ -49,14 +49,19 @@
// because the Python API is based on C, and does not play well with C++
// inheritance.
// clang-format off
#define PY_SSIZE_T_CLEAN
// This inclusion must appear before all the others.
#include <Python.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/pyext/descriptor_containers.h>
#include <google/protobuf/pyext/descriptor_pool.h>
// clang-format on
#include <google/protobuf/descriptor.h>
#include <google/protobuf/pyext/descriptor.h>
#include <google/protobuf/pyext/descriptor_pool.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#include "absl/strings/string_view.h"
#define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob) \
@ -75,9 +80,9 @@ struct PyContainer;
typedef int (*CountMethod)(PyContainer* self);
typedef const void* (*GetByIndexMethod)(PyContainer* self, int index);
typedef const void* (*GetByNameMethod)(PyContainer* self,
ConstStringParam name);
absl::string_view name);
typedef const void* (*GetByCamelcaseNameMethod)(PyContainer* self,
ConstStringParam name);
absl::string_view name);
typedef const void* (*GetByNumberMethod)(PyContainer* self, int index);
typedef PyObject* (*NewObjectFromItemMethod)(const void* descriptor);
typedef const std::string& (*GetItemNameMethod)(const void* descriptor);
@ -175,8 +180,8 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) {
}
return false;
}
*item = self->container_def->get_by_name_fn(self,
StringParam(name, name_size));
*item = self->container_def->get_by_name_fn(
self, absl::string_view(name, name_size));
return true;
}
case PyContainer::KIND_BYCAMELCASENAME: {
@ -192,7 +197,7 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) {
return false;
}
*item = self->container_def->get_by_camelcase_name_fn(
self, StringParam(camelcase_name, name_size));
self, absl::string_view(camelcase_name, name_size));
return true;
}
case PyContainer::KIND_BYNUMBER: {
@ -958,12 +963,12 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->field_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindFieldByName(name);
}
static const void* GetByCamelcaseName(PyContainer* self,
ConstStringParam name) {
absl::string_view name) {
return GetDescriptor(self)->FindFieldByCamelcaseName(name);
}
@ -1028,7 +1033,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->nested_type_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindNestedTypeByName(name);
}
@ -1080,7 +1085,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->enum_type_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindEnumTypeByName(name);
}
@ -1143,7 +1148,7 @@ static int Count(PyContainer* self) {
return count;
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindEnumValueByName(name);
}
@ -1194,7 +1199,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->extension_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindExtensionByName(name);
}
@ -1246,7 +1251,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->oneof_decl_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindOneofByName(name);
}
@ -1304,7 +1309,7 @@ static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->value(index);
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindValueByName(name);
}
@ -1408,7 +1413,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->method_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindMethodByName(name);
}
@ -1462,7 +1467,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->message_type_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindMessageTypeByName(name);
}
@ -1502,7 +1507,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->enum_type_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindEnumTypeByName(name);
}
@ -1542,7 +1547,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->extension_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindExtensionByName(name);
}
@ -1582,7 +1587,7 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->service_count();
}
static const void* GetByName(PyContainer* self, ConstStringParam name) {
static const void* GetByName(PyContainer* self, absl::string_view name) {
return GetDescriptor(self)->FindServiceByName(name);
}

@ -42,7 +42,7 @@
#include <google/protobuf/pyext/message.h>
#include <google/protobuf/pyext/message_factory.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#include <google/protobuf/stubs/hash.h>
#include "absl/strings/string_view.h"
#define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob) \
@ -246,7 +246,7 @@ static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
const Descriptor* message_descriptor =
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
StringParam(name, name_size));
absl::string_view(name, name_size));
if (message_descriptor == nullptr) {
return SetErrorFromCollector(
@ -270,7 +270,7 @@ static PyObject* FindFileByName(PyObject* self, PyObject* arg) {
PyDescriptorPool* py_pool = reinterpret_cast<PyDescriptorPool*>(self);
const FileDescriptor* file_descriptor =
py_pool->pool->FindFileByName(StringParam(name, name_size));
py_pool->pool->FindFileByName(absl::string_view(name, name_size));
if (file_descriptor == nullptr) {
return SetErrorFromCollector(py_pool->error_collector, name, "file");
@ -286,7 +286,7 @@ PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) {
}
const FieldDescriptor* field_descriptor =
self->pool->FindFieldByName(StringParam(name, name_size));
self->pool->FindFieldByName(absl::string_view(name, name_size));
if (field_descriptor == nullptr) {
return SetErrorFromCollector(self->error_collector, name, "field");
}
@ -307,7 +307,7 @@ PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) {
}
const FieldDescriptor* field_descriptor =
self->pool->FindExtensionByName(StringParam(name, name_size));
self->pool->FindExtensionByName(absl::string_view(name, name_size));
if (field_descriptor == nullptr) {
return SetErrorFromCollector(self->error_collector, name,
"extension field");
@ -329,7 +329,7 @@ PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) {
}
const EnumDescriptor* enum_descriptor =
self->pool->FindEnumTypeByName(StringParam(name, name_size));
self->pool->FindEnumTypeByName(absl::string_view(name, name_size));
if (enum_descriptor == nullptr) {
return SetErrorFromCollector(self->error_collector, name, "enum");
}
@ -350,7 +350,7 @@ PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) {
}
const OneofDescriptor* oneof_descriptor =
self->pool->FindOneofByName(StringParam(name, name_size));
self->pool->FindOneofByName(absl::string_view(name, name_size));
if (oneof_descriptor == nullptr) {
return SetErrorFromCollector(self->error_collector, name, "oneof");
}
@ -372,7 +372,7 @@ static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
const ServiceDescriptor* service_descriptor =
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
StringParam(name, name_size));
absl::string_view(name, name_size));
if (service_descriptor == nullptr) {
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
@ -392,7 +392,7 @@ static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
const MethodDescriptor* method_descriptor =
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMethodByName(
StringParam(name, name_size));
absl::string_view(name, name_size));
if (method_descriptor == nullptr) {
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
@ -412,7 +412,7 @@ static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
const FileDescriptor* file_descriptor =
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileContainingSymbol(
StringParam(name, name_size));
absl::string_view(name, name_size));
if (file_descriptor == nullptr) {
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,

@ -48,6 +48,7 @@
#include <google/protobuf/pyext/repeated_composite_container.h>
#include <google/protobuf/pyext/repeated_scalar_container.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#include "absl/strings/string_view.h"
#define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob) \
@ -239,11 +240,11 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) {
PyDescriptorPool* pool = cmessage::GetFactoryForMessage(self->parent)->pool;
const FieldDescriptor* message_extension =
pool->pool->FindExtensionByName(StringParam(name, name_size));
pool->pool->FindExtensionByName(absl::string_view(name, name_size));
if (message_extension == nullptr) {
// Is is the name of a message set extension?
const Descriptor* message_descriptor =
pool->pool->FindMessageTypeByName(StringParam(name, name_size));
pool->pool->FindMessageTypeByName(absl::string_view(name, name_size));
if (message_descriptor && message_descriptor->extension_count() > 0) {
const FieldDescriptor* extension = message_descriptor->extension(0);
if (extension->is_extension() &&

@ -69,6 +69,7 @@
#include <google/protobuf/pyext/unknown_field_set.h>
#include <google/protobuf/pyext/unknown_fields.h>
#include <google/protobuf/util/message_differencer.h>
#include "absl/strings/string_view.h"
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/strtod.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
@ -408,7 +409,7 @@ static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
Py_ssize_t attr_size;
static const char kSuffix[] = "_FIELD_NUMBER";
if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
HasSuffixString(StringPiece(attr, attr_size), kSuffix)) {
HasSuffixString(absl::string_view(attr, attr_size), kSuffix)) {
std::string field_name(attr, attr_size - sizeof(kSuffix) + 1);
LowerString(&field_name);
@ -913,7 +914,7 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor,
return nullptr;
}
const EnumValueDescriptor* enum_value_descriptor =
enum_descriptor->FindValueByName(StringParam(enum_label, size));
enum_descriptor->FindValueByName(absl::string_view(enum_label, size));
if (enum_value_descriptor == nullptr) {
PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label);
return nullptr;
@ -1340,7 +1341,7 @@ int HasFieldByDescriptor(CMessage* self,
}
const FieldDescriptor* FindFieldWithOneofs(const Message* message,
ConstStringParam field_name,
absl::string_view field_name,
bool* in_oneof) {
*in_oneof = false;
const Descriptor* descriptor = message->GetDescriptor();
@ -1389,8 +1390,8 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
Message* message = self->message;
bool is_in_oneof;
const FieldDescriptor* field_descriptor =
FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof);
const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
message, absl::string_view(field_name, size), &is_in_oneof);
if (field_descriptor == nullptr) {
if (!is_in_oneof) {
PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.",
@ -1574,7 +1575,7 @@ PyObject* ClearField(CMessage* self, PyObject* arg) {
AssureWritable(self);
bool is_in_oneof;
const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
self->message, StringParam(field_name, field_size), &is_in_oneof);
self->message, absl::string_view(field_name, field_size), &is_in_oneof);
if (field_descriptor == nullptr) {
if (is_in_oneof) {
// We gave the name of a oneof, and none of its fields are set.
@ -1884,7 +1885,7 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) {
const char* ptr;
internal::ParseContext ctx(
depth, false, &ptr,
StringPiece(static_cast<const char*>(data.buf), data.len));
absl::string_view(static_cast<const char*>(data.buf), data.len));
PyBuffer_Release(&data);
ctx.data().pool = factory->pool->pool;
ctx.data().factory = factory->message_factory;
@ -1976,7 +1977,7 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
if (PyString_AsStringAndSize(arg, &name_data, &name_size) < 0) return nullptr;
const OneofDescriptor* oneof_desc =
self->message->GetDescriptor()->FindOneofByName(
StringParam(name_data, name_size));
absl::string_view(name_data, name_size));
if (oneof_desc == nullptr) {
PyErr_Format(PyExc_ValueError,
"Protocol message has no oneof \"%s\" field.", name_data);

@ -297,8 +297,8 @@ if __name__ == '__main__':
extra_objects = ['../bazel-bin/src/google/protobuf/libprotobuf.a']
else:
extra_objects = ['../libprotobuf.a']
extra_objects += ['../third_party/abseil-cpp/absl/synchronization/libabsl_synchronization.a']
# Include all of these twice to eliminate order-dependence.
# Repeat all of these enough times to eliminate order-dependence.
extra_objects += list(glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
else:

@ -62,14 +62,10 @@ set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/substitute.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.cc
@ -166,27 +162,19 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/casts.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/hash.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/map_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mathutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/once.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stl_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/substitute.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/template_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time.h
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.h
@ -246,13 +234,9 @@ set(libprotobuf_lite_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.cc
)
@ -291,26 +275,18 @@ set(libprotobuf_lite_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/casts.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/hash.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/map_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mathutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/once.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_macros.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stl_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/template_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time.h
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h
)
@ -872,12 +848,7 @@ set(stubs_test_files
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_test.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor_test.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/template_util_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time_test.cc
)

@ -198,7 +198,9 @@ cc_library(
":arena",
"//src/google/protobuf/io",
"//src/google/protobuf/stubs:lite",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)
@ -281,7 +283,13 @@ cc_library(
"//src/google/protobuf/io:printer",
"//src/google/protobuf/io:tokenizer",
"//src/google/protobuf/stubs",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:dynamic_annotations",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)

@ -47,7 +47,7 @@ bool AnyMetadata::PackFrom(Arena* arena, const Message& message) {
}
bool AnyMetadata::PackFrom(Arena* arena, const Message& message,
StringPiece type_url_prefix) {
absl::string_view type_url_prefix) {
type_url_->Set(
GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix), arena);
return message.SerializeToString(value_->Mutable(arena));

@ -52,8 +52,8 @@ extern const char kAnyFullTypeName[]; // "google.protobuf.Any".
extern const char kTypeGoogleApisComPrefix[]; // "type.googleapis.com/".
extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/".
std::string GetTypeUrl(StringPiece message_name,
StringPiece type_url_prefix);
std::string GetTypeUrl(absl::string_view message_name,
absl::string_view type_url_prefix);
// Helper class used to implement google::protobuf::Any.
class PROTOBUF_EXPORT AnyMetadata {
@ -84,13 +84,13 @@ class PROTOBUF_EXPORT AnyMetadata {
// Returns false if serializing the message failed.
template <typename T>
bool PackFrom(Arena* arena, const T& message,
StringPiece type_url_prefix) {
absl::string_view type_url_prefix) {
return InternalPackFrom(arena, message, type_url_prefix,
T::FullMessageName());
}
bool PackFrom(Arena* arena, const Message& message,
StringPiece type_url_prefix);
absl::string_view type_url_prefix);
// Unpacks the payload into the given message. Returns false if the message's
// type doesn't match the type specified in the type URL (i.e., the full
@ -113,11 +113,11 @@ class PROTOBUF_EXPORT AnyMetadata {
private:
bool InternalPackFrom(Arena* arena, const MessageLite& message,
StringPiece type_url_prefix,
StringPiece type_name);
bool InternalUnpackTo(StringPiece type_name,
absl::string_view type_url_prefix,
absl::string_view type_name);
bool InternalUnpackTo(absl::string_view type_name,
MessageLite* message) const;
bool InternalIs(StringPiece type_name) const;
bool InternalIs(absl::string_view type_name) const;
UrlType* type_url_;
ValueType* value_;
@ -132,14 +132,14 @@ class PROTOBUF_EXPORT AnyMetadata {
//
// NOTE: this function is available publicly as a static method on the
// generated message type: google::protobuf::Any::ParseAnyTypeUrl()
bool ParseAnyTypeUrl(StringPiece type_url, std::string* full_type_name);
bool ParseAnyTypeUrl(absl::string_view type_url, std::string* full_type_name);
// Get the proto type name and prefix from Any::type_url value. For example,
// passing "type.googleapis.com/rpc.QueryOrigin" will return
// "type.googleapis.com/" in *url_prefix and "rpc.QueryOrigin" in
// *full_type_name. Returns false if the type_url does not have a "/" in the
// type url separating the full type name.
bool ParseAnyTypeUrl(StringPiece type_url, std::string* url_prefix,
bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix,
std::string* full_type_name);
// See if message is of type google.protobuf.Any, if so, return the descriptors

@ -73,7 +73,7 @@ const char descriptor_table_protodef_google_2fprotobuf_2fany_2eproto[] PROTOBUF_
"anypb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownT"
"ypesb\006proto3"
;
static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once;
static ::absl::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once;
const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = {
false, false, 212, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto,
"google/protobuf/any.proto",
@ -100,7 +100,7 @@ bool Any::GetAnyFieldDescriptors(
message, type_url_field, value_field);
}
bool Any::ParseAnyTypeUrl(
::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url,
::absl::string_view type_url,
std::string* full_type_name) {
return ::_pbi::ParseAnyTypeUrl(type_url, full_type_name);
}

@ -113,7 +113,7 @@ class PROTOBUF_EXPORT Any final :
return _impl_._any_metadata_.PackFrom(GetArena(), message);
}
bool PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message,
::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) {
::absl::string_view type_url_prefix) {
GOOGLE_DCHECK_NE(&message, this);
return _impl_._any_metadata_.PackFrom(GetArena(), message, type_url_prefix);
}
@ -130,7 +130,7 @@ class PROTOBUF_EXPORT Any final :
}
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
bool PackFrom(const T& message,
::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) {
::absl::string_view type_url_prefix) {
return _impl_._any_metadata_.PackFrom<T>(GetArena(), message, type_url_prefix);}
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
bool UnpackTo(T* message) const {
@ -139,7 +139,7 @@ class PROTOBUF_EXPORT Any final :
template<typename T> bool Is() const {
return _impl_._any_metadata_.Is<T>();
}
static bool ParseAnyTypeUrl(::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url,
static bool ParseAnyTypeUrl(::absl::string_view type_url,
std::string* full_type_name);
friend void swap(Any& a, Any& b) {
a.Swap(&b);
@ -194,7 +194,7 @@ class PROTOBUF_EXPORT Any final :
private:
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
static ::absl::string_view FullMessageName() {
return "google.protobuf.Any";
}
protected:

@ -30,6 +30,7 @@
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/any.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
@ -38,13 +39,13 @@ namespace google {
namespace protobuf {
namespace internal {
std::string GetTypeUrl(StringPiece message_name,
StringPiece type_url_prefix) {
std::string GetTypeUrl(absl::string_view message_name,
absl::string_view type_url_prefix) {
if (!type_url_prefix.empty() &&
type_url_prefix[type_url_prefix.size() - 1] == '/') {
return StrCat(type_url_prefix, message_name);
return absl::StrCat(type_url_prefix, message_name);
} else {
return StrCat(type_url_prefix, "/", message_name);
return absl::StrCat(type_url_prefix, "/", message_name);
}
}
@ -53,13 +54,13 @@ const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/";
const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";
bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message,
StringPiece type_url_prefix,
StringPiece type_name) {
absl::string_view type_url_prefix,
absl::string_view type_name) {
type_url_->Set(GetTypeUrl(type_name, type_url_prefix), arena);
return message.SerializeToString(value_->Mutable(arena));
}
bool AnyMetadata::InternalUnpackTo(StringPiece type_name,
bool AnyMetadata::InternalUnpackTo(absl::string_view type_name,
MessageLite* message) const {
if (!InternalIs(type_name)) {
return false;
@ -67,14 +68,14 @@ bool AnyMetadata::InternalUnpackTo(StringPiece type_name,
return message->ParseFromString(value_->Get());
}
bool AnyMetadata::InternalIs(StringPiece type_name) const {
StringPiece type_url = type_url_->Get();
bool AnyMetadata::InternalIs(absl::string_view type_name) const {
absl::string_view type_url = type_url_->Get();
return type_url.size() >= type_name.size() + 1 &&
type_url[type_url.size() - type_name.size() - 1] == '/' &&
HasSuffixString(type_url, type_name);
}
bool ParseAnyTypeUrl(StringPiece type_url, std::string* url_prefix,
bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix,
std::string* full_type_name) {
size_t pos = type_url.find_last_of('/');
if (pos == std::string::npos || pos + 1 == type_url.size()) {
@ -87,7 +88,7 @@ bool ParseAnyTypeUrl(StringPiece type_url, std::string* url_prefix,
return true;
}
bool ParseAnyTypeUrl(StringPiece type_url, std::string* full_type_name) {
bool ParseAnyTypeUrl(absl::string_view type_url, std::string* full_type_name) {
return ParseAnyTypeUrl(type_url, nullptr, full_type_name);
}

@ -31,6 +31,7 @@
#include <google/protobuf/any_test.pb.h>
#include <google/protobuf/unittest.pb.h>
#include <gtest/gtest.h>
#include "absl/strings/str_cat.h"
// Must be included last.

@ -157,7 +157,7 @@ static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2
&::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto,
&::descriptor_table_google_2fprotobuf_2ftype_2eproto,
};
static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once;
static ::absl::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once;
const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = {
false, false, 751, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto,
"google/protobuf/api.proto",

@ -169,7 +169,7 @@ class PROTOBUF_EXPORT Api final :
private:
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
static ::absl::string_view FullMessageName() {
return "google.protobuf.Api";
}
protected:
@ -429,7 +429,7 @@ class PROTOBUF_EXPORT Method final :
private:
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
static ::absl::string_view FullMessageName() {
return "google.protobuf.Method";
}
protected:
@ -667,7 +667,7 @@ class PROTOBUF_EXPORT Mixin final :
private:
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
static ::absl::string_view FullMessageName() {
return "google.protobuf.Mixin";
}
protected:

@ -105,13 +105,11 @@ class GetDeallocator {
size_t* space_allocated_;
};
SerialArena::SerialArena(Block* b, void* owner, ThreadSafeArenaStats* stats)
: space_allocated_(b->size()) {
SerialArena::SerialArena(Block* b, void* owner) : space_allocated_(b->size()) {
owner_ = owner;
set_head(b);
set_ptr(b->Pointer(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize));
limit_ = b->Pointer(b->size() & static_cast<size_t>(-8));
arena_stats_ = stats;
}
SerialArena* SerialArena::New(Memory mem, void* owner,
@ -120,7 +118,7 @@ SerialArena* SerialArena::New(Memory mem, void* owner,
ThreadSafeArenaStats::RecordAllocateStats(
stats, /*used=*/0, /*allocated=*/mem.size, /*wasted=*/0);
auto b = new (mem.ptr) Block{nullptr, mem.size};
return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, owner, stats);
return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, owner);
}
template <typename Deallocator>
@ -137,29 +135,32 @@ SerialArena::Memory SerialArena::Free(Deallocator deallocator) {
PROTOBUF_NOINLINE
void* SerialArena::AllocateAlignedFallback(size_t n,
const AllocationPolicy* policy) {
AllocateNewBlock(n, policy);
const AllocationPolicy* policy,
ThreadSafeArenaStats* stats) {
AllocateNewBlock(n, policy, stats);
return AllocateFromExisting(n);
}
PROTOBUF_NOINLINE
void* SerialArena::AllocateAlignedWithCleanupFallback(
size_t n, size_t align, void (*destructor)(void*),
const AllocationPolicy* policy) {
const AllocationPolicy* policy, ThreadSafeArenaStats* stats) {
size_t required = AlignUpTo(n, align) + cleanup::Size(destructor);
AllocateNewBlock(required, policy);
AllocateNewBlock(required, policy, stats);
return AllocateFromExistingWithCleanupFallback(n, align, destructor);
}
PROTOBUF_NOINLINE
void SerialArena::AddCleanupFallback(void* elem, void (*destructor)(void*),
const AllocationPolicy* policy) {
const AllocationPolicy* policy,
ThreadSafeArenaStats* stats) {
size_t required = cleanup::Size(destructor);
AllocateNewBlock(required, policy);
AllocateNewBlock(required, policy, stats);
AddCleanupFromExisting(elem, destructor);
}
void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy) {
void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy,
ThreadSafeArenaStats* stats) {
// Sync limit to block
head()->cleanup_nodes = limit_;
@ -181,7 +182,7 @@ void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy) {
space_allocated_.store(
space_allocated_.load(std::memory_order_relaxed) + mem.size,
std::memory_order_relaxed);
ThreadSafeArenaStats::RecordAllocateStats(arena_stats_, /*used=*/used,
ThreadSafeArenaStats::RecordAllocateStats(stats, /*used=*/used,
/*allocated=*/mem.size, wasted);
set_head(new (mem.ptr) Block{head(), mem.size});
set_ptr(head()->Pointer(kBlockHeaderSize));
@ -317,12 +318,6 @@ void ThreadSafeArena::InitializeWithPolicy(void* mem, size_t size,
// first block.
constexpr size_t kAPSize = internal::AlignUpTo8(sizeof(AllocationPolicy));
constexpr size_t kMinimumSize = kBlockHeaderSize + kSerialArenaSize + kAPSize;
// The value for alloc_policy_ stores whether or not allocations should be
// recorded.
alloc_policy_.set_should_record_allocs(
policy.metrics_collector != nullptr &&
policy.metrics_collector->RecordAllocs());
// Make sure we have an initial block to store the AllocationPolicy.
if (mem != nullptr && size >= kMinimumSize) {
alloc_policy_.set_is_user_owned_initial_block(true);
@ -395,11 +390,6 @@ ThreadSafeArena::~ThreadSafeArena() {
size_t space_allocated = 0;
auto mem = Free(&space_allocated);
// Policy is about to get deleted.
auto* p = alloc_policy_.get();
ArenaMetricsCollector* collector = p ? p->metrics_collector : nullptr;
if (alloc_policy_.is_user_owned_initial_block()) {
#ifdef ADDRESS_SANITIZER
// Unpoison the initial block, now that it's going back to the user.
@ -409,8 +399,6 @@ ThreadSafeArena::~ThreadSafeArena() {
} else {
GetDeallocator(alloc_policy_.get(), &space_allocated)(mem);
}
if (collector) collector->OnDestroy(space_allocated);
}
SerialArena::Memory ThreadSafeArena::Free(size_t* space_allocated) {
@ -442,11 +430,8 @@ uint64_t ThreadSafeArena::Reset() {
mem.ptr = nullptr;
mem.size = 0;
}
ArenaMetricsCollector* collector = saved_policy.metrics_collector;
if (collector) collector->OnReset(space_allocated);
InitializeWithPolicy(mem.ptr, mem.size, saved_policy);
} else {
GOOGLE_DCHECK(!alloc_policy_.should_record_allocs());
// Nullptr policy
if (alloc_policy_.is_user_owned_initial_block()) {
space_allocated += mem.size;
@ -461,15 +446,13 @@ uint64_t ThreadSafeArena::Reset() {
}
void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*),
const std::type_info* type) {
void (*destructor)(void*)) {
SerialArena* arena;
if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() &&
GetSerialArenaFast(&arena))) {
return arena->AllocateAlignedWithCleanup(n, align, destructor,
alloc_policy_.get());
if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) {
return arena->AllocateAlignedWithCleanup(
n, align, destructor, alloc_policy_.get(), arena_stats_.MutableStats());
} else {
return AllocateAlignedWithCleanupFallback(n, align, destructor, type);
return AllocateAlignedWithCleanupFallback(n, align, destructor);
}
}
@ -478,37 +461,15 @@ void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) {
if (PROTOBUF_PREDICT_FALSE(!GetSerialArenaFast(&arena))) {
arena = GetSerialArenaFallback(&thread_cache());
}
arena->AddCleanup(elem, cleanup, AllocPolicy());
}
PROTOBUF_NOINLINE
void* ThreadSafeArena::AllocateAlignedFallback(size_t n,
const std::type_info* type) {
if (alloc_policy_.should_record_allocs()) {
alloc_policy_.RecordAlloc(type, n);
SerialArena* arena;
if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) {
return arena->AllocateAligned(n, alloc_policy_.get());
}
}
return GetSerialArenaFallback(&thread_cache())
->AllocateAligned(n, alloc_policy_.get());
arena->AddCleanup(elem, cleanup, AllocPolicy(), arena_stats_.MutableStats());
}
PROTOBUF_NOINLINE
void* ThreadSafeArena::AllocateAlignedWithCleanupFallback(
size_t n, size_t align, void (*destructor)(void*),
const std::type_info* type) {
if (alloc_policy_.should_record_allocs()) {
alloc_policy_.RecordAlloc(type, internal::AlignUpTo(n, align));
SerialArena* arena;
if (GetSerialArenaFast(&arena)) {
return arena->AllocateAlignedWithCleanup(n, align, destructor,
alloc_policy_.get());
}
}
size_t n, size_t align, void (*destructor)(void*)) {
return GetSerialArenaFallback(&thread_cache())
->AllocateAlignedWithCleanup(n, align, destructor, alloc_policy_.get());
->AllocateAlignedWithCleanup(n, align, destructor, alloc_policy_.get(),
arena_stats_.MutableStats());
}
uint64_t ThreadSafeArena::SpaceAllocated() const {
@ -563,27 +524,15 @@ SerialArena* ThreadSafeArena::GetSerialArenaFallback(void* me) {
} // namespace internal
PROTOBUF_FUNC_ALIGN(32)
void* Arena::AllocateAlignedNoHook(size_t n) {
return impl_.AllocateAligned(n, nullptr);
}
PROTOBUF_FUNC_ALIGN(32)
void* Arena::AllocateAlignedWithHook(size_t n, const std::type_info* type) {
return impl_.AllocateAligned(n, type);
}
void* Arena::Allocate(size_t n) { return impl_.AllocateAligned(n); }
PROTOBUF_FUNC_ALIGN(32)
void* Arena::AllocateAlignedWithHookForArray(size_t n,
const std::type_info* type) {
return impl_.AllocateAligned<internal::AllocationClient::kArray>(n, type);
void* Arena::AllocateForArray(size_t n) {
return impl_.AllocateAligned<internal::AllocationClient::kArray>(n);
}
PROTOBUF_FUNC_ALIGN(32)
void* Arena::AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*),
const std::type_info* type) {
return impl_.AllocateAlignedWithCleanup(n, align, destructor, type);
void (*destructor)(void*)) {
return impl_.AllocateAlignedWithCleanup(n, align, destructor);
}
} // namespace protobuf

@ -165,7 +165,6 @@ struct ArenaOptions {
res.max_block_size = max_block_size;
res.block_alloc = block_alloc;
res.block_dealloc = block_dealloc;
res.metrics_collector = MetricsCollector();
return res;
}
@ -175,14 +174,6 @@ struct ArenaOptions {
friend class ArenaOptionsTestFriend;
};
// Support for non-RTTI environments. (The metrics hooks API uses type
// information.)
#if PROTOBUF_RTTI
#define RTTI_TYPE_ID(type) (&typeid(type))
#else
#define RTTI_TYPE_ID(type) (nullptr)
#endif
// Arena allocator. Arena allocation replaces ordinary (heap-based) allocation
// with new/delete, and improves performance by aggregating allocations into
// larger blocks and freeing allocations all at once. Protocol messages are
@ -316,14 +307,14 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// Allocates memory with the specific size and alignment.
void* AllocateAligned(size_t size, size_t align = 8) {
if (align <= 8) {
return AllocateAlignedNoHook(internal::AlignUpTo8(size));
return Allocate(internal::AlignUpTo8(size));
} else {
// We are wasting space by over allocating align - 8 bytes. Compared
// to a dedicated function that takes current alignment in consideration.
// Such a scheme would only waste (align - 8)/2 bytes on average, but
// requires a dedicated function in the outline arena allocation
// functions. Possibly re-evaluate tradeoffs later.
return internal::AlignTo(AllocateAlignedNoHook(size + align - 8), align);
return internal::AlignTo(Allocate(size + align - 8), align);
}
}
@ -438,7 +429,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template <typename U>
static Arena* GetOwningArena(Rank1, const U* p) {
(void) p;
return nullptr;
}
@ -469,7 +459,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template <typename U>
static Arena* GetArenaForAllocation(Rank2, const U* p) {
(void) p;
return nullptr;
}
@ -594,16 +583,13 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
}
}
// Allocate and also optionally call collector with the allocated type info
// when allocation recording is enabled.
PROTOBUF_NDEBUG_INLINE void* AllocateInternal(size_t size, size_t align,
void (*destructor)(void*),
const std::type_info* type) {
void (*destructor)(void*)) {
// Monitor allocation if needed.
if (destructor == nullptr) {
return AllocateAlignedWithHook(size, align, type);
return AllocateAligned(size, align);
} else {
return AllocateAlignedWithCleanup(size, align, destructor, type);
return AllocateAlignedWithCleanup(size, align, destructor);
}
}
@ -642,8 +628,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// We count on compiler to realize that if sizeof(T) is a multiple of
// 8 AlignUpTo can be elided.
const size_t n = sizeof(T) * num_elements;
return static_cast<T*>(
AllocateAlignedWithHookForArray(n, alignof(T), RTTI_TYPE_ID(T)));
return static_cast<T*>(AllocateAlignedForArray(n, alignof(T)));
}
template <typename T, typename... Args>
@ -652,8 +637,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
AllocateInternal(sizeof(T), alignof(T),
internal::ObjectDestructor<
InternalHelper<T>::is_destructor_skippable::value,
T>::destructor,
RTTI_TYPE_ID(T)),
T>::destructor),
this, std::forward<Args>(args)...);
}
@ -704,9 +688,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
internal::ObjectDestructor<std::is_trivially_destructible<T>::value,
T>::destructor;
T* result =
new (arena->AllocateInternal(sizeof(T), alignof(T), destructor,
RTTI_TYPE_ID(T)))
T(std::forward<Args>(args)...);
new (arena->AllocateInternal(sizeof(T), alignof(T), destructor))
T(std::forward<Args>(args)...);
return result;
}
}
@ -719,8 +702,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
auto destructor =
internal::ObjectDestructor<std::is_trivially_destructible<T>::value,
T>::destructor;
return new (arena->AllocateInternal(sizeof(T), alignof(T), destructor,
RTTI_TYPE_ID(T)))
return new (arena->AllocateInternal(sizeof(T), alignof(T), destructor))
T(std::forward<Args>(args)...);
}
}
@ -751,42 +733,23 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
return InternalHelper<T>::GetArena(value);
}
void* AllocateAlignedWithHookForArray(size_t n, size_t align,
const std::type_info* type) {
void* AllocateAlignedForArray(size_t n, size_t align) {
if (align <= 8) {
return AllocateAlignedWithHookForArray(internal::AlignUpTo8(n), type);
return AllocateForArray(internal::AlignUpTo8(n));
} else {
// We are wasting space by over allocating align - 8 bytes. Compared
// to a dedicated function that takes current alignment in consideration.
// Such a scheme would only waste (align - 8)/2 bytes on average, but
// requires a dedicated function in the outline arena allocation
// functions. Possibly re-evaluate tradeoffs later.
return internal::AlignTo(
AllocateAlignedWithHookForArray(n + align - 8, type), align);
return internal::AlignTo(AllocateForArray(n + align - 8), align);
}
}
void* AllocateAlignedWithHook(size_t n, size_t align,
const std::type_info* type) {
if (align <= 8) {
return AllocateAlignedWithHook(internal::AlignUpTo8(n), type);
} else {
// We are wasting space by over allocating align - 8 bytes. Compared
// to a dedicated function that takes current alignment in consideration.
// Such a scheme would only waste (align - 8)/2 bytes on average, but
// requires a dedicated function in the outline arena allocation
// functions. Possibly re-evaluate tradeoffs later.
return internal::AlignTo(AllocateAlignedWithHook(n + align - 8, type),
align);
}
}
void* AllocateAlignedNoHook(size_t n);
void* AllocateAlignedWithHook(size_t n, const std::type_info* type);
void* AllocateAlignedWithHookForArray(size_t n, const std::type_info* type);
void* Allocate(size_t n);
void* AllocateForArray(size_t n);
void* AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*),
const std::type_info* type);
void (*destructor)(void*));
template <typename Type>
friend class internal::GenericTypeHandler;
@ -802,9 +765,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
friend struct internal::ArenaTestPeer;
};
// Defined above for supporting environments without RTTI.
#undef RTTI_TYPE_ID
} // namespace protobuf
} // namespace google

@ -249,12 +249,11 @@ struct AllocationPolicy {
size_t max_block_size = kDefaultMaxBlockSize;
void* (*block_alloc)(size_t) = nullptr;
void (*block_dealloc)(void*, size_t) = nullptr;
ArenaMetricsCollector* metrics_collector = nullptr;
bool IsDefault() const {
return start_block_size == kDefaultStartBlockSize &&
max_block_size == kDefaultMaxBlockSize && block_alloc == nullptr &&
block_dealloc == nullptr && metrics_collector == nullptr;
block_dealloc == nullptr;
}
};
@ -291,22 +290,11 @@ class TaggedAllocationPolicyPtr {
set_mask<kUserOwnedInitialBlock>(v);
}
bool should_record_allocs() const {
return static_cast<bool>(get_mask<kRecordAllocs>());
}
void set_should_record_allocs(bool v) { set_mask<kRecordAllocs>(v); }
uintptr_t get_raw() const { return policy_; }
inline void RecordAlloc(const std::type_info* allocated_type,
size_t n) const {
get()->metrics_collector->OnAlloc(allocated_type, n);
}
private:
enum : uintptr_t {
kUserOwnedInitialBlock = 1,
kRecordAllocs = 2,
};
static constexpr uintptr_t kTagsMask = 7;
@ -384,7 +372,8 @@ class PROTOBUF_EXPORT SerialArena {
// the right size. We can statically know if the allocation size can benefit
// from it.
template <AllocationClient alloc_client = AllocationClient::kDefault>
void* AllocateAligned(size_t n, const AllocationPolicy* policy) {
void* AllocateAligned(size_t n, const AllocationPolicy* policy,
ThreadSafeArenaStats* stats) {
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned.
GOOGLE_DCHECK_GE(limit_, ptr());
@ -395,7 +384,7 @@ class PROTOBUF_EXPORT SerialArena {
}
if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) {
return AllocateAlignedFallback(n, policy);
return AllocateAlignedFallback(n, policy, stats);
}
return AllocateFromExisting(n);
}
@ -476,20 +465,22 @@ class PROTOBUF_EXPORT SerialArena {
PROTOBUF_ALWAYS_INLINE
void* AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*),
const AllocationPolicy* policy) {
const AllocationPolicy* policy,
ThreadSafeArenaStats* stats) {
size_t required = AlignUpTo(n, align) + cleanup::Size(destructor);
if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) {
return AllocateAlignedWithCleanupFallback(n, align, destructor, policy);
return AllocateAlignedWithCleanupFallback(n, align, destructor, policy,
stats);
}
return AllocateFromExistingWithCleanupFallback(n, align, destructor);
}
PROTOBUF_ALWAYS_INLINE
void AddCleanup(void* elem, void (*destructor)(void*),
const AllocationPolicy* policy) {
const AllocationPolicy* policy, ThreadSafeArenaStats* stats) {
size_t required = cleanup::Size(destructor);
if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) {
return AddCleanupFallback(elem, destructor, policy);
return AddCleanupFallback(elem, destructor, policy, stats);
}
AddCleanupFromExisting(elem, destructor);
}
@ -582,9 +573,6 @@ class PROTOBUF_EXPORT SerialArena {
// Limiting address up to which memory can be allocated from the head block.
char* limit_;
// For holding sampling information. The pointer is owned by the
// ThreadSafeArena that holds this serial arena.
ThreadSafeArenaStats* arena_stats_;
// Repeated*Field and Arena play together to reduce memory consumption by
// reusing blocks. Currently, natural growth of the repeated field types makes
@ -601,14 +589,18 @@ class PROTOBUF_EXPORT SerialArena {
CachedBlock** cached_blocks_ = nullptr;
// Constructor is private as only New() should be used.
inline SerialArena(Block* b, void* owner, ThreadSafeArenaStats* stats);
void* AllocateAlignedFallback(size_t n, const AllocationPolicy* policy);
inline SerialArena(Block* b, void* owner);
void* AllocateAlignedFallback(size_t n, const AllocationPolicy* policy,
ThreadSafeArenaStats* stats);
void* AllocateAlignedWithCleanupFallback(size_t n, size_t align,
void (*destructor)(void*),
const AllocationPolicy* policy);
const AllocationPolicy* policy,
ThreadSafeArenaStats* stats);
void AddCleanupFallback(void* elem, void (*destructor)(void*),
const AllocationPolicy* policy);
void AllocateNewBlock(size_t n, const AllocationPolicy* policy);
const AllocationPolicy* policy,
ThreadSafeArenaStats* stats);
void AllocateNewBlock(size_t n, const AllocationPolicy* policy,
ThreadSafeArenaStats* stats);
public:
static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(Block));
@ -662,13 +654,14 @@ class PROTOBUF_EXPORT ThreadSafeArena {
uint64_t SpaceUsed() const;
template <AllocationClient alloc_client = AllocationClient::kDefault>
void* AllocateAligned(size_t n, const std::type_info* type) {
void* AllocateAligned(size_t n) {
SerialArena* arena;
if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() &&
GetSerialArenaFast(&arena))) {
return arena->AllocateAligned<alloc_client>(n, AllocPolicy());
if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) {
return arena->AllocateAligned<alloc_client>(n, AllocPolicy(),
arena_stats_.MutableStats());
} else {
return AllocateAlignedFallback(n, type);
return GetSerialArenaFallback(&thread_cache())
->AllocateAligned(n, AllocPolicy(), arena_stats_.MutableStats());
}
}
@ -686,16 +679,14 @@ class PROTOBUF_EXPORT ThreadSafeArena {
// code for the happy path.
PROTOBUF_NDEBUG_INLINE bool MaybeAllocateAligned(size_t n, void** out) {
SerialArena* arena;
if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() &&
GetSerialArenaFast(&arena))) {
if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) {
return arena->MaybeAllocateAligned(n, out);
}
return false;
}
void* AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*),
const std::type_info* type);
void (*destructor)(void*));
// Add object pointer and cleanup function pointer to the list.
void AddCleanup(void* elem, void (*cleanup)(void*));
@ -723,10 +714,8 @@ class PROTOBUF_EXPORT ThreadSafeArena {
const AllocationPolicy* AllocPolicy() const { return alloc_policy_.get(); }
void InitializeFrom(void* mem, size_t size);
void InitializeWithPolicy(void* mem, size_t size, AllocationPolicy policy);
void* AllocateAlignedFallback(size_t n, const std::type_info* type);
void* AllocateAlignedWithCleanupFallback(size_t n, size_t align,
void (*destructor)(void*),
const std::type_info* type);
void (*destructor)(void*));
void Init();
void SetInitialBlock(void* mem, size_t size);

@ -45,7 +45,7 @@
#include <google/protobuf/unittest_arena.pb.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/string_view.h"
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/extension_set.h>

@ -35,7 +35,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include <google/protobuf/message_lite.h>
#include <google/protobuf/parse_context.h>
@ -98,7 +98,7 @@ class ScopedCheckPtrInvariants {
#endif // NDEBUG || !GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL
// Creates a heap allocated std::string value.
inline TaggedStringPtr CreateString(ConstStringParam value) {
inline TaggedStringPtr CreateString(absl::string_view value) {
TaggedStringPtr res;
res.SetAllocated(new std::string(value.data(), value.length()));
return res;
@ -107,7 +107,7 @@ inline TaggedStringPtr CreateString(ConstStringParam value) {
#ifndef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL
// Creates an arena allocated std::string value.
TaggedStringPtr CreateArenaString(Arena& arena, ConstStringParam s) {
TaggedStringPtr CreateArenaString(Arena& arena, absl::string_view s) {
TaggedStringPtr res;
res.SetMutableArena(Arena::Create<std::string>(&arena, s.data(), s.length()));
return res;
@ -117,7 +117,7 @@ TaggedStringPtr CreateArenaString(Arena& arena, ConstStringParam s) {
} // namespace
void ArenaStringPtr::Set(ConstStringParam value, Arena* arena) {
void ArenaStringPtr::Set(absl::string_view value, Arena* arena) {
ScopedCheckPtrInvariants check(&tagged_ptr_);
if (IsDefault()) {
// If we're not on an arena, skip straight to a true string to avoid

@ -40,6 +40,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/port.h>
#include "absl/strings/string_view.h"
#include <google/protobuf/explicitly_constructed.h>
// must be last:
@ -259,12 +260,12 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// instance known to not carry any heap allocated value.
inline void InitAllocated(std::string* str, Arena* arena);
void Set(ConstStringParam value, Arena* arena);
void Set(absl::string_view 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(absl::string_view 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);
@ -406,14 +407,14 @@ inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) {
}
inline void ArenaStringPtr::Set(const char* s, Arena* arena) {
Set(ConstStringParam{s}, arena);
Set(absl::string_view{s}, arena);
}
inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) {
Set(ConstStringParam{s, n}, arena);
Set(absl::string_view{s, n}, arena);
}
inline void ArenaStringPtr::SetBytes(ConstStringParam value, Arena* arena) {
inline void ArenaStringPtr::SetBytes(absl::string_view value, Arena* arena) {
Set(value, arena);
}
@ -426,7 +427,7 @@ inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) {
}
inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) {
Set(ConstStringParam{static_cast<const char*>(p), n}, arena);
Set(absl::string_view{static_cast<const char*>(p), n}, arena);
}
// Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs.

@ -44,7 +44,7 @@
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/string_view.h"
// Must be included last.

@ -455,7 +455,7 @@ class ThreadSafeArenazSamplerTestThread : public Thread {
public:
ThreadSafeArenazSamplerTestThread(const thread::Options& options,
StringPiece name,
absl::string_view name,
google::protobuf::Arena* arena,
absl::Barrier* barrier)
: Thread(options, name), arena_(arena), barrier_(barrier) {}
@ -483,7 +483,7 @@ TEST(ThreadSafeArenazSamplerTest, MultiThread) {
std::vector<std::unique_ptr<ThreadSafeArenazSamplerTestThread>> threads;
for (int i = 0; i < kNumThreads; i++) {
auto t = std::make_unique<ThreadSafeArenazSamplerTestThread>(
options, StrCat("thread", i), &arena, barrier);
options, absl::StrCat("thread", i), &arena, barrier);
t->Start();
threads.push_back(std::move(t));
}

@ -82,7 +82,6 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/stl_util.h>
@ -1946,12 +1945,11 @@ CommandLineInterface::InterpretArgument(const std::string& name,
print_mode_ = PRINT_FREE_FIELDS;
} else {
// Some other flag. Look it up in the generators list.
const GeneratorInfo* generator_info =
FindOrNull(generators_by_flag_name_, name);
const GeneratorInfo* generator_info = FindGeneratorByFlag(name);
if (generator_info == nullptr &&
(plugin_prefix_.empty() || !HasSuffixString(name, "_out"))) {
// Check if it's a generator option flag.
generator_info = FindOrNull(generators_by_option_name_, name);
generator_info = FindGeneratorByOption(name);
if (generator_info != nullptr) {
std::string* parameters =
&generator_parameters_[generator_info->flag_name];
@ -2083,16 +2081,15 @@ Parse PROTO_FILES and generate output based on the options given:
the executable's own name differs.)";
}
for (GeneratorMap::iterator iter = generators_by_flag_name_.begin();
iter != generators_by_flag_name_.end(); ++iter) {
for (const auto& kv : generators_by_flag_name_) {
// FIXME(kenton): If the text is long enough it will wrap, which is ugly,
// but fixing this nicely (e.g. splitting on spaces) is probably more
// trouble than it's worth.
std::cout << std::endl
<< " " << iter->first << "=OUT_DIR "
<< std::string(19 - iter->first.size(),
<< " " << kv.first << "=OUT_DIR "
<< std::string(19 - kv.first.size(),
' ') // Spaces for alignment.
<< iter->second.help_text;
<< kv.second.help_text;
}
std::cout << R"(
@<filename> Read options and filenames from file. If a
@ -2215,12 +2212,6 @@ bool CommandLineInterface::GenerateDependencyManifestFile(
output_filenames.push_back(descriptor_set_out_name_);
}
// Some consumers consider first output as the "primary output" (ninja)
// If this doesn't match their primary output it ignores the manifest.
// The unordered map for output_directories means we can't guarantee the order of files.
// Sorting here makes the "primary output" can be whichever is first alphabetically
std::sort(output_filenames.begin(), output_filenames.end());
int fd;
do {
fd = open(dependency_out_name_.c_str(),
@ -2514,6 +2505,20 @@ void CommandLineInterface::GetTransitiveDependencies(
}
}
const CommandLineInterface::GeneratorInfo*
CommandLineInterface::FindGeneratorByFlag(const std::string& name) const {
auto it = generators_by_flag_name_.find(name);
if (it == generators_by_flag_name_.end()) return nullptr;
return &it->second;
}
const CommandLineInterface::GeneratorInfo*
CommandLineInterface::FindGeneratorByOption(const std::string& option) const {
auto it = generators_by_option_name_.find(option);
if (it == generators_by_option_name_.end()) return nullptr;
return &it->second;
}
namespace {
// Utility function for PrintFreeFieldNumbers.

@ -39,6 +39,7 @@
#define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <set>
@ -49,6 +50,7 @@
#include <vector>
#include <google/protobuf/stubs/common.h>
#include "absl/strings/string_view.h"
// Must be included last.
#include <google/protobuf/port_def.inc>
@ -352,7 +354,11 @@ class PROTOC_EXPORT CommandLineInterface {
CodeGenerator* generator;
std::string help_text;
};
typedef std::map<std::string, GeneratorInfo> GeneratorMap;
const GeneratorInfo* FindGeneratorByFlag(const std::string& name) const;
const GeneratorInfo* FindGeneratorByOption(const std::string& option) const;
using GeneratorMap = std::map<std::string, GeneratorInfo>;
GeneratorMap generators_by_flag_name_;
GeneratorMap generators_by_option_name_;
// A map from generator names to the parameters specified using the option

@ -56,7 +56,7 @@
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
@ -67,6 +67,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h>
// Must be included last.
#include <google/protobuf/port_def.inc>
@ -1779,41 +1780,6 @@ TEST_F(CommandLineInterfaceTest,
"$tmpdir/bar.pb: "
"$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
}
TEST_F(CommandLineInterfaceTest,
DependencyManifestFileIsOrderedByFilePath) {
CreateTempFile("foo.proto",
"syntax = \"proto2\";\n"
"message Foo {}\n");
CreateTempFile("bar.proto",
"syntax = \"proto2\";\n"
"import \"foo.proto\";\n"
"message Bar {\n"
" optional Foo foo = 1;\n"
"}\n");
Run("protocol_compiler --dependency_out=$tmpdir/manifest_a "
"--test_out=$tmpdir "
"--descriptor_set_out=$tmpdir/a.pb --proto_path=$tmpdir bar.proto");
ExpectNoErrors();
ExpectFileContent("manifest_a",
"$tmpdir/a.pb \\\n"
"$tmpdir/bar.proto.MockCodeGenerator.test_generator: "
"$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
Run("protocol_compiler --dependency_out=$tmpdir/manifest_z "
"--test_out=$tmpdir "
"--descriptor_set_out=$tmpdir/z.pb --proto_path=$tmpdir bar.proto");
ExpectNoErrors();
ExpectFileContent("manifest_z",
"$tmpdir/bar.proto.MockCodeGenerator.test_generator \\\n"
"$tmpdir/z.pb: "
"$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
}
#endif // !_WIN32
TEST_F(CommandLineInterfaceTest, TestArgumentFile) {
@ -2622,7 +2588,7 @@ class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> {
bool Run(const std::string& command, bool specify_proto_files = true) {
std::vector<std::string> args;
args.push_back("protoc");
for (StringPiece split_piece :
for (absl::string_view split_piece :
Split(command, " ", true)) {
args.push_back(std::string(split_piece));
}
@ -2632,7 +2598,7 @@ class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> {
args.push_back("--proto_path=" + TestUtil::TestSourceDir());
break;
case DESCRIPTOR_SET_IN:
args.push_back(StrCat("--descriptor_set_in=",
args.push_back(absl::StrCat("--descriptor_set_in=",
unittest_proto_descriptor_set_filename_));
break;
default:

@ -42,7 +42,7 @@
// "generate_descriptor_proto.sh" and add
// descriptor.pb.{h,cc} to your changelist.
#include <map>
#include <string>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
@ -51,20 +51,25 @@
#include <google/protobuf/test_util2.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/container/flat_hash_map.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/stl_util.h>
namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {
namespace {
std::string FindWithDefault(
const absl::flat_hash_map<std::string, std::string>& m,
const std::string& k, const std::string& v) {
auto it = m.find(k);
if (it == m.end()) return v;
return it->second;
}
class MockErrorCollector : public MultiFileErrorCollector {
public:
@ -95,7 +100,6 @@ class MockGeneratorContext : public GeneratorContext {
File::GetContents(TestUtil::TestSourceDir() + "/" + physical_filename,
&actual_contents, true))
<< physical_filename;
CleanStringLineEndings(&actual_contents, false);
#ifdef WRITE_FILES // Define to debug mismatched files.
GOOGLE_CHECK_OK(File::SetContents("/tmp/expected.cc", expected_contents,
@ -135,8 +139,8 @@ const char* test_protos[][2] = {
TEST(BootstrapTest, GeneratedFilesMatch) {
// We need a mapping from the actual file to virtual and actual path
// of the data to compare to.
std::map<std::string, std::string> vpath_map;
std::map<std::string, std::string> rpath_map;
absl::flat_hash_map<std::string, std::string> vpath_map;
absl::flat_hash_map<std::string, std::string> rpath_map;
rpath_map["third_party/protobuf/test_messages_proto2"] =
"net/proto2/z_generated_example/test_messages_proto2";
rpath_map["third_party/protobuf/test_messages_proto3"] =

@ -228,7 +228,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
}
format(
"inline bool $classname$_Parse(\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, $classname$* "
" ::absl::string_view name, $classname$* "
"value) "
"{\n"
" return ::$proto_ns$::internal::ParseNamedEnum<$classname$>(\n"
@ -237,7 +237,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
} else {
format(
"bool $classname$_Parse(\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, $classname$* "
" ::absl::string_view name, $classname$* "
"value);\n");
}
}
@ -305,7 +305,7 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) const {
"}\n");
format(
"static inline bool "
"$nested_name$_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name,\n"
"$nested_name$_Parse(::absl::string_view name,\n"
" $resolved_name$* value) {\n"
" return $classname$_Parse(name, value);\n"
"}\n");
@ -435,7 +435,7 @@ void EnumGenerator::GenerateMethods(int idx, io::Printer* printer) {
CountUniqueValues(descriptor_));
format(
"bool $classname$_Parse(\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, $classname$* "
" ::absl::string_view name, $classname$* "
"value) "
"{\n"
" int int_value;\n"

@ -61,6 +61,8 @@ class EnumGenerator {
EnumGenerator(const EnumDescriptor* descriptor,
const std::map<std::string, std::string>& vars,
const Options& options);
EnumGenerator(const EnumGenerator&) = delete;
EnumGenerator& operator=(const EnumGenerator&) = delete;
~EnumGenerator();
// Generate header code defining the enum. This code should be placed
@ -95,7 +97,6 @@ class EnumGenerator {
std::map<std::string, std::string> variables_;
friend class FileGenerator;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
};
} // namespace cpp

@ -48,6 +48,8 @@ namespace cpp {
class EnumFieldGenerator : public FieldGenerator {
public:
EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options);
EnumFieldGenerator(const EnumFieldGenerator&) = delete;
EnumFieldGenerator& operator=(const EnumFieldGenerator&) = delete;
~EnumFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -66,15 +68,14 @@ class EnumFieldGenerator : public FieldGenerator {
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
};
class EnumOneofFieldGenerator : public EnumFieldGenerator {
public:
EnumOneofFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
EnumOneofFieldGenerator(const EnumOneofFieldGenerator&) = delete;
EnumOneofFieldGenerator& operator=(const EnumOneofFieldGenerator&) = delete;
~EnumOneofFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -82,9 +83,6 @@ class EnumOneofFieldGenerator : public EnumFieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumOneofFieldGenerator);
};
class RepeatedEnumFieldGenerator : public FieldGenerator {
@ -92,6 +90,9 @@ class RepeatedEnumFieldGenerator : public FieldGenerator {
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
~RepeatedEnumFieldGenerator() override;
RepeatedEnumFieldGenerator(const RepeatedEnumFieldGenerator&) = delete;
RepeatedEnumFieldGenerator& operator=(const RepeatedEnumFieldGenerator&) =
delete;
// implements FieldGenerator ---------------------------------------
void GeneratePrivateMembers(io::Printer* printer) const override;
@ -112,9 +113,6 @@ class RepeatedEnumFieldGenerator : public FieldGenerator {
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator);
};
} // namespace cpp

@ -38,6 +38,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/descriptor.pb.h>
@ -86,14 +87,14 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
variables_["name"] = ResolveKeyword(name);
variables_["constant_name"] = FieldConstantName(descriptor_);
variables_["field_type"] =
StrCat(static_cast<int>(descriptor_->type()));
absl::StrCat(static_cast<int>(descriptor_->type()));
variables_["packed"] = descriptor_->is_packed() ? "true" : "false";
std::string scope =
IsScoped() ? ClassName(descriptor_->extension_scope(), false) + "::" : "";
variables_["scope"] = scope;
variables_["scoped_name"] = ExtensionName(descriptor_);
variables_["number"] = StrCat(descriptor_->number());
variables_["number"] = absl::StrCat(descriptor_->number());
bool add_verify_fn =
// Only verify msgs.
@ -104,7 +105,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
variables_["verify_fn"] =
add_verify_fn
? StrCat("&", FieldMessageTypeName(descriptor_, options_),
? absl::StrCat("&", FieldMessageTypeName(descriptor_, options_),
"::InternalVerify")
: "nullptr";
}

@ -66,6 +66,8 @@ class ExtensionGenerator {
explicit ExtensionGenerator(const FieldDescriptor* descriptor,
const Options& options,
MessageSCCAnalyzer* scc_analyzer);
ExtensionGenerator(const ExtensionGenerator&) = delete;
ExtensionGenerator& operator=(const ExtensionGenerator&) = delete;
~ExtensionGenerator();
// Header stuff.
@ -83,8 +85,6 @@ class ExtensionGenerator {
MessageSCCAnalyzer* scc_analyzer_;
std::map<std::string, std::string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
};
} // namespace cpp

@ -38,7 +38,8 @@
#include <memory>
#include <string>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/compiler/cpp/primitive_field.h>
@ -47,6 +48,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/compiler/cpp/enum_field.h>
#include <google/protobuf/compiler/cpp/map_field.h>
#include <google/protobuf/compiler/cpp/message_field.h>
@ -62,22 +64,22 @@ using internal::WireFormat;
namespace {
void MaySetAnnotationVariable(const Options& options,
StringPiece annotation_name,
StringPiece substitute_template_prefix,
StringPiece prepared_template,
int field_index, StringPiece access_type,
absl::string_view annotation_name,
absl::string_view substitute_template_prefix,
absl::string_view prepared_template,
int field_index, absl::string_view access_type,
std::map<std::string, std::string>* variables) {
if (options.field_listener_options.forbidden_field_listener_events.count(
std::string(annotation_name)))
return;
(*variables)[StrCat("annotate_", annotation_name)] = strings::Substitute(
StrCat(substitute_template_prefix, prepared_template, ");\n"),
(*variables)[absl::StrCat("annotate_", annotation_name)] = strings::Substitute(
absl::StrCat(substitute_template_prefix, prepared_template, ");\n"),
field_index, access_type);
}
std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
StringPiece proto_ns,
StringPiece field_member) {
absl::string_view proto_ns,
absl::string_view field_member) {
std::string field_name = google::protobuf::compiler::cpp::FieldName(descriptor);
std::string field_pointer =
descriptor->options().ctype() == google::protobuf::FieldOptions::STRING
@ -85,13 +87,13 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
: "$0";
if (descriptor->default_value_string().empty()) {
return strings::Substitute(StrCat("_internal_has_", field_name, "() ? ",
return strings::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ",
field_pointer, ": nullptr"),
field_member);
}
if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING_PIECE) {
return strings::Substitute(StrCat("_internal_has_", field_name, "() ? ",
return strings::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ",
field_pointer, ": nullptr"),
field_member);
}
@ -101,15 +103,15 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
? "&$1.get()"
: "&$1";
return strings::Substitute(
StrCat("_internal_has_", field_name, "() ? ", field_pointer, " : ",
absl::StrCat("_internal_has_", field_name, "() ? ", field_pointer, " : ",
default_value_pointer),
field_member, MakeDefaultFieldName(descriptor));
}
std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor,
StringPiece field_member) {
absl::string_view field_member) {
if (descriptor->default_value_string().empty()) {
return StrCat("&", field_member);
return absl::StrCat("&", field_member);
}
if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING) {
@ -118,7 +120,7 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor,
MakeDefaultFieldName(descriptor));
}
return StrCat("&", field_member);
return absl::StrCat("&", field_member);
}
} // namespace
@ -134,12 +136,12 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor,
"annotate_release", "annotate_set", "annotate_size",
"annotate_clear", "annotate_add_mutable",
};
for (size_t i = 0; i < GOOGLE_ARRAYSIZE(kAccessorsAnnotations); ++i) {
for (size_t i = 0; i < ABSL_ARRAYSIZE(kAccessorsAnnotations); ++i) {
(*variables)[kAccessorsAnnotations[i]] = "";
}
if (options.annotate_accessor) {
for (size_t i = 0; i < GOOGLE_ARRAYSIZE(kAccessorsAnnotations); ++i) {
(*variables)[kAccessorsAnnotations[i]] = StrCat(
for (size_t i = 0; i < ABSL_ARRAYSIZE(kAccessorsAnnotations); ++i) {
(*variables)[kAccessorsAnnotations[i]] = absl::StrCat(
" ", FieldName(descriptor), "_AccessedNoStrip = true;\n");
}
}
@ -155,7 +157,7 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor,
descriptor->real_containing_oneof();
const std::string proto_ns = (*variables)["proto_ns"];
const std::string substitute_template_prefix =
StrCat(" ", (*variables)["tracker"], ".$1<$0>(this, ");
absl::StrCat(" ", (*variables)["tracker"], ".$1<$0>(this, ");
std::string prepared_template;
// Flat template is needed if the prepared one is introspecting the values
@ -187,12 +189,12 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor,
GenerateTemplateForSingleString(descriptor, field_member);
}
} else {
prepared_template = StrCat("&", field_member);
prepared_template = absl::StrCat("&", field_member);
}
if (descriptor->is_repeated() && !descriptor->is_map() &&
descriptor->type() != FieldDescriptor::TYPE_MESSAGE &&
descriptor->type() != FieldDescriptor::TYPE_GROUP) {
prepared_flat_template = StrCat("&", field_member);
prepared_flat_template = absl::StrCat("&", field_member);
} else {
prepared_flat_template = prepared_template;
}
@ -240,14 +242,14 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
(*variables)["ns"] = Namespace(descriptor, options);
(*variables)["name"] = FieldName(descriptor);
(*variables)["index"] = StrCat(descriptor->index());
(*variables)["number"] = StrCat(descriptor->number());
(*variables)["index"] = absl::StrCat(descriptor->index());
(*variables)["number"] = absl::StrCat(descriptor->number());
(*variables)["classname"] = ClassName(FieldScope(descriptor), false);
(*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type());
bool split = ShouldSplit(descriptor, options);
(*variables)["field"] = FieldMemberName(descriptor, split);
(*variables)["tag_size"] = StrCat(
(*variables)["tag_size"] = absl::StrCat(
WireFormat::TagSize(descriptor->number(), descriptor->type()));
(*variables)["deprecated_attr"] = DeprecatedAttribute(options, descriptor);
@ -271,12 +273,12 @@ void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) {
GOOGLE_CHECK_EQ(has_bit_index, -1);
return;
}
variables_["set_hasbit"] = StrCat(
variables_["set_hasbit"] = absl::StrCat(
variables_["has_bits"], "[", has_bit_index / 32, "] |= 0x",
strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8), "u;");
variables_["clear_hasbit"] = StrCat(
absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8), "u;");
variables_["clear_hasbit"] = absl::StrCat(
variables_["has_bits"], "[", has_bit_index / 32, "] &= ~0x",
strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8), "u;");
absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8), "u;");
}
void FieldGenerator::SetInlinedStringIndex(int32_t inlined_string_index) {
@ -287,16 +289,16 @@ void FieldGenerator::SetInlinedStringIndex(int32_t inlined_string_index) {
// The first bit is the tracking bit for on demand registering ArenaDtor.
GOOGLE_CHECK_GT(inlined_string_index, 0)
<< "_inlined_string_donated_'s bit 0 is reserved for arena dtor tracking";
variables_["inlined_string_donated"] = StrCat(
variables_["inlined_string_donated"] = absl::StrCat(
"(", variables_["inlined_string_donated_array"], "[",
inlined_string_index / 32, "] & 0x",
strings::Hex(1u << (inlined_string_index % 32), strings::ZERO_PAD_8),
absl::Hex(1u << (inlined_string_index % 32), absl::kZeroPad8),
"u) != 0;");
variables_["donating_states_word"] =
StrCat(variables_["inlined_string_donated_array"], "[",
absl::StrCat(variables_["inlined_string_donated_array"], "[",
inlined_string_index / 32, "]");
variables_["mask_for_undonate"] = StrCat(
"~0x", strings::Hex(1u << (inlined_string_index % 32), strings::ZERO_PAD_8),
variables_["mask_for_undonate"] = absl::StrCat(
"~0x", absl::Hex(1u << (inlined_string_index % 32), absl::kZeroPad8),
"u");
}

@ -74,6 +74,8 @@ class FieldGenerator {
explicit FieldGenerator(const FieldDescriptor* descriptor,
const Options& options)
: descriptor_(descriptor), options_(options) {}
FieldGenerator(const FieldGenerator&) = delete;
FieldGenerator& operator=(const FieldGenerator&) = delete;
virtual ~FieldGenerator();
virtual void GenerateSerializeWithCachedSizes(
io::Printer* printer) const final{};
@ -219,9 +221,6 @@ class FieldGenerator {
const FieldDescriptor* descriptor_;
const Options& options_;
std::map<std::string, std::string> variables_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
};
// Convenience class which constructs FieldGenerators for a Descriptor.
@ -229,6 +228,8 @@ class FieldGeneratorMap {
public:
FieldGeneratorMap(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
FieldGeneratorMap(const FieldGeneratorMap&) = delete;
FieldGeneratorMap& operator=(const FieldGeneratorMap&) = delete;
~FieldGeneratorMap();
const FieldGenerator& get(const FieldDescriptor* field) const;
@ -255,8 +256,6 @@ class FieldGeneratorMap {
static FieldGenerator* MakeGenerator(const FieldDescriptor* field,
const Options& options,
MessageSCCAnalyzer* scc_analyzer);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
};
} // namespace cpp

@ -45,6 +45,8 @@
#include <google/protobuf/compiler/scc.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/cpp/enum.h>
#include <google/protobuf/compiler/cpp/extension.h>
#include <google/protobuf/compiler/cpp/field.h>
@ -172,7 +174,7 @@ void FileGenerator::GenerateMacroUndefs(io::Printer* printer) {
for (int i = 0; i < fields.size(); i++) {
const std::string& name = fields[i]->name();
static const char* kMacroNames[] = {"major", "minor"};
for (int j = 0; j < GOOGLE_ARRAYSIZE(kMacroNames); ++j) {
for (int j = 0; j < ABSL_ARRAYSIZE(kMacroNames); ++j) {
if (name == kMacroNames[j]) {
names_to_undef.push_back(name);
break;
@ -500,7 +502,7 @@ void FileGenerator::GenerateSourceDefaultInstance(int idx,
" $1$ _instance;\n"
" };\n"
"};\n",
StrCat(generator->classname_, "::Impl_::Split"));
absl::StrCat(generator->classname_, "::Impl_::Split"));
// NO_DESTROY is not necessary for correctness. The empty destructor is
// enough. However, the empty destructor fails to be elided in some
// configurations (like non-opt or with certain sanitizers). NO_DESTROY is
@ -879,7 +881,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
format("{ ");
for (int i = 0; i < file_data.size();) {
for (int j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) {
format("'$1$', ", CEscape(file_data.substr(i, 1)));
format("'$1$', ", absl::CEscape(file_data.substr(i, 1)));
}
format("\n");
}
@ -890,7 +892,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
format(
"\"$1$\"\n",
EscapeTrigraphs(CEscape(file_data.substr(i, kBytesPerLine))));
EscapeTrigraphs(absl::CEscape(file_data.substr(i, kBytesPerLine))));
}
}
format(";\n");
@ -925,7 +927,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
// so disable for now.
bool eager = false;
format(
"static ::_pbi::once_flag $desc_table$_once;\n"
"static ::absl::once_flag $desc_table$_once;\n"
"const ::_pbi::DescriptorTable $desc_table$ = {\n"
" false, $1$, $2$, $3$,\n"
" \"$filename$\",\n"

@ -70,6 +70,8 @@ class FileGenerator {
public:
// See generator.cc for the meaning of dllexport_decl.
FileGenerator(const FileDescriptor* file, const Options& options);
FileGenerator(const FileGenerator&) = delete;
FileGenerator& operator=(const FileGenerator&) = delete;
~FileGenerator();
// Shared code between the two header generators below.
@ -197,8 +199,6 @@ class FileGenerator {
std::vector<std::unique_ptr<EnumGenerator>> enum_generators_;
std::vector<std::unique_ptr<ServiceGenerator>> service_generators_;
std::vector<std::unique_ptr<ExtensionGenerator>> extension_generators_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};
} // namespace cpp

@ -42,6 +42,7 @@
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/cpp/file.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/descriptor.pb.h>
@ -56,7 +57,7 @@ CppGenerator::~CppGenerator() {}
namespace {
std::string NumberedCcFileName(const std::string& basename, int number) {
return StrCat(basename, ".out/", number, ".cc");
return absl::StrCat(basename, ".out/", number, ".cc");
}
} // namespace

@ -55,6 +55,8 @@ namespace cpp {
class PROTOC_EXPORT CppGenerator : public CodeGenerator {
public:
CppGenerator();
CppGenerator(const CppGenerator&) = delete;
CppGenerator& operator=(const CppGenerator&) = delete;
~CppGenerator() override;
enum class Runtime {
@ -94,7 +96,6 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
private:
bool opensource_runtime_ = true;
std::string runtime_include_base_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppGenerator);
};
} // namespace cpp

@ -45,22 +45,26 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/descriptor.h>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include <google/protobuf/stubs/strutil.h>
#include "absl/synchronization/mutex.h"
#include <google/protobuf/compiler/cpp/names.h>
#include <google/protobuf/compiler/cpp/options.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/compiler/scc.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/stubs/hash.h>
#include "absl/synchronization/mutex.h"
#include <google/protobuf/compiler/cpp/names.h>
#include <google/protobuf/compiler/cpp/options.h>
#include <google/protobuf/descriptor.pb.h>
// Must be last.
#include <google/protobuf/port_def.inc>
@ -418,7 +422,7 @@ std::string QualifiedClassName(const EnumDescriptor* d) {
std::string ExtensionName(const FieldDescriptor* d) {
if (const Descriptor* scope = d->extension_scope())
return StrCat(ClassName(scope), "::", ResolveKeyword(d->name()));
return absl::StrCat(ClassName(scope), "::", ResolveKeyword(d->name()));
return ResolveKeyword(d->name());
}
@ -529,15 +533,15 @@ std::string FieldName(const FieldDescriptor* field) {
}
std::string FieldMemberName(const FieldDescriptor* field, bool split) {
StringPiece prefix =
absl::string_view prefix =
IsMapEntryMessage(field->containing_type()) ? "" : "_impl_.";
StringPiece split_prefix = split ? "_split_->" : "";
absl::string_view split_prefix = split ? "_split_->" : "";
if (field->real_containing_oneof() == nullptr) {
return StrCat(prefix, split_prefix, FieldName(field), "_");
return absl::StrCat(prefix, split_prefix, FieldName(field), "_");
}
// Oneof fields are never split.
GOOGLE_CHECK(!split);
return StrCat(prefix, field->containing_oneof()->name(), "_.",
return absl::StrCat(prefix, field->containing_oneof()->name(), "_.",
FieldName(field), "_");
}
@ -551,7 +555,7 @@ std::string QualifiedOneofCaseConstantName(const FieldDescriptor* field) {
GOOGLE_DCHECK(field->containing_oneof());
const std::string qualification =
QualifiedClassName(field->containing_type());
return StrCat(qualification, "::", OneofCaseConstantName(field));
return absl::StrCat(qualification, "::", OneofCaseConstantName(field));
}
std::string EnumValueName(const EnumValueDescriptor* enum_value) {
@ -596,7 +600,7 @@ std::string FieldConstantName(const FieldDescriptor* field) {
// This field's camelcase name is not unique. As a hack, add the field
// number to the constant name. This makes the constant rather useless,
// but what can we do?
result += "_" + StrCat(field->number());
result += "_" + absl::StrCat(field->number());
}
return result;
@ -732,9 +736,9 @@ std::string Int32ToString(int number) {
if (number == std::numeric_limits<int32_t>::min()) {
// This needs to be special-cased, see explanation here:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661
return StrCat(number + 1, " - 1");
return absl::StrCat(number + 1, " - 1");
} else {
return StrCat(number);
return absl::StrCat(number);
}
}
@ -742,13 +746,13 @@ static std::string Int64ToString(int64_t number) {
if (number == std::numeric_limits<int64_t>::min()) {
// This needs to be special-cased, see explanation here:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661
return StrCat("int64_t{", number + 1, "} - 1");
return absl::StrCat("int64_t{", number + 1, "} - 1");
}
return StrCat("int64_t{", number, "}");
return absl::StrCat("int64_t{", number, "}");
}
static std::string UInt64ToString(uint64_t number) {
return StrCat("uint64_t{", number, "u}");
return absl::StrCat("uint64_t{", number, "u}");
}
std::string DefaultValue(const FieldDescriptor* field) {
@ -760,7 +764,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_INT32:
return Int32ToString(field->default_value_int32());
case FieldDescriptor::CPPTYPE_UINT32:
return StrCat(field->default_value_uint32()) + "u";
return absl::StrCat(field->default_value_uint32()) + "u";
case FieldDescriptor::CPPTYPE_INT64:
return Int64ToString(field->default_value_int64());
case FieldDescriptor::CPPTYPE_UINT64:
@ -806,7 +810,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
Int32ToString(field->default_value_enum()->number()));
case FieldDescriptor::CPPTYPE_STRING:
return "\"" +
EscapeTrigraphs(CEscape(field->default_value_string())) +
EscapeTrigraphs(absl::CEscape(field->default_value_string())) +
"\"";
case FieldDescriptor::CPPTYPE_MESSAGE:
return "*" + FieldMessageTypeName(field, options) +
@ -823,13 +827,13 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
std::string FilenameIdentifier(const std::string& filename) {
std::string result;
for (int i = 0; i < filename.size(); i++) {
if (ascii_isalnum(filename[i])) {
if (absl::ascii_isalnum(filename[i])) {
result.push_back(filename[i]);
} else {
// Not alphanumeric. To avoid any possibility of name conflicts we
// use the hex code for the character.
StrAppend(&result, "_",
strings::Hex(static_cast<uint8_t>(filename[i])));
absl::StrAppend(&result, "_",
absl::Hex(static_cast<uint8_t>(filename[i])));
}
}
return result;
@ -845,9 +849,9 @@ std::string QualifiedFileLevelSymbol(const FileDescriptor* file,
const std::string& name,
const Options& options) {
if (file->package().empty()) {
return StrCat("::", name);
return absl::StrCat("::", name);
}
return StrCat(Namespace(file, options), "::", name);
return absl::StrCat(Namespace(file, options), "::", name);
}
// Escape C++ trigraphs by escaping question marks to \?

@ -50,6 +50,7 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/port.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
// Must be included last.
#include <google/protobuf/port_def.inc>
@ -468,7 +469,7 @@ inline bool IsCrossFileMessage(const FieldDescriptor* field) {
}
inline std::string MakeDefaultName(const FieldDescriptor* field) {
return StrCat("_i_give_permission_to_break_this_code_default_",
return absl::StrCat("_i_give_permission_to_break_this_code_default_",
FieldName(field), "_");
}
@ -483,11 +484,11 @@ inline std::string MakeDefaultName(const FieldDescriptor* field) {
// exists at some nested level like:
// internal_container_._i_give_permission_to_break_this_code_default_field_;
inline std::string MakeDefaultFieldName(const FieldDescriptor* field) {
return StrCat("Impl_::", MakeDefaultName(field));
return absl::StrCat("Impl_::", MakeDefaultName(field));
}
inline std::string MakeVarintCachedSizeName(const FieldDescriptor* field) {
return StrCat("_", FieldName(field), "_cached_byte_size_");
return absl::StrCat("_", FieldName(field), "_cached_byte_size_");
}
// Semantically distinct from MakeVarintCachedSizeName in that it gives the C++
@ -503,7 +504,7 @@ inline std::string MakeVarintCachedSizeName(const FieldDescriptor* field) {
// internal_container_._field_cached_byte_size_;
inline std::string MakeVarintCachedSizeFieldName(const FieldDescriptor* field,
bool split) {
return StrCat("_impl_.", split ? "_split_->" : "", "_",
return absl::StrCat("_impl_.", split ? "_split_->" : "", "_",
FieldName(field), "_cached_byte_size_");
}
@ -835,9 +836,9 @@ class PROTOC_EXPORT Formatter {
template <typename I, typename = typename std::enable_if<
std::is_integral<I>::value>::type>
static std::string ToString(I x) {
return StrCat(x);
return absl::StrCat(x);
}
static std::string ToString(strings::Hex x) { return StrCat(x); }
static std::string ToString(absl::Hex x) { return absl::StrCat(x); }
static std::string ToString(const FieldDescriptor* d) { return Payload(d); }
static std::string ToString(const Descriptor* d) { return Payload(d); }
static std::string ToString(const EnumDescriptor* d) { return Payload(d); }

@ -33,6 +33,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include <google/protobuf/compiler/cpp/helpers.h>
@ -65,8 +66,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
(*variables)["val_wire_type"] =
"TYPE_" + ToUpper(DeclaredTypeMethodName(val->type()));
(*variables)["map_classname"] = ClassName(descriptor->message_type(), false);
(*variables)["number"] = StrCat(descriptor->number());
(*variables)["tag"] = StrCat(internal::WireFormat::MakeTag(descriptor));
(*variables)["number"] = absl::StrCat(descriptor->number());
(*variables)["tag"] = absl::StrCat(internal::WireFormat::MakeTag(descriptor));
if (HasDescriptorMethods(descriptor->file(), options)) {
(*variables)["lite"] = "";

@ -46,6 +46,8 @@ class MapFieldGenerator : public FieldGenerator {
public:
MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
MapFieldGenerator(const MapFieldGenerator&) = delete;
MapFieldGenerator& operator=(const MapFieldGenerator&) = delete;
~MapFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -71,8 +73,6 @@ class MapFieldGenerator : public FieldGenerator {
private:
const bool has_required_fields_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator);
};
} // namespace cpp

@ -53,7 +53,11 @@
#include <google/protobuf/map_entry_lite.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/stringprintf.h>
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/cpp/enum.h>
#include <google/protobuf/compiler/cpp/extension.h>
@ -62,7 +66,6 @@
#include <google/protobuf/compiler/cpp/padding_optimizer.h>
#include <google/protobuf/compiler/cpp/parse_function_generator.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/hash.h>
// Must be included last.
@ -88,21 +91,21 @@ static constexpr int kNoHasbit = -1;
// masks must be non-zero.
std::string ConditionalToCheckBitmasks(
const std::vector<uint32_t>& masks, bool return_success = true,
StringPiece has_bits_var = "_impl_._has_bits_") {
absl::string_view has_bits_var = "_impl_._has_bits_") {
std::vector<std::string> parts;
for (int i = 0; i < masks.size(); i++) {
if (masks[i] == 0) continue;
std::string m = StrCat("0x", strings::Hex(masks[i], strings::ZERO_PAD_8));
std::string m = absl::StrCat("0x", absl::Hex(masks[i], absl::kZeroPad8));
// Each xor evaluates to 0 if the expected bits are present.
parts.push_back(
StrCat("((", has_bits_var, "[", i, "] & ", m, ") ^ ", m, ")"));
absl::StrCat("((", has_bits_var, "[", i, "] & ", m, ") ^ ", m, ")"));
}
GOOGLE_CHECK(!parts.empty());
// If we have multiple parts, each expected to be 0, then bitwise-or them.
std::string result =
parts.size() == 1
? parts[0]
: StrCat("(", Join(parts, "\n | "), ")");
: absl::StrCat("(", absl::StrJoin(parts, "\n | "), ")");
return result + (return_success ? " == 0" : " != 0");
}
@ -116,7 +119,7 @@ void PrintPresenceCheck(const Formatter& format, const FieldDescriptor* field,
format("cached_has_bits = $has_bits$[$1$];\n", *cached_has_word_index);
}
const std::string mask =
StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
absl::StrCat(absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8));
format("if (cached_has_bits & 0x$1$u) {\n", mask);
} else {
format("if (has_$1$()) {\n", FieldName(field));
@ -496,7 +499,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index,
if (this_word != first_word) {
format(" ||\n ");
}
format.Set("mask", strings::Hex(mask, strings::ZERO_PAD_8));
format.Set("mask", absl::Hex(mask, absl::kZeroPad8));
if (this_word == cached_has_word_index) {
format("(cached_has_bits & 0x$mask$u) != 0");
} else {
@ -518,15 +521,15 @@ bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* printer) {
}
void MaySetAnnotationVariable(const Options& options,
StringPiece annotation_name,
StringPiece injector_template_prefix,
StringPiece injector_template_suffix,
absl::string_view annotation_name,
absl::string_view injector_template_prefix,
absl::string_view injector_template_suffix,
std::map<std::string, std::string>* variables) {
if (options.field_listener_options.forbidden_field_listener_events.count(
std::string(annotation_name)))
return;
(*variables)[StrCat("annotate_", annotation_name)] = strings::Substitute(
StrCat(injector_template_prefix, injector_template_suffix),
(*variables)[absl::StrCat("annotate_", annotation_name)] = strings::Substitute(
absl::StrCat(injector_template_prefix, injector_template_suffix),
(*variables)["classtype"]);
}
@ -555,8 +558,8 @@ void GenerateExtensionAnnotations(
if (!HasTracker(descriptor, options)) {
return;
}
StringPiece tracker = (*variables)["tracker"];
StringPiece extensions = (*variables)["extensions"];
absl::string_view tracker = (*variables)["tracker"];
absl::string_view extensions = (*variables)["extensions"];
for (const auto& annotation : accessor_annotations_to_hooks) {
const std::string& annotation_name = annotation.first;
const std::string& listener_call = annotation.second;
@ -565,7 +568,7 @@ void GenerateExtensionAnnotations(
!StrContains(annotation_name, "clear")) {
// Primitive fields accessors.
// "Has" is here as users calling "has" on a repeated field is a mistake.
(*variables)[annotation_name] = StrCat(
(*variables)[annotation_name] = absl::StrCat(
" ", tracker, ".", listener_call,
"(this, id.number(), _proto_TypeTraits::GetPtr(id.number(), ",
extensions, ", id.default_value_ref()));");
@ -575,17 +578,17 @@ void GenerateExtensionAnnotations(
// Repeated index accessors.
std::string str_index = "index";
if (StrContains(annotation_name, "add")) {
str_index = StrCat(extensions, ".ExtensionSize(id.number()) - 1");
str_index = absl::StrCat(extensions, ".ExtensionSize(id.number()) - 1");
}
(*variables)[annotation_name] =
StrCat(" ", tracker, ".", listener_call,
absl::StrCat(" ", tracker, ".", listener_call,
"(this, id.number(), "
"_proto_TypeTraits::GetPtr(id.number(), ",
extensions, ", ", str_index, "));");
} else if (StrContains(annotation_name, "list") ||
StrContains(annotation_name, "size")) {
// Repeated full accessors.
(*variables)[annotation_name] = StrCat(
(*variables)[annotation_name] = absl::StrCat(
" ", tracker, ".", listener_call,
"(this, id.number(), _proto_TypeTraits::GetRepeatedPtr(id.number(), ",
extensions, "));");
@ -635,7 +638,7 @@ MessageGenerator::MessageGenerator(
if (HasTracker(descriptor_, options_)) {
const std::string injector_template =
StrCat(" ", variables_["tracker"], ".");
absl::StrCat(" ", variables_["tracker"], ".");
MaySetAnnotationVariable(options, "serialize", injector_template,
"OnSerialize(this);\n", &variables_);
@ -1079,7 +1082,7 @@ void MessageGenerator::GenerateSingularFieldHasBits(
format.Set("has_array_index", has_bit_index / 32);
format.Set("has_mask",
strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8));
format(
"inline bool $classname$::_internal_has_$name$() const {\n"
" bool value = "
@ -1216,7 +1219,7 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field,
int has_bit_index = HasBitIndex(field);
format.Set("has_array_index", has_bit_index / 32);
format.Set("has_mask",
strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8));
format("$has_bits$[$has_array_index$] &= ~0x$has_mask$u;\n");
}
}
@ -1266,7 +1269,7 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) {
format.Set("field_name", UnderscoresToCamelCase(field->name(), true));
format.Set("oneof_name", field->containing_oneof()->name());
format.Set("oneof_index",
StrCat(field->containing_oneof()->index()));
absl::StrCat(field->containing_oneof()->index()));
GenerateOneofMemberHasBits(field, format);
} else {
// Singular field.
@ -1525,8 +1528,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
" return $any_metadata$.PackFrom(GetArena(), message);\n"
"}\n"
"bool PackFrom(const ::$proto_ns$::Message& message,\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url_prefix) {\n"
" ::absl::string_view type_url_prefix) {\n"
" $DCHK$_NE(&message, this);\n"
" return $any_metadata$.PackFrom(GetArena(), message, "
"type_url_prefix);\n"
@ -1548,8 +1550,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"!std::is_convertible<T, const ::$proto_ns$::Message&>"
"::value>::type>\n"
"bool PackFrom(const T& message,\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url_prefix) {\n"
" ::absl::string_view type_url_prefix) {\n"
" return $any_metadata$.PackFrom<T>(GetArena(), message, "
"type_url_prefix);"
"}\n"
@ -1567,8 +1568,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"}\n"
"template <typename T>\n"
"bool PackFrom(const T& message,\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url_prefix) {\n"
" ::absl::string_view type_url_prefix) {\n"
" return $any_metadata$.PackFrom(GetArena(), message, "
"type_url_prefix);\n"
"}\n"
@ -1581,8 +1581,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"template<typename T> bool Is() const {\n"
" return $any_metadata$.Is<T>();\n"
"}\n"
"static bool ParseAnyTypeUrl(::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url,\n"
"static bool ParseAnyTypeUrl(::absl::string_view type_url,\n"
" std::string* full_type_name);\n");
}
@ -1700,11 +1699,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
// Friend AnyMetadata so that it can call this FullMessageName() method.
"\nprivate:\n"
"friend class ::$proto_ns$::internal::AnyMetadata;\n"
"static $1$ FullMessageName() {\n"
"static ::absl::string_view FullMessageName() {\n"
" return \"$full_name$\";\n"
"}\n",
options_.opensource_runtime ? "::PROTOBUF_NAMESPACE_ID::StringPiece"
: "::StringPiece");
"}\n");
format(
// TODO(gerbens) Make this private! Currently people are deriving from
@ -1859,7 +1856,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
const size_t sizeof_has_bits = HasBitsSize();
const std::string has_bits_decl =
sizeof_has_bits == 0 ? ""
: StrCat("::$proto_ns$::internal::HasBits<",
: absl::StrCat("::$proto_ns$::internal::HasBits<",
sizeof_has_bits, "> _has_bits_;\n");
format(
@ -2092,7 +2089,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) {
}
format(
"bool $classname$::ParseAnyTypeUrl(\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url,\n"
" ::absl::string_view type_url,\n"
" std::string* full_type_name) {\n"
" return ::_pbi::ParseAnyTypeUrl(type_url, full_type_name);\n"
"}\n"
@ -2359,7 +2356,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(
entries += has_bit_indices_.size();
for (int i = 0; i < has_bit_indices_.size(); i++) {
const std::string index =
has_bit_indices_[i] >= 0 ? StrCat(has_bit_indices_[i]) : "~0u";
has_bit_indices_[i] >= 0 ? absl::StrCat(has_bit_indices_[i]) : "~0u";
format("$1$,\n", index);
}
}
@ -2368,7 +2365,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(
for (int inlined_string_index : inlined_string_indices_) {
const std::string index =
inlined_string_index >= 0
? StrCat(inlined_string_index, ", // inlined_string_index")
? absl::StrCat(inlined_string_index, ", // inlined_string_index")
: "~0u,";
format("$1$\n", index);
}
@ -3112,7 +3109,7 @@ void MessageGenerator::GenerateClear(io::Printer* printer) {
// Emit an if() that will let us skip the whole chunk if none are set.
uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_);
std::string chunk_mask_str =
StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8));
absl::StrCat(absl::Hex(chunk_mask, absl::kZeroPad8));
// Check (up to) 8 has_bits at a time if we have more than one field in
// this chunk. Due to field layout ordering, we may check
@ -3472,7 +3469,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* printer) {
// Emit an if() that will let us skip the whole chunk if none are set.
uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_);
std::string chunk_mask_str =
StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8));
absl::StrCat(absl::Hex(chunk_mask, absl::kZeroPad8));
// Check (up to) 8 has_bits at a time if we have more than one field in
// this chunk. Due to field layout ordering, we may check
@ -3520,8 +3517,8 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* printer) {
// Check hasbit, using cached bits.
GOOGLE_CHECK(HasHasbit(field));
int has_bit_index = has_bit_indices_[field->index()];
const std::string mask = StrCat(
strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
const std::string mask = absl::StrCat(
absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8));
format("if (cached_has_bits & 0x$1$u) {\n", mask);
format.Indent();
@ -3710,7 +3707,7 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* printer,
int has_bit_index = HasBitIndex(field);
if (cached_has_bits_index == has_bit_index / 32) {
const std::string mask =
StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
absl::StrCat(absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8));
format("if (cached_has_bits & 0x$1$u) {\n", mask);
} else {
@ -3735,8 +3732,8 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* printer,
void MessageGenerator::GenerateSerializeOneExtensionRange(
io::Printer* printer, const Descriptor::ExtensionRange* range) {
std::map<std::string, std::string> vars = variables_;
vars["start"] = StrCat(range->start);
vars["end"] = StrCat(range->end);
vars["start"] = absl::StrCat(range->start);
vars["end"] = absl::StrCat(range->end);
Formatter format(printer, vars);
format("// Extension range [$start$, $end$)\n");
format(
@ -4265,7 +4262,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) {
// Emit an if() that will let us skip the whole chunk if none are set.
uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_);
std::string chunk_mask_str =
StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8));
absl::StrCat(absl::Hex(chunk_mask, absl::kZeroPad8));
// Check (up to) 8 has_bits at a time if we have more than one field in
// this chunk. Due to field layout ordering, we may check

@ -70,6 +70,8 @@ class MessageGenerator {
const std::map<std::string, std::string>& vars,
int index_in_file_messages, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
MessageGenerator(const MessageGenerator&) = delete;
MessageGenerator& operator=(const MessageGenerator&) = delete;
~MessageGenerator();
// Append the two types of nested generators to the corresponding vector.
@ -221,7 +223,6 @@ class MessageGenerator {
std::map<std::string, std::string> variables_;
friend class FileGenerator;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
};
} // namespace cpp

@ -51,6 +51,8 @@ class MessageFieldGenerator : public FieldGenerator {
MessageFieldGenerator(const FieldDescriptor* descriptor,
const Options& options,
MessageSCCAnalyzer* scc_analyzer);
MessageFieldGenerator(const MessageFieldGenerator&) = delete;
MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete;
~MessageFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -81,9 +83,6 @@ class MessageFieldGenerator : public FieldGenerator {
protected:
const bool implicit_weak_field_;
const bool has_required_fields_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
};
class MessageOneofFieldGenerator : public MessageFieldGenerator {
@ -91,6 +90,9 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
const Options& options,
MessageSCCAnalyzer* scc_analyzer);
MessageOneofFieldGenerator(const MessageOneofFieldGenerator&) = delete;
MessageOneofFieldGenerator& operator=(const MessageOneofFieldGenerator&) =
delete;
~MessageOneofFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -106,9 +108,6 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateIsInitialized(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator);
};
class RepeatedMessageFieldGenerator : public FieldGenerator {
@ -116,6 +115,9 @@ class RepeatedMessageFieldGenerator : public FieldGenerator {
RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor,
const Options& options,
MessageSCCAnalyzer* scc_analyzer);
RepeatedMessageFieldGenerator(const RepeatedMessageFieldGenerator&) = delete;
RepeatedMessageFieldGenerator& operator=(
const RepeatedMessageFieldGenerator&) = delete;
~RepeatedMessageFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -136,8 +138,6 @@ class RepeatedMessageFieldGenerator : public FieldGenerator {
private:
const bool implicit_weak_field_;
const bool has_required_fields_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator);
};
} // namespace cpp

@ -36,6 +36,7 @@
#include <utility>
#include <google/protobuf/wire_format.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/generated_message_tctable_gen.h>
#include <google/protobuf/generated_message_tctable_impl.h>
@ -634,7 +635,7 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) {
? "uint32_t"
: "uint64_t";
func_name =
StrCat("::_pbi::TcParser::SingularVarintNoZag1<", field_type,
absl::StrCat("::_pbi::TcParser::SingularVarintNoZag1<", field_type,
", offsetof(", //
ClassName(info.field->containing_type()), //
", ", //
@ -929,7 +930,7 @@ void ParseFunctionGenerator::GenerateStrings(Formatter& format,
std::string field_name;
field_name = "nullptr";
if (HasDescriptorMethods(field->file(), options_)) {
field_name = StrCat("\"", field->full_name(), "\"");
field_name = absl::StrCat("\"", field->full_name(), "\"");
}
format("::_pbi::VerifyUTF8(str, $1$)", field_name);
switch (level) {
@ -998,7 +999,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
format(
"ctx->set_lazy_eager_verify_func($1$);\n",
eager_verify
? StrCat("&", ClassName(field->message_type(), true),
? absl::StrCat("&", ClassName(field->message_type(), true),
"::InternalVerify")
: "nullptr");
}
@ -1087,12 +1088,12 @@ void ParseFunctionGenerator::GenerateFieldBody(
{{"name", FieldName(field)},
{"primitive_type", PrimitiveTypeName(options_, field->cpp_type())}});
if (field->is_repeated()) {
format.AddMap({{"put_field", StrCat("add_", FieldName(field))},
{"mutable_field", StrCat("add_", FieldName(field))}});
format.AddMap({{"put_field", absl::StrCat("add_", FieldName(field))},
{"mutable_field", absl::StrCat("add_", FieldName(field))}});
} else {
format.AddMap(
{{"put_field", StrCat("set_", FieldName(field))},
{"mutable_field", StrCat("mutable_", FieldName(field))}});
{{"put_field", absl::StrCat("set_", FieldName(field))},
{"mutable_field", absl::StrCat("mutable_", FieldName(field))}});
}
uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype);
switch (wiretype) {
@ -1353,7 +1354,7 @@ void PopulateFastFieldEntry(const Descriptor* descriptor,
TailCallTableInfo::FastFieldInfo& info) {
.....
if (name == "V8S1") {
info.func_name = StrCat(
info.func_name = absl::StrCat(
"::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(", //
ClassName(descriptor), //
", ", //
@ -1362,7 +1363,7 @@ void PopulateFastFieldEntry(const Descriptor* descriptor,
HasHasbit(field) ? entry.hasbit_idx : 63, //
">()");
} else if (name == "V32S1") {
info.func_name = StrCat(
info.func_name = absl::StrCat(
"::_pbi::TcParser::SingularVarintNoZag1<uint32_t, offsetof(", //
ClassName(descriptor), //
", ", //
@ -1371,7 +1372,7 @@ void PopulateFastFieldEntry(const Descriptor* descriptor,
HasHasbit(field) ? entry.hasbit_idx : 63, //
">()");
} else if (name == "V64S1") {
info.func_name = StrCat(
info.func_name = absl::StrCat(
"::_pbi::TcParser::SingularVarintNoZag1<uint64_t, offsetof(", //
ClassName(descriptor), //
", ", //
@ -1380,7 +1381,7 @@ void PopulateFastFieldEntry(const Descriptor* descriptor,
HasHasbit(field) ? entry.hasbit_idx : 63, //
">()");
} else {
info.func_name = StrCat("::_pbi::TcParser::Fast", name);
info.func_name = absl::StrCat("::_pbi::TcParser::Fast", name);
}
info.aux_idx = aux_idx;
}

@ -37,6 +37,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/cpp/helpers.h>
namespace google {
@ -108,10 +109,10 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
bool cold = ShouldSplit(descriptor, options);
(*variables)["cached_byte_size_field"] =
MakeVarintCachedSizeFieldName(descriptor, cold);
(*variables)["tag"] = StrCat(internal::WireFormat::MakeTag(descriptor));
(*variables)["tag"] = absl::StrCat(internal::WireFormat::MakeTag(descriptor));
int fixed_size = FixedSize(descriptor->type());
if (fixed_size != -1) {
(*variables)["fixed_size"] = StrCat(fixed_size);
(*variables)["fixed_size"] = absl::StrCat(fixed_size);
}
(*variables)["wire_format_field_type"] = FieldDescriptorProto_Type_Name(
static_cast<FieldDescriptorProto_Type>(descriptor->type()));

@ -49,6 +49,8 @@ class PrimitiveFieldGenerator : public FieldGenerator {
public:
PrimitiveFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete;
PrimitiveFieldGenerator& operator=(const PrimitiveFieldGenerator&) = delete;
~PrimitiveFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -67,15 +69,15 @@ class PrimitiveFieldGenerator : public FieldGenerator {
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
};
class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
public:
PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
PrimitiveOneofFieldGenerator(const PrimitiveOneofFieldGenerator&) = delete;
PrimitiveOneofFieldGenerator& operator=(const PrimitiveOneofFieldGenerator&) =
delete;
~PrimitiveOneofFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -83,15 +85,16 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveOneofFieldGenerator);
};
class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
public:
RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
RepeatedPrimitiveFieldGenerator(const RepeatedPrimitiveFieldGenerator&) =
delete;
RepeatedPrimitiveFieldGenerator& operator=(
const RepeatedPrimitiveFieldGenerator&) = delete;
~RepeatedPrimitiveFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -113,9 +116,6 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator);
};
} // namespace cpp

@ -84,6 +84,8 @@ void ServiceGenerator::GenerateInterface(io::Printer* printer) {
" // This class should be treated as an abstract interface.\n"
" inline $classname$() {};\n"
" public:\n"
" $classname$(const $classname$&) = delete;\n"
" $classname$& operator=(const $classname$&) = delete;\n"
" virtual ~$classname$();\n");
printer->Indent();
@ -114,8 +116,6 @@ void ServiceGenerator::GenerateInterface(io::Printer* printer) {
printer->Outdent();
format(
"\n"
" private:\n"
" GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$);\n"
"};\n"
"\n");
}
@ -132,6 +132,8 @@ void ServiceGenerator::GenerateStubDefinition(io::Printer* printer) {
"$classname$_Stub(::$proto_ns$::RpcChannel* channel);\n"
"$classname$_Stub(::$proto_ns$::RpcChannel* channel,\n"
" ::$proto_ns$::Service::ChannelOwnership ownership);\n"
"$classname$_Stub(const $classname$_Stub&) = delete;\n"
"$classname$_Stub& operator=(const $classname$_Stub&) = delete;\n"
"~$classname$_Stub();\n"
"\n"
"inline ::$proto_ns$::RpcChannel* channel() { return channel_; }\n"
@ -146,7 +148,6 @@ void ServiceGenerator::GenerateStubDefinition(io::Printer* printer) {
" private:\n"
" ::$proto_ns$::RpcChannel* channel_;\n"
" bool owns_channel_;\n"
" GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$_Stub);\n"
"};\n"
"\n");
}
@ -244,9 +245,6 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
const MethodDescriptor* method = descriptor_->method(i);
Formatter format_method(printer, vars_);
InitMethodVariables(method, options_, &format_method);
// Note: down_cast does not work here because it only works on pointers,
// not references.
format_method(
" case $1$:\n"
" $name$(controller,\n"

@ -60,6 +60,8 @@ class ServiceGenerator {
explicit ServiceGenerator(const ServiceDescriptor* descriptor,
const std::map<std::string, std::string>& vars,
const Options& options);
ServiceGenerator(const ServiceGenerator&) = delete;
ServiceGenerator& operator=(const ServiceGenerator&) = delete;
~ServiceGenerator();
// Header stuff.
@ -112,7 +114,6 @@ class ServiceGenerator {
int index_in_metadata_;
friend class FileGenerator;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
};
} // namespace cpp

@ -36,6 +36,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/descriptor.pb.h>
@ -57,7 +58,7 @@ void SetStringVariables(const FieldDescriptor* descriptor,
(*variables)["default"] = DefaultValue(options, descriptor);
(*variables)["default_length"] =
StrCat(descriptor->default_value_string().length());
absl::StrCat(descriptor->default_value_string().length());
(*variables)["default_variable_name"] = MakeDefaultName(descriptor);
(*variables)["default_variable_field"] = MakeDefaultFieldName(descriptor);
@ -67,7 +68,7 @@ void SetStringVariables(const FieldDescriptor* descriptor,
(*variables)["lazy_variable_args"] = "";
} else {
(*variables)["lazy_variable"] =
StrCat(QualifiedClassName(descriptor->containing_type(), options),
absl::StrCat(QualifiedClassName(descriptor->containing_type(), options),
"::", MakeDefaultFieldName(descriptor));
(*variables)["default_string"] = (*variables)["lazy_variable"] + ".get()";
@ -89,7 +90,7 @@ void SetStringVariables(const FieldDescriptor* descriptor,
if (options.opensource_runtime) {
(*variables)["string_piece"] = "::std::string";
} else {
(*variables)["string_piece"] = "::StringPiece";
(*variables)["string_piece"] = "::absl::string_view";
}
}
@ -571,7 +572,7 @@ StringOneofFieldGenerator::StringOneofFieldGenerator(
SetCommonOneofFieldVariables(descriptor, &variables_);
variables_["field_name"] = UnderscoresToCamelCase(descriptor->name(), true);
variables_["oneof_index"] =
StrCat(descriptor->containing_oneof()->index());
absl::StrCat(descriptor->containing_oneof()->index());
}
StringOneofFieldGenerator::~StringOneofFieldGenerator() {}
@ -716,7 +717,7 @@ void RepeatedStringFieldGenerator::GenerateAccessorDeclarations(
if (!options_.opensource_runtime) {
format(
"$deprecated_attr$void ${1$set_$name$$}$(int index, "
"StringPiece value);\n",
"absl::string_view value);\n",
descriptor_);
}
format(
@ -729,7 +730,7 @@ void RepeatedStringFieldGenerator::GenerateAccessorDeclarations(
descriptor_);
if (!options_.opensource_runtime) {
format(
"$deprecated_attr$void ${1$add_$name$$}$(StringPiece value);\n",
"$deprecated_attr$void ${1$add_$name$$}$(absl::string_view value);\n",
descriptor_);
}
format(
@ -811,7 +812,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
if (!options_.opensource_runtime) {
format(
"inline void "
"$classname$::set_$name$(int index, StringPiece value) {\n"
"$classname$::set_$name$(int index, absl::string_view value) {\n"
" $field$.Mutable(index)->assign(value.data(), value.size());\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
@ -847,7 +848,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n");
if (!options_.opensource_runtime) {
format(
"inline void $classname$::add_$name$(StringPiece value) {\n"
"inline void $classname$::add_$name$(absl::string_view value) {\n"
" $field$.Add()->assign(value.data(), value.size());\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n"

@ -49,6 +49,8 @@ class StringFieldGenerator : public FieldGenerator {
public:
StringFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
StringFieldGenerator(const StringFieldGenerator&) = delete;
StringFieldGenerator& operator=(const StringFieldGenerator&) = delete;
~StringFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -78,13 +80,15 @@ class StringFieldGenerator : public FieldGenerator {
private:
bool inlined_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator);
};
class StringOneofFieldGenerator : public StringFieldGenerator {
public:
StringOneofFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
StringOneofFieldGenerator(const StringOneofFieldGenerator&) = delete;
StringOneofFieldGenerator& operator=(const StringOneofFieldGenerator&) =
delete;
~StringOneofFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -96,15 +100,15 @@ class StringOneofFieldGenerator : public StringFieldGenerator {
void GenerateMessageClearingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOneofFieldGenerator);
};
class RepeatedStringFieldGenerator : public FieldGenerator {
public:
RepeatedStringFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
RepeatedStringFieldGenerator(const RepeatedStringFieldGenerator&) = delete;
RepeatedStringFieldGenerator& operator=(const RepeatedStringFieldGenerator&) =
delete;
~RepeatedStringFieldGenerator() override;
// implements FieldGenerator ---------------------------------------
@ -122,9 +126,6 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator);
};
} // namespace cpp

@ -50,7 +50,7 @@
#include <vector>
#include <google/protobuf/compiler/cpp/unittest.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/string_view.h"
#ifndef _MSC_VER
// We exclude this large proto because it's too large for
// visual studio to compile (report internal errors).
@ -64,7 +64,7 @@
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/casts.h>
#include "absl/base/casts.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/compiler/cpp/test_bad_identifiers.pb.h>
@ -601,7 +601,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, UpcastCopyFrom) {
TestUtil::SetAllFields(&message1);
const Message* source = implicit_cast<const Message*>(&message1);
const Message* source = absl::implicit_cast<const Message*>(&message1);
message2.CopyFrom(*source);
TestUtil::ExpectAllFieldsSet(message2);
@ -1821,7 +1821,7 @@ TEST_F(OneofTest, UpcastCopyFrom) {
message1.mutable_foogroup()->set_a(123);
EXPECT_TRUE(message1.has_foogroup());
const Message* source = implicit_cast<const Message*>(&message1);
const Message* source = absl::implicit_cast<const Message*>(&message1);
message2.CopyFrom(*source);
EXPECT_TRUE(message2.has_foogroup());

@ -58,6 +58,8 @@ cc_library(
deps = [
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings",
],
)

@ -80,12 +80,12 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print("[pbr::OriginalName(\"$original_name$\", PreferredAlias = false)] $name$ = $number$,\n",
"original_name", original_name,
"name", name,
"number", StrCat(number));
"number", absl::StrCat(number));
} else {
printer->Print("[pbr::OriginalName(\"$original_name$\")] $name$ = $number$,\n",
"original_name", original_name,
"name", name,
"number", StrCat(number));
"number", absl::StrCat(number));
}
}
printer->Outdent();

@ -63,13 +63,13 @@ void FieldGeneratorBase::SetCommonFieldVariables(
uint tag = internal::WireFormat::MakeTag(descriptor_);
uint8_t tag_array[5];
io::CodedOutputStream::WriteTagToArray(tag, tag_array);
std::string tag_bytes = StrCat(tag_array[0]);
std::string tag_bytes = absl::StrCat(tag_array[0]);
for (int i = 1; i < part_tag_size; i++) {
tag_bytes += ", " + StrCat(tag_array[i]);
tag_bytes += ", " + absl::StrCat(tag_array[i]);
}
(*variables)["tag"] = StrCat(tag);
(*variables)["tag_size"] = StrCat(tag_size);
(*variables)["tag"] = absl::StrCat(tag);
(*variables)["tag_size"] = absl::StrCat(tag_size);
(*variables)["tag_bytes"] = tag_bytes;
if (descriptor_->type() == FieldDescriptor::Type::TYPE_GROUP) {
@ -77,12 +77,12 @@ void FieldGeneratorBase::SetCommonFieldVariables(
descriptor_->number(),
internal::WireFormatLite::WIRETYPE_END_GROUP);
io::CodedOutputStream::WriteTagToArray(tag, tag_array);
tag_bytes = StrCat(tag_array[0]);
tag_bytes = absl::StrCat(tag_array[0]);
for (int i = 1; i < part_tag_size; i++) {
tag_bytes += ", " + StrCat(tag_array[i]);
tag_bytes += ", " + absl::StrCat(tag_array[i]);
}
variables_["end_tag"] = StrCat(tag);
variables_["end_tag"] = absl::StrCat(tag);
variables_["end_tag_bytes"] = tag_bytes;
}
@ -108,8 +108,8 @@ void FieldGeneratorBase::SetCommonFieldVariables(
(*variables)["has_not_property_check"] = "!" + (*variables)["has_property_check"];
(*variables)["other_has_not_property_check"] = "!" + (*variables)["other_has_property_check"];
if (presenceIndex_ != -1) {
std::string hasBitsNumber = StrCat(presenceIndex_ / 32);
std::string hasBitsMask = StrCat(1 << (presenceIndex_ % 32));
std::string hasBitsNumber = absl::StrCat(presenceIndex_ / 32);
std::string hasBitsMask = absl::StrCat(1 << (presenceIndex_ % 32));
(*variables)["has_field_check"] = "(_hasBits" + hasBitsNumber + " & " + hasBitsMask + ") != 0";
(*variables)["set_has_field"] = "_hasBits" + hasBitsNumber + " |= " + hasBitsMask;
(*variables)["clear_has_field"] = "_hasBits" + hasBitsNumber + " &= ~" + hasBitsMask;
@ -325,7 +325,7 @@ std::string FieldGeneratorBase::GetStringDefaultValueInternal(const FieldDescrip
else
return "global::System.Text.Encoding.UTF8.GetString(global::System."
"Convert.FromBase64String(\"" +
StringToBase64(descriptor->default_value_string()) + "\"), 0, " + StrCat(descriptor->default_value_string().length()) + ")";
StringToBase64(descriptor->default_value_string()) + "\"), 0, " + absl::StrCat(descriptor->default_value_string().length()) + ")";
}
std::string FieldGeneratorBase::GetBytesDefaultValueInternal(const FieldDescriptor* descriptor) {
@ -361,7 +361,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
} else if (std::isnan(value)) {
return "double.NaN";
}
return StrCat(value) + "D";
return absl::StrCat(value) + "D";
}
case FieldDescriptor::TYPE_FLOAT: {
float value = descriptor->default_value_float();
@ -372,18 +372,18 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
} else if (std::isnan(value)) {
return "float.NaN";
}
return StrCat(value) + "F";
return absl::StrCat(value) + "F";
}
case FieldDescriptor::TYPE_INT64:
return StrCat(descriptor->default_value_int64()) + "L";
return absl::StrCat(descriptor->default_value_int64()) + "L";
case FieldDescriptor::TYPE_UINT64:
return StrCat(descriptor->default_value_uint64()) + "UL";
return absl::StrCat(descriptor->default_value_uint64()) + "UL";
case FieldDescriptor::TYPE_INT32:
return StrCat(descriptor->default_value_int32());
return absl::StrCat(descriptor->default_value_int32());
case FieldDescriptor::TYPE_FIXED64:
return StrCat(descriptor->default_value_uint64()) + "UL";
return absl::StrCat(descriptor->default_value_uint64()) + "UL";
case FieldDescriptor::TYPE_FIXED32:
return StrCat(descriptor->default_value_uint32());
return absl::StrCat(descriptor->default_value_uint32());
case FieldDescriptor::TYPE_BOOL:
if (descriptor->default_value_bool()) {
return "true";
@ -395,15 +395,15 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
case FieldDescriptor::TYPE_BYTES:
return GetBytesDefaultValueInternal(descriptor);
case FieldDescriptor::TYPE_UINT32:
return StrCat(descriptor->default_value_uint32());
return absl::StrCat(descriptor->default_value_uint32());
case FieldDescriptor::TYPE_SFIXED32:
return StrCat(descriptor->default_value_int32());
return absl::StrCat(descriptor->default_value_int32());
case FieldDescriptor::TYPE_SFIXED64:
return StrCat(descriptor->default_value_int64()) + "L";
return absl::StrCat(descriptor->default_value_int64()) + "L";
case FieldDescriptor::TYPE_SINT32:
return StrCat(descriptor->default_value_int32());
return absl::StrCat(descriptor->default_value_int32());
case FieldDescriptor::TYPE_SINT64:
return StrCat(descriptor->default_value_int64()) + "L";
return absl::StrCat(descriptor->default_value_int64()) + "L";
default:
GOOGLE_LOG(FATAL)<< "Unknown field type.";
return "";
@ -411,7 +411,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
}
std::string FieldGeneratorBase::number() {
return StrCat(descriptor_->number());
return absl::StrCat(descriptor_->number());
}
std::string FieldGeneratorBase::capitalized_type_name() {

@ -55,6 +55,10 @@
#include <google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h>
#include <google/protobuf/compiler/csharp/csharp_wrapper_field.h>
#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "absl/strings/ascii.h"
namespace google {
namespace protobuf {
namespace compiler {
@ -218,18 +222,18 @@ std::string ShoutyToPascalCase(const std::string& input) {
char previous = '_';
for (int i = 0; i < input.size(); i++) {
char current = input[i];
if (!ascii_isalnum(current)) {
if (!absl::ascii_isalnum(current)) {
previous = current;
continue;
}
if (!ascii_isalnum(previous)) {
result += ascii_toupper(current);
} else if (ascii_isdigit(previous)) {
result += ascii_toupper(current);
} else if (ascii_islower(previous)) {
if (!absl::ascii_isalnum(previous)) {
result += absl::ascii_toupper(current);
} else if (absl::ascii_isdigit(previous)) {
result += absl::ascii_toupper(current);
} else if (absl::ascii_islower(previous)) {
result += current;
} else {
result += ascii_tolower(current);
result += absl::ascii_tolower(current);
}
previous = current;
}
@ -247,7 +251,7 @@ std::string TryRemovePrefix(const std::string& prefix, const std::string& value)
std::string prefix_to_match = "";
for (size_t i = 0; i < prefix.size(); i++) {
if (prefix[i] != '_') {
prefix_to_match += ascii_tolower(prefix[i]);
prefix_to_match += absl::ascii_tolower(prefix[i]);
}
}
@ -260,7 +264,7 @@ std::string TryRemovePrefix(const std::string& prefix, const std::string& value)
if (value[value_index] == '_') {
continue;
}
if (ascii_tolower(value[value_index]) != prefix_to_match[prefix_index++]) {
if (absl::ascii_tolower(value[value_index]) != prefix_to_match[prefix_index++]) {
// Failed to match the prefix - bail out early.
return value;
}
@ -294,7 +298,7 @@ std::string GetEnumValueName(const std::string& enum_name, const std::string& en
std::string result = ShoutyToPascalCase(stripped);
// Just in case we have an enum name of FOO and a value of FOO_2... make sure the returned
// string is a valid identifier.
if (ascii_isdigit(result[0])) {
if (absl::ascii_isdigit(result[0])) {
result = "_" + result;
}
return result;
@ -398,7 +402,7 @@ std::string GetFieldConstantName(const FieldDescriptor* field) {
std::string GetPropertyName(const FieldDescriptor* descriptor) {
// Names of members declared or overridden in the message.
static const auto& reserved_member_names = *new std::unordered_set<std::string>({
static const auto& reserved_member_names = *new absl::flat_hash_set<absl::string_view>({
"Types",
"Descriptor",
"Equals",

@ -49,6 +49,9 @@
#include <google/protobuf/compiler/csharp/csharp_message.h>
#include <google/protobuf/compiler/csharp/csharp_names.h>
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
namespace google {
namespace protobuf {
namespace compiler {
@ -161,7 +164,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < has_bit_field_count_; i++) {
// don't use arrays since all arrays are heap allocated, saving allocations
// use ints instead of bytes since bytes lack bitwise operators, saving casts
printer->Print("private int _hasBits$i$;\n", "i", StrCat(i));
printer->Print("private int _hasBits$i$;\n", "i", absl::StrCat(i));
}
WriteGeneratedCodeAttributes(printer);
@ -173,10 +176,10 @@ void MessageGenerator::Generate(io::Printer* printer) {
// Access the message descriptor via the relevant file descriptor or containing message descriptor.
if (!descriptor_->containing_type()) {
vars["descriptor_accessor"] = GetReflectionClassName(descriptor_->file())
+ ".Descriptor.MessageTypes[" + StrCat(descriptor_->index()) + "]";
+ ".Descriptor.MessageTypes[" + absl::StrCat(descriptor_->index()) + "]";
} else {
vars["descriptor_accessor"] = GetClassName(descriptor_->containing_type())
+ ".Descriptor.NestedTypes[" + StrCat(descriptor_->index()) + "]";
+ ".Descriptor.NestedTypes[" + absl::StrCat(descriptor_->index()) + "]";
}
WriteGeneratedCodeAttributes(printer);
@ -216,7 +219,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
"public const int $field_constant_name$ = $index$;\n",
"field_name", fieldDescriptor->name(),
"field_constant_name", GetFieldConstantName(fieldDescriptor),
"index", StrCat(fieldDescriptor->number()));
"index", absl::StrCat(fieldDescriptor->number()));
std::unique_ptr<FieldGeneratorBase> generator(
CreateFieldGeneratorInternal(fieldDescriptor));
generator->GenerateMembers(printer);
@ -240,7 +243,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
const FieldDescriptor* field = oneof->field(j);
printer->Print("$oneof_case_name$ = $index$,\n",
"oneof_case_name", GetOneofCaseName(field),
"index", StrCat(field->number()));
"index", absl::StrCat(field->number()));
}
printer->Outdent();
printer->Print("}\n");
@ -382,7 +385,7 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) {
"public $class_name$($class_name$ other) : this() {\n");
printer->Indent();
for (int i = 0; i < has_bit_field_count_; i++) {
printer->Print("_hasBits$i$ = other._hasBits$i$;\n", "i", StrCat(i));
printer->Print("_hasBits$i$ = other._hasBits$i$;\n", "i", absl::StrCat(i));
}
// Clone non-oneof fields first (treating optional proto3 fields as non-oneof)
for (int i = 0; i < descriptor_->field_count(); i++) {
@ -698,7 +701,7 @@ void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_pars
printer->Print(
"case $end_tag$:\n"
" return;\n",
"end_tag", StrCat(end_tag_));
"end_tag", absl::StrCat(end_tag_));
}
if (has_extension_ranges_) {
printer->Print(vars,
@ -727,13 +730,13 @@ void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_pars
printer->Print(
"case $packed_tag$:\n",
"packed_tag",
StrCat(
absl::StrCat(
internal::WireFormatLite::MakeTag(
field->number(),
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED)));
}
printer->Print("case $tag$: {\n", "tag", StrCat(tag));
printer->Print("case $tag$: {\n", "tag", absl::StrCat(tag));
printer->Indent();
std::unique_ptr<FieldGeneratorBase> generator(
CreateFieldGeneratorInternal(field));

@ -215,7 +215,7 @@ void PrimitiveFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {
} else {
printer->Print(
"size += $tag_size$ + $fixed_size$;\n",
"fixed_size", StrCat(fixedSize),
"fixed_size", absl::StrCat(fixedSize),
"tag_size", variables_["tag_size"]);
}
printer->Outdent();

@ -213,7 +213,7 @@ void ReflectionClassGenerator::WriteDescriptor(io::Printer* printer) {
for (int i = 0; i < file_->extension_count(); i++) {
extensions.push_back(GetFullExtensionName(file_->extension(i)));
}
printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", Join(extensions, ", "));
printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", absl::StrJoin(extensions, ", "));
}
else {
printer->Print("null, ");
@ -265,7 +265,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
for (int i = 0; i < descriptor->field_count(); i++) {
fields.push_back(GetPropertyName(descriptor->field(i)));
}
printer->Print("new[]{ \"$fields$\" }, ", "fields", Join(fields, "\", \""));
printer->Print("new[]{ \"$fields$\" }, ", "fields", absl::StrJoin(fields, "\", \""));
}
else {
printer->Print("null, ");
@ -278,7 +278,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
for (int i = 0; i < descriptor->oneof_decl_count(); i++) {
oneofs.push_back(UnderscoresToCamelCase(descriptor->oneof_decl(i)->name(), true));
}
printer->Print("new[]{ \"$oneofs$\" }, ", "oneofs", Join(oneofs, "\", \""));
printer->Print("new[]{ \"$oneofs$\" }, ", "oneofs", absl::StrJoin(oneofs, "\", \""));
}
else {
printer->Print("null, ");
@ -291,7 +291,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
for (int i = 0; i < descriptor->enum_type_count(); i++) {
enums.push_back(GetClassName(descriptor->enum_type(i)));
}
printer->Print("new[]{ typeof($enums$) }, ", "enums", Join(enums, "), typeof("));
printer->Print("new[]{ typeof($enums$) }, ", "enums", absl::StrJoin(enums, "), typeof("));
}
else {
printer->Print("null, ");
@ -303,7 +303,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
for (int i = 0; i < descriptor->extension_count(); i++) {
extensions.push_back(GetFullExtensionName(descriptor->extension(i)));
}
printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", Join(extensions, ", "));
printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", absl::StrJoin(extensions, ", "));
}
else {
printer->Print("null, ");

@ -50,6 +50,7 @@
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_join.h"
#include <google/protobuf/io/io_win32.h>
#ifdef _WIN32
@ -297,7 +298,7 @@ static std::string CanonicalizePath(std::string path) {
canonical_parts.push_back(part);
}
}
std::string result = Join(canonical_parts, "/");
std::string result = absl::StrJoin(canonical_parts, "/");
if (!path.empty() && path[0] == '/') {
// Restore leading slash.
result = '/' + result;

@ -35,7 +35,6 @@
#include <google/protobuf/compiler/importer.h>
#include <memory>
#include <unordered_map>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
@ -46,8 +45,9 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/container/flat_hash_map.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/strutil.h>
namespace google {
@ -93,24 +93,22 @@ class MockSourceTree : public SourceTree {
MockSourceTree() {}
~MockSourceTree() override {}
void AddFile(const std::string& name, const char* contents) {
void AddFile(absl::string_view name, const char* contents) {
files_[name] = contents;
}
// implements SourceTree -------------------------------------------
io::ZeroCopyInputStream* Open(const std::string& filename) override {
const char* contents = FindPtrOrNull(files_, filename);
if (contents == nullptr) {
return nullptr;
} else {
return new io::ArrayInputStream(contents, strlen(contents));
}
auto it = files_.find(filename);
if (it == files_.end()) return nullptr;
return new io::ArrayInputStream(it->second,
static_cast<int>(strlen(it->second)));
}
std::string GetLastErrorMessage() override { return "File not found."; }
private:
std::unordered_map<std::string, const char*> files_;
absl::flat_hash_map<std::string, const char*> files_;
};
// ===================================================================

@ -32,10 +32,10 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/field.h>
#include <google/protobuf/compiler/java/helpers.h>
#include <google/protobuf/compiler/java/name_resolver.h>
#include <google/protobuf/stubs/map_util.h>
namespace google {
namespace protobuf {
@ -159,8 +159,8 @@ void Context::InitializeFieldGeneratorInfoForFields(
// For fields conflicting with some other fields, we append the field
// number to their field names in generated code to avoid conflicts.
if (is_conflict[i]) {
info.name += StrCat(field->number());
info.capitalized_name += StrCat(field->number());
info.name += absl::StrCat(field->number());
info.capitalized_name += absl::StrCat(field->number());
info.disambiguated_reason = conflict_reason[i];
}
field_generator_info_map_[field] = info;
@ -169,24 +169,22 @@ void Context::InitializeFieldGeneratorInfoForFields(
const FieldGeneratorInfo* Context::GetFieldGeneratorInfo(
const FieldDescriptor* field) const {
const FieldGeneratorInfo* result =
FindOrNull(field_generator_info_map_, field);
if (result == NULL) {
auto it = field_generator_info_map_.find(field);
if (it == field_generator_info_map_.end()) {
GOOGLE_LOG(FATAL) << "Can not find FieldGeneratorInfo for field: "
<< field->full_name();
}
return result;
return &it->second;
}
const OneofGeneratorInfo* Context::GetOneofGeneratorInfo(
const OneofDescriptor* oneof) const {
const OneofGeneratorInfo* result =
FindOrNull(oneof_generator_info_map_, oneof);
if (result == NULL) {
auto it = oneof_generator_info_map_.find(oneof);
if (it == oneof_generator_info_map_.end()) {
GOOGLE_LOG(FATAL) << "Can not find OneofGeneratorInfo for oneof: "
<< oneof->name();
}
return result;
return &it->second;
}
// Does this message class have generated parsing, serialization, and other

@ -31,11 +31,11 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__
#define GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__
#include <map>
#include <memory>
#include <vector>
#include <google/protobuf/stubs/common.h>
#include "absl/container/flat_hash_map.h"
#include <google/protobuf/compiler/java/options.h>
namespace google {
@ -97,9 +97,9 @@ class Context {
const std::vector<const FieldDescriptor*>& fields);
std::unique_ptr<ClassNameResolver> name_resolver_;
std::map<const FieldDescriptor*, FieldGeneratorInfo>
absl::flat_hash_map<const FieldDescriptor*, FieldGeneratorInfo>
field_generator_info_map_;
std::map<const OneofDescriptor*, OneofGeneratorInfo>
absl::flat_hash_map<const OneofDescriptor*, OneofGeneratorInfo>
oneof_generator_info_map_;
Options options_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context);

@ -39,6 +39,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -105,8 +106,8 @@ void EnumGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < canonical_values_.size(); i++) {
std::map<std::string, std::string> vars;
vars["name"] = canonical_values_[i]->name();
vars["index"] = StrCat(canonical_values_[i]->index());
vars["number"] = StrCat(canonical_values_[i]->number());
vars["index"] = absl::StrCat(canonical_values_[i]->index());
vars["number"] = absl::StrCat(canonical_values_[i]->number());
WriteEnumValueDocComment(printer, canonical_values_[i]);
if (canonical_values_[i]->options().deprecated()) {
printer->Print("@java.lang.Deprecated\n");
@ -148,7 +149,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->value_count(); i++) {
std::map<std::string, std::string> vars;
vars["name"] = descriptor_->value(i)->name();
vars["number"] = StrCat(descriptor_->value(i)->number());
vars["number"] = absl::StrCat(descriptor_->value(i)->number());
vars["{"] = "";
vars["}"] = "";
vars["deprecation"] = descriptor_->value(i)->options().deprecated()
@ -220,7 +221,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < canonical_values_.size(); i++) {
printer->Print("case $number$: return $name$;\n", "name",
canonical_values_[i]->name(), "number",
StrCat(canonical_values_[i]->number()));
absl::StrCat(canonical_values_[i]->number()));
}
printer->Outdent();
@ -290,7 +291,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
" return $file$.getDescriptor().getEnumTypes().get($index$);\n",
"file",
name_resolver_->GetClassName(descriptor_->file(), immutable_api_),
"index", StrCat(descriptor_->index()));
"index", absl::StrCat(descriptor_->index()));
} else {
printer->Print(
" return $parent$.$descriptor$.getEnumTypes().get($index$);\n",
@ -303,7 +304,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
.no_standard_descriptor_accessor()
? "getDefaultInstance().getDescriptorForType()"
: "getDescriptor()",
"index", StrCat(descriptor_->index()));
"index", absl::StrCat(descriptor_->index()));
}
printer->Print(

@ -42,6 +42,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -72,10 +73,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = StrCat(
absl::StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = absl::StrCat(
static_cast<int32_t>(internal::WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
(*variables)["tag_size"] = absl::StrCat(
internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler

@ -43,6 +43,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -80,10 +81,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = StrCat(
absl::StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = absl::StrCat(
static_cast<int32_t>(internal::WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
(*variables)["tag_size"] = absl::StrCat(
internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
@ -98,10 +99,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
if (HasHasbit(descriptor)) {
if (!context->options().opensource_runtime) {
(*variables)["bit_field_id"] = StrCat(messageBitIndex / 32);
(*variables)["bit_field_id"] = absl::StrCat(messageBitIndex / 32);
(*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
(*variables)["bit_field_mask"] =
StrCat(1 << (messageBitIndex % 32));
absl::StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

@ -39,12 +39,12 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
#include <google/protobuf/compiler/java/name_resolver.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/map_util.h>
namespace google {
namespace protobuf {
@ -89,7 +89,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < canonical_values_.size(); i++) {
std::map<std::string, std::string> vars;
vars["name"] = canonical_values_[i]->name();
vars["number"] = StrCat(canonical_values_[i]->number());
vars["number"] = absl::StrCat(canonical_values_[i]->number());
WriteEnumValueDocComment(printer, canonical_values_[i]);
if (canonical_values_[i]->options().deprecated()) {
printer->Print("@java.lang.Deprecated\n");
@ -123,7 +123,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->value_count(); i++) {
std::map<std::string, std::string> vars;
vars["name"] = descriptor_->value(i)->name();
vars["number"] = StrCat(descriptor_->value(i)->number());
vars["number"] = absl::StrCat(descriptor_->value(i)->number());
vars["{"] = "";
vars["}"] = "";
vars["deprecation"] = descriptor_->value(i)->options().deprecated()
@ -182,7 +182,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < canonical_values_.size(); i++) {
printer->Print("case $number$: return $name$;\n", "name",
canonical_values_[i]->name(), "number",
StrCat(canonical_values_[i]->number()));
absl::StrCat(canonical_values_[i]->number()));
}
printer->Outdent();

@ -36,6 +36,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -74,9 +75,9 @@ void ExtensionGenerator::InitTemplateVars(
vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor);
vars["containing_type"] =
name_resolver->GetClassName(descriptor->containing_type(), immutable);
vars["number"] = StrCat(descriptor->number());
vars["number"] = absl::StrCat(descriptor->number());
vars["constant_name"] = FieldConstantName(descriptor);
vars["index"] = StrCat(descriptor->index());
vars["index"] = absl::StrCat(descriptor->index());
vars["default"] = descriptor->is_repeated()
? ""
: DefaultValue(descriptor, immutable, name_resolver,
@ -159,7 +160,7 @@ int ImmutableExtensionGenerator::GenerateNonNestedInitializationCode(
printer->Print(
"$name$.internalInit(descriptor.getExtensions().get($index$));\n",
"name", UnderscoresToCamelCaseCheckReserved(descriptor_), "index",
StrCat(descriptor_->index()));
absl::StrCat(descriptor_->index()));
bytecode_estimate += 21;
}
return bytecode_estimate;

@ -40,6 +40,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/enum_field.h>
@ -250,7 +251,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
(*variables)["capitalized_name"] = info->capitalized_name;
(*variables)["disambiguated_reason"] = info->disambiguated_reason;
(*variables)["constant_name"] = FieldConstantName(descriptor);
(*variables)["number"] = StrCat(descriptor->number());
(*variables)["number"] = absl::StrCat(descriptor->number());
(*variables)["kt_dsl_builder"] = "_builder";
// These variables are placeholders to pick out the beginning and ends of
// identifiers for annotations (when doing so with existing variables would
@ -285,13 +286,13 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor,
(*variables)["oneof_name"] = info->name;
(*variables)["oneof_capitalized_name"] = info->capitalized_name;
(*variables)["oneof_index"] =
StrCat(descriptor->containing_oneof()->index());
absl::StrCat(descriptor->containing_oneof()->index());
(*variables)["oneof_stored_type"] = GetOneofStoredType(descriptor);
(*variables)["set_oneof_case_message"] =
info->name + "Case_ = " + StrCat(descriptor->number());
info->name + "Case_ = " + absl::StrCat(descriptor->number());
(*variables)["clear_oneof_case_message"] = info->name + "Case_ = 0";
(*variables)["has_oneof_case_message"] =
info->name + "Case_ == " + StrCat(descriptor->number());
info->name + "Case_ == " + absl::StrCat(descriptor->number());
}
void PrintExtraFieldInfo(const std::map<std::string, std::string>& variables,

@ -42,6 +42,7 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/enum.h>
#include <google/protobuf/compiler/java/enum_lite.h>
@ -175,10 +176,10 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate,
if ((*bytecode_estimate) > bytesPerMethod) {
++(*method_num);
printer->Print(chain_statement, "method_num", StrCat(*method_num));
printer->Print(chain_statement, "method_num", absl::StrCat(*method_num));
printer->Outdent();
printer->Print("}\n");
printer->Print(method_decl, "method_num", StrCat(*method_num));
printer->Print(method_decl, "method_num", absl::StrCat(*method_num));
printer->Indent();
*bytecode_estimate = 0;
}
@ -567,11 +568,11 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
" $scope$.getExtensions().get($index$),\n"
" (com.google.protobuf.Message) defaultExtensionInstance);\n"
"}\n",
"scope", scope, "index", StrCat(field->index()), "class",
"scope", scope, "index", absl::StrCat(field->index()), "class",
name_resolver_->GetImmutableClassName(field->message_type()));
} else {
printer->Print("registry.add($scope$.getExtensions().get($index$));\n",
"scope", scope, "index", StrCat(field->index()));
"scope", scope, "index", absl::StrCat(field->index()));
}
}
printer->Print(

@ -42,12 +42,14 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/name_resolver.h>
#include <google/protobuf/compiler/java/names.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/hash.h> // for hash<T *>
// Must be last.
#include <google/protobuf/port_def.inc>
@ -157,8 +159,8 @@ void PrintEnumVerifierLogic(io::Printer* printer,
const char* var_name,
const char* terminating_string, bool enforce_lite) {
std::string enum_verifier_string =
enforce_lite ? StrCat(var_name, ".internalGetVerifier()")
: StrCat(
enforce_lite ? absl::StrCat(var_name, ".internalGetVerifier()")
: absl::StrCat(
"new com.google.protobuf.Internal.EnumVerifier() {\n"
" @java.lang.Override\n"
" public boolean isInRange(int number) {\n"
@ -169,7 +171,7 @@ void PrintEnumVerifierLogic(io::Printer* printer,
" }");
printer->Print(
variables,
StrCat(enum_verifier_string, terminating_string).c_str());
absl::StrCat(enum_verifier_string, terminating_string).c_str());
}
std::string UnderscoresToCamelCase(const std::string& input,
@ -291,7 +293,7 @@ std::string EscapeKotlinKeywords(std::string name) {
escaped_packages.push_back(package);
}
}
return Join(escaped_packages, ".");
return absl::StrJoin(escaped_packages, ".");
}
std::string UniqueFileScopeIdentifier(const Descriptor* descriptor) {
@ -602,14 +604,14 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
// of FieldDescriptor to call.
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return StrCat(field->default_value_int32());
return absl::StrCat(field->default_value_int32());
case FieldDescriptor::CPPTYPE_UINT32:
// Need to print as a signed int since Java has no unsigned.
return StrCat(static_cast<int32_t>(field->default_value_uint32()));
return absl::StrCat(static_cast<int32_t>(field->default_value_uint32()));
case FieldDescriptor::CPPTYPE_INT64:
return StrCat(field->default_value_int64()) + "L";
return absl::StrCat(field->default_value_int64()) + "L";
case FieldDescriptor::CPPTYPE_UINT64:
return StrCat(static_cast<int64_t>(field->default_value_uint64())) +
return absl::StrCat(static_cast<int64_t>(field->default_value_uint64())) +
"L";
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field->default_value_double();
@ -643,19 +645,19 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
// See comments in Internal.java for gory details.
return strings::Substitute(
"com.google.protobuf.Internal.bytesDefaultValue(\"$0\")",
CEscape(field->default_value_string()));
absl::CEscape(field->default_value_string()));
} else {
return "com.google.protobuf.ByteString.EMPTY";
}
} else {
if (AllAscii(field->default_value_string())) {
// All chars are ASCII. In this case CEscape() works fine.
return "\"" + CEscape(field->default_value_string()) + "\"";
return "\"" + absl::CEscape(field->default_value_string()) + "\"";
} else {
// See comments in Internal.java for gory details.
return strings::Substitute(
"com.google.protobuf.Internal.stringDefaultValue(\"$0\")",
CEscape(field->default_value_string()));
absl::CEscape(field->default_value_string()));
}
}
@ -728,7 +730,7 @@ const char* bit_masks[] = {
std::string GetBitFieldName(int index) {
std::string varName = "bitField";
varName += StrCat(index);
varName += absl::StrCat(index);
varName += "_";
return varName;
}

@ -44,6 +44,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
@ -115,7 +117,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
std::map<std::string, std::string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
vars["index"] = StrCat(descriptor_->index());
vars["index"] = absl::StrCat(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
if (descriptor_->containing_type() != NULL) {
vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type());
@ -159,7 +161,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
int bytecode_estimate = 0;
std::map<std::string, std::string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
vars["index"] = StrCat(descriptor_->index());
vars["index"] = absl::StrCat(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
if (descriptor_->containing_type() != NULL) {
vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type());
@ -432,7 +434,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
vars["oneof_index"] = StrCat((oneof)->index());
vars["oneof_index"] = absl::StrCat((oneof)->index());
vars["{"] = "";
vars["}"] = "";
// oneofCase_ and oneof_
@ -455,7 +457,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"$deprecation$$field_name$($field_number$),\n", "deprecation",
field->options().deprecated() ? "@java.lang.Deprecated " : "",
"field_name", ToUpper(field->name()), "field_number",
StrCat(field->number()));
absl::StrCat(field->number()));
printer->Annotate("field_name", field);
}
printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
@ -486,7 +488,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(" case $field_number$: return $field_name$;\n",
"field_number", StrCat(field->number()),
"field_number", absl::StrCat(field->number()),
"field_name", ToUpper(field->name()));
}
printer->Print(
@ -519,7 +521,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->field_count(); i++) {
printer->Print("public static final int $constant_name$ = $number$;\n",
"constant_name", FieldConstantName(descriptor_->field(i)),
"number", StrCat(descriptor_->field(i)->number()));
"number", absl::StrCat(descriptor_->field(i)->number()));
printer->Annotate("constant_name", descriptor_->field(i));
field_generators_.get(descriptor_->field(i)).GenerateMembers(printer);
printer->Print("\n");
@ -835,7 +837,7 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods(
printer->Print(
"case $number$:\n"
" return internalGet$capitalized_name$();\n",
"number", StrCat(field->number()), "capitalized_name",
"number", absl::StrCat(field->number()), "capitalized_name",
info->capitalized_name);
}
printer->Print(
@ -1045,7 +1047,7 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("case $field_number$:\n", "field_number",
StrCat(field->number()));
absl::StrCat(field->number()));
printer->Indent();
field_generators_.get(field).GenerateEqualsCode(printer);
printer->Print("break;\n");
@ -1119,7 +1121,7 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("case $field_number$:\n", "field_number",
StrCat(field->number()));
absl::StrCat(field->number()));
printer->Indent();
field_generators_.get(field).GenerateHashCode(printer);
printer->Print("break;\n");
@ -1223,7 +1225,7 @@ void ImmutableMessageGenerator::GenerateParsingConstructor(
field->number(), WireFormat::WireTypeForFieldType(field->type()));
printer->Print("case $tag$: {\n", "tag",
StrCat(static_cast<int32_t>(tag)));
absl::StrCat(static_cast<int32_t>(tag)));
printer->Indent();
field_generators_.get(field).GenerateParsingCode(printer);
@ -1239,7 +1241,7 @@ void ImmutableMessageGenerator::GenerateParsingConstructor(
uint32_t packed_tag = WireFormatLite::MakeTag(
field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
printer->Print("case $tag$: {\n", "tag",
StrCat(static_cast<int32_t>(packed_tag)));
absl::StrCat(static_cast<int32_t>(packed_tag)));
printer->Indent();
field_generators_.get(field).GenerateParsingCodeFromPacked(printer);

@ -43,6 +43,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
@ -127,7 +129,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
vars["oneof_index"] = StrCat(oneof->index());
vars["oneof_index"] = absl::StrCat(oneof->index());
// oneofCase_ and oneof_
printer->Print(vars,
"private int $oneof_name$Case_ = 0;\n"
@ -233,7 +235,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
printer->Print(
"case $number$:\n"
" return internalGet$capitalized_name$();\n",
"number", StrCat(field->number()), "capitalized_name",
"number", absl::StrCat(field->number()), "capitalized_name",
info->capitalized_name);
}
printer->Print(
@ -258,7 +260,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
printer->Print(
"case $number$:\n"
" return internalGetMutable$capitalized_name$();\n",
"number", StrCat(field->number()), "capitalized_name",
"number", absl::StrCat(field->number()), "capitalized_name",
info->capitalized_name);
}
printer->Print(

@ -43,6 +43,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
@ -100,7 +101,7 @@ void MessageBuilderLiteGenerator::Generate(io::Printer* printer) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
vars["oneof_index"] = StrCat(oneof->index());
vars["oneof_index"] = absl::StrCat(oneof->index());
// oneofCase() and clearOneof()
printer->Print(vars,

@ -41,6 +41,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>

@ -44,6 +44,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
@ -239,7 +241,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
vars["oneof_index"] = StrCat((oneof)->index());
vars["oneof_index"] = absl::StrCat((oneof)->index());
if (context_->options().opensource_runtime) {
// oneofCase_ and oneof_
printer->Print(vars,
@ -253,7 +255,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("$field_name$($field_number$),\n", "field_name",
ToUpper(field->name()), "field_number",
StrCat(field->number()));
absl::StrCat(field->number()));
}
printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
ToUpper(vars["oneof_name"]));
@ -281,7 +283,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(" case $field_number$: return $field_name$;\n",
"field_number", StrCat(field->number()),
"field_number", absl::StrCat(field->number()),
"field_name", ToUpper(field->name()));
}
printer->Print(
@ -317,7 +319,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->field_count(); i++) {
printer->Print("public static final int $constant_name$ = $number$;\n",
"constant_name", FieldConstantName(descriptor_->field(i)),
"number", StrCat(descriptor_->field(i)->number()));
"number", absl::StrCat(descriptor_->field(i)->number()));
field_generators_.get(descriptor_->field(i)).GenerateMembers(printer);
printer->Print("\n");
}

@ -32,6 +32,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.h>
#include "absl/strings/str_cat.h"
namespace google {
namespace protobuf {
@ -41,7 +42,7 @@ namespace java {
void GenerateSerializeExtensionRange(io::Printer* printer,
const Descriptor::ExtensionRange* range) {
printer->Print("extensionWriter.writeUntil($end$, output);\n", "end",
StrCat(range->end));
absl::StrCat(range->end));
}
} // namespace java

@ -40,6 +40,7 @@
#include <gmock/gmock.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/java/generator.h>
#include <google/protobuf/test_util2.h>
@ -60,10 +61,10 @@ int CompileJavaProto(std::string proto_file_name) {
CommandLineInterface cli;
cli.RegisterGenerator("--java_out", &java_generator, /*help_text=*/"");
std::string proto_path = StrCat(
std::string proto_path = absl::StrCat(
"--proto_path=",
TestUtil::GetTestDataPath("third_party/protobuf/compiler/java"));
std::string java_out = StrCat("--java_out=", TestTempDir());
std::string java_out = absl::StrCat("--java_out=", TestTempDir());
const char* argv[] = {
"protoc",
@ -83,11 +84,11 @@ TEST(MessageSerializationTest, CollapseAdjacentExtensionRanges) {
GOOGLE_CHECK_OK(File::GetContents(
// Open-source codebase does not support file::JoinPath, so we manually
// concatenate instead.
StrCat(TestTempDir(),
absl::StrCat(TestTempDir(),
"/TestMessageWithManyExtensionRanges.java"),
&java_source, true));
// Open-source codebase does not support constexpr StringPiece.
// Open-source codebase does not support constexpr absl::string_view.
static constexpr const char kWriteUntilCall[] = "extensionWriter.writeUntil(";
std::vector<std::string> range_ends;

@ -43,6 +43,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -117,8 +118,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["capitalized_type"] = GetCapitalizedType(
descriptor, /* immutable = */ true, context->options());
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
absl::StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
if (IsReferenceType(GetJavaType(descriptor))) {
(*variables)["null_check"] =
@ -139,7 +140,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
: "";
int fixed_size = FixedSize(GetType(descriptor));
if (fixed_size != -1) {
(*variables)["fixed_size"] = StrCat(fixed_size);
(*variables)["fixed_size"] = absl::StrCat(fixed_size);
}
(*variables)["on_changed"] = "onChanged();";

@ -43,6 +43,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -82,8 +84,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["capitalized_type"] = GetCapitalizedType(
descriptor, /* immutable = */ true, context->options());
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
absl::StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
@ -147,7 +149,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
: "";
int fixed_size = FixedSize(GetType(descriptor));
if (fixed_size != -1) {
(*variables)["fixed_size"] = StrCat(fixed_size);
(*variables)["fixed_size"] = absl::StrCat(fixed_size);
}
if (HasHasbit(descriptor)) {

@ -36,6 +36,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -96,7 +97,7 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
" return $file$.getDescriptor().getServices().get($index$);\n"
"}\n",
"file", name_resolver_->GetImmutableClassName(descriptor_->file()),
"index", StrCat(descriptor_->index()));
"index", absl::StrCat(descriptor_->index()));
GenerateGetDescriptorForType(printer);
// Generate more stuff.
@ -216,7 +217,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["index"] = absl::StrCat(i);
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
@ -263,7 +264,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod(
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["index"] = absl::StrCat(i);
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
@ -308,7 +309,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["index"] = absl::StrCat(i);
vars["type"] =
(which == REQUEST)
? name_resolver_->GetImmutableClassName(method->input_type())
@ -363,7 +364,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Indent();
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["index"] = absl::StrCat(i);
vars["output"] = GetOutput(method);
printer->Print(vars,
"channel.callMethod(\n"
@ -427,7 +428,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Indent();
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["index"] = absl::StrCat(i);
vars["output"] = GetOutput(method);
printer->Print(vars,
"return ($output$) channel.callBlockingMethod(\n"

@ -38,7 +38,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/escaping.h"
#include <google/protobuf/compiler/java/helpers.h>
#include <google/protobuf/compiler/java/name_resolver.h>
#include <google/protobuf/compiler/java/names.h>
@ -159,7 +159,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
}
}
printer->Print("\"$data$\"", "data",
CEscape(file_data.substr(i, kBytesPerLine)));
absl::CEscape(file_data.substr(i, kBytesPerLine)));
}
printer->Outdent();

@ -44,6 +44,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -76,8 +77,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["capitalized_type"] = "String";
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
absl::StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
(*variables)["null_check"] =
" if (value == null) {\n"

@ -44,6 +44,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/helpers.h>
@ -77,8 +78,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["capitalized_type"] = "java.lang.String";
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
absl::StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = absl::StrCat(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
@ -101,10 +102,10 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
if (HasHasbit(descriptor)) {
if (!context->options().opensource_runtime) {
(*variables)["bit_field_id"] = StrCat(messageBitIndex / 32);
(*variables)["bit_field_id"] = absl::StrCat(messageBitIndex / 32);
(*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
(*variables)["bit_field_mask"] =
StrCat(1 << (messageBitIndex % 32));
absl::StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

@ -74,7 +74,7 @@ std::string CommaSeparatedList(
for (size_t i = 0; i < all_files.size(); i++) {
names.push_back(all_files[i]->name());
}
return Join(names, ",");
return absl::StrJoin(names, ",");
}
static const char* kFirstInsertionPointName = "first_mock_insertion_point";

@ -46,6 +46,7 @@ cc_library(
deps = [
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/strings",
],
)

@ -38,6 +38,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/escaping.h"
namespace google {
namespace protobuf {
namespace compiler {
@ -47,9 +49,9 @@ std::string SafelyPrintIntToCode(int v) {
if (v == std::numeric_limits<int>::min()) {
// Some compilers try to parse -2147483648 as two tokens and then get spicy
// about the fact that +2147483648 cannot be represented as an int.
return StrCat(v + 1, " - 1");
return absl::StrCat(v + 1, " - 1");
} else {
return StrCat(v);
return absl::StrCat(v);
}
}
} // namespace
@ -207,7 +209,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
for (int i = 0; i < text_blob.size(); i += kBytesPerLine) {
printer->Print(
"\n \"$data$\"",
"data", EscapeTrigraphs(CEscape(text_blob.substr(i, kBytesPerLine))));
"data", EscapeTrigraphs(absl::CEscape(text_blob.substr(i, kBytesPerLine))));
}
printer->Print(
";\n"
@ -237,7 +239,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
" enumVerifier:$name$_IsValidValue\n"
" extraTextFormatInfo:extraTextFormatInfo];\n",
"name", name_,
"extraTextFormatInfo", CEscape(text_format_decode_data.Data()));
"extraTextFormatInfo", absl::CEscape(text_format_decode_data.Data()));
}
printer->Print(
" GPBEnumDescriptor *expected = nil;\n"

@ -86,7 +86,7 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
vars["root_class_and_method_name"] = root_class_and_method_name_;
const std::string containing_type = ClassName(descriptor_->containing_type());
vars["extended_type"] = ObjCClass(containing_type);
vars["number"] = StrCat(descriptor_->number());
vars["number"] = absl::StrCat(descriptor_->number());
std::vector<std::string> options;
if (descriptor_->is_repeated()) options.push_back("GPBExtensionRepeated");

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

Loading…
Cancel
Save