From 65f86885aa18fda4358521fe2bb1e4f5dd049821 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Tue, 4 Oct 2022 12:18:10 -0700 Subject: [PATCH 01/29] Force uninstall protobuf in python macos builds We are seeing failures in brew uninstall protobuf due to no package. Change this to a force install to avoid the error. --- kokoro/release/python/macos/build_artifacts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kokoro/release/python/macos/build_artifacts.sh b/kokoro/release/python/macos/build_artifacts.sh index 296bd9aef3..d79d2f6b40 100755 --- a/kokoro/release/python/macos/build_artifacts.sh +++ b/kokoro/release/python/macos/build_artifacts.sh @@ -3,7 +3,7 @@ set -ex # Remove any pre-existing protobuf installation. -brew uninstall protobuf +brew uninstall -f protobuf # change to repo root pushd $(dirname $0)/../../../.. From 1085f8528a41e4e94363af1d541590e25f2ebb19 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Tue, 4 Oct 2022 20:43:28 +0000 Subject: [PATCH 02/29] Fix spelling errors (#10717) --- .github/workflows/codespell.yml | 2 +- conformance/conformance_test.h | 2 +- objectivec/GPBCodedInputStream.h | 2 +- python/google/protobuf/internal/message_test.py | 2 +- src/google/protobuf/descriptor.h | 2 +- src/google/protobuf/text_format.cc | 4 ++-- update_version.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 41dc715db2..887c8a2381 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -13,4 +13,4 @@ jobs: with: check_filenames: true skip: ./.git,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./.github/workflows/codespell.yml - ignore_words_list: "alow,alse,ba,cleare,copyable,cloneable,dedup,dur,errorprone,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur" + ignore_words_list: "alow,alse,ba,cleare,copyable,cloneable,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur" diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index 286159837a..83d94f894d 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h @@ -124,7 +124,7 @@ class ForkPipeRunner : public ConformanceTestRunner { // class MyConformanceTestSuite : public ConformanceTestSuite { // public: // void RunSuiteImpl() { -// // INSERT ACTURAL TESTS. +// // INSERT ACTUAL TESTS. // } // }; // diff --git a/objectivec/GPBCodedInputStream.h b/objectivec/GPBCodedInputStream.h index fbe5009c92..1886ccf61b 100644 --- a/objectivec/GPBCodedInputStream.h +++ b/objectivec/GPBCodedInputStream.h @@ -220,7 +220,7 @@ CF_EXTERN_C_END /** * Moves the limit to the given byte offset starting at the current location. * - * @exception GPBCodedInputStreamException If the requested bytes exceeed the + * @exception GPBCodedInputStreamException If the requested bytes exceed the * current limit. * * @param byteLimit The number of bytes to move the limit, offset to the current diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index bd1df8cc77..40abfe4a2b 100644 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -2229,7 +2229,7 @@ class Proto3Test(unittest.TestCase): def testMapItems(self): # Map items used to have strange behaviors when use c extension. Because - # [] may reorder the map and invalidate any exsting iterators. + # [] may reorder the map and invalidate any existing iterators. # TODO(jieluo): Check if [] reordering the map is a bug or intended # behavior. msg = map_unittest_pb2.TestMap() diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 1b8728ec63..6e536e5705 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -896,7 +896,7 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { // formats the default value appropriately and returns it as a string. // Must have a default value to call this. If quote_string_type is true, then - // types of CPPTYPE_STRING whill be surrounded by quotes and CEscaped. + // types of CPPTYPE_STRING will be surrounded by quotes and CEscaped. std::string DefaultValueAsString(bool quote_string_type) const; // Helper function that returns the field type name for DebugString. diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 19110499d7..05987d3b13 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -981,7 +981,7 @@ class TextFormat::Parser::ParserImpl { } // Consumes an identifier and saves its value in the identifier parameter. - // Returns false if the token is not of type IDENTFIER. + // Returns false if the token is not of type IDENTIFIER. bool ConsumeIdentifier(std::string* identifier) { if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) { *identifier = tokenizer_.current().text; @@ -2290,7 +2290,7 @@ class MapEntryMessageComparator { namespace internal { class MapFieldPrinterHelper { public: - // DynamicMapSorter::Sort cannot be used because it enfores syncing with + // DynamicMapSorter::Sort cannot be used because it enforces syncing with // repeated field. static bool SortMap(const Message& message, const Reflection* reflection, const FieldDescriptor* field, diff --git a/update_version.py b/update_version.py index 0ab9cc098c..cb9f4dbec6 100755 --- a/update_version.py +++ b/update_version.py @@ -80,7 +80,7 @@ def RewriteXml(filename, rewriter, add_xml_prefix=True): # document.toxml() always prepend the XML version without inserting new line. # We wants to preserve as much of the original formatting as possible, so we # will remove the default XML version and replace it with our custom one when - # whever necessary. + # wherever necessary. content = document.toxml().replace('', '') file_handle = open(filename, 'wb') if add_xml_prefix: From c44d62371f06428e39d61dfac7f34b18f772f1f9 Mon Sep 17 00:00:00 2001 From: Matt Fowles Kulukundis Date: Wed, 6 Jul 2022 16:56:10 +0300 Subject: [PATCH 03/29] Merge pull request #10200 from tonydnewell/bugfix/protobuf-7474 Fix for grpc.tools #17995 & protobuf #7474 (handle UTF-8 paths in argumentfile) --- src/google/protobuf/compiler/subprocess.cc | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index 764f9aba38..6f547db795 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -47,6 +47,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -113,7 +114,7 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) { } // Setup STARTUPINFO to redirect handles. - STARTUPINFOA startup_info; + STARTUPINFOW startup_info; ZeroMemory(&startup_info, sizeof(startup_info)); startup_info.cb = sizeof(startup_info); startup_info.dwFlags = STARTF_USESTDHANDLES; @@ -125,17 +126,30 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) { GOOGLE_LOG(FATAL) << "GetStdHandle: " << Win32ErrorMessage(GetLastError()); } + // get wide string version of program as the path may contain non-ascii characters + std::wstring wprogram; + if (!io::win32::strings::utf8_to_wcs(program.c_str(), &wprogram)) { + GOOGLE_LOG(FATAL) << "utf8_to_wcs: " << Win32ErrorMessage(GetLastError()); + } + // Invoking cmd.exe allows for '.bat' files from the path as well as '.exe'. + std::string command_line = "cmd.exe /c \"" + program + "\""; + + // get wide string version of command line as the path may contain non-ascii characters + std::wstring wcommand_line; + if (!io::win32::strings::utf8_to_wcs(command_line.c_str(), &wcommand_line)) { + GOOGLE_LOG(FATAL) << "utf8_to_wcs: " << Win32ErrorMessage(GetLastError()); + } + // Using a malloc'ed string because CreateProcess() can mutate its second // parameter. - char* command_line = - portable_strdup(("cmd.exe /c \"" + program + "\"").c_str()); + wchar_t *wcommand_line_copy = _wcsdup(wcommand_line.c_str()); // Create the process. PROCESS_INFORMATION process_info; - if (CreateProcessA((search_mode == SEARCH_PATH) ? nullptr : program.c_str(), - (search_mode == SEARCH_PATH) ? command_line : nullptr, + if (CreateProcessW((search_mode == SEARCH_PATH) ? nullptr : wprogram.c_str(), + (search_mode == SEARCH_PATH) ? wcommand_line_copy : NULL, nullptr, // process security attributes nullptr, // thread security attributes TRUE, // inherit handles? @@ -155,7 +169,7 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) { CloseHandleOrDie(stdin_pipe_read); CloseHandleOrDie(stdout_pipe_write); - free(command_line); + free(wcommand_line_copy); } bool Subprocess::Communicate(const Message& input, Message* output, From a39fa12f4118c68a64bcf90512a29b96d341e996 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 7 Oct 2022 18:02:01 +0000 Subject: [PATCH 04/29] Upgrade to kotlin 1.6 --- java/kotlin-lite/pom.xml | 2 +- java/kotlin-lite/pom_template.xml | 2 +- java/kotlin/pom.xml | 2 +- java/kotlin/pom_template.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 1b856dffa5..60bd0d4a1d 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -16,7 +16,7 @@ - 1.5.0 + 1.6.0 diff --git a/java/kotlin-lite/pom_template.xml b/java/kotlin-lite/pom_template.xml index 92be0ea668..f8a3397408 100644 --- a/java/kotlin-lite/pom_template.xml +++ b/java/kotlin-lite/pom_template.xml @@ -17,6 +17,6 @@ - 1.5.0 + 1.6.0 diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 3be4b09611..846a1acc39 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -16,7 +16,7 @@ - 1.5.0 + 1.6.0 diff --git a/java/kotlin/pom_template.xml b/java/kotlin/pom_template.xml index c8ddcad9aa..0feae33e54 100644 --- a/java/kotlin/pom_template.xml +++ b/java/kotlin/pom_template.xml @@ -17,7 +17,7 @@ - 1.5.0 + 1.6.0 From a971d06fc290766b6b31a0dc3926e76a0079eb99 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sun, 9 Oct 2022 15:57:39 -0400 Subject: [PATCH 05/29] 21.x No longer define no_threadlocal on OpenBSD --- src/google/protobuf/stubs/platform_macros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 24799600dc..d10faf9aa2 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -122,11 +122,11 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR #undef GOOGLE_PROTOBUF_PLATFORM_ERROR -#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) || defined(__OpenBSD__) +#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) // Android ndk does not support the __thread keyword very well yet. Here // we use pthread_key_create()/pthread_getspecific()/... methods for // TLS support on android. -// iOS and OpenBSD also do not support the __thread keyword. +// iOS also does not support the __thread keyword. #define GOOGLE_PROTOBUF_NO_THREADLOCAL #endif From 0ee5525a75f1dd36c4acf14462a5905f56e1478b Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Mon, 10 Oct 2022 19:42:25 +0000 Subject: [PATCH 06/29] Upgrade kokoro to Xcode 14 (#10732) * Upgrade kokoro to Xcode 14 * Fix osx errors --- kokoro/macos/prepare_build_macos_rc | 2 +- objectivec/DevTools/full_mac_build.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kokoro/macos/prepare_build_macos_rc b/kokoro/macos/prepare_build_macos_rc index 8f99f105fa..9b9b2df7b8 100755 --- a/kokoro/macos/prepare_build_macos_rc +++ b/kokoro/macos/prepare_build_macos_rc @@ -15,7 +15,7 @@ brew uninstall protobuf ## # Select Xcode version -export DEVELOPER_DIR=/Applications/Xcode_13.3.1.app/Contents/Developer +export DEVELOPER_DIR=/Applications/Xcode_14.app/Contents/Developer sudo xcode-select -s "${DEVELOPER_DIR}" ## diff --git a/objectivec/DevTools/full_mac_build.sh b/objectivec/DevTools/full_mac_build.sh index 0e183f20ca..98b71a6d9d 100755 --- a/objectivec/DevTools/full_mac_build.sh +++ b/objectivec/DevTools/full_mac_build.sh @@ -295,7 +295,7 @@ if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then -disable-concurrent-destination-testing ) ;; - 11.* | 12.* | 13.*) + 11.* | 12.* | 13.* | 14.*) # Dropped 32bit as Apple doesn't seem support the simulators either. XCODEBUILD_TEST_BASE_IOS+=( -destination "platform=iOS Simulator,name=iPhone 8,OS=latest" # 64bit @@ -363,7 +363,7 @@ if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then -destination "platform=tvOS Simulator,name=Apple TV 4K,OS=latest" ) ;; - 13.*) + 13.* | 14.*) XCODEBUILD_TEST_BASE_TVOS+=( -destination "platform=tvOS Simulator,name=Apple TV 4K (2nd generation),OS=latest" ) From 1594ac1a2ee761a342109d2c1b2b660c4085d6b0 Mon Sep 17 00:00:00 2001 From: Jerry Berg <107155935+googleberg@users.noreply.github.com> Date: Wed, 12 Oct 2022 14:00:18 -0600 Subject: [PATCH 07/29] Merge pull request #10770 from protocolbuffers/googleberg-cl-480629524 Mark default instance as immutable first to avoid race during static initialization of default instances. --- .../java/com/google/protobuf/GeneratedMessageLite.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index d4151f4490..1ef2143503 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -407,8 +407,13 @@ public abstract class GeneratedMessageLite< protected static > void registerDefaultInstance( Class clazz, T defaultInstance) { + // Default instances must be immutable. + // Marking immutable here to avoid extra bytecode in every generated message class. + // Only calling "markImmutable" rather than "makeImmutable" because for Default Instances: + // 1. All sub-messages are initialized to null / default instances and thus immutable + // 2. All lists are initialized to default instance empty lists which are also immutable. + defaultInstance.markImmutable(); defaultInstanceMap.put(clazz, defaultInstance); - defaultInstance.makeImmutable(); } protected static Object newMessageInfo( From fa5a9e1035fcf42fbe5035ae14e442c67c3b53b6 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 13 Oct 2022 09:52:30 +0800 Subject: [PATCH 08/29] Auto capitalize enums name in Ruby (#10454) (#10763) This closes #1965. --- .../compatibility_tests/v3.0.0/tests/basic.rb | 4 ++-- ruby/ext/google/protobuf_c/message.c | 9 ++++++-- .../protobuf/jruby/RubyEnumDescriptor.java | 23 ++++++++++++++++--- ruby/tests/basic_test.proto | 1 + ruby/tests/basic_test_proto2.proto | 1 + ruby/tests/common_tests.rb | 19 +++++++++------ ruby/tests/generated_code.proto | 2 ++ ruby/tests/generated_code_proto2.proto | 2 ++ ruby/tests/repeated_field_test.rb | 1 + 9 files changed, 48 insertions(+), 14 deletions(-) diff --git a/ruby/compatibility_tests/v3.0.0/tests/basic.rb b/ruby/compatibility_tests/v3.0.0/tests/basic.rb index 7228144cb1..d45c19678f 100755 --- a/ruby/compatibility_tests/v3.0.0/tests/basic.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/basic.rb @@ -667,8 +667,8 @@ module BasicTest assert m["z"] == :C m["z"] = 2 assert m["z"] == :B - m["z"] = 4 - assert m["z"] == 4 + m["z"] = 5 + assert m["z"] == 5 assert_raise RangeError do m["z"] = :Z end diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 6b8bbaa3c5..31d7dbbb44 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1290,15 +1290,20 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { int n = upb_EnumDef_ValueCount(e); for (int i = 0; i < n; i++) { const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); - const char* name = upb_EnumValueDef_Name(ev); + char* name = strdup(upb_EnumValueDef_Name(ev)); int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { - rb_warn( + if (name[0] >= 'a' && name[0] <= 'z') { + name[0] -= 32; // auto capitalize + } else { + rb_warn( "Enum value '%s' does not start with an uppercase letter " "as is required for Ruby constants.", name); + } } rb_define_const(mod, name, INT2NUM(value)); + free(name); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1); diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java index 65328676e1..0eb7c939cb 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java @@ -162,9 +162,10 @@ public class RubyEnumDescriptor extends RubyObject { boolean defaultValueRequiredButNotFound = descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3; for (EnumValueDescriptor value : descriptor.getValues()) { - String name = value.getName(); - // Make sure its a valid constant name before trying to create it - if (Character.isUpperCase(name.codePointAt(0))) { + String name = fixEnumConstantName(value.getName()); + // Make sure it's a valid constant name before trying to create it + int ch = name.codePointAt(0); + if (Character.isUpperCase(ch)) { enumModule.defineConstant(name, runtime.newFixnum(value.getNumber())); } else { runtime @@ -189,6 +190,22 @@ public class RubyEnumDescriptor extends RubyObject { return enumModule; } + private static String fixEnumConstantName(String name) { + if (name != null && name.length() > 0) { + int ch = name.codePointAt(0); + if (ch >= 'a' && ch <= 'z') { + // Protobuf enums can start with lowercase letters, while Ruby's constant should + // always start with uppercase letters. We tolerate this case by capitalizing + // the first character if possible. + return new StringBuilder() + .appendCodePoint(Character.toUpperCase(ch)) + .append(name.substring(1)) + .toString(); + } + } + return name; + } + private EnumDescriptor descriptor; private EnumDescriptorProto.Builder builder; private IRubyObject name; diff --git a/ruby/tests/basic_test.proto b/ruby/tests/basic_test.proto index fb70f479db..d480d48e54 100644 --- a/ruby/tests/basic_test.proto +++ b/ruby/tests/basic_test.proto @@ -73,6 +73,7 @@ enum TestEnum { A = 1; B = 2; C = 3; + v0 = 4; } message TestEmbeddedMessageParent { diff --git a/ruby/tests/basic_test_proto2.proto b/ruby/tests/basic_test_proto2.proto index 0c1a2b9836..ac705ed630 100644 --- a/ruby/tests/basic_test_proto2.proto +++ b/ruby/tests/basic_test_proto2.proto @@ -69,6 +69,7 @@ enum TestEnum { A = 1; B = 2; C = 3; + v0 = 4; } enum TestNonZeroEnum { diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 5918c8a8b1..928842553f 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -331,14 +331,16 @@ module CommonTests l.push :A l.push :B l.push :C - assert l.count == 3 + l.push :v0 + assert l.count == 4 assert_raise RangeError do l.push :D end assert l[0] == :A + assert l[3] == :v0 - l.push 4 - assert l[3] == 4 + l.push 5 + assert l[4] == 5 end def test_rptfield_initialize @@ -542,8 +544,8 @@ module CommonTests assert m["z"] == :C m["z"] = 2 assert m["z"] == :B - m["z"] = 4 - assert m["z"] == 4 + m["z"] = 5 + assert m["z"] == 5 assert_raise RangeError do m["z"] = :Z end @@ -712,14 +714,17 @@ module CommonTests assert proto_module::TestEnum::A == 1 assert proto_module::TestEnum::B == 2 assert proto_module::TestEnum::C == 3 + assert proto_module::TestEnum::V0 == 4 assert proto_module::TestEnum::lookup(1) == :A assert proto_module::TestEnum::lookup(2) == :B assert proto_module::TestEnum::lookup(3) == :C + assert proto_module::TestEnum::lookup(4) == :v0 assert proto_module::TestEnum::resolve(:A) == 1 assert proto_module::TestEnum::resolve(:B) == 2 assert proto_module::TestEnum::resolve(:C) == 3 + assert proto_module::TestEnum::resolve(:v0) == 4 end def test_enum_const_get_helpers @@ -788,7 +793,7 @@ module CommonTests assert_raise(NoMethodError) { m.a } assert_raise(NoMethodError) { m.a_const_const } end - + def test_repeated_push m = proto_module::TestMessage.new @@ -1762,7 +1767,7 @@ module CommonTests assert_raise(FrozenErrorType) { m.repeated_msg = proto_module::TestMessage2.new } assert_raise(FrozenErrorType) { m.repeated_enum = :A } end - + def test_eq m1 = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2']) m2 = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2']) diff --git a/ruby/tests/generated_code.proto b/ruby/tests/generated_code.proto index bfdfa5aa78..5f017ba7ca 100644 --- a/ruby/tests/generated_code.proto +++ b/ruby/tests/generated_code.proto @@ -67,6 +67,8 @@ enum TestEnum { A = 1; B = 2; C = 3; + + v0 = 4; } message testLowercaseNested { diff --git a/ruby/tests/generated_code_proto2.proto b/ruby/tests/generated_code_proto2.proto index 1e957219fa..1a50b84be5 100644 --- a/ruby/tests/generated_code_proto2.proto +++ b/ruby/tests/generated_code_proto2.proto @@ -68,6 +68,8 @@ enum TestEnum { A = 1; B = 2; C = 3; + + v0 = 4; } message TestUnknown { diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 881810cdc5..de96869960 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -697,6 +697,7 @@ class RepeatedFieldTest < Test::Unit::TestCase value :A, 1 value :B, 2 value :C, 3 + value :v0, 4 end end From dda7ffdc4fc9683f7e32f5b9c65d466e5513850a Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 11 Oct 2022 21:13:55 +0000 Subject: [PATCH 09/29] Edit toolchain to work with absl dep --- toolchain/BUILD.bazel | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/toolchain/BUILD.bazel b/toolchain/BUILD.bazel index b171c227b9..20a435c76f 100644 --- a/toolchain/BUILD.bazel +++ b/toolchain/BUILD.bazel @@ -91,11 +91,16 @@ cc_toolchain_config( cc_toolchain_config( name = "osx-aarch_64-config", extra_compiler_flags = [ - "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" + "-I/usr/tools/xcode_14_0/macosx/usr/include/c++/v1", + "-I/usr/tools/xcode_14_0/macosx/usr/include", + "-F/usr/tools/xcode_14_0/macosx/System/Library/Frameworks", + "-Wno-error=nullability-completeness", + "-Wno-error=availability", + "-Wno-error=elaborated-enum-base", ], + extra_linker_flags = ["-framework CoreFoundation"], linker_path = "/usr/tools", - sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", + sysroot = "/usr/tools/xcode_14_0/macosx", target_cpu = "aarch64", target_full_name = "aarch64-apple-macosx11.3", ) @@ -103,11 +108,16 @@ cc_toolchain_config( cc_toolchain_config( name = "osx-x86_64-config", extra_compiler_flags = [ - "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" + "-I/usr/tools/xcode_14_0/macosx/usr/include/c++/v1", + "-I/usr/tools/xcode_14_0/macosx/usr/include", + "-F/usr/tools/xcode_14_0/macosx/System/Library/Frameworks", + "-Wno-error=nullability-completeness", + "-Wno-error=availability", + "-Wno-error=elaborated-enum-base", ], + extra_linker_flags = ["-framework CoreFoundation"], linker_path = "/usr/tools", - sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", + sysroot = "/usr/tools/xcode_14_0/macosx", target_cpu = "x86_64", target_full_name = "x86_64-apple-macosx11.3", ) @@ -122,6 +132,7 @@ cc_toolchain_config( extra_include = "/usr/lib/gcc/i686-w64-mingw32", extra_linker_flags = [ "-L/usr/lib/gcc/i686-w64-mingw32/8.3-posix", + "-ldbghelp", "-pthread", ], linker_path = "/usr/bin/ld", @@ -139,6 +150,7 @@ cc_toolchain_config( extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include", extra_linker_flags = [ "-L/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix", + "-ldbghelp", ], linker_path = "/usr/bin/ld", sysroot = "/usr/x86_64-w64-mingw32", From 3c49bd4e84d8e32cf80f26feceda7b55e688aa33 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:59:10 -0700 Subject: [PATCH 10/29] Bump upb to latest version after fixes applied (#10783) --- protobuf_deps.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index ae4021df06..425c4b4834 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -114,6 +114,6 @@ def protobuf_deps(): _github_archive( name = "upb", repo = "https://github.com/protocolbuffers/upb", - commit = "a5477045acaa34586420942098f5fecd3570f577", - sha256 = "0d6af8c8c00b3d733721f8d890ef43dd40f537c2e815b529085c1a6c30a21084", + commit = "230d502d6ea96fc9d40f02ad26c20fe85a627648", + sha256 = "28488db7f638ed5a433f7ac3b67e6b62932c155c2cd9987a2c534a3591f3b2dd", ) From 591fe403c964a9501e5d3d72b4d2da6446d389d9 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Tue, 18 Oct 2022 09:29:11 -0700 Subject: [PATCH 11/29] 21.x 202210180838 (#10785) * Updating version.json and repo version numbers to: 21.8 * Update changelog Co-authored-by: Protobuf Team Bot --- CHANGES.txt | 15 ++++++++++++ Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 ++--- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/package.xml | 23 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 6 ++--- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- version.json | 20 ++++++++-------- 38 files changed, 84 insertions(+), 54 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b890eed8ac..92ba28d9ca 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,18 @@ +2022-10-18 version 21.8 (C++/Java/Python/PHP/Objective-C/C#/Ruby) + + Other + * Fix for grpc.tools #17995 & protobuf #7474 (handle UTF-8 paths in argumentfile) (#10721) + + C++ + * 21.x No longer define no_threadlocal on OpenBSD (#10743) + + Java + * Mark default instance as immutable first to avoid race during static initialization of default instances (#10771) + + Ruby + * Auto capitalize enums name in Ruby (#10454) (#10763) + + 2022-09-29 version 21.7 (C++/Java/Python/PHP/Objective-C/C#/Ruby) Java * Refactoring java full runtime to reuse sub-message builders and prepare to diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 1bbbd38489..f4876ae990 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.21.7' + s.version = '3.21.8' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index 627430dad0..22a991990f 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.21.7' + s.version = '3.21.8' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/configure.ac b/configure.ac index b9e28aa2f4..d69fad621a 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.21.7],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.21.8],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 54a8d0cf82..64f78d0b3e 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.21.7 + 3.21.8 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index f10db5e89a..36d82156ee 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.21.7 + 3.21.8 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 0b56993b36..798ce212f6 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.21.7 + 3.21.8 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.21.7 + 3.21.8 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.21.7' + implementation 'com.google.protobuf:protobuf-java:3.21.8' ``` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index dc655626c3..ebbad006ea 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.21.7 + 3.21.8 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index a6da8c850e..bedb61b915 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 60bd0d4a1d..ace12aa6fa 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 846a1acc39..4e30d5dea3 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index bd9c5a5bb8..87b917a7bd 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.21.7 + 3.21.8 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index a78ff979b3..69bd30cc09 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index b3c511e177..e066235937 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 31fcbf269b..1c0ee7b687 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-java-util diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 3b9febbe86..18ab2f53af 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-packages@google.com yes - 2022-09-29 - + 2022-10-13 + - 3.21.7 - 3.21.7 + 3.21.8 + 3.21.8 stable @@ -1433,5 +1433,20 @@ G A release. + + + 3.21.8 + 3.21.8 + + + stable + stable + + 2022-10-13 + + BSD-3-Clause + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 77b61c2358..14bd16c40d 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.21.7" +#define PHP_PROTOBUF_VERSION "3.21.8" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index 591a4ba7db..cc6cf85c55 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,3 +1,3 @@ -PROTOC_VERSION = '21.7' -PROTOBUF_JAVA_VERSION = '3.21.7' -PROTOBUF_PYTHON_VERSION = '4.21.7' +PROTOC_VERSION = "21.8" +PROTOBUF_JAVA_VERSION = "3.21.8" +PROTOBUF_PYTHON_VERSION = "4.21.8" diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 8910337605..cb0c2be34c 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.21.7 + 3.21.8 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 70d564a90a..6b0df47af0 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.21.7' +__version__ = '4.21.8' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 692264ca47..5f226b0fec 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.21.7" + s.version = "3.21.8" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index 15fddeb352..c533dd7848 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.21.7 + 3.21.8 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.21.7 + 3.21.8 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index 0e915a42c8..231b95ba5c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 32:7:0 +PROTOBUF_VERSION = 32:8:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index a9c35be12b..8ed4b18ddf 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index c88f6d2149..dceb70c780 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 3e2bc50225..b8a0d71408 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index dde688e80b..beb0139440 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 0b80557f28..9721670b4e 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index d57dedb44d..fa8f1a7a7a 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index b36afc6bff..045871cfcb 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 9b2156d447..356ea47713 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -178,7 +178,7 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3021007 +#define PROTOBUF_VERSION 3021008 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index ea9031c48c..98a3d3e6b1 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 82280eace8..4283b77638 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index d06a32b42f..647b4d1d85 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,7 +82,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3021007 +#define GOOGLE_PROTOBUF_VERSION 3021008 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 5c196f8825..dc10d1cc47 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 0c82fa2242..8ac8fa8d4a 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 01e860d92f..590a1d98d1 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/version.json b/version.json index 28011e1fb4..3d1ec53977 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "21.x": { - "protoc_version": "21.8-dev", + "protoc_version": "21.8", "lts": false, - "date": "2022-09-29", + "date": "2022-10-13", "languages": { - "cpp": "3.21.8-dev", - "csharp": "3.21.8-dev", - "java": "3.21.8-dev", - "javascript": "3.21.8-dev", - "objectivec": "3.21.8-dev", - "php": "3.21.8-dev", - "python": "4.21.8-dev", - "ruby": "3.21.8-dev" + "cpp": "3.21.8", + "csharp": "3.21.8", + "java": "3.21.8", + "javascript": "3.21.8", + "objectivec": "3.21.8", + "php": "3.21.8", + "python": "4.21.8", + "ruby": "3.21.8" } } } \ No newline at end of file From 80b583acdf592bc66ce39d595248c8807da9598d Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Tue, 18 Oct 2022 16:00:03 -0700 Subject: [PATCH 12/29] 21.x 202210181433 (#10787) * Updating version.json and repo version numbers to: 21.8 * Update version.json to: 21.9-dev Co-authored-by: Protobuf Team Bot --- version.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/version.json b/version.json index 3d1ec53977..7a8e1fc747 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "21.x": { - "protoc_version": "21.8", + "protoc_version": "21.9-dev", "lts": false, - "date": "2022-10-13", + "date": "2022-10-18", "languages": { - "cpp": "3.21.8", - "csharp": "3.21.8", - "java": "3.21.8", - "javascript": "3.21.8", - "objectivec": "3.21.8", - "php": "3.21.8", - "python": "4.21.8", - "ruby": "3.21.8" + "cpp": "3.21.9-dev", + "csharp": "3.21.9-dev", + "java": "3.21.9-dev", + "javascript": "3.21.9-dev", + "objectivec": "3.21.9-dev", + "php": "3.21.9-dev", + "python": "4.21.9-dev", + "ruby": "3.21.9-dev" } } } \ No newline at end of file From 86594306aa85eddbea39eddd180a2d198f835930 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 19 Oct 2022 16:56:53 -0700 Subject: [PATCH 13/29] Sync from Piper @482325250 PROTOBUF_SYNC_PIPER --- .../compiler/command_line_interface.cc | 4 +- .../compiler/command_line_interface.h | 6 +- .../protobuf/compiler/cpp/enum_field.cc | 3 +- src/google/protobuf/compiler/cpp/extension.h | 3 +- src/google/protobuf/compiler/cpp/field.cc | 32 ++++----- src/google/protobuf/compiler/cpp/field.h | 12 ++-- src/google/protobuf/compiler/cpp/file.h | 3 +- src/google/protobuf/compiler/cpp/helpers.cc | 8 +-- src/google/protobuf/compiler/cpp/helpers.h | 16 ++--- src/google/protobuf/compiler/cpp/map_field.cc | 10 ++- src/google/protobuf/compiler/cpp/message.cc | 22 +++--- src/google/protobuf/compiler/cpp/message.h | 4 +- .../protobuf/compiler/cpp/message_field.cc | 10 ++- .../compiler/cpp/parse_function_generator.cc | 3 +- .../compiler/cpp/parse_function_generator.h | 15 ++-- .../protobuf/compiler/cpp/primitive_field.cc | 8 +-- src/google/protobuf/compiler/cpp/service.h | 5 +- .../protobuf/compiler/cpp/string_field.cc | 8 +-- .../compiler/csharp/csharp_field_base.cc | 4 +- .../compiler/csharp/csharp_field_base.h | 8 +-- .../compiler/csharp/csharp_message.cc | 59 +++++++-------- src/google/protobuf/compiler/java/enum.cc | 7 +- .../protobuf/compiler/java/enum_field.cc | 3 +- .../protobuf/compiler/java/enum_field.h | 5 +- .../protobuf/compiler/java/enum_field_lite.cc | 26 +++---- .../protobuf/compiler/java/enum_field_lite.h | 5 +- .../protobuf/compiler/java/enum_lite.cc | 7 +- .../protobuf/compiler/java/extension.cc | 8 +-- src/google/protobuf/compiler/java/extension.h | 11 ++- .../protobuf/compiler/java/extension_lite.cc | 3 +- src/google/protobuf/compiler/java/field.cc | 25 +++---- src/google/protobuf/compiler/java/field.h | 18 +++-- src/google/protobuf/compiler/java/helpers.cc | 9 +-- src/google/protobuf/compiler/java/helpers.h | 9 +-- .../protobuf/compiler/java/map_field.cc | 52 ++++++-------- src/google/protobuf/compiler/java/map_field.h | 2 +- .../protobuf/compiler/java/map_field_lite.cc | 8 +-- .../protobuf/compiler/java/map_field_lite.h | 2 +- src/google/protobuf/compiler/java/message.cc | 10 +-- .../protobuf/compiler/java/message_builder.cc | 2 +- .../compiler/java/message_builder_lite.cc | 2 +- .../protobuf/compiler/java/message_field.cc | 26 ++++--- .../protobuf/compiler/java/message_field.h | 4 +- .../compiler/java/message_field_lite.cc | 23 +++--- .../compiler/java/message_field_lite.h | 4 +- .../protobuf/compiler/java/message_lite.cc | 7 +- .../protobuf/compiler/java/primitive_field.cc | 72 +++++++++---------- .../protobuf/compiler/java/primitive_field.h | 4 +- .../compiler/java/primitive_field_lite.cc | 71 +++++++++--------- .../compiler/java/primitive_field_lite.h | 4 +- src/google/protobuf/compiler/java/service.cc | 14 ++-- .../protobuf/compiler/java/string_field.cc | 11 +-- .../protobuf/compiler/java/string_field.h | 4 +- .../compiler/java/string_field_lite.cc | 11 +-- .../compiler/java/string_field_lite.h | 4 +- .../compiler/objectivec/enum_field.cc | 6 +- .../protobuf/compiler/objectivec/extension.cc | 5 +- .../protobuf/compiler/objectivec/field.cc | 6 +- .../protobuf/compiler/objectivec/field.h | 3 +- .../protobuf/compiler/objectivec/file.cc | 2 +- .../compiler/objectivec/import_writer.cc | 10 ++- .../compiler/objectivec/import_writer.h | 3 +- .../protobuf/compiler/objectivec/message.cc | 3 +- .../compiler/objectivec/message_field.cc | 6 +- .../protobuf/compiler/objectivec/names.cc | 29 ++++---- .../protobuf/compiler/objectivec/oneof.h | 3 +- .../compiler/objectivec/primitive_field.cc | 6 +- .../protobuf/compiler/python/generator.cc | 29 ++++---- .../protobuf/compiler/python/pyi_generator.h | 3 +- src/google/protobuf/io/printer.h | 33 +++------ third_party/utf8_range | 2 +- 71 files changed, 392 insertions(+), 473 deletions(-) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 4ac86d4bd0..6b6ca1b498 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -425,7 +425,7 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext { // The files_ field maps from path keys to file content values. It's a map // instead of an unordered_map so that files are written in order (good when // writing zips). - absl::flat_hash_map files_; + std::map files_; const std::vector& parsed_files_; bool had_error_; }; @@ -1493,7 +1493,7 @@ CommandLineInterface::ParseArgumentStatus CommandLineInterface::ParseArguments( // Make sure each plugin option has a matching plugin output. bool foundUnknownPluginOption = false; - for (absl::flat_hash_map::const_iterator i = + for (std::map::const_iterator i = plugin_parameters_.begin(); i != plugin_parameters_.end(); ++i) { if (plugins_.find(i->first) != plugins_.end()) { diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 7e1cd58f5d..92454145b7 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -367,9 +367,9 @@ class PROTOC_EXPORT CommandLineInterface { // flag. For example, if the user invokes the compiler with: // protoc --foo_out=outputdir --foo_opt=enable_bar ... // Then there will be an entry ("--foo_out", "enable_bar") in this map. - absl::flat_hash_map generator_parameters_; + std::map generator_parameters_; // Similar to generator_parameters_, but stores the parameters for plugins. - absl::flat_hash_map plugin_parameters_; + std::map plugin_parameters_; // See AllowPlugins(). If this is empty, plugins aren't allowed. std::string plugin_prefix_; @@ -377,7 +377,7 @@ class PROTOC_EXPORT CommandLineInterface { // Maps specific plugin names to files. When executing a plugin, this map // is searched first to find the plugin executable. If not found here, the // PATH (or other OS-specific search strategy) is searched. - absl::flat_hash_map plugins_; + std::map plugins_; // Stuff parsed from command line. enum Mode { diff --git a/src/google/protobuf/compiler/cpp/enum_field.cc b/src/google/protobuf/compiler/cpp/enum_field.cc index c1df1b5307..0ac1451c7d 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/enum_field.cc @@ -36,7 +36,6 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -48,7 +47,7 @@ namespace cpp { namespace { void SetEnumVariables(const FieldDescriptor* descriptor, - absl::flat_hash_map* variables, + std::map* variables, const Options& options) { SetCommonFieldVariables(descriptor, variables, options); const EnumValueDescriptor* default_value = descriptor->default_value_enum(); diff --git a/src/google/protobuf/compiler/cpp/extension.h b/src/google/protobuf/compiler/cpp/extension.h index c8097529b7..1c0e020b99 100644 --- a/src/google/protobuf/compiler/cpp/extension.h +++ b/src/google/protobuf/compiler/cpp/extension.h @@ -38,7 +38,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/port.h" @@ -85,7 +84,7 @@ class ExtensionGenerator { Options options_; MessageSCCAnalyzer* scc_analyzer_; - absl::flat_hash_map variables_; + std::map variables_; }; } // namespace cpp diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index 7637ff1119..3199dce889 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -38,7 +38,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" @@ -63,12 +62,12 @@ using internal::WireFormat; namespace { -void MaySetAnnotationVariable( - const Options& options, absl::string_view annotation_name, - absl::string_view substitute_template_prefix, - absl::string_view prepared_template, int field_index, - absl::string_view access_type, - absl::flat_hash_map* variables) { +void MaySetAnnotationVariable(const Options& options, + 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* variables) { if (options.field_listener_options.forbidden_field_listener_events.count( std::string(annotation_name))) return; @@ -125,9 +124,9 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor, } // namespace -void AddAccessorAnnotations( - const FieldDescriptor* descriptor, const Options& options, - absl::flat_hash_map* variables) { +void AddAccessorAnnotations(const FieldDescriptor* descriptor, + const Options& options, + std::map* variables) { // Can be expanded to include more specific calls, for example, for arena or // clear calls. static constexpr const char* kAccessorsAnnotations[] = { @@ -262,7 +261,7 @@ absl::flat_hash_map FieldVars( // TODO(b/245791219): Refactor AddAccessorAnnotations to avoid this // workaround. - absl::flat_hash_map workaround = { + std::map workaround = { {"field", vars["field"]}, {"tracker", "Impl_::_tracker_"}, }; @@ -274,10 +273,9 @@ absl::flat_hash_map FieldVars( return vars; } -void SetCommonFieldVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables, - const Options& options) { +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + std::map* variables, + const Options& options) { SetCommonMessageDataVariables(descriptor->containing_type(), variables); for (auto& pair : FieldVars(descriptor, options)) { @@ -296,14 +294,14 @@ absl::flat_hash_map OneofFieldVars( void SetCommonOneofFieldVariables( const FieldDescriptor* descriptor, - absl::flat_hash_map* variables) { + std::map* variables) { for (auto& pair : OneofFieldVars(descriptor)) { variables->emplace(pair); } } void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { - if (!internal::cpp::HasHasbit(descriptor_) || has_bit_index < 0) { + if (!internal::cpp::HasHasbit(descriptor_)) { GOOGLE_CHECK_EQ(has_bit_index, -1); return; } diff --git a/src/google/protobuf/compiler/cpp/field.h b/src/google/protobuf/compiler/cpp/field.h index 7a745f4d17..db0d64d30e 100644 --- a/src/google/protobuf/compiler/cpp/field.h +++ b/src/google/protobuf/compiler/cpp/field.h @@ -41,7 +41,6 @@ #include #include "google/protobuf/descriptor.h" -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/options.h" @@ -68,14 +67,13 @@ absl::flat_hash_map OneofFieldVars( // field code generators. // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', // 'deprecation']. -void SetCommonFieldVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables, - const Options& options); +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + std::map* variables, + const Options& options); void SetCommonOneofFieldVariables( const FieldDescriptor* descriptor, - absl::flat_hash_map* variables); + std::map* variables); class FieldGenerator { public: @@ -228,7 +226,7 @@ class FieldGenerator { protected: const FieldDescriptor* descriptor_; const Options& options_; - absl::flat_hash_map variables_; + std::map variables_; }; // Convenience class which constructs FieldGenerators for a Descriptor. diff --git a/src/google/protobuf/compiler/cpp/file.h b/src/google/protobuf/compiler/cpp/file.h index a1d2bcc67a..cd38345043 100644 --- a/src/google/protobuf/compiler/cpp/file.h +++ b/src/google/protobuf/compiler/cpp/file.h @@ -44,7 +44,6 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/compiler/scc.h" -#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "google/protobuf/compiler/cpp/enum.h" #include "google/protobuf/compiler/cpp/extension.h" @@ -196,7 +195,7 @@ class FileGenerator { // This member is unused and should be deleted once all old-style variable // maps are gone. // TODO(b/245791219) - absl::flat_hash_map variables_; + std::map variables_; // Contains the post-order walk of all the messages (and child messages) in // this file. If you need a pre-order walk just reverse iterate. diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc index 1f40d3d440..383629f4f1 100644 --- a/src/google/protobuf/compiler/cpp/helpers.cc +++ b/src/google/protobuf/compiler/cpp/helpers.cc @@ -252,7 +252,7 @@ absl::flat_hash_map MessageVars( void SetCommonMessageDataVariables( const Descriptor* descriptor, - absl::flat_hash_map* variables) { + std::map* variables) { for (auto& pair : MessageVars(descriptor)) { variables->emplace(pair); } @@ -286,9 +286,9 @@ absl::flat_hash_map UnknownFieldsVars( }; } -void SetUnknownFieldsVariable( - const Descriptor* descriptor, const Options& options, - absl::flat_hash_map* variables) { +void SetUnknownFieldsVariable(const Descriptor* descriptor, + const Options& options, + std::map* variables) { for (auto& pair : UnknownFieldsVars(descriptor, options)) { variables->emplace(pair); } diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index dbd2dd56c5..4967452ca8 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -94,14 +94,14 @@ absl::flat_hash_map MessageVars( // Variables to access message data from the message scope. void SetCommonMessageDataVariables( const Descriptor* descriptor, - absl::flat_hash_map* variables); + std::map* variables); absl::flat_hash_map UnknownFieldsVars( const Descriptor* desc, const Options& opts); -void SetUnknownFieldsVariable( - const Descriptor* descriptor, const Options& options, - absl::flat_hash_map* variables); +void SetUnknownFieldsVariable(const Descriptor* descriptor, + const Options& options, + std::map* variables); bool GetBootstrapBasename(const Options& options, const std::string& basename, std::string* bootstrap_basename); @@ -794,7 +794,7 @@ class PROTOC_EXPORT Formatter { public: explicit Formatter(io::Printer* printer) : printer_(printer) {} Formatter(io::Printer* printer, - const absl::flat_hash_map& vars) + const std::map& vars) : printer_(printer), vars_(vars) {} template @@ -802,7 +802,7 @@ class PROTOC_EXPORT Formatter { vars_[key] = ToString(value); } - void AddMap(const absl::flat_hash_map& vars) { + void AddMap(const std::map& vars) { for (const auto& keyval : vars) vars_[keyval.first] = keyval.second; } @@ -844,12 +844,12 @@ class PROTOC_EXPORT Formatter { private: Formatter* format_; - absl::flat_hash_map vars_; + std::map vars_; }; private: io::Printer* printer_; - absl::flat_hash_map vars_; + std::map vars_; // Convenience overloads to accept different types as arguments. static std::string ToString(const std::string& s) { return s; } diff --git a/src/google/protobuf/compiler/cpp/map_field.cc b/src/google/protobuf/compiler/cpp/map_field.cc index 0518c6acd3..e320a435b8 100644 --- a/src/google/protobuf/compiler/cpp/map_field.cc +++ b/src/google/protobuf/compiler/cpp/map_field.cc @@ -31,19 +31,17 @@ #include "google/protobuf/compiler/cpp/map_field.h" #include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "absl/strings/str_cat.h" namespace google { namespace protobuf { namespace compiler { namespace cpp { -void SetMessageVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables, - const Options& options) { +void SetMessageVariables(const FieldDescriptor* descriptor, + std::map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = ClassName(descriptor->message_type(), false); (*variables)["full_name"] = descriptor->full_name(); diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index f527c4e814..38f60946eb 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -278,9 +278,9 @@ bool HasHasMethod(const FieldDescriptor* field) { // Collects map entry message type information. void CollectMapInfo(const Options& options, const Descriptor* descriptor, - absl::flat_hash_map* variables) { + std::map* variables) { GOOGLE_CHECK(IsMapEntryMessage(descriptor)); - absl::flat_hash_map& vars = *variables; + std::map& vars = *variables; const FieldDescriptor* key = descriptor->map_key(); const FieldDescriptor* val = descriptor->map_value(); vars["key_cpp"] = PrimitiveTypeName(options, key->cpp_type()); @@ -429,7 +429,7 @@ class ColdChunkSkipper { const std::vector& has_bit_indices_; const AccessInfoMap* access_info_map_; const double cold_threshold_; - absl::flat_hash_map variables_; + std::map variables_; int limit_chunk_ = -1; }; @@ -640,11 +640,11 @@ absl::flat_hash_map ClassVars(const Descriptor* desc, // =================================================================== -MessageGenerator::MessageGenerator( - const Descriptor* descriptor, - const absl::flat_hash_map&, - int index_in_file_messages, const Options& options, - MessageSCCAnalyzer* scc_analyzer) +MessageGenerator::MessageGenerator(const Descriptor* descriptor, + const std::map&, + int index_in_file_messages, + const Options& options, + MessageSCCAnalyzer* scc_analyzer) : descriptor_(descriptor), index_in_file_messages_(index_in_file_messages), options_(options), @@ -779,7 +779,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { for (auto field : ordered_fields) { Formatter::SaveState save(&format); - absl::flat_hash_map vars; + std::map vars; SetCommonFieldVariables(field, &vars, options_); auto v = p->WithVars(std::move(vars)); format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field)); @@ -1290,7 +1290,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { Formatter format(p); if (IsMapEntryMessage(descriptor_)) { - absl::flat_hash_map vars; + std::map vars; CollectMapInfo(options_, descriptor_, &vars); vars["lite"] = HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite"; @@ -3749,7 +3749,7 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p, void MessageGenerator::GenerateSerializeOneExtensionRange( io::Printer* p, const Descriptor::ExtensionRange* range) { - absl::flat_hash_map vars = variables_; + std::map vars = variables_; vars["start"] = absl::StrCat(range->start); vars["end"] = absl::StrCat(range->end); Formatter format(p, vars); diff --git a/src/google/protobuf/compiler/cpp/message.h b/src/google/protobuf/compiler/cpp/message.h index 0c9409df72..019660692a 100644 --- a/src/google/protobuf/compiler/cpp/message.h +++ b/src/google/protobuf/compiler/cpp/message.h @@ -61,7 +61,7 @@ namespace cpp { class MessageGenerator { public: MessageGenerator(const Descriptor* descriptor, - const absl::flat_hash_map& ignored, + const std::map& ignored, int index_in_file_messages, const Options& options, MessageSCCAnalyzer* scc_analyzer); @@ -214,7 +214,7 @@ class MessageGenerator { MessageSCCAnalyzer* scc_analyzer_; - absl::flat_hash_map variables_; + std::map variables_; }; diff --git a/src/google/protobuf/compiler/cpp/message_field.cc b/src/google/protobuf/compiler/cpp/message_field.cc index 06db2fb35b..e8d2a74dae 100644 --- a/src/google/protobuf/compiler/cpp/message_field.cc +++ b/src/google/protobuf/compiler/cpp/message_field.cc @@ -35,10 +35,9 @@ #include "google/protobuf/compiler/cpp/message_field.h" #include "google/protobuf/io/printer.h" -#include "absl/container/flat_hash_map.h" -#include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "absl/strings/str_cat.h" namespace google { namespace protobuf { @@ -56,10 +55,9 @@ std::string ReinterpretCast(const std::string& type, } } -void SetMessageVariables( - const FieldDescriptor* descriptor, const Options& options, - bool implicit_weak, - absl::flat_hash_map* variables) { +void SetMessageVariables(const FieldDescriptor* descriptor, + const Options& options, bool implicit_weak, + std::map* variables) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = FieldMessageTypeName(descriptor, options); (*variables)["casted_member"] = ReinterpretCast( diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index 74fdbd2fdd..74a9a9899d 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -38,7 +38,6 @@ #include #include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/generated_message_tctable_gen.h" @@ -110,7 +109,7 @@ ParseFunctionGenerator::ParseFunctionGenerator( const std::vector& has_bit_indices, const std::vector& inlined_string_indices, const Options& options, MessageSCCAnalyzer* scc_analyzer, - const absl::flat_hash_map& vars) + const std::map& vars) : descriptor_(descriptor), scc_analyzer_(scc_analyzer), options_(options), diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.h b/src/google/protobuf/compiler/cpp/parse_function_generator.h index 33ed17c07c..b55feda112 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.h +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.h @@ -38,7 +38,6 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/wire_format_lite.h" -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/generated_message_tctable_gen.h" @@ -52,12 +51,12 @@ namespace cpp { // (and any associated supporting members). class ParseFunctionGenerator { public: - ParseFunctionGenerator( - const Descriptor* descriptor, int max_has_bit_index, - const std::vector& has_bit_indices, - const std::vector& inlined_string_indices, const Options& options, - MessageSCCAnalyzer* scc_analyzer, - const absl::flat_hash_map& vars); + ParseFunctionGenerator(const Descriptor* descriptor, int max_has_bit_index, + const std::vector& has_bit_indices, + const std::vector& inlined_string_indices, + const Options& options, + MessageSCCAnalyzer* scc_analyzer, + const std::map& vars); // Emits class-level method declarations to `printer`: void GenerateMethodDecls(io::Printer* printer); @@ -127,7 +126,7 @@ class ParseFunctionGenerator { const Descriptor* descriptor_; MessageSCCAnalyzer* scc_analyzer_; const Options& options_; - absl::flat_hash_map variables_; + std::map variables_; std::unique_ptr tc_table_info_; std::vector inlined_string_indices_; const std::vector ordered_fields_; diff --git a/src/google/protobuf/compiler/cpp/primitive_field.cc b/src/google/protobuf/compiler/cpp/primitive_field.cc index 143f6e578d..b2144c3111 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -36,7 +36,6 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -99,10 +98,9 @@ int FixedSize(FieldDescriptor::Type type) { return -1; } -void SetPrimitiveVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables, - const Options& options) { +void SetPrimitiveVariables(const FieldDescriptor* descriptor, + std::map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = PrimitiveTypeName(options, descriptor->cpp_type()); (*variables)["default"] = DefaultValue(options, descriptor); diff --git a/src/google/protobuf/compiler/cpp/service.h b/src/google/protobuf/compiler/cpp/service.h index be11bf7221..34b891423b 100644 --- a/src/google/protobuf/compiler/cpp/service.h +++ b/src/google/protobuf/compiler/cpp/service.h @@ -39,7 +39,6 @@ #include #include "google/protobuf/descriptor.h" -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/io/printer.h" @@ -51,7 +50,7 @@ class ServiceGenerator { public: // See generator.cc for the meaning of dllexport_decl. ServiceGenerator(const ServiceDescriptor* descriptor, - const absl::flat_hash_map& vars, + const std::map& vars, const Options& options) : descriptor_(descriptor), options_(&options), vars_(vars) { vars_["classname"] = descriptor_->name(); @@ -99,7 +98,7 @@ class ServiceGenerator { const ServiceDescriptor* descriptor_; const Options* options_; - absl::flat_hash_map vars_; + std::map vars_; int index_in_metadata_; diff --git a/src/google/protobuf/compiler/cpp/string_field.cc b/src/google/protobuf/compiler/cpp/string_field.cc index 2730f3dbf5..b1aadfb56e 100644 --- a/src/google/protobuf/compiler/cpp/string_field.cc +++ b/src/google/protobuf/compiler/cpp/string_field.cc @@ -34,7 +34,6 @@ #include "google/protobuf/compiler/cpp/string_field.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/descriptor.pb.h" @@ -46,10 +45,9 @@ namespace cpp { namespace { -void SetStringVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables, - const Options& options) { +void SetStringVariables(const FieldDescriptor* descriptor, + std::map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); const std::string kNS = "::" + ProtobufNamespace(options) + "::internal::"; diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index d934300d3e..bc45d740ba 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -52,7 +52,7 @@ namespace compiler { namespace csharp { void FieldGeneratorBase::SetCommonFieldVariables( - absl::flat_hash_map* variables) { + std::map* variables) { // Note: this will be valid even though the tag emitted for packed and unpacked versions of // repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which // never effects the tag size. @@ -124,7 +124,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( } void FieldGeneratorBase::SetCommonOneofFieldVariables( - absl::flat_hash_map* variables) { + std::map* variables) { (*variables)["oneof_name"] = oneof_name(); if (SupportsPresenceApi(descriptor_)) { (*variables)["has_property_check"] = "Has" + property_name(); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 719438eea2..75fe19bfb3 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -34,7 +34,6 @@ #include #include "google/protobuf/compiler/code_generator.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" @@ -78,7 +77,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { protected: const FieldDescriptor* descriptor_; const int presenceIndex_; - absl::flat_hash_map variables_; + std::map variables_; void AddDeprecatedFlag(io::Printer* printer); void AddNullCheck(io::Printer* printer); @@ -86,7 +85,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { void AddPublicMemberAttributes(io::Printer* printer); void SetCommonOneofFieldVariables( - absl::flat_hash_map* variables); + std::map* variables); std::string oneof_property_name(); std::string oneof_case_name(); @@ -102,8 +101,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { std::string capitalized_type_name(); private: - void SetCommonFieldVariables( - absl::flat_hash_map* variables); + void SetCommonFieldVariables(std::map* variables); std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor); std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor); }; diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 7d03ccf1c6..bdbd480a61 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -35,14 +35,13 @@ #include #include "google/protobuf/compiler/code_generator.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_enum.h" #include "google/protobuf/compiler/csharp/csharp_field_base.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/names.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" @@ -115,7 +114,7 @@ void MessageGenerator::AddSerializableAttribute(io::Printer* printer) { } void MessageGenerator::Generate(io::Printer* printer) { - absl::flat_hash_map vars; + std::map vars; vars["class_name"] = class_name(); vars["access_level"] = class_access_level(); @@ -377,7 +376,7 @@ bool MessageGenerator::HasNestedGeneratedTypes() } void MessageGenerator::GenerateCloningCode(io::Printer* printer) { - absl::flat_hash_map vars; + std::map vars; WriteGeneratedCodeAttributes(printer); vars["class_name"] = class_name(); printer->Print( @@ -441,30 +440,32 @@ void MessageGenerator::GenerateFreezingCode(io::Printer* printer) { } void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { - absl::flat_hash_map vars; - vars["class_name"] = class_name(); + std::map vars; + vars["class_name"] = class_name(); - // Equality - WriteGeneratedCodeAttributes(printer); - printer->Print(vars, - "public override bool Equals(object other) {\n" - " return Equals(other as $class_name$);\n" - "}\n\n"); - WriteGeneratedCodeAttributes(printer); - printer->Print(vars, - "public bool Equals($class_name$ other) {\n" - " if (ReferenceEquals(other, null)) {\n" - " return false;\n" - " }\n" - " if (ReferenceEquals(other, this)) {\n" - " return true;\n" - " }\n"); - printer->Indent(); - for (int i = 0; i < descriptor_->field_count(); i++) { - std::unique_ptr generator( - CreateFieldGeneratorInternal(descriptor_->field(i))); - generator->WriteEquals(printer); - } + // Equality + WriteGeneratedCodeAttributes(printer); + printer->Print( + vars, + "public override bool Equals(object other) {\n" + " return Equals(other as $class_name$);\n" + "}\n\n"); + WriteGeneratedCodeAttributes(printer); + printer->Print( + vars, + "public bool Equals($class_name$ other) {\n" + " if (ReferenceEquals(other, null)) {\n" + " return false;\n" + " }\n" + " if (ReferenceEquals(other, this)) {\n" + " return true;\n" + " }\n"); + printer->Indent(); + for (int i = 0; i < descriptor_->field_count(); i++) { + std::unique_ptr generator( + CreateFieldGeneratorInternal(descriptor_->field(i))); + generator->WriteEquals(printer); + } for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) { printer->Print("if ($property_name$Case != other.$property_name$Case) return false;\n", "property_name", UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), true)); @@ -606,7 +607,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { // Note: These are separate from GenerateMessageSerializationMethods() // because they need to be generated even for messages that are optimized // for code size. - absl::flat_hash_map vars; + std::map vars; vars["class_name"] = class_name(); WriteGeneratedCodeAttributes(printer); @@ -686,7 +687,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { } void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_parse_context) { - absl::flat_hash_map vars; + std::map vars; vars["maybe_ref_input"] = use_parse_context ? "ref input" : "input"; printer->Print( diff --git a/src/google/protobuf/compiler/java/enum.cc b/src/google/protobuf/compiler/java/enum.cc index 5a1a2b0fe6..788c9dd60f 100644 --- a/src/google/protobuf/compiler/java/enum.cc +++ b/src/google/protobuf/compiler/java/enum.cc @@ -38,7 +38,6 @@ #include #include "google/protobuf/io/printer.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -104,7 +103,7 @@ void EnumGenerator::Generate(io::Printer* printer) { } for (int i = 0; i < canonical_values_.size(); i++) { - absl::flat_hash_map vars; + std::map vars; vars["name"] = canonical_values_[i]->name(); vars["index"] = absl::StrCat(canonical_values_[i]->index()); vars["number"] = absl::StrCat(canonical_values_[i]->number()); @@ -136,7 +135,7 @@ void EnumGenerator::Generate(io::Printer* printer) { // ----------------------------------------------------------------- for (int i = 0; i < aliases_.size(); i++) { - absl::flat_hash_map vars; + std::map vars; vars["classname"] = descriptor_->name(); vars["name"] = aliases_[i].value->name(); vars["canonical_name"] = aliases_[i].canonical_value->name(); @@ -147,7 +146,7 @@ void EnumGenerator::Generate(io::Printer* printer) { } for (int i = 0; i < descriptor_->value_count(); i++) { - absl::flat_hash_map vars; + std::map vars; vars["name"] = descriptor_->value(i)->name(); vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["{"] = ""; diff --git a/src/google/protobuf/compiler/java/enum_field.cc b/src/google/protobuf/compiler/java/enum_field.cc index ed5413c9d1..b6c8dc796c 100644 --- a/src/google/protobuf/compiler/java/enum_field.cc +++ b/src/google/protobuf/compiler/java/enum_field.cc @@ -42,7 +42,6 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -62,7 +61,7 @@ namespace { void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, + std::map* variables, Context* context) { SetCommonFieldVariables(descriptor, info, variables); diff --git a/src/google/protobuf/compiler/java/enum_field.h b/src/google/protobuf/compiler/java/enum_field.h index 09960c6b06..25ab0738da 100644 --- a/src/google/protobuf/compiler/java/enum_field.h +++ b/src/google/protobuf/compiler/java/enum_field.h @@ -38,7 +38,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -91,7 +90,7 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; }; @@ -154,7 +153,7 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/enum_field_lite.cc b/src/google/protobuf/compiler/java/enum_field_lite.cc index e9861245dd..470bc9d2fd 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -42,9 +42,7 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" -#include "absl/strings/str_join.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -70,13 +68,13 @@ bool EnableExperimentalRuntimeForLite() { void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, + std::map* variables, Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->enum_type()); - variables->emplace("kt_type", EscapeKotlinKeywords((*variables)["type"])); + (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->enum_type()); (*variables)["default"] = @@ -91,12 +89,11 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - variables->emplace( - "kt_deprecation", + (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", - (*variables)["name"], " is deprecated\") ") - : ""); + ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + + " is deprecated\") " + : ""; (*variables)["required"] = descriptor->is_required() ? "true" : "false"; if (HasHasbit(descriptor)) { @@ -120,9 +117,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_has_field_bit_message"] = ""; (*variables)["clear_has_field_bit_message"] = ""; - variables->emplace("is_field_present_message", - absl::StrCat((*variables)["name"], "_ != ", - (*variables)["default"], ".getNumber()")); + (*variables)["is_field_present_message"] = + (*variables)["name"] + "_ != " + (*variables)["default"] + + ".getNumber()"; } (*variables)["get_has_field_bit_from_local"] = @@ -131,10 +128,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, GenerateSetBitToLocal(messageBitIndex); if (SupportUnknownEnumValue(descriptor->file())) { - variables->emplace("unknown", - absl::StrCat((*variables)["type"], ".UNRECOGNIZED")); + (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED"; } else { - variables->emplace("unknown", (*variables)["default"]); + (*variables)["unknown"] = (*variables)["default"]; } // We use `x.getClass()` as a null check because it generates less bytecode diff --git a/src/google/protobuf/compiler/java/enum_field_lite.h b/src/google/protobuf/compiler/java/enum_field_lite.h index e2319bdba9..8d7a7d1cf4 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.h +++ b/src/google/protobuf/compiler/java/enum_field_lite.h @@ -39,7 +39,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -84,7 +83,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -132,7 +131,7 @@ class RepeatedImmutableEnumFieldLiteGenerator private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/enum_lite.cc b/src/google/protobuf/compiler/java/enum_lite.cc index 7bb7478898..47cae62bc2 100644 --- a/src/google/protobuf/compiler/java/enum_lite.cc +++ b/src/google/protobuf/compiler/java/enum_lite.cc @@ -38,7 +38,6 @@ #include #include "google/protobuf/io/printer.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -87,7 +86,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { printer->Indent(); for (int i = 0; i < canonical_values_.size(); i++) { - absl::flat_hash_map vars; + std::map vars; vars["name"] = canonical_values_[i]->name(); vars["number"] = absl::StrCat(canonical_values_[i]->number()); WriteEnumValueDocComment(printer, canonical_values_[i]); @@ -110,7 +109,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { // ----------------------------------------------------------------- for (int i = 0; i < aliases_.size(); i++) { - absl::flat_hash_map vars; + std::map vars; vars["classname"] = descriptor_->name(); vars["name"] = aliases_[i].value->name(); vars["canonical_name"] = aliases_[i].canonical_value->name(); @@ -121,7 +120,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { } for (int i = 0; i < descriptor_->value_count(); i++) { - absl::flat_hash_map vars; + std::map vars; vars["name"] = descriptor_->value(i)->name(); vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["{"] = ""; diff --git a/src/google/protobuf/compiler/java/extension.cc b/src/google/protobuf/compiler/java/extension.cc index 1bee360479..24a392edd8 100644 --- a/src/google/protobuf/compiler/java/extension.cc +++ b/src/google/protobuf/compiler/java/extension.cc @@ -35,7 +35,6 @@ #include "google/protobuf/compiler/java/extension.h" #include "google/protobuf/io/printer.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -69,9 +68,8 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} void ExtensionGenerator::InitTemplateVars( const FieldDescriptor* descriptor, const std::string& scope, bool immutable, ClassNameResolver* name_resolver, - absl::flat_hash_map* vars_pointer, - Context* context) { - absl::flat_hash_map& vars = *vars_pointer; + std::map* vars_pointer, Context* context) { + std::map& vars = *vars_pointer; vars["scope"] = scope; vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor); vars["containing_type"] = @@ -118,7 +116,7 @@ void ExtensionGenerator::InitTemplateVars( } void ImmutableExtensionGenerator::Generate(io::Printer* printer) { - absl::flat_hash_map vars; + std::map vars; const bool kUseImmutableNames = true; InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, &vars, context_); diff --git a/src/google/protobuf/compiler/java/extension.h b/src/google/protobuf/compiler/java/extension.h index e2df9ed5d2..b9dc99597b 100644 --- a/src/google/protobuf/compiler/java/extension.h +++ b/src/google/protobuf/compiler/java/extension.h @@ -38,7 +38,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/port.h" namespace google { @@ -82,11 +81,11 @@ class ExtensionGenerator { virtual int GenerateRegistrationCode(io::Printer* printer) = 0; protected: - static void InitTemplateVars( - const FieldDescriptor* descriptor, const std::string& scope, - bool immutable, ClassNameResolver* name_resolver, - absl::flat_hash_map* vars_pointer, - Context* context); + static void InitTemplateVars(const FieldDescriptor* descriptor, + const std::string& scope, bool immutable, + ClassNameResolver* name_resolver, + std::map* vars_pointer, + Context* context); }; class ImmutableExtensionGenerator : public ExtensionGenerator { diff --git a/src/google/protobuf/compiler/java/extension_lite.cc b/src/google/protobuf/compiler/java/extension_lite.cc index f6d7581db7..e18dc6536a 100644 --- a/src/google/protobuf/compiler/java/extension_lite.cc +++ b/src/google/protobuf/compiler/java/extension_lite.cc @@ -31,7 +31,6 @@ #include "google/protobuf/compiler/java/extension_lite.h" #include "google/protobuf/io/printer.h" -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -61,7 +60,7 @@ ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator( ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {} void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) { - absl::flat_hash_map vars; + std::map vars; const bool kUseImmutableNames = true; InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, &vars, context_); diff --git a/src/google/protobuf/compiler/java/field.cc b/src/google/protobuf/compiler/java/field.cc index 49648503bb..831f88ab2d 100644 --- a/src/google/protobuf/compiler/java/field.cc +++ b/src/google/protobuf/compiler/java/field.cc @@ -39,7 +39,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/java/context.h" @@ -242,9 +241,9 @@ template <> FieldGeneratorMap::~FieldGeneratorMap() {} -void SetCommonFieldVariables( - const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, - absl::flat_hash_map* variables) { +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + const FieldGeneratorInfo* info, + std::map* variables) { (*variables)["field_name"] = descriptor->name(); (*variables)["name"] = info->name; (*variables)["classname"] = descriptor->containing_type()->name(); @@ -274,16 +273,15 @@ void SetCommonFieldVariables( (*variables)["annotation_field_type"] = std::string(FieldTypeName(descriptor->type())) + "_LIST"; if (descriptor->is_packed()) { - variables->emplace( - "annotation_field_type", - absl::StrCat((*variables)["annotation_field_type"], "_PACKED")); + (*variables)["annotation_field_type"] = + (*variables)["annotation_field_type"] + "_PACKED"; } } } -void SetCommonOneofVariables( - const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, - absl::flat_hash_map* variables) { +void SetCommonOneofVariables(const FieldDescriptor* descriptor, + const OneofGeneratorInfo* info, + std::map* variables) { (*variables)["oneof_name"] = info->name; (*variables)["oneof_capitalized_name"] = info->capitalized_name; (*variables)["oneof_index"] = @@ -296,10 +294,9 @@ void SetCommonOneofVariables( info->name + "Case_ == " + absl::StrCat(descriptor->number()); } -void PrintExtraFieldInfo( - const absl::flat_hash_map& variables, - io::Printer* printer) { - const absl::flat_hash_map::const_iterator it = +void PrintExtraFieldInfo(const std::map& variables, + io::Printer* printer) { + const std::map::const_iterator it = variables.find("disambiguated_reason"); if (it != variables.end() && !it->second.empty()) { printer->Print( diff --git a/src/google/protobuf/compiler/java/field.h b/src/google/protobuf/compiler/java/field.h index bcd644b73e..5ac57cd4e1 100644 --- a/src/google/protobuf/compiler/java/field.h +++ b/src/google/protobuf/compiler/java/field.h @@ -43,7 +43,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/descriptor.h" -#include "absl/container/flat_hash_map.h" #include "google/protobuf/port.h" namespace google { @@ -170,19 +169,18 @@ struct OneofGeneratorInfo { }; // Set some common variables used in variable FieldGenerators. -void SetCommonFieldVariables( - const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, - absl::flat_hash_map* variables); +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + const FieldGeneratorInfo* info, + std::map* variables); // Set some common oneof variables used in OneofFieldGenerators. -void SetCommonOneofVariables( - const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, - absl::flat_hash_map* variables); +void SetCommonOneofVariables(const FieldDescriptor* descriptor, + const OneofGeneratorInfo* info, + std::map* variables); // Print useful comments before a field's accessors. -void PrintExtraFieldInfo( - const absl::flat_hash_map& variables, - io::Printer* printer); +void PrintExtraFieldInfo(const std::map& variables, + io::Printer* printer); } // namespace java } // namespace compiler diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index 700dc61e90..d13941c6ed 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -84,10 +84,11 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter, printer->Print(ptemplate.c_str(), "annotation_file", annotation_file); } -void PrintEnumVerifierLogic( - io::Printer* printer, const FieldDescriptor* descriptor, - const absl::flat_hash_map& variables, - const char* var_name, const char* terminating_string, bool enforce_lite) { +void PrintEnumVerifierLogic(io::Printer* printer, + const FieldDescriptor* descriptor, + const std::map& variables, + const char* var_name, + const char* terminating_string, bool enforce_lite) { std::string enum_verifier_string = enforce_lite ? absl::StrCat(var_name, ".internalGetVerifier()") : absl::StrCat( diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index d068375c66..9273ae3c0b 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -74,10 +74,11 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$', // If a GeneratedMessageLite contains non-lite enums, then its verifier // must be instantiated inline, rather than retrieved from the enum class. -void PrintEnumVerifierLogic( - io::Printer* printer, const FieldDescriptor* descriptor, - const absl::flat_hash_map& variables, - const char* var_name, const char* terminating_string, bool enforce_lite); +void PrintEnumVerifierLogic(io::Printer* printer, + const FieldDescriptor* descriptor, + const std::map& variables, + const char* var_name, + const char* terminating_string, bool enforce_lite); // Converts a name to camel-case. If cap_first_letter is true, capitalize the // first letter. diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index c739a37a83..2b69bb6e29 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -31,7 +31,6 @@ #include "google/protobuf/compiler/java/map_field.h" #include "google/protobuf/io/printer.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" @@ -89,10 +88,10 @@ std::string WireType(const FieldDescriptor* field) { std::string(FieldTypeName(field->type())); } -void SetMessageVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, Context* context, - absl::flat_hash_map* variables) { +void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, const FieldGeneratorInfo* info, + Context* context, + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); ClassNameResolver* name_resolver = context->GetNameResolver(); @@ -134,8 +133,8 @@ void SetMessageVariables( if (valueJavaType == JAVATYPE_ENUM) { // We store enums as Integers internally. (*variables)["value_type"] = "int"; - variables->emplace("value_type_pass_through_nullness", - (*variables)["value_type"]); + (*variables)["value_type_pass_through_nullness"] = + (*variables)["value_type"]; (*variables)["boxed_value_type"] = "java.lang.Integer"; (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = @@ -144,15 +143,13 @@ void SetMessageVariables( (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); - variables->emplace( - "value_enum_type_pass_through_nullness", - absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])); + (*variables)["value_enum_type_pass_through_nullness"] = + pass_through_nullness + (*variables)["value_enum_type"]; if (SupportUnknownEnumValue(descriptor->file())) { // Map unknown values to a special UNRECOGNIZED value if supported. - variables->emplace( - "unrecognized_value", - absl::StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED")); + (*variables)["unrecognized_value"] = + (*variables)["value_enum_type"] + ".UNRECOGNIZED"; } else { // Map unknown values to the default value if we don't have UNRECOGNIZED. (*variables)["unrecognized_value"] = @@ -161,36 +158,31 @@ void SetMessageVariables( } else { (*variables)["value_type"] = TypeName(value, name_resolver, false); - variables->emplace( - "value_type_pass_through_nullness", - absl::StrCat( - (IsReferenceType(valueJavaType) ? pass_through_nullness : ""), - (*variables)["value_type"])); + (*variables)["value_type_pass_through_nullness"] = + (IsReferenceType(valueJavaType) ? pass_through_nullness : "") + + (*variables)["value_type"]; (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = DefaultValue(value, true, name_resolver, context->options()); } - variables->emplace("type_parameters", - absl::StrCat((*variables)["boxed_key_type"], ", ", - (*variables)["boxed_value_type"])); + (*variables)["type_parameters"] = + (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - variables->emplace( - "kt_deprecation", + (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", - (*variables)["name"], " is deprecated\") ") - : ""); + ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + + " is deprecated\") " + : ""; (*variables)["on_changed"] = "onChanged();"; - variables->emplace("default_entry", - absl::StrCat((*variables)["capitalized_name"], - "DefaultEntryHolder.defaultEntry")); - variables->emplace("map_field_parameter", (*variables)["default_entry"]); + (*variables)["default_entry"] = + (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry"; + (*variables)["map_field_parameter"] = (*variables)["default_entry"]; (*variables)["descriptor"] = name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; diff --git a/src/google/protobuf/compiler/java/map_field.h b/src/google/protobuf/compiler/java/map_field.h index 611fd15575..434150820b 100644 --- a/src/google/protobuf/compiler/java/map_field.h +++ b/src/google/protobuf/compiler/java/map_field.h @@ -68,7 +68,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; Context* context_; void GenerateMapGetters(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/java/map_field_lite.cc b/src/google/protobuf/compiler/java/map_field_lite.cc index 0eff2a3986..22bc306586 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/src/google/protobuf/compiler/java/map_field_lite.cc @@ -90,10 +90,10 @@ std::string WireType(const FieldDescriptor* field) { std::string(FieldTypeName(field->type())); } -void SetMessageVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, Context* context, - absl::flat_hash_map* variables) { +void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, const FieldGeneratorInfo* info, + Context* context, + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); ClassNameResolver* name_resolver = context->GetNameResolver(); diff --git a/src/google/protobuf/compiler/java/map_field_lite.h b/src/google/protobuf/compiler/java/map_field_lite.h index aac8b003ad..46a2d9f884 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.h +++ b/src/google/protobuf/compiler/java/map_field_lite.h @@ -61,7 +61,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index 561ffc6720..eae7bb3bcc 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -115,7 +115,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( // the outermost class in the file. This way, they will be initialized in // a deterministic order. - absl::flat_hash_map vars; + std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["index"] = absl::StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); @@ -159,7 +159,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( int ImmutableMessageGenerator::GenerateStaticVariableInitializers( io::Printer* printer) { int bytecode_estimate = 0; - absl::flat_hash_map vars; + std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["index"] = absl::StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); @@ -196,7 +196,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers( void ImmutableMessageGenerator::GenerateFieldAccessorTable( io::Printer* printer, int* bytecode_estimate) { - absl::flat_hash_map vars; + std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { // We can only make these package-private since the classes that use them @@ -314,7 +314,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { void ImmutableMessageGenerator::Generate(io::Printer* printer) { bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - absl::flat_hash_map variables; + std::map variables; variables["static"] = is_own_file ? "" : "static "; variables["classname"] = descriptor_->name(); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); @@ -426,7 +426,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { } // oneof - absl::flat_hash_map vars; + std::map vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = diff --git a/src/google/protobuf/compiler/java/message_builder.cc b/src/google/protobuf/compiler/java/message_builder.cc index 1bfc5e449a..150c4e6c4c 100644 --- a/src/google/protobuf/compiler/java/message_builder.cc +++ b/src/google/protobuf/compiler/java/message_builder.cc @@ -126,7 +126,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { } // oneof - absl::flat_hash_map vars; + std::map vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = diff --git a/src/google/protobuf/compiler/java/message_builder_lite.cc b/src/google/protobuf/compiler/java/message_builder_lite.cc index 89f3bdc698..1f9d13e9b6 100644 --- a/src/google/protobuf/compiler/java/message_builder_lite.cc +++ b/src/google/protobuf/compiler/java/message_builder_lite.cc @@ -82,7 +82,7 @@ MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {} void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { WriteMessageDocComment(printer, descriptor_); - absl::flat_hash_map vars = { + std::map vars = { {"{", ""}, {"}", ""}, {"classname", name_resolver_->GetImmutableClassName(descriptor_)}, diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 10888aeafe..0e06ed77d8 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -39,7 +39,6 @@ #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" @@ -56,16 +55,16 @@ namespace java { namespace { -void SetMessageVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, - Context* context) { +void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->message_type()); - variables->emplace("kt_type", EscapeKotlinKeywords((*variables)["type"])); + (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->message_type()); (*variables)["group_or_message"] = @@ -75,12 +74,11 @@ void SetMessageVariables( // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - variables->emplace( - "kt_deprecation", + (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", - (*variables)["name"], " is deprecated\") ") - : ""); + ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + + " is deprecated\") " + : ""; (*variables)["on_changed"] = "onChanged();"; (*variables)["ver"] = GeneratedCodeVersionSuffix(); (*variables)["get_parser"] = @@ -108,8 +106,8 @@ void SetMessageVariables( (*variables)["set_has_field_bit_builder"] = ""; (*variables)["clear_has_field_bit_builder"] = ""; - variables->emplace("is_field_present_message", - absl::StrCat((*variables)["name"], "_ != null")); + (*variables)["is_field_present_message"] = + (*variables)["name"] + "_ != null"; } // For repeated builders, one bit is used for whether the array is immutable. diff --git a/src/google/protobuf/compiler/java/message_field.h b/src/google/protobuf/compiler/java/message_field.h index ed83183400..4fe5ac7df4 100644 --- a/src/google/protobuf/compiler/java/message_field.h +++ b/src/google/protobuf/compiler/java/message_field.h @@ -92,7 +92,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; Context* context_; @@ -165,7 +165,7 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; void PrintNestedBuilderCondition(io::Printer* printer, diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index 42962eb016..d01ccc102d 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -56,16 +56,16 @@ namespace java { namespace { -void SetMessageVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, - Context* context) { +void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, + int builderBitIndex, const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->message_type()); - variables->emplace("kt_type", EscapeKotlinKeywords((*variables)["type"])); + (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->message_type()); (*variables)["group_or_message"] = @@ -75,12 +75,11 @@ void SetMessageVariables( // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - variables->emplace( - "kt_deprecation", + (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", - (*variables)["name"], " is deprecated\") ") - : ""); + ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + + " is deprecated\") " + : ""; (*variables)["required"] = descriptor->is_required() ? "true" : "false"; if (HasHasbit(descriptor)) { @@ -99,7 +98,7 @@ void SetMessageVariables( (*variables)["clear_has_field_bit_message"] = ""; (*variables)["is_field_present_message"] = - absl::StrCat((*variables)["name"], "_ != null"); + (*variables)["name"] + "_ != null"; } (*variables)["get_has_field_bit_from_local"] = diff --git a/src/google/protobuf/compiler/java/message_field_lite.h b/src/google/protobuf/compiler/java/message_field_lite.h index f82bdcf1ba..c5387a6ffe 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.h +++ b/src/google/protobuf/compiler/java/message_field_lite.h @@ -83,7 +83,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; const int messageBitIndex_; ClassNameResolver* name_resolver_; Context* context_; @@ -136,7 +136,7 @@ class RepeatedImmutableMessageFieldLiteGenerator protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; Context* context_; }; diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 8eae02a3ce..475a30b9f5 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -117,7 +117,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true, "OrBuilder"); - absl::flat_hash_map variables = { + std::map variables = { {"{", ""}, {"}", ""}, {"deprecation", @@ -173,8 +173,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - absl::flat_hash_map variables = {{"{", ""}, - {"}", ""}}; + std::map variables = {{"{", ""}, {"}", ""}}; variables["static"] = is_own_file ? " " : " static "; variables["classname"] = descriptor_->name(); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); @@ -243,7 +242,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { } // oneof - absl::flat_hash_map vars = {{"{", ""}, {"}", ""}}; + std::map vars = {{"{", ""}, {"}", ""}}; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = diff --git a/src/google/protobuf/compiler/java/primitive_field.cc b/src/google/protobuf/compiler/java/primitive_field.cc index 8121f000c6..87dbdb6a50 100644 --- a/src/google/protobuf/compiler/java/primitive_field.cc +++ b/src/google/protobuf/compiler/java/primitive_field.cc @@ -57,55 +57,54 @@ using internal::WireFormat; namespace { -void SetPrimitiveVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, - Context* context) { +void SetPrimitiveVariables(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); JavaType javaType = GetJavaType(descriptor); (*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType); - variables->emplace("field_type", (*variables)["type"]); + (*variables)["field_type"] = (*variables)["type"]; - std::string name = (*variables)["name"]; if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE || javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT || javaType == JAVATYPE_LONG) { std::string capitalized_type = UnderscoresToCamelCase( PrimitiveTypeName(javaType), /*cap_first_letter=*/true); (*variables)["field_list_type"] = - absl::StrCat("com.google.protobuf.Internal.", capitalized_type, "List"); - (*variables)["empty_list"] = - absl::StrCat("empty", capitalized_type, "List()"); - (*variables)["create_list"] = - absl::StrCat("new", capitalized_type, "List()"); + "com.google.protobuf.Internal." + capitalized_type + "List"; + (*variables)["empty_list"] = "empty" + capitalized_type + "List()"; + (*variables)["create_list"] = "new" + capitalized_type + "List()"; (*variables)["mutable_copy_list"] = - absl::StrCat("mutableCopy(", name, "_)"); + "mutableCopy(" + (*variables)["name"] + "_)"; (*variables)["name_make_immutable"] = - absl::StrCat(name, "_.makeImmutable()"); + (*variables)["name"] + "_.makeImmutable()"; (*variables)["repeated_get"] = - absl::StrCat(name, "_.get", capitalized_type); + (*variables)["name"] + "_.get" + capitalized_type; (*variables)["repeated_add"] = - absl::StrCat(name, "_.add", capitalized_type); + (*variables)["name"] + "_.add" + capitalized_type; (*variables)["repeated_set"] = - absl::StrCat(name, "_.set", capitalized_type); + (*variables)["name"] + "_.set" + capitalized_type; } else { - std::string boxed_type = (*variables)["boxed_type"]; (*variables)["field_list_type"] = - absl::StrCat("java.util.List<", boxed_type, ">"); + "java.util.List<" + (*variables)["boxed_type"] + ">"; (*variables)["create_list"] = - absl::StrCat("new java.util.ArrayList<", boxed_type, ">()"); - (*variables)["mutable_copy_list"] = - absl::StrCat("new java.util.ArrayList<", boxed_type, ">(", name, "_)"); + "new java.util.ArrayList<" + (*variables)["boxed_type"] + ">()"; + (*variables)["mutable_copy_list"] = "new java.util.ArrayList<" + + (*variables)["boxed_type"] + ">(" + + (*variables)["name"] + "_)"; (*variables)["empty_list"] = "java.util.Collections.emptyList()"; - (*variables)["name_make_immutable"] = absl::StrCat( - name, "_ = java.util.Collections.unmodifiableList(", name, "_)"); - (*variables)["repeated_get"] = absl::StrCat(name, "_.get"); - (*variables)["repeated_add"] = absl::StrCat(name, "_.add"); - (*variables)["repeated_set"] = absl::StrCat(name, "_.set"); + (*variables)["name_make_immutable"] = + (*variables)["name"] + "_ = java.util.Collections.unmodifiableList(" + + (*variables)["name"] + "_)"; + (*variables)["repeated_get"] = (*variables)["name"] + "_.get"; + (*variables)["repeated_add"] = (*variables)["name"] + "_.add"; + (*variables)["repeated_set"] = (*variables)["name"] + "_.set"; } (*variables)["default"] = @@ -135,8 +134,8 @@ void SetPrimitiveVariables( descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", name, - " is deprecated\") ") + ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + + " is deprecated\") " : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { @@ -166,20 +165,21 @@ void SetPrimitiveVariables( switch (descriptor->type()) { case FieldDescriptor::TYPE_BYTES: (*variables)["is_field_present_message"] = - absl::StrCat("!", name, "_.isEmpty()"); + "!" + (*variables)["name"] + "_.isEmpty()"; break; case FieldDescriptor::TYPE_FLOAT: (*variables)["is_field_present_message"] = - absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); + "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] + + "_) != 0"; break; case FieldDescriptor::TYPE_DOUBLE: - (*variables)["is_field_present_message"] = absl::StrCat( - "java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); + (*variables)["is_field_present_message"] = + "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] + + "_) != 0"; break; default: - variables->emplace( - "is_field_present_message", - absl::StrCat(name, "_ != ", (*variables)["default"])); + (*variables)["is_field_present_message"] = + (*variables)["name"] + "_ != " + (*variables)["default"]; break; } } diff --git a/src/google/protobuf/compiler/java/primitive_field.h b/src/google/protobuf/compiler/java/primitive_field.h index dd5c1de1b3..d8104ba5f6 100644 --- a/src/google/protobuf/compiler/java/primitive_field.h +++ b/src/google/protobuf/compiler/java/primitive_field.h @@ -92,7 +92,7 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; }; @@ -155,7 +155,7 @@ class RepeatedImmutablePrimitiveFieldGenerator private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.cc b/src/google/protobuf/compiler/java/primitive_field_lite.cc index cf398b03d4..e370815326 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/primitive_field_lite.cc @@ -66,17 +66,18 @@ bool EnableExperimentalRuntimeForLite() { #endif // !PROTOBUF_EXPERIMENT } -void SetPrimitiveVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, - Context* context) { +void SetPrimitiveVariables(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); JavaType javaType = GetJavaType(descriptor); (*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType); - variables->emplace("field_type", (*variables)["type"]); + (*variables)["field_type"] = (*variables)["type"]; (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver, context->options()); (*variables)["capitalized_type"] = GetCapitalizedType( @@ -89,47 +90,43 @@ void SetPrimitiveVariables( std::string capitalized_type = UnderscoresToCamelCase( PrimitiveTypeName(javaType), true /* cap_next_letter */); - std::string name = (*variables)["name"]; switch (javaType) { case JAVATYPE_INT: case JAVATYPE_LONG: case JAVATYPE_FLOAT: case JAVATYPE_DOUBLE: case JAVATYPE_BOOLEAN: - (*variables)["field_list_type"] = absl::StrCat( - "com.google.protobuf.Internal.", capitalized_type, "List"); - (*variables)["empty_list"] = - absl::StrCat("empty", capitalized_type, "List()"); + (*variables)["field_list_type"] = + "com.google.protobuf.Internal." + capitalized_type + "List"; + (*variables)["empty_list"] = "empty" + capitalized_type + "List()"; (*variables)["make_name_unmodifiable"] = - absl::StrCat(name, "_.makeImmutable()"); + (*variables)["name"] + "_.makeImmutable()"; (*variables)["repeated_get"] = - absl::StrCat(name, "_.get", capitalized_type); + (*variables)["name"] + "_.get" + capitalized_type; (*variables)["repeated_add"] = - absl::StrCat(name, "_.add", capitalized_type); + (*variables)["name"] + "_.add" + capitalized_type; (*variables)["repeated_set"] = - absl::StrCat(name, "_.set", capitalized_type); + (*variables)["name"] + "_.set" + capitalized_type; (*variables)["visit_type"] = capitalized_type; - (*variables)["visit_type_list"] = - absl::StrCat("visit", capitalized_type, "List"); + (*variables)["visit_type_list"] = "visit" + capitalized_type + "List"; break; default: - variables->emplace( - "field_list_type", - absl::StrCat("com.google.protobuf.Internal.ProtobufList<", - (*variables)["boxed_type"], ">")); + (*variables)["field_list_type"] = + "com.google.protobuf.Internal.ProtobufList<" + + (*variables)["boxed_type"] + ">"; (*variables)["empty_list"] = "emptyProtobufList()"; (*variables)["make_name_unmodifiable"] = - absl::StrCat(name, "_.makeImmutable()"); - (*variables)["repeated_get"] = absl::StrCat(name, "_.get"); - (*variables)["repeated_add"] = absl::StrCat(name, "_.add"); - (*variables)["repeated_set"] = absl::StrCat(name, "_.set"); + (*variables)["name"] + "_.makeImmutable()"; + (*variables)["repeated_get"] = (*variables)["name"] + "_.get"; + (*variables)["repeated_add"] = (*variables)["name"] + "_.add"; + (*variables)["repeated_set"] = (*variables)["name"] + "_.set"; (*variables)["visit_type"] = "ByteString"; (*variables)["visit_type_list"] = "visitList"; } if (javaType == JAVATYPE_BYTES) { (*variables)["bytes_default"] = - absl::AsciiStrToUpper(name) + "_DEFAULT_VALUE"; + absl::AsciiStrToUpper((*variables)["name"]) + "_DEFAULT_VALUE"; } if (IsReferenceType(javaType)) { @@ -146,8 +143,8 @@ void SetPrimitiveVariables( descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", name, - " is deprecated\") ") + ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + + " is deprecated\") " : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { @@ -172,20 +169,21 @@ void SetPrimitiveVariables( switch (descriptor->type()) { case FieldDescriptor::TYPE_BYTES: (*variables)["is_field_present_message"] = - absl::StrCat("!", name, "_.isEmpty()"); + "!" + (*variables)["name"] + "_.isEmpty()"; break; case FieldDescriptor::TYPE_FLOAT: (*variables)["is_field_present_message"] = - absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); + "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] + + "_) != 0"; break; case FieldDescriptor::TYPE_DOUBLE: - (*variables)["is_field_present_message"] = absl::StrCat( - "java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); + (*variables)["is_field_present_message"] = + "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] + + "_) != 0"; break; default: - variables->emplace( - "is_field_present_message", - absl::StrCat(name, "_ != " + (*variables)["default"])); + (*variables)["is_field_present_message"] = + (*variables)["name"] + "_ != " + (*variables)["default"]; break; } } @@ -195,8 +193,7 @@ void SetPrimitiveVariables( (*variables)["set_has_field_bit_to_local"] = GenerateSetBitToLocal(messageBitIndex); // Annotations often use { and } variables to denote ranges. - (*variables)["{"] = ""; - (*variables)["}"] = ""; + (*variables)["{"] = (*variables)["}"] = ""; } } // namespace diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.h b/src/google/protobuf/compiler/java/primitive_field_lite.h index 3665d4570b..410b7d608f 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/primitive_field_lite.h @@ -83,7 +83,7 @@ class ImmutablePrimitiveFieldLiteGenerator protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -133,7 +133,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/service.cc b/src/google/protobuf/compiler/java/service.cc index cb539c7b12..d0c525b8c4 100644 --- a/src/google/protobuf/compiler/java/service.cc +++ b/src/google/protobuf/compiler/java/service.cc @@ -215,7 +215,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - absl::flat_hash_map vars; + std::map vars; vars["index"] = absl::StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); @@ -262,7 +262,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod( for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - absl::flat_hash_map vars; + std::map vars; vars["index"] = absl::StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); @@ -307,7 +307,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - absl::flat_hash_map vars; + std::map vars; vars["index"] = absl::StrCat(i); vars["type"] = (which == REQUEST) @@ -362,7 +362,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { printer->Print(" {\n"); printer->Indent(); - absl::flat_hash_map vars; + std::map vars; vars["index"] = absl::StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, @@ -426,7 +426,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { printer->Print(" {\n"); printer->Indent(); - absl::flat_hash_map vars; + std::map vars; vars["index"] = absl::StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, @@ -449,7 +449,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { void ImmutableServiceGenerator::GenerateMethodSignature( io::Printer* printer, const MethodDescriptor* method, IsAbstract is_abstract) { - absl::flat_hash_map vars; + std::map vars; vars["name"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); @@ -463,7 +463,7 @@ void ImmutableServiceGenerator::GenerateMethodSignature( void ImmutableServiceGenerator::GenerateBlockingMethodSignature( io::Printer* printer, const MethodDescriptor* method) { - absl::flat_hash_map vars; + std::map vars; vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); diff --git a/src/google/protobuf/compiler/java/string_field.cc b/src/google/protobuf/compiler/java/string_field.cc index 4d13f1b53f..910ee8e0ee 100644 --- a/src/google/protobuf/compiler/java/string_field.cc +++ b/src/google/protobuf/compiler/java/string_field.cc @@ -59,11 +59,12 @@ using internal::WireFormatLite; namespace { -void SetPrimitiveVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, - Context* context) { +void SetPrimitiveVariables(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; diff --git a/src/google/protobuf/compiler/java/string_field.h b/src/google/protobuf/compiler/java/string_field.h index 515238e1df..c9b6256d5d 100644 --- a/src/google/protobuf/compiler/java/string_field.h +++ b/src/google/protobuf/compiler/java/string_field.h @@ -91,7 +91,7 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; }; @@ -152,7 +152,7 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/string_field_lite.cc b/src/google/protobuf/compiler/java/string_field_lite.cc index 69532a31d2..df86df7876 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.cc +++ b/src/google/protobuf/compiler/java/string_field_lite.cc @@ -59,11 +59,12 @@ using internal::WireFormatLite; namespace { -void SetPrimitiveVariables( - const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - absl::flat_hash_map* variables, - Context* context) { +void SetPrimitiveVariables(const FieldDescriptor* descriptor, + int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, + ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["empty_list"] = diff --git a/src/google/protobuf/compiler/java/string_field_lite.h b/src/google/protobuf/compiler/java/string_field_lite.h index f0894fb510..f35da288f9 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.h +++ b/src/google/protobuf/compiler/java/string_field_lite.h @@ -84,7 +84,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { protected: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; const int messageBitIndex_; ClassNameResolver* name_resolver_; Context* context_; @@ -133,7 +133,7 @@ class RepeatedImmutableStringFieldLiteGenerator private: const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; ClassNameResolver* name_resolver_; Context* context_; }; diff --git a/src/google/protobuf/compiler/objectivec/enum_field.cc b/src/google/protobuf/compiler/objectivec/enum_field.cc index 4b6e2fe7d5..cf0a3df498 100644 --- a/src/google/protobuf/compiler/objectivec/enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/enum_field.cc @@ -34,7 +34,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" #include "google/protobuf/io/printer.h" @@ -46,9 +45,8 @@ namespace objectivec { namespace { -void SetEnumVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables) { +void SetEnumVariables(const FieldDescriptor* descriptor, + std::map* variables) { std::string type = EnumName(descriptor->enum_type()); (*variables)["storage_type"] = type; // For non repeated fields, if it was defined in a different file, the diff --git a/src/google/protobuf/compiler/objectivec/extension.cc b/src/google/protobuf/compiler/objectivec/extension.cc index 38371e5ed4..91f008ec61 100644 --- a/src/google/protobuf/compiler/objectivec/extension.cc +++ b/src/google/protobuf/compiler/objectivec/extension.cc @@ -37,7 +37,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" @@ -65,7 +64,7 @@ ExtensionGenerator::ExtensionGenerator(const std::string& root_class_name, } void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { - absl::flat_hash_map vars; + std::map vars; vars["method_name"] = method_name_; if (IsRetainedName(method_name_)) { vars["storage_attribute"] = " NS_RETURNS_NOT_RETAINED"; @@ -92,7 +91,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { void ExtensionGenerator::GenerateStaticVariablesInitialization( io::Printer* printer) { - absl::flat_hash_map vars; + std::map vars; 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); diff --git a/src/google/protobuf/compiler/objectivec/field.cc b/src/google/protobuf/compiler/objectivec/field.cc index 6e73e8dbb8..6274b9d05e 100644 --- a/src/google/protobuf/compiler/objectivec/field.cc +++ b/src/google/protobuf/compiler/objectivec/field.cc @@ -37,7 +37,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/enum_field.h" #include "google/protobuf/compiler/objectivec/helpers.h" @@ -54,9 +53,8 @@ namespace objectivec { namespace { -void SetCommonFieldVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables) { +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + std::map* variables) { std::string camel_case_name = FieldName(descriptor); std::string raw_field_name; if (descriptor->type() == FieldDescriptor::TYPE_GROUP) { diff --git a/src/google/protobuf/compiler/objectivec/field.h b/src/google/protobuf/compiler/objectivec/field.h index 07dc14ea6b..07643720ec 100644 --- a/src/google/protobuf/compiler/objectivec/field.h +++ b/src/google/protobuf/compiler/objectivec/field.h @@ -37,7 +37,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/match.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -105,7 +104,7 @@ class FieldGenerator { bool WantsHasProperty() const; const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; }; class SingleFieldGenerator : public FieldGenerator { diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index 95f6d156c2..fd7b644579 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -626,7 +626,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { // File descriptor only needed if there are messages to use it. if (!message_generators_.empty()) { - absl::flat_hash_map vars; + std::map vars; vars["root_class_name"] = root_class_name_; vars["package"] = file_->package(); vars["objc_prefix"] = FileClassPrefix(file_); diff --git a/src/google/protobuf/compiler/objectivec/import_writer.cc b/src/google/protobuf/compiler/objectivec/import_writer.cc index 563f5dedf1..b276ea5634 100644 --- a/src/google/protobuf/compiler/objectivec/import_writer.cc +++ b/src/google/protobuf/compiler/objectivec/import_writer.cc @@ -36,7 +36,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "google/protobuf/compiler/objectivec/line_consumer.h" @@ -56,14 +55,13 @@ namespace { class ProtoFrameworkCollector : public LineConsumer { public: explicit ProtoFrameworkCollector( - absl::flat_hash_map* - inout_proto_file_to_framework_name) + std::map* inout_proto_file_to_framework_name) : map_(inout_proto_file_to_framework_name) {} bool ConsumeLine(absl::string_view line, std::string* out_error) override; private: - absl::flat_hash_map* map_; + std::map* map_; }; bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line, @@ -90,7 +88,7 @@ bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line, absl::string_view proto_file = absl::StripAsciiWhitespace( proto_file_list.substr(start, offset - start)); if (!proto_file.empty()) { - absl::flat_hash_map::iterator existing_entry = + std::map::iterator existing_entry = map_->find(std::string(proto_file)); if (existing_entry != map_->end()) { std::cerr << "warning: duplicate proto file reference, replacing " @@ -149,7 +147,7 @@ void ImportWriter::AddFile(const FileDescriptor* file, ParseFrameworkMappings(); } - absl::flat_hash_map::iterator proto_lookup = + std::map::iterator proto_lookup = proto_file_to_framework_name_.find(file->name()); if (proto_lookup != proto_file_to_framework_name_.end()) { other_framework_imports_.push_back( diff --git a/src/google/protobuf/compiler/objectivec/import_writer.h b/src/google/protobuf/compiler/objectivec/import_writer.h index d36fe34cb2..f3fb63b4b7 100644 --- a/src/google/protobuf/compiler/objectivec/import_writer.h +++ b/src/google/protobuf/compiler/objectivec/import_writer.h @@ -35,7 +35,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" @@ -69,7 +68,7 @@ class ImportWriter { const std::string named_framework_to_proto_path_mappings_path_; const std::string runtime_import_prefix_; const bool include_wkt_imports_; - absl::flat_hash_map proto_file_to_framework_name_; + std::map proto_file_to_framework_name_; bool need_to_parse_mapping_file_; std::vector protobuf_imports_; diff --git a/src/google/protobuf/compiler/objectivec/message.cc b/src/google/protobuf/compiler/objectivec/message.cc index 19a24c45a7..49375713ee 100644 --- a/src/google/protobuf/compiler/objectivec/message.cc +++ b/src/google/protobuf/compiler/objectivec/message.cc @@ -39,7 +39,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/enum.h" @@ -518,7 +517,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { printer->Outdent(); } - absl::flat_hash_map vars; + std::map vars; vars["classname"] = class_name_; vars["rootclassname"] = root_classname_; vars["fields"] = has_fields ? "fields" : "NULL"; diff --git a/src/google/protobuf/compiler/objectivec/message_field.cc b/src/google/protobuf/compiler/objectivec/message_field.cc index 5c695cd3cc..1f174f6ea4 100644 --- a/src/google/protobuf/compiler/objectivec/message_field.cc +++ b/src/google/protobuf/compiler/objectivec/message_field.cc @@ -34,7 +34,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" @@ -45,9 +44,8 @@ namespace objectivec { namespace { -void SetMessageVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables) { +void SetMessageVariables(const FieldDescriptor* descriptor, + std::map* variables) { const std::string& message_type = ClassName(descriptor->message_type()); const std::string& containing_class = ClassName(descriptor->containing_type()); diff --git a/src/google/protobuf/compiler/objectivec/names.cc b/src/google/protobuf/compiler/objectivec/names.cc index 702da78434..a82f8b2818 100644 --- a/src/google/protobuf/compiler/objectivec/names.cc +++ b/src/google/protobuf/compiler/objectivec/names.cc @@ -41,7 +41,6 @@ #include #include "google/protobuf/compiler/code_generator.h" -#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" @@ -84,16 +83,16 @@ class SimpleLineCollector : public LineConsumer { class PackageToPrefixesCollector : public LineConsumer { public: - PackageToPrefixesCollector(const std::string& usage, - absl::flat_hash_map* - inout_package_to_prefix_map) + PackageToPrefixesCollector( + const std::string& usage, + std::map* inout_package_to_prefix_map) : usage_(usage), prefix_map_(inout_package_to_prefix_map) {} bool ConsumeLine(absl::string_view line, std::string* out_error) override; private: const std::string usage_; - absl::flat_hash_map* prefix_map_; + std::map* prefix_map_; }; class PrefixModeStorage { @@ -130,7 +129,7 @@ class PrefixModeStorage { private: bool use_package_name_; - absl::flat_hash_map package_to_prefix_map_; + std::map package_to_prefix_map_; std::string package_to_prefix_mappings_path_; std::string exception_path_; std::string forced_prefix_; @@ -188,7 +187,7 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings( const std::string lookup_key = package.empty() ? no_package_prefix + file->name() : package; - absl::flat_hash_map::const_iterator prefix_lookup = + std::map::const_iterator prefix_lookup = package_to_prefix_map_.find(lookup_key); if (prefix_lookup != package_to_prefix_map_.end()) { @@ -1022,10 +1021,9 @@ bool PackageToPrefixesCollector::ConsumeLine(absl::string_view line, return true; } -bool LoadExpectedPackagePrefixes( - const std::string& expected_prefixes_path, - absl::flat_hash_map* prefix_map, - std::string* out_error) { +bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path, + std::map* prefix_map, + std::string* out_error) { if (expected_prefixes_path.empty()) { return true; } @@ -1036,8 +1034,7 @@ bool LoadExpectedPackagePrefixes( bool ValidateObjCClassPrefix( const FileDescriptor* file, const std::string& expected_prefixes_path, - const absl::flat_hash_map& - expected_package_prefixes, + const std::map& expected_package_prefixes, bool prefixes_must_be_registered, bool require_prefixes, std::string* out_error) { // Reminder: An explicit prefix option of "" is valid in case the default @@ -1060,7 +1057,7 @@ bool ValidateObjCClassPrefix( // Check: Error - See if there was an expected prefix for the package and // report if it doesn't match (wrong or missing). - absl::flat_hash_map::const_iterator package_match = + std::map::const_iterator package_match = expected_package_prefixes.find(lookup_key); if (package_match != expected_package_prefixes.end()) { // There was an entry, and... @@ -1098,7 +1095,7 @@ bool ValidateObjCClassPrefix( if (!prefix.empty() && have_expected_prefix_file) { // For a non empty prefix, look for any other package that uses the prefix. std::string other_package_for_prefix; - for (absl::flat_hash_map::const_iterator i = + for (std::map::const_iterator i = expected_package_prefixes.begin(); i != expected_package_prefixes.end(); ++i) { if (i->second == prefix) { @@ -1216,7 +1213,7 @@ bool ValidateObjCClassPrefixes(const std::vector& files, } // Load the expected package prefixes, if available, to validate against. - absl::flat_hash_map expected_package_prefixes; + std::map expected_package_prefixes; if (!LoadExpectedPackagePrefixes(validation_options.expected_prefixes_path, &expected_package_prefixes, out_error)) { return false; diff --git a/src/google/protobuf/compiler/objectivec/oneof.h b/src/google/protobuf/compiler/objectivec/oneof.h index a35a2f6ba0..ea79251613 100644 --- a/src/google/protobuf/compiler/objectivec/oneof.h +++ b/src/google/protobuf/compiler/objectivec/oneof.h @@ -36,7 +36,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -68,7 +67,7 @@ class OneofGenerator { private: const OneofDescriptor* descriptor_; - absl::flat_hash_map variables_; + std::map variables_; }; } // namespace objectivec diff --git a/src/google/protobuf/compiler/objectivec/primitive_field.cc b/src/google/protobuf/compiler/objectivec/primitive_field.cc index 45eeb0a520..d116ec0462 100644 --- a/src/google/protobuf/compiler/objectivec/primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/primitive_field.cc @@ -33,7 +33,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/io/printer.h" @@ -112,9 +111,8 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) { return nullptr; } -void SetPrimitiveVariables( - const FieldDescriptor* descriptor, - absl::flat_hash_map* variables) { +void SetPrimitiveVariables(const FieldDescriptor* descriptor, + std::map* variables) { std::string primitive_name = PrimitiveTypeName(descriptor); (*variables)["type"] = primitive_name; (*variables)["storage_type"] = primitive_name; diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index 1475267337..0f51a7d2a3 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -54,7 +54,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" @@ -434,7 +433,7 @@ void Generator::PrintImports() const { // Prints the single file descriptor for this file. void Generator::PrintFileDescriptor() const { - absl::flat_hash_map m; + std::map m; m["descriptor_name"] = kDescriptorKey; m["name"] = file_->name(); m["package"] = file_->package(); @@ -509,7 +508,7 @@ void Generator::PrintAllNestedEnumsInFile() const { // enum name to a Python EnumDescriptor object equivalent to // enum_descriptor. void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { - absl::flat_hash_map m; + std::map m; std::string module_level_descriptor_name = ModuleLevelDescriptorName(enum_descriptor); m["descriptor_name"] = module_level_descriptor_name; @@ -584,7 +583,7 @@ void Generator::PrintServices() const { void Generator::PrintServiceDescriptor( const ServiceDescriptor& descriptor) const { - absl::flat_hash_map m; + std::map m; m["service_name"] = ModuleLevelServiceDescriptorName(descriptor); m["name"] = descriptor.name(); m["file"] = kDescriptorKey; @@ -634,7 +633,7 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { // // Mutually recursive with PrintNestedDescriptors(). void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { - absl::flat_hash_map m; + std::map m; m["name"] = message_descriptor.name(); m["full_name"] = message_descriptor.full_name(); m["file"] = kDescriptorKey; @@ -785,7 +784,7 @@ void Generator::PrintMessage(const Descriptor& message_descriptor, to_register->push_back(qualified_name); PrintNestedMessages(message_descriptor, qualified_name, to_register); - absl::flat_hash_map m; + std::map m; m["descriptor_key"] = kDescriptorKey; m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor); printer_->Print(m, "'$descriptor_key$' : $descriptor_name$,\n"); @@ -840,7 +839,7 @@ void Generator::FixForeignFieldsInDescriptor( FixContainingTypeInDescriptor(enum_descriptor, &descriptor); } for (int i = 0; i < descriptor.oneof_decl_count(); ++i) { - absl::flat_hash_map m; + std::map m; const OneofDescriptor* oneof = descriptor.oneof_decl(i); m["descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["oneof_name"] = oneof->name(); @@ -859,7 +858,7 @@ void Generator::FixForeignFieldsInDescriptor( } void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { - absl::flat_hash_map m; + std::map m; m["descriptor_name"] = kDescriptorKey; m["message_name"] = descriptor.name(); m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor); @@ -871,7 +870,7 @@ void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { void Generator::AddServiceToFileDescriptor( const ServiceDescriptor& descriptor) const { - absl::flat_hash_map m; + std::map m; m["descriptor_name"] = kDescriptorKey; m["service_name"] = descriptor.name(); m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor); @@ -883,7 +882,7 @@ void Generator::AddServiceToFileDescriptor( void Generator::AddEnumToFileDescriptor( const EnumDescriptor& descriptor) const { - absl::flat_hash_map m; + std::map m; m["descriptor_name"] = kDescriptorKey; m["enum_name"] = descriptor.name(); m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor); @@ -895,7 +894,7 @@ void Generator::AddEnumToFileDescriptor( void Generator::AddExtensionToFileDescriptor( const FieldDescriptor& descriptor) const { - absl::flat_hash_map m; + std::map m; m["descriptor_name"] = kDescriptorKey; m["field_name"] = descriptor.name(); m["resolved_name"] = ResolveKeyword(descriptor.name()); @@ -919,7 +918,7 @@ void Generator::FixForeignFieldsInField( const std::string& python_dict_name) const { const std::string field_referencing_expression = FieldReferencingExpression(containing_type, field, python_dict_name); - absl::flat_hash_map m; + std::map m; m["field_ref"] = field_referencing_expression; const Descriptor* foreign_message_type = field.message_type(); if (foreign_message_type) { @@ -1015,7 +1014,7 @@ void Generator::FixForeignFieldsInExtension( const FieldDescriptor& extension_field) const { GOOGLE_CHECK(extension_field.is_extension()); - absl::flat_hash_map m; + std::map m; // Confusingly, for FieldDescriptors that happen to be extensions, // containing_type() means "extended type." // On the other hand, extension_scope() will give us what we normally @@ -1047,7 +1046,7 @@ void Generator::PrintEnumValueDescriptor( // More circular references. ::sigh:: std::string options_string; descriptor.options().SerializeToString(&options_string); - absl::flat_hash_map m; + std::map m; m["name"] = descriptor.name(); m["index"] = absl::StrCat(descriptor.index()); m["number"] = absl::StrCat(descriptor.number()); @@ -1075,7 +1074,7 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field, bool is_extension) const { std::string options_string; field.options().SerializeToString(&options_string); - absl::flat_hash_map m; + std::map m; m["name"] = field.name(); m["full_name"] = field.full_name(); m["index"] = absl::StrCat(field.index()); diff --git a/src/google/protobuf/compiler/python/pyi_generator.h b/src/google/protobuf/compiler/python/pyi_generator.h index 8a32a98481..7f1e5d839d 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.h +++ b/src/google/protobuf/compiler/python/pyi_generator.h @@ -39,7 +39,6 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/synchronization/mutex.h" #include "google/protobuf/compiler/code_generator.h" @@ -107,7 +106,7 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera mutable io::Printer* printer_; // Set in Generate(). Under mutex_. // import_map will be a mapping from filename to module alias, e.g. // "google3/foo/bar.py" -> "_bar" - mutable absl::flat_hash_map import_map_; + mutable std::map import_map_; }; } // namespace python diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index 68d58f0823..450e90ffc8 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -534,10 +535,10 @@ class PROTOBUF_EXPORT Printer { // Pushes a new variable lookup frame that stores `vars` by reference. // // Returns an RAII object that pops the lookup frame. - template + template auto WithVars(const Map* vars) { var_lookups_.emplace_back([vars](absl::string_view var) -> LookupResult { - auto it = vars->find(StringType(var)); + auto it = vars->find(std::string(var)); if (it == vars->end()) { return absl::nullopt; } @@ -553,12 +554,11 @@ class PROTOBUF_EXPORT Printer { // // Returns an RAII object that pops the lookup frame. template , - typename StringType = absl::string_view, std::enable_if_t::value, int> = 0> auto WithVars(Map&& vars) { var_lookups_.emplace_back([vars = std::forward(vars)]( absl::string_view var) -> LookupResult { - auto it = vars.find(StringType(var)); + auto it = vars.find(std::string(var)); if (it == vars.end()) { return absl::nullopt; } @@ -581,11 +581,11 @@ class PROTOBUF_EXPORT Printer { // Pushes a new annotation lookup frame that stores `vars` by reference. // // Returns an RAII object that pops the lookup frame. - template + template auto WithAnnotations(const Map* vars) { annotation_lookups_.emplace_back( [vars](absl::string_view var) -> absl::optional { - auto it = vars->find(StringType(var)); + auto it = vars->find(std::string(var)); if (it == vars->end()) { return absl::nullopt; } @@ -605,7 +605,7 @@ class PROTOBUF_EXPORT Printer { annotation_lookups_.emplace_back( [vars = std::forward(vars)]( absl::string_view var) -> absl::optional { - auto it = vars.find(var); + auto it = vars.find(std::string(var)); if (it == vars.end()) { return absl::nullopt; } @@ -671,19 +671,6 @@ class PROTOBUF_EXPORT Printer { PrintImpl(text, {}, opts); } - // TODO(b/243140651) Delete this once migrating callers to containers with - // heterogeneous lookup. - void Print(const std::map& vars, - absl::string_view text) { - PrintOptions opts; - opts.checks_are_debug_only = true; - opts.use_substitution_map = true; - opts.allow_digit_substitions = false; - - auto pop = WithVars, std::string>(&vars); - PrintImpl(text, {}, opts); - } - template void Print(absl::string_view text, const Args&... args) { static_assert(sizeof...(args) % 2 == 0, ""); @@ -691,10 +678,10 @@ class PROTOBUF_EXPORT Printer { // Include an extra arg, since a zero-length array is ill-formed, and // MSVC complains. absl::string_view vars[] = {args..., ""}; - absl::flat_hash_map map; + absl::flat_hash_map map; map.reserve(sizeof...(args) / 2); for (size_t i = 0; i < sizeof...(args); i += 2) { - map.emplace(vars[i], vars[i + 1]); + map.emplace(std::string(vars[i]), std::string(vars[i + 1])); } Print(map, text); @@ -751,7 +738,7 @@ class PROTOBUF_EXPORT Printer { // FormatInternal is a helper function not meant to use directly, use // compiler::cpp::Formatter instead. void FormatInternal(absl::Span args, - const absl::flat_hash_map& vars, + const std::map& vars, absl::string_view format) { PrintOptions opts; opts.use_curly_brace_substitutions = true; diff --git a/third_party/utf8_range b/third_party/utf8_range index 45fbf543fe..a67b76f9f4 160000 --- a/third_party/utf8_range +++ b/third_party/utf8_range @@ -1 +1 @@ -Subproject commit 45fbf543fec00020a08650791a37575319a3ea1d +Subproject commit a67b76f9f40107f2c78a5aa860bb6ce37ed83d85 From c1202610e06393c1e2b9853592d1b62b7c99a7c5 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 19 Oct 2022 16:13:56 -0700 Subject: [PATCH 14/29] Updating changelog --- CHANGES.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index c110dcbffe..52eee948ef 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,6 +37,12 @@ * Introduce the Printer::{SetRedactDebugString,SetRandomizeDebugString} private flags. * Introduce global flags to control Printer::{SetRedactDebugString, SetRandomizeDebugString}. * proto3 string fields no longer trigger clang-tidy warning bugprone-branch-clone. + * Fix the API of DescriptorUpgrader::set_allow_unknown_dependencies to set to True always, and to populate into the DescriptorPool as well. + * Report line numbers consistently in text-format deprecated-field warnings. + * Reserve C++20 keywords + * Fixed C++ code generation for protos that use int32_t, uint32_t, int64_t, uint64_t, size_t as field names. + * Annotate generated C++ public aliases for enum types. + * Change default arena max block size from 8K to 32K. Kotlin @@ -57,6 +63,12 @@ * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. * Change the Lite runtime to prefer merging from the wireformat into mutable messages rather than building up a new immutable object before merging. This way results in fewer allocations and copy operations. * Move proto wireformat parsing functionality from the private "parsing constructor" to the Builder class. + * Refactoring java full runtime to reuse sub-message builders and prepare to migrate parsing logic from parse constructor to builder. + * Move proto wireformat parsing functionality from the private "parsing constructor" to the Builder class. + * Change the Lite runtime to prefer merging from the wireformat into mutable messages rather than building up a new immutable object before merging. This way results in fewer allocations and copy operations. + * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. + * Fix TextFormat parser to build up recurring (but supposedly not repeated) sub-messages directly from text rather than building a new sub-message and merging the fully formed message into the existing field. + * Fix bug in nested builder caching logic where cleared sub-field builders would remain dirty after a clear and build in a parent layer. https://github.com/protocolbuffers/protobuf/issues/10624 Python * Changes ordering of printed fields in .pyi files from lexicographic to the same ordering found in the proto descriptor. @@ -66,6 +78,7 @@ Compiler * Print full path name of source .proto file on error + * Include proto message type in the annotation comments. 2022-10-18 version 21.8 (C++/Java/Python/PHP/Objective-C/C#/Ruby) From 0d8ac768a14a5f91d2322e2316e094445b8794e2 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 24 Oct 2022 10:33:34 -0700 Subject: [PATCH 15/29] Target macOS 10.9 (#10802) (#10807) Update toolchain to target macosx 10.9 to fix https://github.com/protocolbuffers/protobuf/issues/10799 Co-authored-by: deannagarcia <69992229+deannagarcia@users.noreply.github.com> --- toolchain/BUILD.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/BUILD.bazel b/toolchain/BUILD.bazel index 20a435c76f..5bc8c8a030 100644 --- a/toolchain/BUILD.bazel +++ b/toolchain/BUILD.bazel @@ -102,7 +102,7 @@ cc_toolchain_config( linker_path = "/usr/tools", sysroot = "/usr/tools/xcode_14_0/macosx", target_cpu = "aarch64", - target_full_name = "aarch64-apple-macosx11.3", + target_full_name = "aarch64-apple-macosx10.9", ) cc_toolchain_config( @@ -119,7 +119,7 @@ cc_toolchain_config( linker_path = "/usr/tools", sysroot = "/usr/tools/xcode_14_0/macosx", target_cpu = "x86_64", - target_full_name = "x86_64-apple-macosx11.3", + target_full_name = "x86_64-apple-macosx10.9", ) cc_toolchain_config( From 449b6e860f52f2e166790295e599826348edd5c2 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 19 Oct 2022 16:19:03 -0700 Subject: [PATCH 16/29] Fixing merge issues --- .bazelrc | 34 +++++++++++++++ CMakeLists.txt | 4 ++ cmake/protobuf-config.cmake.in | 1 + cmake/utf8_range.cmake | 8 ++-- kokoro/windows/prepare_build_win64.bat | 2 +- protobuf_deps.bzl | 4 +- python/google/protobuf/pyext/message.cc | 1 - python/setup.py | 2 + .../compiler/csharp/csharp_map_field.cc | 2 +- .../generated_message_tctable_lite.cc | 42 +++++++++++-------- third_party/utf8_range | 2 +- 11 files changed, 76 insertions(+), 26 deletions(-) diff --git a/.bazelrc b/.bazelrc index 554440cfe3..de30d6b48c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1,35 @@ build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 + +build:dbg --compilation_mode=dbg + +build:opt --compilation_mode=opt + +build:san-common --config=dbg --strip=never --copt=-O0 --copt=-fno-omit-frame-pointer + +build:asan --config=san-common --copt=-fsanitize=address --linkopt=-fsanitize=address +build:asan --copt=-DADDRESS_SANITIZER=1 +# ASAN hits ODR violations with shared linkage due to rules_proto. +build:asan --dynamic_mode=off + +build:msan --config=san-common --copt=-fsanitize=memory --linkopt=-fsanitize=memory +build:msan --copt=-fsanitize-memory-track-origins +build:msan --copt=-fsanitize-memory-use-after-dtor +build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1 +build:msan --copt=-DMEMORY_SANITIZER=1 + +# Use our instrumented LLVM libc++ in Kokoro. +build:kokoro-msan --config=msan +build:kokoro-msan --linkopt=-L/opt/libcxx_msan/lib +build:kokoro-msan --linkopt=-Wl,-rpath,/opt/libcxx_msan/lib +build:kokoro-msan --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ + + +build:tsan --config=san-common --copt=-fsanitize=thread --linkopt=-fsanitize=thread +build:tsan --copt=-DTHREAD_SANITIZER=1 + +build:ubsan --config=san-common --copt=-fsanitize=undefined --linkopt=-fsanitize=undefined +build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 +build:ubsan --copt=-DUNDEFINED_SANITIZER=1 +# Workaround for the fact that Bazel links with $CC, not $CXX +# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748 +build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c91c7b447..d490527747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,10 @@ endif() if(POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif() +# option() honor variables +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif (POLICY CMP0077) # Project project(protobuf C CXX) diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index 1a8d243a74..44805c79a7 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -4,6 +4,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") # Depend packages @_protobuf_FIND_ZLIB@ @_protobuf_FIND_ABSL@ +@_protobuf_FIND_UTF8_RANGE@ # Imported targets include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") diff --git a/cmake/utf8_range.cmake b/cmake/utf8_range.cmake index 90f5ff1ea5..4dcfa4bcca 100644 --- a/cmake/utf8_range.cmake +++ b/cmake/utf8_range.cmake @@ -1,4 +1,4 @@ -set(utf8_range_ENABLE_TESTS OFF) +set(utf8_range_ENABLE_TESTS OFF CACHE BOOL "Disable utf8_range tests") if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/utf8_range/CMakeLists.txt") message(FATAL_ERROR @@ -8,5 +8,7 @@ if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/utf8_range/CMakeLists.txt") " git submodule update --init --recursive\n") endif() -set(utf8_range_ENABLE_INSTALL ${protobuf_INSTALL}) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/utf8_range third_party/utf8_range) \ No newline at end of file +set(utf8_range_ENABLE_INSTALL ${protobuf_INSTALL} CACHE BOOL "Set install") +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/utf8_range third_party/utf8_range) + +set(_protobuf_FIND_UTF8_RANGE "if(NOT TARGET utf8_range)\n find_package(utf8_range CONFIG)\nendif()") diff --git a/kokoro/windows/prepare_build_win64.bat b/kokoro/windows/prepare_build_win64.bat index d8eb2a2b30..37d27ac7a7 100644 --- a/kokoro/windows/prepare_build_win64.bat +++ b/kokoro/windows/prepare_build_win64.bat @@ -13,4 +13,4 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary @rem Convert Windows line breaks to Unix line breaks @rem This allows text-matching tests to pass -find . -type f -print0 | xargs -0 d2u +@find . -type f -print0 | xargs -0 d2u diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 47d6b251d4..82e7bf279d 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -67,8 +67,8 @@ def protobuf_deps(): _github_archive( name = "utf8_range", repo = "https://github.com/protocolbuffers/utf8_range", - commit = "a67b76f9f40107f2c78a5aa860bb6ce37ed83d85", - sha256 = "de5f99318f3b5073dd99f3d4ca31e00e90a86cc400fb375e2147ae1fd41711ed", + commit = "de0b4a8ff9b5d4c98108bdfe723291a33c52c54f", + sha256 = "5da960e5e5d92394c809629a03af3c7709d2d3d0ca731dacb3a9fb4bf28f7702", ) if not native.existing_rule("rules_cc"): diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 532fc3cb4e..f4dd00dabf 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -70,7 +70,6 @@ #include "google/protobuf/pyext/unknown_field_set.h" #include "google/protobuf/pyext/unknown_fields.h" #include "google/protobuf/util/message_differencer.h" -#include "strings/util.h" #include "absl/strings/string_view.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/strtod.h" diff --git a/python/setup.py b/python/setup.py index 7a553594a7..9a95ff8f88 100755 --- a/python/setup.py +++ b/python/setup.py @@ -297,6 +297,8 @@ if __name__ == '__main__': extra_objects = ['../bazel-bin/src/google/protobuf/libprotobuf.a'] else: extra_objects = ['../libprotobuf.a'] + extra_objects += list( + glob.iglob('../third_party/utf8_range/*.a')) # Repeat all of these enough times to eliminate order-dependence. extra_objects += list( glob.iglob('../third_party/abseil-cpp/absl/**/*.a')) diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index efe87f2a6a..50d8b1d828 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -88,7 +88,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { printer->Print( variables_, - "$name$_.Add(other.$name$_);\n"); + "$name$_.MergeFrom(other.$name$_);\n"); } void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index a2a6c5720c..ea8f4fb005 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -297,23 +297,31 @@ const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { &Error, // kSplitMask | FieldKind::kFkMap }; // Just to be sure we got the order right, above. - static_assert(0 == FieldKind::kFkNone); - static_assert(1 == FieldKind::kFkVarint); - static_assert(2 == FieldKind::kFkPackedVarint); - static_assert(3 == FieldKind::kFkFixed); - static_assert(4 == FieldKind::kFkPackedFixed); - static_assert(5 == FieldKind::kFkString); - static_assert(6 == FieldKind::kFkMessage); - static_assert(7 == FieldKind::kFkMap); - - static_assert(8 == (+field_layout::kSplitMask | FieldKind::kFkNone)); - static_assert(9 == (+field_layout::kSplitMask | FieldKind::kFkVarint)); - static_assert(10 == (+field_layout::kSplitMask | FieldKind::kFkPackedVarint)); - static_assert(11 == (+field_layout::kSplitMask | FieldKind::kFkFixed)); - static_assert(12 == (+field_layout::kSplitMask | FieldKind::kFkPackedFixed)); - static_assert(13 == (+field_layout::kSplitMask | FieldKind::kFkString)); - static_assert(14 == (+field_layout::kSplitMask | FieldKind::kFkMessage)); - static_assert(15 == (+field_layout::kSplitMask | FieldKind::kFkMap)); + static_assert(0 == FieldKind::kFkNone, "Invalid table order"); + static_assert(1 == FieldKind::kFkVarint, "Invalid table order"); + static_assert(2 == FieldKind::kFkPackedVarint, "Invalid table order"); + static_assert(3 == FieldKind::kFkFixed, "Invalid table order"); + static_assert(4 == FieldKind::kFkPackedFixed, "Invalid table order"); + static_assert(5 == FieldKind::kFkString, "Invalid table order"); + static_assert(6 == FieldKind::kFkMessage, "Invalid table order"); + static_assert(7 == FieldKind::kFkMap, "Invalid table order"); + + static_assert(8 == (+field_layout::kSplitMask | FieldKind::kFkNone), + "Invalid table order"); + static_assert(9 == (+field_layout::kSplitMask | FieldKind::kFkVarint), + "Invalid table order"); + static_assert(10 == (+field_layout::kSplitMask | FieldKind::kFkPackedVarint), + "Invalid table order"); + static_assert(11 == (+field_layout::kSplitMask | FieldKind::kFkFixed), + "Invalid table order"); + static_assert(12 == (+field_layout::kSplitMask | FieldKind::kFkPackedFixed), + "Invalid table order"); + static_assert(13 == (+field_layout::kSplitMask | FieldKind::kFkString), + "Invalid table order"); + static_assert(14 == (+field_layout::kSplitMask | FieldKind::kFkMessage), + "Invalid table order"); + static_assert(15 == (+field_layout::kSplitMask | FieldKind::kFkMap), + "Invalid table order"); TailCallParseFunc parse_fn = kMiniParseTable[field_type]; PROTOBUF_MUSTTAIL return parse_fn(PROTOBUF_TC_PARAM_PASS); diff --git a/third_party/utf8_range b/third_party/utf8_range index a67b76f9f4..de0b4a8ff9 160000 --- a/third_party/utf8_range +++ b/third_party/utf8_range @@ -1 +1 @@ -Subproject commit a67b76f9f40107f2c78a5aa860bb6ce37ed83d85 +Subproject commit de0b4a8ff9b5d4c98108bdfe723291a33c52c54f From 3b4fdac42a6ec145412953ae578e7eb0cfcb800d Mon Sep 17 00:00:00 2001 From: Alexander Timin Date: Tue, 25 Oct 2022 00:52:59 +0100 Subject: [PATCH 17/29] Update options.md (#10808) --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index 87f7dca50b..7b86ea2803 100644 --- a/docs/options.md +++ b/docs/options.md @@ -348,3 +348,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Pigweed protobuf compiler * Website: https://pigweed.dev/pw_protobuf * Extension: 1155 + +1. Perfetto + * Website: https://perfetto.dev + * Extension: 1156 From 5c6c86858876e95230c9a2962dd709bb788a041a Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 25 Oct 2022 16:13:27 +0100 Subject: [PATCH 18/29] Rename C# files to indicate generated code (#10801) * Change C# generation script to use .pb.cs extension * Rename generated C# files This was performed by running generate_protos.sh and then removing the old files. Notes: - This does not change the conformance test generated C# code - This does not change the compatibility C# code - There's currently no clean-up operation in generate_protos.sh to remove old .pb.cs files (which would now be feasible) - The changes to TestMessagesProto2.pb.cs are just due to formatting and a new Objective-C option * Fix well-known type source files for C# Bazel build --- csharp/.gitignore | 5 +++++ csharp/BUILD.bazel | 22 +++++++++---------- csharp/generate_protos.sh | 3 +++ .../{Addressbook.cs => Addressbook.pb.cs} | 0 ...ttestProto3.cs => MapUnittestProto3.pb.cs} | 0 ...agesProto2.cs => TestMessagesProto2.pb.cs} | 0 ...agesProto3.cs => TestMessagesProto3.pb.cs} | 0 .../{Unittest.cs => Unittest.pb.cs} | 0 ...3.cs => UnittestCustomOptionsProto3.pb.cs} | 0 ...UnittestImport.cs => UnittestImport.pb.cs} | 0 ...rtProto3.cs => UnittestImportProto3.pb.cs} | 0 ...rtPublic.cs => UnittestImportPublic.pb.cs} | 0 ...o3.cs => UnittestImportPublicProto3.pb.cs} | 0 ...Issue6936A.cs => UnittestIssue6936A.pb.cs} | 0 ...Issue6936B.cs => UnittestIssue6936B.pb.cs} | 0 ...Issue6936C.cs => UnittestIssue6936C.pb.cs} | 0 ...UnittestIssues.cs => UnittestIssues.pb.cs} | 0 ...UnittestProto3.cs => UnittestProto3.pb.cs} | 0 ...tional.cs => UnittestProto3Optional.pb.cs} | 0 ...s => UnittestSelfreferentialOptions.pb.cs} | 0 ...nTypes.cs => UnittestWellKnownTypes.pb.cs} | 0 .../Compiler/{Plugin.cs => Plugin.pb.cs} | 0 .../{Descriptor.cs => Descriptor.pb.cs} | 0 .../WellKnownTypes/{Any.cs => Any.pb.cs} | 0 .../WellKnownTypes/{Api.cs => Api.pb.cs} | 0 .../{Duration.cs => Duration.pb.cs} | 0 .../WellKnownTypes/{Empty.cs => Empty.pb.cs} | 0 .../{FieldMask.cs => FieldMask.pb.cs} | 0 .../{SourceContext.cs => SourceContext.pb.cs} | 0 .../{Struct.cs => Struct.pb.cs} | 0 .../{Timestamp.cs => Timestamp.pb.cs} | 0 .../WellKnownTypes/{Type.cs => Type.pb.cs} | 0 .../{Wrappers.cs => Wrappers.pb.cs} | 0 33 files changed, 19 insertions(+), 11 deletions(-) rename csharp/src/AddressBook/{Addressbook.cs => Addressbook.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{MapUnittestProto3.cs => MapUnittestProto3.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{TestMessagesProto2.cs => TestMessagesProto2.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{TestMessagesProto3.cs => TestMessagesProto3.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{Unittest.cs => Unittest.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestCustomOptionsProto3.cs => UnittestCustomOptionsProto3.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestImport.cs => UnittestImport.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestImportProto3.cs => UnittestImportProto3.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestImportPublic.cs => UnittestImportPublic.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestImportPublicProto3.cs => UnittestImportPublicProto3.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestIssue6936A.cs => UnittestIssue6936A.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestIssue6936B.cs => UnittestIssue6936B.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestIssue6936C.cs => UnittestIssue6936C.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestIssues.cs => UnittestIssues.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestProto3.cs => UnittestProto3.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestProto3Optional.cs => UnittestProto3Optional.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestSelfreferentialOptions.cs => UnittestSelfreferentialOptions.pb.cs} (100%) rename csharp/src/Google.Protobuf.Test.TestProtos/{UnittestWellKnownTypes.cs => UnittestWellKnownTypes.pb.cs} (100%) rename csharp/src/Google.Protobuf/Compiler/{Plugin.cs => Plugin.pb.cs} (100%) rename csharp/src/Google.Protobuf/Reflection/{Descriptor.cs => Descriptor.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Any.cs => Any.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Api.cs => Api.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Duration.cs => Duration.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Empty.cs => Empty.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{FieldMask.cs => FieldMask.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{SourceContext.cs => SourceContext.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Struct.cs => Struct.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Timestamp.cs => Timestamp.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Type.cs => Type.pb.cs} (100%) rename csharp/src/Google.Protobuf/WellKnownTypes/{Wrappers.cs => Wrappers.pb.cs} (100%) diff --git a/csharp/.gitignore b/csharp/.gitignore index 62c96383ce..56ac1494d6 100644 --- a/csharp/.gitignore +++ b/csharp/.gitignore @@ -33,3 +33,8 @@ lib/protoc.exe # Benchmark output BenchmarkDotNet.Artifacts/ + +# Reinstate generated code for test files +!any_test.pb.* +!map*unittest.pb.* +!unittest*.pb.* diff --git a/csharp/BUILD.bazel b/csharp/BUILD.bazel index 9f9e83a511..23fbe411f9 100644 --- a/csharp/BUILD.bazel +++ b/csharp/BUILD.bazel @@ -45,17 +45,17 @@ filegroup( filegroup( name = "wkt_cs_srcs", srcs = [ - "src/Google.Protobuf/Reflection/Descriptor.cs", - "src/Google.Protobuf/WellKnownTypes/Any.cs", - "src/Google.Protobuf/WellKnownTypes/Api.cs", - "src/Google.Protobuf/WellKnownTypes/Duration.cs", - "src/Google.Protobuf/WellKnownTypes/Empty.cs", - "src/Google.Protobuf/WellKnownTypes/FieldMask.cs", - "src/Google.Protobuf/WellKnownTypes/SourceContext.cs", - "src/Google.Protobuf/WellKnownTypes/Struct.cs", - "src/Google.Protobuf/WellKnownTypes/Timestamp.cs", - "src/Google.Protobuf/WellKnownTypes/Type.cs", - "src/Google.Protobuf/WellKnownTypes/Wrappers.cs", + "src/Google.Protobuf/Reflection/Descriptor.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Any.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Api.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Duration.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Empty.pb.cs", + "src/Google.Protobuf/WellKnownTypes/FieldMask.pb.cs", + "src/Google.Protobuf/WellKnownTypes/SourceContext.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Struct.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Timestamp.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Type.pb.cs", + "src/Google.Protobuf/WellKnownTypes/Wrappers.pb.cs", ], visibility = ["//src/google/protobuf/compiler/csharp:__pkg__"], ) diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh index cfd6082708..8be4428405 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -32,6 +32,7 @@ fi # descriptor.proto and well-known types $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ --csharp_opt=base_namespace=Google.Protobuf \ + --csharp_opt=file_extension=.pb.cs \ src/google/protobuf/descriptor.proto \ src/google/protobuf/any.proto \ src/google/protobuf/api.proto \ @@ -52,6 +53,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ $PROTOC -Isrc -Icsharp/protos \ --experimental_allow_proto3_optional \ --csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \ + --csharp_opt=file_extension=.pb.cs \ --descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \ --include_source_info \ --include_imports \ @@ -75,4 +77,5 @@ $PROTOC -Isrc -Icsharp/protos \ # AddressBook sample protos $PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \ + --csharp_opt=file_extension=.pb.cs \ examples/addressbook.proto diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.pb.cs similarity index 100% rename from csharp/src/AddressBook/Addressbook.cs rename to csharp/src/AddressBook/Addressbook.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/Unittest.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.pb.cs diff --git a/csharp/src/Google.Protobuf/Compiler/Plugin.cs b/csharp/src/Google.Protobuf/Compiler/Plugin.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/Compiler/Plugin.cs rename to csharp/src/Google.Protobuf/Compiler/Plugin.pb.cs diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/Reflection/Descriptor.cs rename to csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Any.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Any.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Api.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Api.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Duration.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Empty.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Type.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Type.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.pb.cs From 69cc6eabf7b240a50d81316e00fe5d162d8aa6dd Mon Sep 17 00:00:00 2001 From: Derek Perez Date: Tue, 25 Oct 2022 09:14:14 -0700 Subject: [PATCH 19/29] Replace libc strdup usage with internal impl to restore musl compat. (#10811) --- ruby/ext/google/protobuf_c/message.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 629513663a..b9de9d9532 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1274,7 +1274,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { int n = upb_EnumDef_ValueCount(e); for (int i = 0; i < n; i++) { const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); - char* name = strdup(upb_EnumValueDef_Name(ev)); + upb_Arena* arena = upb_Arena_New(); + const char* src_name = upb_EnumValueDef_Name(ev); + char* name = upb_strdup2(src_name, strlen(src_name), arena); int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { if (name[0] >= 'a' && name[0] <= 'z') { @@ -1287,7 +1289,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { } } rb_define_const(mod, name, INT2NUM(value)); - free(name); + upb_Arena_Free(arena); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1); From 4fbefdadde1b9bc2ab95048fad258f82fbb23b33 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 25 Oct 2022 09:30:37 -0700 Subject: [PATCH 20/29] Update changelogs --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 52eee948ef..770f859163 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -69,6 +69,7 @@ * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. * Fix TextFormat parser to build up recurring (but supposedly not repeated) sub-messages directly from text rather than building a new sub-message and merging the fully formed message into the existing field. * Fix bug in nested builder caching logic where cleared sub-field builders would remain dirty after a clear and build in a parent layer. https://github.com/protocolbuffers/protobuf/issues/10624 + * Performance test for TextFormat to verify fix for https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-h4h5-3hr4-j3g2 Python * Changes ordering of printed fields in .pyi files from lexicographic to the same ordering found in the proto descriptor. From 0ddbbf9a6160ef54d557c7c508077cc88e023577 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 25 Oct 2022 10:14:00 -0700 Subject: [PATCH 21/29] Fix sync issues --- src/google/protobuf/arenastring.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 0d093e5450..45a8773db2 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -423,6 +423,7 @@ inline void ArenaStringPtr::SetBytes(absl::string_view value, Arena* arena) { } template <> +PROTOBUF_EXPORT void ArenaStringPtr::Set(const std::string& value, Arena* arena); template <> From 33bc6fb2a4a907b322fa7b3abcebdc6bb69ac4c4 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:26:51 -0700 Subject: [PATCH 22/29] Replace libc strdup usage with internal impl to restore musl compat. (#10811) (#10818) Co-authored-by: Derek Perez --- ruby/ext/google/protobuf_c/message.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 31d7dbbb44..fd83dc1c49 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1290,7 +1290,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { int n = upb_EnumDef_ValueCount(e); for (int i = 0; i < n; i++) { const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); - char* name = strdup(upb_EnumValueDef_Name(ev)); + upb_Arena* arena = upb_Arena_New(); + const char* src_name = upb_EnumValueDef_Name(ev); + char* name = upb_strdup2(src_name, strlen(src_name), arena); int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { if (name[0] >= 'a' && name[0] <= 'z') { @@ -1303,7 +1305,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { } } rb_define_const(mod, name, INT2NUM(value)); - free(name); + upb_Arena_Free(arena); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1); From 573a1851dc9d65db87a686c52bb03530c840d609 Mon Sep 17 00:00:00 2001 From: zhangskz <89936743+zhangskz@users.noreply.github.com> Date: Tue, 25 Oct 2022 18:15:55 -0400 Subject: [PATCH 23/29] Update zlib to 1.2.13 (#10819) This pulls in the fix for CVE-2022-37434. (PR'ed to main already in https://github.com/protocolbuffers/protobuf/pull/10786) --- protobuf_deps.bzl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 425c4b4834..115320fb29 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -48,9 +48,12 @@ def protobuf_deps(): http_archive( name = "zlib", build_file = "@com_google_protobuf//:third_party/zlib.BUILD", - sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff", - strip_prefix = "zlib-1.2.11", - urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"], + sha256 = "d14c38e313afc35a9a8760dadf26042f51ea0f5d154b0630a31da0540107fb98", + strip_prefix = "zlib-1.2.13", + urls = [ + "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.xz", + "https://zlib.net/zlib-1.2.13.tar.xz", + ], ) if not native.existing_rule("rules_cc"): From ae9e22b3626ef9d17d15929ba38a5cf179737eae Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 26 Oct 2022 17:00:43 +0100 Subject: [PATCH 24/29] Clean up the dotnet test output (#10821) Prior to this change, running "dotnet test" would result in a warning about csc only supporting C# up to version 5, and warnings of unrecognized warnings being suppressed. With this change in place, the test output doesn't include anything from csc. --- .../src/Google.Protobuf.Test/RefStructCompatibilityTest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs b/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs index f3651df397..82f59b1abb 100644 --- a/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs +++ b/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs @@ -67,7 +67,10 @@ namespace Google.Protobuf // We build the code with GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE to avoid the use of ref struct in the generated code. var compatibilityFlag = "-define:GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE"; var sources = "*.cs"; // the generated sources from the TestProtos project - var args = $"-langversion:3 -target:library {compatibilityFlag} -reference:{testProtosOutputDir}\\Google.Protobuf.dll -out:{testProtosOutputDir}\\TestProtos.RefStructCompatibilityTest.OldCompiler.dll {sources}"; + // We suppress CS1691, which flags a warning for the generated line of + // #pragma warning disable 1591, 0612, 3021, 8981 + // because CS8981 is unknown to this version of the compiler. + var args = $"-langversion:3 -nologo -nowarn:1691 -target:library {compatibilityFlag} -reference:{testProtosOutputDir}\\Google.Protobuf.dll -out:{testProtosOutputDir}\\TestProtos.RefStructCompatibilityTest.OldCompiler.dll {sources}"; RunOldCsharpCompilerAndCheckSuccess(args, testProtosProjectDir); } From 0135eb0e525fbb59c2753d7397de61e4fa07d346 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 26 Oct 2022 09:08:51 -0700 Subject: [PATCH 25/29] Updating version.json and repo version numbers to: 21.9 --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 ++--- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/package.xml | 23 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 6 ++--- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- version.json | 20 ++++++++-------- 37 files changed, 69 insertions(+), 54 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index f4876ae990..2215db277b 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.21.8' + s.version = '3.21.9' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index 22a991990f..832609a041 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.21.8' + s.version = '3.21.9' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/configure.ac b/configure.ac index d69fad621a..00a52e7679 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.21.8],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.21.9],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 64f78d0b3e..c909720743 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.21.8 + 3.21.9 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 36d82156ee..04c98ea379 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.21.8 + 3.21.9 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 798ce212f6..c9fab2537f 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.21.8 + 3.21.9 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.21.8 + 3.21.9 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.21.8' + implementation 'com.google.protobuf:protobuf-java:3.21.9' ``` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index ebbad006ea..19e23fb196 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.21.8 + 3.21.9 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index bedb61b915..c920d1fe91 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.9 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index ace12aa6fa..86da157fd0 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.9 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 4e30d5dea3..981cf7f67b 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.9 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 87b917a7bd..eef237052a 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.21.8 + 3.21.9 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 69bd30cc09..4b3c84f272 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.9 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index e066235937..6560ddef31 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.9 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 1c0ee7b687..14209ff01c 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.9 protobuf-java-util diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 18ab2f53af..d8bd2b13f3 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-packages@google.com yes - 2022-10-13 - + 2022-10-26 + - 3.21.8 - 3.21.8 + 3.21.9 + 3.21.9 stable @@ -1448,5 +1448,20 @@ G A release. + + + 3.21.9 + 3.21.9 + + + stable + stable + + 2022-10-26 + + BSD-3-Clause + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 14bd16c40d..25689498df 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.21.8" +#define PHP_PROTOBUF_VERSION "3.21.9" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index cc6cf85c55..4c44f3da5d 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,3 +1,3 @@ -PROTOC_VERSION = "21.8" -PROTOBUF_JAVA_VERSION = "3.21.8" -PROTOBUF_PYTHON_VERSION = "4.21.8" +PROTOC_VERSION = "21.9" +PROTOBUF_JAVA_VERSION = "3.21.9" +PROTOBUF_PYTHON_VERSION = "4.21.9" diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index cb0c2be34c..b65abce2b6 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.21.8 + 3.21.9 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 6b0df47af0..e7b197e5d1 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.21.8' +__version__ = '4.21.9' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 5f226b0fec..43933eb081 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.21.8" + s.version = "3.21.9" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index c533dd7848..04ffaa823e 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.21.8 + 3.21.9 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.21.8 + 3.21.9 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index 231b95ba5c..7a612db6d7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 32:8:0 +PROTOBUF_VERSION = 32:9:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 8ed4b18ddf..982e9cfaca 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index dceb70c780..3e746de5f7 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index b8a0d71408..65c2cb0f81 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index beb0139440..27282dad12 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 9721670b4e..c913020d82 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index fa8f1a7a7a..329e81930b 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 045871cfcb..20a3d4c3bc 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 356ea47713..f00daf721e 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -178,7 +178,7 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3021008 +#define PROTOBUF_VERSION 3021009 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 98a3d3e6b1..acf27735b5 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 4283b77638..134a1bd35a 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 647b4d1d85..8a1db2bb7d 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,7 +82,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3021008 +#define GOOGLE_PROTOBUF_VERSION 3021009 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index dc10d1cc47..e437d11dcf 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 8ac8fa8d4a..2267fb743b 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 590a1d98d1..064bd371dc 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/version.json b/version.json index 7a8e1fc747..e7f5ba106a 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "21.x": { - "protoc_version": "21.9-dev", + "protoc_version": "21.9", "lts": false, - "date": "2022-10-18", + "date": "2022-10-26", "languages": { - "cpp": "3.21.9-dev", - "csharp": "3.21.9-dev", - "java": "3.21.9-dev", - "javascript": "3.21.9-dev", - "objectivec": "3.21.9-dev", - "php": "3.21.9-dev", - "python": "4.21.9-dev", - "ruby": "3.21.9-dev" + "cpp": "3.21.9", + "csharp": "3.21.9", + "java": "3.21.9", + "javascript": "3.21.9", + "objectivec": "3.21.9", + "php": "3.21.9", + "python": "4.21.9", + "ruby": "3.21.9" } } } \ No newline at end of file From 90b73ac3f0b10320315c2ca0d03a5a9b095d2f66 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 26 Oct 2022 17:50:48 +0000 Subject: [PATCH 26/29] Updating changelog --- CHANGES.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 92ba28d9ca..b3e4120ae5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,14 @@ +2022-10-26 version 21.9 (C++/Java/Python/PHP/Objective-C/C#/Ruby) + + C++ + * Update zlib to 1.2.13 (#10819) + + Python + * Target MacOS 10.9 to fix #10799 (#10807) + + Ruby + * Replace libc strdup usage with internal impl to restore musl compat (#10818) + 2022-10-18 version 21.8 (C++/Java/Python/PHP/Objective-C/C#/Ruby) Other From e4a4de98907d3c3fd82d7f9473249710d82b3e49 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 26 Oct 2022 21:36:41 +0000 Subject: [PATCH 27/29] Update version.json to: 21.10-dev --- version.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/version.json b/version.json index e7f5ba106a..194cefcc3e 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "21.x": { - "protoc_version": "21.9", + "protoc_version": "21.10-dev", "lts": false, "date": "2022-10-26", "languages": { - "cpp": "3.21.9", - "csharp": "3.21.9", - "java": "3.21.9", - "javascript": "3.21.9", - "objectivec": "3.21.9", - "php": "3.21.9", - "python": "4.21.9", - "ruby": "3.21.9" + "cpp": "3.21.10-dev", + "csharp": "3.21.10-dev", + "java": "3.21.10-dev", + "javascript": "3.21.10-dev", + "objectivec": "3.21.10-dev", + "php": "3.21.10-dev", + "python": "4.21.10-dev", + "ruby": "3.21.10-dev" } } } \ No newline at end of file From 0ab63a7699ea47fac827804cf9d660bbae1cc584 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 26 Oct 2022 20:10:29 -0700 Subject: [PATCH 28/29] Sync from Piper @484138213 PROTOBUF_SYNC_PIPER --- CHANGES.txt | 1 + conformance/conformance.proto | 12 +-- .../RefStructCompatibilityTest.cs | 5 +- generate_changelog.py | 29 ++++++++ .../java/com/google/protobuf/ByteString.java | 13 ++-- python/setup.py | 29 ++++++++ .../compiler/command_line_interface.cc | 22 +++--- .../compiler/command_line_interface.h | 6 +- .../compiler/cpp/bootstrap_unittest.cc | 6 +- src/google/protobuf/compiler/cpp/enum.cc | 2 +- src/google/protobuf/compiler/cpp/enum.h | 1 - .../protobuf/compiler/cpp/enum_field.cc | 11 ++- src/google/protobuf/compiler/cpp/extension.cc | 2 - src/google/protobuf/compiler/cpp/extension.h | 3 +- src/google/protobuf/compiler/cpp/field.cc | 37 +++++----- src/google/protobuf/compiler/cpp/field.h | 17 +++-- src/google/protobuf/compiler/cpp/file.cc | 3 +- src/google/protobuf/compiler/cpp/file.h | 3 +- src/google/protobuf/compiler/cpp/generator.cc | 2 +- src/google/protobuf/compiler/cpp/helpers.cc | 15 ++-- src/google/protobuf/compiler/cpp/helpers.h | 22 +++--- src/google/protobuf/compiler/cpp/map_field.cc | 12 ++- src/google/protobuf/compiler/cpp/message.cc | 36 ++++----- src/google/protobuf/compiler/cpp/message.h | 11 +-- .../protobuf/compiler/cpp/message_field.cc | 37 ++++++---- .../compiler/cpp/parse_function_generator.cc | 4 +- .../compiler/cpp/parse_function_generator.h | 15 ++-- .../protobuf/compiler/cpp/primitive_field.cc | 10 ++- src/google/protobuf/compiler/cpp/service.cc | 3 +- src/google/protobuf/compiler/cpp/service.h | 10 ++- .../protobuf/compiler/cpp/string_field.cc | 26 ++++--- .../compiler/csharp/csharp_field_base.cc | 54 +++++++++----- .../compiler/csharp/csharp_field_base.h | 8 +- .../compiler/csharp/csharp_map_field.cc | 2 +- .../compiler/csharp/csharp_message.cc | 60 ++++++++------- src/google/protobuf/compiler/java/enum.cc | 8 +- .../protobuf/compiler/java/enum_field.cc | 36 ++++----- .../protobuf/compiler/java/enum_field.h | 5 +- .../protobuf/compiler/java/enum_field_lite.cc | 37 +++++----- .../protobuf/compiler/java/enum_field_lite.h | 5 +- .../protobuf/compiler/java/enum_lite.cc | 8 +- .../protobuf/compiler/java/extension.cc | 8 +- src/google/protobuf/compiler/java/extension.h | 11 +-- .../protobuf/compiler/java/extension_lite.cc | 5 +- src/google/protobuf/compiler/java/field.cc | 27 ++++--- src/google/protobuf/compiler/java/field.h | 18 +++-- src/google/protobuf/compiler/java/helpers.cc | 9 +-- src/google/protobuf/compiler/java/helpers.h | 9 +-- .../protobuf/compiler/java/map_field.cc | 54 ++++++++------ src/google/protobuf/compiler/java/map_field.h | 2 +- .../protobuf/compiler/java/map_field_lite.cc | 55 ++++++++------ .../protobuf/compiler/java/map_field_lite.h | 2 +- src/google/protobuf/compiler/java/message.cc | 11 ++- .../protobuf/compiler/java/message_builder.cc | 4 +- .../compiler/java/message_builder_lite.cc | 4 +- .../protobuf/compiler/java/message_field.cc | 29 ++++---- .../protobuf/compiler/java/message_field.h | 4 +- .../compiler/java/message_field_lite.cc | 28 +++---- .../compiler/java/message_field_lite.h | 4 +- .../protobuf/compiler/java/message_lite.cc | 10 ++- .../protobuf/compiler/java/name_resolver.cc | 1 - .../protobuf/compiler/java/primitive_field.cc | 73 +++++++++---------- .../protobuf/compiler/java/primitive_field.h | 4 +- .../compiler/java/primitive_field_lite.cc | 73 ++++++++++--------- .../compiler/java/primitive_field_lite.h | 4 +- src/google/protobuf/compiler/java/service.cc | 14 ++-- .../protobuf/compiler/java/string_field.cc | 29 ++++---- .../protobuf/compiler/java/string_field.h | 4 +- .../compiler/java/string_field_lite.cc | 32 ++++---- .../compiler/java/string_field_lite.h | 4 +- .../protobuf/compiler/objectivec/enum.cc | 1 - .../compiler/objectivec/enum_field.cc | 18 +++-- .../protobuf/compiler/objectivec/extension.cc | 6 +- .../protobuf/compiler/objectivec/field.cc | 7 +- .../protobuf/compiler/objectivec/field.h | 4 +- .../protobuf/compiler/objectivec/file.cc | 4 +- .../compiler/objectivec/import_writer.cc | 25 +++---- .../compiler/objectivec/import_writer.h | 3 +- .../protobuf/compiler/objectivec/map_field.cc | 1 - .../protobuf/compiler/objectivec/message.cc | 8 +- .../compiler/objectivec/message_field.cc | 7 +- .../protobuf/compiler/objectivec/names.cc | 53 +++++++------- .../protobuf/compiler/objectivec/oneof.cc | 1 - .../protobuf/compiler/objectivec/oneof.h | 4 +- .../compiler/objectivec/primitive_field.cc | 7 +- .../protobuf/compiler/python/generator.cc | 31 ++++---- .../protobuf/compiler/python/pyi_generator.cc | 12 +-- .../protobuf/compiler/python/pyi_generator.h | 4 +- src/google/protobuf/io/printer.cc | 2 +- src/google/protobuf/io/printer.h | 41 ++++++++--- 90 files changed, 780 insertions(+), 619 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 52eee948ef..770f859163 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -69,6 +69,7 @@ * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. * Fix TextFormat parser to build up recurring (but supposedly not repeated) sub-messages directly from text rather than building a new sub-message and merging the fully formed message into the existing field. * Fix bug in nested builder caching logic where cleared sub-field builders would remain dirty after a clear and build in a parent layer. https://github.com/protocolbuffers/protobuf/issues/10624 + * Performance test for TextFormat to verify fix for https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-h4h5-3hr4-j3g2 Python * Changes ordering of printed fields in .pyi files from lexicographic to the same ordering found in the proto descriptor. diff --git a/conformance/conformance.proto b/conformance/conformance.proto index a213437f89..bee04d160d 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -58,7 +58,7 @@ enum WireFormat { UNSPECIFIED = 0; PROTOBUF = 1; JSON = 2; - JSPB = 3; // Google internal only. Opensource testees just skip it. + JSPB = 3; // Only used inside Google. Opensource testees just skip it. TEXT_FORMAT = 4; } @@ -72,8 +72,8 @@ enum TestCategory { // https://developers.google.com/protocol-buffers/docs/proto3#json_options // for more detail. JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; - // Test jspb wire format. Google internal only. Opensource testees just skip - // it. + // Test jspb wire format. Only used inside Google. Opensource testees just + // skip it. JSPB_TEST = 4; // Test text format. For cpp, java and python, testees can already deal with // this type. Testees of other languages can simply skip it. @@ -99,7 +99,7 @@ message ConformanceRequest { oneof payload { bytes protobuf_payload = 1; string json_payload = 2; - // Google internal only. Opensource testees just skip it. + // Only used inside Google. Opensource testees just skip it. string jspb_payload = 7; string text_payload = 8; } @@ -163,8 +163,8 @@ message ConformanceResponse { string skipped = 5; // If the input was successfully parsed and the requested output was JSPB, - // serialize to JSPB and set it in this field. JSPB is google internal only - // format. Opensource testees can just skip it. + // serialize to JSPB and set it in this field. JSPB is only used inside + // Google. Opensource testees can just skip it. string jspb_payload = 7; // If the input was successfully parsed and the requested output was diff --git a/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs b/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs index f3651df397..82f59b1abb 100644 --- a/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs +++ b/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs @@ -67,7 +67,10 @@ namespace Google.Protobuf // We build the code with GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE to avoid the use of ref struct in the generated code. var compatibilityFlag = "-define:GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE"; var sources = "*.cs"; // the generated sources from the TestProtos project - var args = $"-langversion:3 -target:library {compatibilityFlag} -reference:{testProtosOutputDir}\\Google.Protobuf.dll -out:{testProtosOutputDir}\\TestProtos.RefStructCompatibilityTest.OldCompiler.dll {sources}"; + // We suppress CS1691, which flags a warning for the generated line of + // #pragma warning disable 1591, 0612, 3021, 8981 + // because CS8981 is unknown to this version of the compiler. + var args = $"-langversion:3 -nologo -nowarn:1691 -target:library {compatibilityFlag} -reference:{testProtosOutputDir}\\Google.Protobuf.dll -out:{testProtosOutputDir}\\TestProtos.RefStructCompatibilityTest.OldCompiler.dll {sources}"; RunOldCsharpCompilerAndCheckSuccess(args, testProtosProjectDir); } diff --git a/generate_changelog.py b/generate_changelog.py index fe7e95bc42..7117ef8ff2 100755 --- a/generate_changelog.py +++ b/generate_changelog.py @@ -1,4 +1,33 @@ #!/usr/bin/env python +# Protocol Buffers - Google's data interchange format +# Copyright 2008 Google Inc. All rights reserved. +# https://developers.google.com/protocol-buffers/ +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Generates a friendly list of changes per language since the last release.""" diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 1acbad08b4..2569d5dad4 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -432,7 +432,10 @@ public abstract class ByteString implements Iterable, Serializable { return copyFrom(bytes, 0, bytes.length); } - /** Wraps the given bytes into a {@code ByteString}. Intended for internal only usage. */ + /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal usage within the + * library. + */ static ByteString wrap(ByteBuffer buffer) { if (buffer.hasArray()) { final int offset = buffer.arrayOffset(); @@ -443,8 +446,8 @@ public abstract class ByteString implements Iterable, Serializable { } /** - * Wraps the given bytes into a {@code ByteString}. Intended for internal only usage to force a - * classload of ByteString before LiteralByteString. + * Wraps the given bytes into a {@code ByteString}. Intended for internal usage within the library + * to force a classload of ByteString before LiteralByteString. */ static ByteString wrap(byte[] bytes) { // TODO(dweis): Return EMPTY when bytes are empty to reduce allocations? @@ -452,8 +455,8 @@ public abstract class ByteString implements Iterable, Serializable { } /** - * Wraps the given bytes into a {@code ByteString}. Intended for internal only usage to force a - * classload of ByteString before BoundedByteString and LiteralByteString. + * Wraps the given bytes into a {@code ByteString}. Intended for internal usage within the library + * to force a classload of ByteString before BoundedByteString and LiteralByteString. */ static ByteString wrap(byte[] bytes, int offset, int length) { return new BoundedByteString(bytes, offset, length); diff --git a/python/setup.py b/python/setup.py index 9a95ff8f88..2b6d281426 100755 --- a/python/setup.py +++ b/python/setup.py @@ -1,4 +1,33 @@ #! /usr/bin/env python +# Protocol Buffers - Google's data interchange format +# Copyright 2008 Google Inc. All rights reserved. +# https://developers.google.com/protocol-buffers/ +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # See README for usage instructions. diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 6b6ca1b498..7cff1e3563 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -34,6 +34,8 @@ #include "google/protobuf/compiler/command_line_interface.h" +#include "absl/container/flat_hash_map.h" + #include "google/protobuf/stubs/platform_macros.h" #include @@ -425,7 +427,7 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext { // The files_ field maps from path keys to file content values. It's a map // instead of an unordered_map so that files are written in order (good when // writing zips). - std::map files_; + absl::flat_hash_map files_; const std::vector& parsed_files_; bool had_error_; }; @@ -1493,19 +1495,15 @@ CommandLineInterface::ParseArgumentStatus CommandLineInterface::ParseArguments( // Make sure each plugin option has a matching plugin output. bool foundUnknownPluginOption = false; - for (std::map::const_iterator i = - plugin_parameters_.begin(); - i != plugin_parameters_.end(); ++i) { - if (plugins_.find(i->first) != plugins_.end()) { + for (const auto& kv : plugin_parameters_) { + if (plugins_.find(kv.first) != plugins_.end()) { continue; } bool foundImplicitPlugin = false; - for (std::vector::const_iterator j = - output_directives_.begin(); - j != output_directives_.end(); ++j) { - if (j->generator == nullptr) { - std::string plugin_name = PluginName(plugin_prefix_, j->name); - if (plugin_name == i->first) { + for (const auto& d : output_directives_) { + if (d.generator == nullptr) { + std::string plugin_name = PluginName(plugin_prefix_, d.name); + if (plugin_name == kv.first) { foundImplicitPlugin = true; break; } @@ -1514,7 +1512,7 @@ CommandLineInterface::ParseArgumentStatus CommandLineInterface::ParseArguments( if (!foundImplicitPlugin) { std::cerr << "Unknown flag: " // strip prefix + "gen-" and add back "_opt" - << "--" + i->first.substr(plugin_prefix_.size() + 4) + "_opt" + << "--" + kv.first.substr(plugin_prefix_.size() + 4) + "_opt" << std::endl; foundUnknownPluginOption = true; } diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 92454145b7..7e1cd58f5d 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -367,9 +367,9 @@ class PROTOC_EXPORT CommandLineInterface { // flag. For example, if the user invokes the compiler with: // protoc --foo_out=outputdir --foo_opt=enable_bar ... // Then there will be an entry ("--foo_out", "enable_bar") in this map. - std::map generator_parameters_; + absl::flat_hash_map generator_parameters_; // Similar to generator_parameters_, but stores the parameters for plugins. - std::map plugin_parameters_; + absl::flat_hash_map plugin_parameters_; // See AllowPlugins(). If this is empty, plugins aren't allowed. std::string plugin_prefix_; @@ -377,7 +377,7 @@ class PROTOC_EXPORT CommandLineInterface { // Maps specific plugin names to files. When executing a plugin, this map // is searched first to find the plugin executable. If not found here, the // PATH (or other OS-specific search strategy) is searched. - std::map plugins_; + absl::flat_hash_map plugins_; // Stuff parsed from command line. enum Mode { diff --git a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc index 3ea5d733dc..8d2b60e9ad 100644 --- a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc @@ -63,7 +63,7 @@ namespace compiler { namespace cpp { namespace { std::string FindWithDefault( - const absl::flat_hash_map& m, + const absl::flat_hash_map& m, const std::string& k, const std::string& v) { auto it = m.find(k); if (it == m.end()) return v; @@ -138,8 +138,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. - absl::flat_hash_map vpath_map; - absl::flat_hash_map rpath_map; + absl::flat_hash_map vpath_map; + absl::flat_hash_map 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"] = diff --git a/src/google/protobuf/compiler/cpp/enum.cc b/src/google/protobuf/compiler/cpp/enum.cc index c000b48212..7d03aa56e4 100644 --- a/src/google/protobuf/compiler/cpp/enum.cc +++ b/src/google/protobuf/compiler/cpp/enum.cc @@ -54,7 +54,7 @@ namespace protobuf { namespace compiler { namespace cpp { namespace { -absl::flat_hash_map EnumVars( +absl::flat_hash_map EnumVars( const EnumDescriptor* enum_, const Options& options, const EnumValueDescriptor* min, const EnumValueDescriptor* max) { auto classname = ClassName(enum_, false); diff --git a/src/google/protobuf/compiler/cpp/enum.h b/src/google/protobuf/compiler/cpp/enum.h index 158a548976..49a262d40d 100644 --- a/src/google/protobuf/compiler/cpp/enum.h +++ b/src/google/protobuf/compiler/cpp/enum.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ -#include #include #include diff --git a/src/google/protobuf/compiler/cpp/enum_field.cc b/src/google/protobuf/compiler/cpp/enum_field.cc index 0ac1451c7d..10768f9041 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/enum_field.cc @@ -34,8 +34,10 @@ #include "google/protobuf/compiler/cpp/enum_field.h" -#include "google/protobuf/io/printer.h" +#include + #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -46,9 +48,10 @@ namespace cpp { namespace { -void SetEnumVariables(const FieldDescriptor* descriptor, - std::map* variables, - const Options& options) { +void SetEnumVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); const EnumValueDescriptor* default_value = descriptor->default_value_enum(); (*variables)["type"] = QualifiedClassName(descriptor->enum_type(), options); diff --git a/src/google/protobuf/compiler/cpp/extension.cc b/src/google/protobuf/compiler/cpp/extension.cc index 9b6ddc8938..ada93f7697 100644 --- a/src/google/protobuf/compiler/cpp/extension.cc +++ b/src/google/protobuf/compiler/cpp/extension.cc @@ -34,8 +34,6 @@ #include "google/protobuf/compiler/cpp/extension.h" -#include - #include "google/protobuf/io/printer.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" diff --git a/src/google/protobuf/compiler/cpp/extension.h b/src/google/protobuf/compiler/cpp/extension.h index 1c0e020b99..4d7d081194 100644 --- a/src/google/protobuf/compiler/cpp/extension.h +++ b/src/google/protobuf/compiler/cpp/extension.h @@ -38,6 +38,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/port.h" @@ -84,7 +85,7 @@ class ExtensionGenerator { Options options_; MessageSCCAnalyzer* scc_analyzer_; - std::map variables_; + absl::flat_hash_map variables_; }; } // namespace cpp diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index 1ec6bf7421..50f86e1e7f 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -38,6 +38,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" @@ -46,7 +47,6 @@ #include "google/protobuf/compiler/cpp/string_field.h" #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" #include "google/protobuf/compiler/cpp/enum_field.h" #include "google/protobuf/compiler/cpp/map_field.h" @@ -62,12 +62,12 @@ using internal::WireFormat; namespace { -void MaySetAnnotationVariable(const Options& options, - 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* variables) { +void MaySetAnnotationVariable( + const Options& options, absl::string_view annotation_name, + absl::string_view substitute_template_prefix, + absl::string_view prepared_template, int field_index, + absl::string_view access_type, + absl::flat_hash_map* variables) { if (options.field_listener_options.forbidden_field_listener_events.count( std::string(annotation_name))) return; @@ -124,9 +124,9 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor, } // namespace -void AddAccessorAnnotations(const FieldDescriptor* descriptor, - const Options& options, - std::map* variables) { +void AddAccessorAnnotations( + const FieldDescriptor* descriptor, const Options& options, + absl::flat_hash_map* variables) { // Can be expanded to include more specific calls, for example, for arena or // clear calls. static constexpr const char* kAccessorsAnnotations[] = { @@ -232,10 +232,10 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, "OnAddMutable", variables); } -absl::flat_hash_map FieldVars( +absl::flat_hash_map FieldVars( const FieldDescriptor* desc, const Options& opts) { bool split = ShouldSplit(desc, opts); - absl::flat_hash_map vars = { + absl::flat_hash_map vars = { {"ns", Namespace(desc, opts)}, {"name", FieldName(desc)}, {"index", absl::StrCat(desc->index())}, @@ -261,7 +261,7 @@ absl::flat_hash_map FieldVars( // TODO(b/245791219): Refactor AddAccessorAnnotations to avoid this // workaround. - std::map workaround = { + absl::flat_hash_map workaround = { {"field", vars["field"]}, {"tracker", "Impl_::_tracker_"}, }; @@ -273,9 +273,10 @@ absl::flat_hash_map FieldVars( return vars; } -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - std::map* variables, - const Options& options) { +void SetCommonFieldVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables, + const Options& options) { SetCommonMessageDataVariables(descriptor->containing_type(), variables); for (auto& pair : FieldVars(descriptor, options)) { @@ -283,7 +284,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, } } -absl::flat_hash_map OneofFieldVars( +absl::flat_hash_map OneofFieldVars( const FieldDescriptor* descriptor) { if (descriptor->containing_oneof() == nullptr) { return {}; @@ -294,7 +295,7 @@ absl::flat_hash_map OneofFieldVars( void SetCommonOneofFieldVariables( const FieldDescriptor* descriptor, - std::map* variables) { + absl::flat_hash_map* variables) { for (auto& pair : OneofFieldVars(descriptor)) { variables->emplace(pair); } diff --git a/src/google/protobuf/compiler/cpp/field.h b/src/google/protobuf/compiler/cpp/field.h index db0d64d30e..a10d552cd9 100644 --- a/src/google/protobuf/compiler/cpp/field.h +++ b/src/google/protobuf/compiler/cpp/field.h @@ -36,11 +36,11 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ #include -#include #include #include #include "google/protobuf/descriptor.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/options.h" @@ -57,23 +57,24 @@ namespace protobuf { namespace compiler { namespace cpp { -absl::flat_hash_map FieldVars( +absl::flat_hash_map FieldVars( const FieldDescriptor* desc, const Options& opts); -absl::flat_hash_map OneofFieldVars( +absl::flat_hash_map OneofFieldVars( const FieldDescriptor* descriptor); // Helper function: set variables in the map that are the same for all // field code generators. // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', // 'deprecation']. -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - std::map* variables, - const Options& options); +void SetCommonFieldVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables, + const Options& options); void SetCommonOneofFieldVariables( const FieldDescriptor* descriptor, - std::map* variables); + absl::flat_hash_map* variables); class FieldGenerator { public: @@ -226,7 +227,7 @@ class FieldGenerator { protected: const FieldDescriptor* descriptor_; const Options& options_; - std::map variables_; + absl::flat_hash_map variables_; }; // Convenience class which constructs FieldGenerators for a Descriptor. diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index d3dac8b113..759b43d12a 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -35,7 +35,6 @@ #include "google/protobuf/compiler/cpp/file.h" #include -#include #include #include #include @@ -71,7 +70,7 @@ namespace protobuf { namespace compiler { namespace cpp { namespace { -absl::flat_hash_map FileVars( +absl::flat_hash_map FileVars( const FileDescriptor* file, const Options& options) { return { {"filename", file->name()}, diff --git a/src/google/protobuf/compiler/cpp/file.h b/src/google/protobuf/compiler/cpp/file.h index cd38345043..3cb297e4a6 100644 --- a/src/google/protobuf/compiler/cpp/file.h +++ b/src/google/protobuf/compiler/cpp/file.h @@ -44,6 +44,7 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/compiler/scc.h" +#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "google/protobuf/compiler/cpp/enum.h" #include "google/protobuf/compiler/cpp/extension.h" @@ -195,7 +196,7 @@ class FileGenerator { // This member is unused and should be deleted once all old-style variable // maps are gone. // TODO(b/245791219) - std::map variables_; + absl::flat_hash_map variables_; // Contains the post-order walk of all the messages (and child messages) in // this file. If you need a pre-order walk just reverse iterate. diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index 737441ca5a..278354ca06 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -55,7 +55,7 @@ std::string NumberedCcFileName(absl::string_view basename, int number) { return absl::StrCat(basename, ".out/", number, ".cc"); } -absl::flat_hash_map CommonVars( +absl::flat_hash_map CommonVars( const Options& options) { bool is_oss = options.opensource_runtime; return { diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc index 383629f4f1..d32d4c1a6c 100644 --- a/src/google/protobuf/compiler/cpp/helpers.cc +++ b/src/google/protobuf/compiler/cpp/helpers.cc @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -232,7 +231,7 @@ bool IsLazilyVerifiedLazy(const FieldDescriptor* field, return false; } -absl::flat_hash_map MessageVars( +absl::flat_hash_map MessageVars( const Descriptor* desc) { absl::string_view prefix = IsMapEntryMessage(desc) ? "" : "_impl_."; return { @@ -252,13 +251,13 @@ absl::flat_hash_map MessageVars( void SetCommonMessageDataVariables( const Descriptor* descriptor, - std::map* variables) { + absl::flat_hash_map* variables) { for (auto& pair : MessageVars(descriptor)) { variables->emplace(pair); } } -absl::flat_hash_map UnknownFieldsVars( +absl::flat_hash_map UnknownFieldsVars( const Descriptor* desc, const Options& opts) { std::string proto_ns = ProtobufNamespace(opts); @@ -286,9 +285,9 @@ absl::flat_hash_map UnknownFieldsVars( }; } -void SetUnknownFieldsVariable(const Descriptor* descriptor, - const Options& options, - std::map* variables) { +void SetUnknownFieldsVariable( + const Descriptor* descriptor, const Options& options, + absl::flat_hash_map* variables) { for (auto& pair : UnknownFieldsVars(descriptor, options)) { variables->emplace(pair); } @@ -1362,7 +1361,7 @@ bool GetBootstrapBasename(const Options& options, const std::string& basename, static const auto* bootstrap_mapping = // TODO(b/242858704) Replace these with string_view once we remove // StringPiece. - new absl::flat_hash_map{ + new absl::flat_hash_map{ {"net/proto2/proto/descriptor", "third_party/protobuf/descriptor"}, {"net/proto2/compiler/proto/plugin", diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index 4967452ca8..fbce6003ce 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -88,20 +88,20 @@ inline std::string DeprecatedAttribute(const Options& /* options */, extern const char kThickSeparator[]; extern const char kThinSeparator[]; -absl::flat_hash_map MessageVars( +absl::flat_hash_map MessageVars( const Descriptor* desc); // Variables to access message data from the message scope. void SetCommonMessageDataVariables( const Descriptor* descriptor, - std::map* variables); + absl::flat_hash_map* variables); -absl::flat_hash_map UnknownFieldsVars( +absl::flat_hash_map UnknownFieldsVars( const Descriptor* desc, const Options& opts); -void SetUnknownFieldsVariable(const Descriptor* descriptor, - const Options& options, - std::map* variables); +void SetUnknownFieldsVariable( + const Descriptor* descriptor, const Options& options, + absl::flat_hash_map* variables); bool GetBootstrapBasename(const Options& options, const std::string& basename, std::string* bootstrap_basename); @@ -794,15 +794,15 @@ class PROTOC_EXPORT Formatter { public: explicit Formatter(io::Printer* printer) : printer_(printer) {} Formatter(io::Printer* printer, - const std::map& vars) + const absl::flat_hash_map& vars) : printer_(printer), vars_(vars) {} template - void Set(const std::string& key, const T& value) { + void Set(absl::string_view key, const T& value) { vars_[key] = ToString(value); } - void AddMap(const std::map& vars) { + void AddMap(const absl::flat_hash_map& vars) { for (const auto& keyval : vars) vars_[keyval.first] = keyval.second; } @@ -844,12 +844,12 @@ class PROTOC_EXPORT Formatter { private: Formatter* format_; - std::map vars_; + absl::flat_hash_map vars_; }; private: io::Printer* printer_; - std::map vars_; + absl::flat_hash_map vars_; // Convenience overloads to accept different types as arguments. static std::string ToString(const std::string& s) { return s; } diff --git a/src/google/protobuf/compiler/cpp/map_field.cc b/src/google/protobuf/compiler/cpp/map_field.cc index e320a435b8..529a54f060 100644 --- a/src/google/protobuf/compiler/cpp/map_field.cc +++ b/src/google/protobuf/compiler/cpp/map_field.cc @@ -30,18 +30,22 @@ #include "google/protobuf/compiler/cpp/map_field.h" +#include + #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" -#include "google/protobuf/compiler/cpp/helpers.h" #include "absl/strings/str_cat.h" +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { namespace protobuf { namespace compiler { namespace cpp { -void SetMessageVariables(const FieldDescriptor* descriptor, - std::map* variables, - const Options& options) { +void SetMessageVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = ClassName(descriptor->message_type(), false); (*variables)["full_name"] = descriptor->full_name(); diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 51f94d10be..bf54fb4289 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -36,10 +36,10 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -52,6 +52,7 @@ #include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -277,10 +278,11 @@ bool HasHasMethod(const FieldDescriptor* field) { } // Collects map entry message type information. -void CollectMapInfo(const Options& options, const Descriptor* descriptor, - std::map* variables) { +void CollectMapInfo( + const Options& options, const Descriptor* descriptor, + absl::flat_hash_map* variables) { GOOGLE_CHECK(IsMapEntryMessage(descriptor)); - std::map& vars = *variables; + absl::flat_hash_map& vars = *variables; const FieldDescriptor* key = descriptor->map_key(); const FieldDescriptor* val = descriptor->map_value(); vars["key_cpp"] = PrimitiveTypeName(options, key->cpp_type()); @@ -429,7 +431,7 @@ class ColdChunkSkipper { const std::vector& has_bit_indices_; const AccessInfoMap* access_info_map_; const double cold_threshold_; - std::map variables_; + absl::flat_hash_map variables_; int limit_chunk_ = -1; }; @@ -509,7 +511,7 @@ bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* p) { } void AnnotationVar(const Descriptor* desc, const Options& options, - absl::flat_hash_map& vars, + absl::flat_hash_map& vars, absl::string_view name, absl::string_view val) { if (!HasTracker(desc, options) || options.field_listener_options.forbidden_field_listener_events.count( @@ -520,9 +522,9 @@ void AnnotationVar(const Descriptor* desc, const Options& options, vars.emplace(name, absl::StrCat(absl::StripAsciiWhitespace(val), "\n")); } -absl::flat_hash_map ClassVars(const Descriptor* desc, - Options opts) { - absl::flat_hash_map vars = MessageVars(desc); +absl::flat_hash_map ClassVars( + const Descriptor* desc, Options opts) { + absl::flat_hash_map vars = MessageVars(desc); vars.emplace("classname", ClassName(desc, false)); vars.emplace("classtype", QualifiedClassName(desc, opts)); vars.emplace("full_name", desc->full_name()); @@ -640,11 +642,11 @@ absl::flat_hash_map ClassVars(const Descriptor* desc, // =================================================================== -MessageGenerator::MessageGenerator(const Descriptor* descriptor, - const std::map&, - int index_in_file_messages, - const Options& options, - MessageSCCAnalyzer* scc_analyzer) +MessageGenerator::MessageGenerator( + const Descriptor* descriptor, + const absl::flat_hash_map&, + int index_in_file_messages, const Options& options, + MessageSCCAnalyzer* scc_analyzer) : descriptor_(descriptor), index_in_file_messages_(index_in_file_messages), options_(options), @@ -779,7 +781,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { for (auto field : ordered_fields) { Formatter::SaveState save(&format); - std::map vars; + absl::flat_hash_map vars; SetCommonFieldVariables(field, &vars, options_); auto v = p->WithVars(std::move(vars)); format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field)); @@ -1290,7 +1292,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { Formatter format(p); if (IsMapEntryMessage(descriptor_)) { - std::map vars; + absl::flat_hash_map vars; CollectMapInfo(options_, descriptor_, &vars); vars["lite"] = HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite"; @@ -3749,7 +3751,7 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p, void MessageGenerator::GenerateSerializeOneExtensionRange( io::Printer* p, const Descriptor::ExtensionRange* range) { - std::map vars = variables_; + absl::flat_hash_map vars = variables_; vars["start"] = absl::StrCat(range->start); vars["end"] = absl::StrCat(range->end); Formatter format(p, vars); diff --git a/src/google/protobuf/compiler/cpp/message.h b/src/google/protobuf/compiler/cpp/message.h index 019660692a..5de18734d0 100644 --- a/src/google/protobuf/compiler/cpp/message.h +++ b/src/google/protobuf/compiler/cpp/message.h @@ -60,10 +60,11 @@ namespace compiler { namespace cpp { class MessageGenerator { public: - MessageGenerator(const Descriptor* descriptor, - const std::map& ignored, - int index_in_file_messages, const Options& options, - MessageSCCAnalyzer* scc_analyzer); + MessageGenerator( + const Descriptor* descriptor, + const absl::flat_hash_map& ignored, + int index_in_file_messages, const Options& options, + MessageSCCAnalyzer* scc_analyzer); MessageGenerator(const MessageGenerator&) = delete; MessageGenerator& operator=(const MessageGenerator&) = delete; @@ -214,7 +215,7 @@ class MessageGenerator { MessageSCCAnalyzer* scc_analyzer_; - std::map variables_; + absl::flat_hash_map variables_; }; diff --git a/src/google/protobuf/compiler/cpp/message_field.cc b/src/google/protobuf/compiler/cpp/message_field.cc index e8d2a74dae..aad0f7e32f 100644 --- a/src/google/protobuf/compiler/cpp/message_field.cc +++ b/src/google/protobuf/compiler/cpp/message_field.cc @@ -35,9 +35,10 @@ #include "google/protobuf/compiler/cpp/message_field.h" #include "google/protobuf/io/printer.h" +#include "absl/container/flat_hash_map.h" +#include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/helpers.h" -#include "absl/strings/str_cat.h" namespace google { namespace protobuf { @@ -55,28 +56,34 @@ std::string ReinterpretCast(const std::string& type, } } -void SetMessageVariables(const FieldDescriptor* descriptor, - const Options& options, bool implicit_weak, - std::map* variables) { +void SetMessageVariables( + const FieldDescriptor* descriptor, const Options& options, + bool implicit_weak, + absl::flat_hash_map* variables) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = FieldMessageTypeName(descriptor, options); - (*variables)["casted_member"] = ReinterpretCast( - (*variables)["type"] + "*", (*variables)["field"], implicit_weak); - (*variables)["casted_member_const"] = - ReinterpretCast("const " + (*variables)["type"] + "&", - "*" + (*variables)["field"], implicit_weak); + variables->insert( + {"casted_member", ReinterpretCast(absl::StrCat((*variables)["type"], "*"), + (*variables)["field"], implicit_weak)}); + variables->insert( + {"casted_member_const", + ReinterpretCast(absl::StrCat("const ", (*variables)["type"], "&"), + absl::StrCat("*", (*variables)["field"]), + implicit_weak)}); (*variables)["type_default_instance"] = QualifiedDefaultInstanceName(descriptor->message_type(), options); (*variables)["type_default_instance_ptr"] = ReinterpretCast( "const ::PROTOBUF_NAMESPACE_ID::MessageLite*", QualifiedDefaultInstancePtr(descriptor->message_type(), options), implicit_weak); - (*variables)["type_reference_function"] = - implicit_weak ? (" ::" + ProtobufNamespace(options) + - "::internal::StrongReference(reinterpret_cast(\n" + - (*variables)["type_default_instance"] + "));\n") - : ""; + variables->insert( + {"type_reference_function", + implicit_weak + ? absl::StrCat(" ::", ProtobufNamespace(options), + "::internal::StrongReference(reinterpret_cast(\n", + (*variables)["type_default_instance"], "));\n") + : ""}); // NOTE: Escaped here to unblock proto1->proto2 migration. // TODO(liujisi): Extend this to apply for other conflicting methods. (*variables)["release_name"] = diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index 74a9a9899d..04db1a6ee5 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -32,12 +32,12 @@ #include #include -#include #include #include #include #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/generated_message_tctable_gen.h" @@ -109,7 +109,7 @@ ParseFunctionGenerator::ParseFunctionGenerator( const std::vector& has_bit_indices, const std::vector& inlined_string_indices, const Options& options, MessageSCCAnalyzer* scc_analyzer, - const std::map& vars) + const absl::flat_hash_map& vars) : descriptor_(descriptor), scc_analyzer_(scc_analyzer), options_(options), diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.h b/src/google/protobuf/compiler/cpp/parse_function_generator.h index b55feda112..f3198b5f0f 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.h +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.h @@ -38,6 +38,7 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/wire_format_lite.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/generated_message_tctable_gen.h" @@ -51,12 +52,12 @@ namespace cpp { // (and any associated supporting members). class ParseFunctionGenerator { public: - ParseFunctionGenerator(const Descriptor* descriptor, int max_has_bit_index, - const std::vector& has_bit_indices, - const std::vector& inlined_string_indices, - const Options& options, - MessageSCCAnalyzer* scc_analyzer, - const std::map& vars); + ParseFunctionGenerator( + const Descriptor* descriptor, int max_has_bit_index, + const std::vector& has_bit_indices, + const std::vector& inlined_string_indices, const Options& options, + MessageSCCAnalyzer* scc_analyzer, + const absl::flat_hash_map& vars); // Emits class-level method declarations to `printer`: void GenerateMethodDecls(io::Printer* printer); @@ -126,7 +127,7 @@ class ParseFunctionGenerator { const Descriptor* descriptor_; MessageSCCAnalyzer* scc_analyzer_; const Options& options_; - std::map variables_; + absl::flat_hash_map variables_; std::unique_ptr tc_table_info_; std::vector inlined_string_indices_; const std::vector ordered_fields_; diff --git a/src/google/protobuf/compiler/cpp/primitive_field.cc b/src/google/protobuf/compiler/cpp/primitive_field.cc index b2144c3111..5b0f97164b 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -34,8 +34,11 @@ #include "google/protobuf/compiler/cpp/primitive_field.h" +#include + #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -98,9 +101,10 @@ int FixedSize(FieldDescriptor::Type type) { return -1; } -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - std::map* variables, - const Options& options) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = PrimitiveTypeName(options, descriptor->cpp_type()); (*variables)["default"] = DefaultValue(options, descriptor); diff --git a/src/google/protobuf/compiler/cpp/service.cc b/src/google/protobuf/compiler/cpp/service.cc index baa58b97ce..518628ac9c 100644 --- a/src/google/protobuf/compiler/cpp/service.cc +++ b/src/google/protobuf/compiler/cpp/service.cc @@ -34,7 +34,6 @@ #include "google/protobuf/compiler/cpp/service.h" -#include #include #include "absl/strings/str_cat.h" @@ -85,7 +84,7 @@ void ServiceGenerator::GenerateDeclarations(io::Printer* printer) { const ::$proto_ns$::MethodDescriptor* method) const override; }; - class $dllexport_decl $$classname$_Stub : public $classname$ { + class $dllexport_decl $$classname$_Stub final : public $classname$ { public: $classname$_Stub(::$proto_ns$::RpcChannel* channel); $classname$_Stub(::$proto_ns$::RpcChannel* channel, diff --git a/src/google/protobuf/compiler/cpp/service.h b/src/google/protobuf/compiler/cpp/service.h index 34b891423b..b38591b62b 100644 --- a/src/google/protobuf/compiler/cpp/service.h +++ b/src/google/protobuf/compiler/cpp/service.h @@ -39,6 +39,7 @@ #include #include "google/protobuf/descriptor.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/io/printer.h" @@ -49,9 +50,10 @@ namespace cpp { class ServiceGenerator { public: // See generator.cc for the meaning of dllexport_decl. - ServiceGenerator(const ServiceDescriptor* descriptor, - const std::map& vars, - const Options& options) + ServiceGenerator( + const ServiceDescriptor* descriptor, + const absl::flat_hash_map& vars, + const Options& options) : descriptor_(descriptor), options_(&options), vars_(vars) { vars_["classname"] = descriptor_->name(); vars_["full_name"] = descriptor_->full_name(); @@ -98,7 +100,7 @@ class ServiceGenerator { const ServiceDescriptor* descriptor_; const Options* options_; - std::map vars_; + absl::flat_hash_map vars_; int index_in_metadata_; diff --git a/src/google/protobuf/compiler/cpp/string_field.cc b/src/google/protobuf/compiler/cpp/string_field.cc index b1aadfb56e..92d340fec1 100644 --- a/src/google/protobuf/compiler/cpp/string_field.cc +++ b/src/google/protobuf/compiler/cpp/string_field.cc @@ -34,6 +34,9 @@ #include "google/protobuf/compiler/cpp/string_field.h" +#include + +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/descriptor.pb.h" @@ -45,13 +48,12 @@ namespace cpp { namespace { -void SetStringVariables(const FieldDescriptor* descriptor, - std::map* variables, - const Options& options) { +void SetStringVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables, + const Options& options) { SetCommonFieldVariables(descriptor, variables, options); - const std::string kNS = "::" + ProtobufNamespace(options) + "::internal::"; - const std::string kArenaStringPtr = kNS + "ArenaStringPtr"; (*variables)["default"] = DefaultValue(options, descriptor); (*variables)["default_length"] = @@ -60,17 +62,21 @@ void SetStringVariables(const FieldDescriptor* descriptor, (*variables)["default_variable_field"] = MakeDefaultFieldName(descriptor); if (descriptor->default_value_string().empty()) { - (*variables)["default_string"] = kNS + "GetEmptyStringAlreadyInited()"; - (*variables)["default_value"] = "&" + (*variables)["default_string"]; + const std::string default_string = + absl::StrCat("::", ProtobufNamespace(options), + "::internal::GetEmptyStringAlreadyInited()"); + (*variables)["default_string"] = default_string; + (*variables)["default_value"] = absl::StrCat("&", default_string); (*variables)["lazy_variable_args"] = ""; } else { - (*variables)["lazy_variable"] = + const std::string lazy_variable = absl::StrCat(QualifiedClassName(descriptor->containing_type(), options), "::", MakeDefaultFieldName(descriptor)); + (*variables)["lazy_variable"] = lazy_variable; - (*variables)["default_string"] = (*variables)["lazy_variable"] + ".get()"; + (*variables)["default_string"] = absl::StrCat(lazy_variable, ".get()"); (*variables)["default_value"] = "nullptr"; - (*variables)["lazy_variable_args"] = (*variables)["lazy_variable"] + ", "; + (*variables)["lazy_variable_args"] = absl::StrCat(lazy_variable, ", "); } (*variables)["pointer_type"] = diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index bc45d740ba..158bf71074 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -33,15 +33,16 @@ #include #include #include +#include #include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/names.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -52,7 +53,7 @@ namespace compiler { namespace csharp { void FieldGeneratorBase::SetCommonFieldVariables( - std::map* variables) { + absl::flat_hash_map* variables) { // Note: this will be valid even though the tag emitted for packed and unpacked versions of // repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which // never effects the tag size. @@ -98,33 +99,46 @@ void FieldGeneratorBase::SetCommonFieldVariables( (*variables)["capitalized_type_name"] = capitalized_type_name(); (*variables)["number"] = number(); if (has_default_value() && !SupportsPresenceApi(descriptor_)) { - (*variables)["name_def_message"] = - (*variables)["name"] + "_ = " + (*variables)["default_value"]; + variables->insert({"name_def_message", + absl::StrCat((*variables)["name"], + "_ = ", (*variables)["default_value"])}); } else { - (*variables)["name_def_message"] = (*variables)["name"] + "_"; + variables->insert( + {"name_def_message", absl::StrCat((*variables)["name"], "_")}); } if (SupportsPresenceApi(descriptor_)) { - (*variables)["has_property_check"] = "Has" + (*variables)["property_name"]; - (*variables)["other_has_property_check"] = "other.Has" + (*variables)["property_name"]; - (*variables)["has_not_property_check"] = "!" + (*variables)["has_property_check"]; - (*variables)["other_has_not_property_check"] = "!" + (*variables)["other_has_property_check"]; + variables->insert({"has_property_check", + absl::StrCat("Has", (*variables)["property_name"])}); + variables->insert( + {"other_has_property_check", + absl::StrCat("other.Has", (*variables)["property_name"])}); + variables->insert({"has_not_property_check", + absl::StrCat("!", (*variables)["has_property_check"])}); + variables->insert( + {"other_has_not_property_check", + absl::StrCat("!", (*variables)["other_has_property_check"])}); if (presenceIndex_ != -1) { - 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; + const int hasBitsNumber = presenceIndex_ / 32; + const int hasBitsMask = 1 << (presenceIndex_ % 32); + (*variables)["has_field_check"] = absl::StrCat( + "(_hasBits", hasBitsNumber, " & ", hasBitsMask, ") != 0"); + (*variables)["set_has_field"] = + absl::StrCat("_hasBits", hasBitsNumber, " |= ", hasBitsMask); + (*variables)["clear_has_field"] = + absl::StrCat("_hasBits", hasBitsNumber, " &= ~", hasBitsMask); } } else { - (*variables)["has_property_check"] = - (*variables)["property_name"] + " != " + (*variables)["default_value"]; - (*variables)["other_has_property_check"] = "other." + - (*variables)["property_name"] + " != " + (*variables)["default_value"]; + variables->insert({"has_property_check", + absl::StrCat((*variables)["property_name"], + " != ", (*variables)["default_value"])}); + variables->insert({"other_has_property_check", + absl::StrCat("other.", (*variables)["property_name"], + " != ", (*variables)["default_value"])}); } } void FieldGeneratorBase::SetCommonOneofFieldVariables( - std::map* variables) { + absl::flat_hash_map* variables) { (*variables)["oneof_name"] = oneof_name(); if (SupportsPresenceApi(descriptor_)) { (*variables)["has_property_check"] = "Has" + property_name(); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 75fe19bfb3..933bbd4916 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -34,6 +34,7 @@ #include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" @@ -77,7 +78,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { protected: const FieldDescriptor* descriptor_; const int presenceIndex_; - std::map variables_; + absl::flat_hash_map variables_; void AddDeprecatedFlag(io::Printer* printer); void AddNullCheck(io::Printer* printer); @@ -85,7 +86,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { void AddPublicMemberAttributes(io::Printer* printer); void SetCommonOneofFieldVariables( - std::map* variables); + absl::flat_hash_map* variables); std::string oneof_property_name(); std::string oneof_case_name(); @@ -101,7 +102,8 @@ class FieldGeneratorBase : public SourceGeneratorBase { std::string capitalized_type_name(); private: - void SetCommonFieldVariables(std::map* variables); + void SetCommonFieldVariables( + absl::flat_hash_map* variables); std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor); std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor); }; diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index 50d8b1d828..efe87f2a6a 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -88,7 +88,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { printer->Print( variables_, - "$name$_.MergeFrom(other.$name$_);\n"); + "$name$_.Add(other.$name$_);\n"); } void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index bdbd480a61..d5c803fce6 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -31,17 +31,17 @@ #include "google/protobuf/compiler/csharp/csharp_message.h" #include -#include #include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_enum.h" #include "google/protobuf/compiler/csharp/csharp_field_base.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/names.h" #include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/compiler/csharp/names.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" @@ -114,7 +114,7 @@ void MessageGenerator::AddSerializableAttribute(io::Printer* printer) { } void MessageGenerator::Generate(io::Printer* printer) { - std::map vars; + absl::flat_hash_map vars; vars["class_name"] = class_name(); vars["access_level"] = class_access_level(); @@ -376,7 +376,7 @@ bool MessageGenerator::HasNestedGeneratedTypes() } void MessageGenerator::GenerateCloningCode(io::Printer* printer) { - std::map vars; + absl::flat_hash_map vars; WriteGeneratedCodeAttributes(printer); vars["class_name"] = class_name(); printer->Print( @@ -440,32 +440,30 @@ void MessageGenerator::GenerateFreezingCode(io::Printer* printer) { } void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { - std::map vars; - vars["class_name"] = class_name(); + absl::flat_hash_map vars; + vars["class_name"] = class_name(); - // Equality - WriteGeneratedCodeAttributes(printer); - printer->Print( - vars, - "public override bool Equals(object other) {\n" - " return Equals(other as $class_name$);\n" - "}\n\n"); - WriteGeneratedCodeAttributes(printer); - printer->Print( - vars, - "public bool Equals($class_name$ other) {\n" - " if (ReferenceEquals(other, null)) {\n" - " return false;\n" - " }\n" - " if (ReferenceEquals(other, this)) {\n" - " return true;\n" - " }\n"); - printer->Indent(); - for (int i = 0; i < descriptor_->field_count(); i++) { - std::unique_ptr generator( - CreateFieldGeneratorInternal(descriptor_->field(i))); - generator->WriteEquals(printer); - } + // Equality + WriteGeneratedCodeAttributes(printer); + printer->Print(vars, + "public override bool Equals(object other) {\n" + " return Equals(other as $class_name$);\n" + "}\n\n"); + WriteGeneratedCodeAttributes(printer); + printer->Print(vars, + "public bool Equals($class_name$ other) {\n" + " if (ReferenceEquals(other, null)) {\n" + " return false;\n" + " }\n" + " if (ReferenceEquals(other, this)) {\n" + " return true;\n" + " }\n"); + printer->Indent(); + for (int i = 0; i < descriptor_->field_count(); i++) { + std::unique_ptr generator( + CreateFieldGeneratorInternal(descriptor_->field(i))); + generator->WriteEquals(printer); + } for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) { printer->Print("if ($property_name$Case != other.$property_name$Case) return false;\n", "property_name", UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), true)); @@ -607,7 +605,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { // Note: These are separate from GenerateMessageSerializationMethods() // because they need to be generated even for messages that are optimized // for code size. - std::map vars; + absl::flat_hash_map vars; vars["class_name"] = class_name(); WriteGeneratedCodeAttributes(printer); @@ -687,7 +685,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { } void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_parse_context) { - std::map vars; + absl::flat_hash_map vars; vars["maybe_ref_input"] = use_parse_context ? "ref input" : "input"; printer->Print( diff --git a/src/google/protobuf/compiler/java/enum.cc b/src/google/protobuf/compiler/java/enum.cc index 788c9dd60f..f290623cac 100644 --- a/src/google/protobuf/compiler/java/enum.cc +++ b/src/google/protobuf/compiler/java/enum.cc @@ -34,10 +34,10 @@ #include "google/protobuf/compiler/java/enum.h" -#include #include #include "google/protobuf/io/printer.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -103,7 +103,7 @@ void EnumGenerator::Generate(io::Printer* printer) { } for (int i = 0; i < canonical_values_.size(); i++) { - std::map vars; + absl::flat_hash_map vars; vars["name"] = canonical_values_[i]->name(); vars["index"] = absl::StrCat(canonical_values_[i]->index()); vars["number"] = absl::StrCat(canonical_values_[i]->number()); @@ -135,7 +135,7 @@ void EnumGenerator::Generate(io::Printer* printer) { // ----------------------------------------------------------------- for (int i = 0; i < aliases_.size(); i++) { - std::map vars; + absl::flat_hash_map vars; vars["classname"] = descriptor_->name(); vars["name"] = aliases_[i].value->name(); vars["canonical_name"] = aliases_[i].canonical_value->name(); @@ -146,7 +146,7 @@ void EnumGenerator::Generate(io::Printer* printer) { } for (int i = 0; i < descriptor_->value_count(); i++) { - std::map vars; + absl::flat_hash_map vars; vars["name"] = descriptor_->value(i)->name(); vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["{"] = ""; diff --git a/src/google/protobuf/compiler/java/enum_field.cc b/src/google/protobuf/compiler/java/enum_field.cc index b6c8dc796c..022511ff71 100644 --- a/src/google/protobuf/compiler/java/enum_field.cc +++ b/src/google/protobuf/compiler/java/enum_field.cc @@ -35,13 +35,13 @@ #include "google/protobuf/compiler/java/enum_field.h" #include -#include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -58,16 +58,16 @@ namespace java { namespace { -void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetEnumVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->enum_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])}); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->enum_type()); (*variables)["default"] = @@ -82,11 +82,12 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); @@ -106,9 +107,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_has_field_bit_builder"] = ""; (*variables)["clear_has_field_bit_builder"] = ""; - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"] + - ".getNumber()"; + variables->insert({"is_field_present_message", + absl::StrCat((*variables)["name"], "_ != ", + (*variables)["default"], ".getNumber()")}); } // For repeated builders, one bit is used for whether the array is immutable. @@ -122,9 +123,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, GenerateSetBitToLocal(messageBitIndex); if (SupportUnknownEnumValue(descriptor->file())) { - (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED"; + variables->insert( + {"unknown", absl::StrCat((*variables)["type"], ".UNRECOGNIZED")}); } else { - (*variables)["unknown"] = (*variables)["default"]; + variables->insert({"unknown", (*variables)["default"]}); } } diff --git a/src/google/protobuf/compiler/java/enum_field.h b/src/google/protobuf/compiler/java/enum_field.h index 25ab0738da..e0fc5c1fae 100644 --- a/src/google/protobuf/compiler/java/enum_field.h +++ b/src/google/protobuf/compiler/java/enum_field.h @@ -38,6 +38,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -90,7 +91,7 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; @@ -153,7 +154,7 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/enum_field_lite.cc b/src/google/protobuf/compiler/java/enum_field_lite.cc index 470bc9d2fd..e2a1a6e149 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -35,14 +35,15 @@ #include "google/protobuf/compiler/java/enum_field_lite.h" #include -#include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -65,16 +66,16 @@ bool EnableExperimentalRuntimeForLite() { #endif // !PROTOBUF_EXPERIMENT } -void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetEnumVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->enum_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])}); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->enum_type()); (*variables)["default"] = @@ -89,11 +90,12 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; if (HasHasbit(descriptor)) { @@ -117,9 +119,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_has_field_bit_message"] = ""; (*variables)["clear_has_field_bit_message"] = ""; - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"] + - ".getNumber()"; + variables->insert({"is_field_present_message", + absl::StrCat((*variables)["name"], "_ != ", + (*variables)["default"], ".getNumber()")}); } (*variables)["get_has_field_bit_from_local"] = @@ -128,9 +130,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, GenerateSetBitToLocal(messageBitIndex); if (SupportUnknownEnumValue(descriptor->file())) { - (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED"; + variables->insert( + {"unknown", absl::StrCat((*variables)["type"], ".UNRECOGNIZED")}); } else { - (*variables)["unknown"] = (*variables)["default"]; + variables->insert({"unknown", (*variables)["default"]}); } // We use `x.getClass()` as a null check because it generates less bytecode diff --git a/src/google/protobuf/compiler/java/enum_field_lite.h b/src/google/protobuf/compiler/java/enum_field_lite.h index 8d7a7d1cf4..17a95ac7f7 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.h +++ b/src/google/protobuf/compiler/java/enum_field_lite.h @@ -39,6 +39,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -83,7 +84,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -131,7 +132,7 @@ class RepeatedImmutableEnumFieldLiteGenerator private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/enum_lite.cc b/src/google/protobuf/compiler/java/enum_lite.cc index 47cae62bc2..dc222541b0 100644 --- a/src/google/protobuf/compiler/java/enum_lite.cc +++ b/src/google/protobuf/compiler/java/enum_lite.cc @@ -34,10 +34,10 @@ #include "google/protobuf/compiler/java/enum_lite.h" -#include #include #include "google/protobuf/io/printer.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -86,7 +86,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { printer->Indent(); for (int i = 0; i < canonical_values_.size(); i++) { - std::map vars; + absl::flat_hash_map vars; vars["name"] = canonical_values_[i]->name(); vars["number"] = absl::StrCat(canonical_values_[i]->number()); WriteEnumValueDocComment(printer, canonical_values_[i]); @@ -109,7 +109,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { // ----------------------------------------------------------------- for (int i = 0; i < aliases_.size(); i++) { - std::map vars; + absl::flat_hash_map vars; vars["classname"] = descriptor_->name(); vars["name"] = aliases_[i].value->name(); vars["canonical_name"] = aliases_[i].canonical_value->name(); @@ -120,7 +120,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { } for (int i = 0; i < descriptor_->value_count(); i++) { - std::map vars; + absl::flat_hash_map vars; vars["name"] = descriptor_->value(i)->name(); vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["{"] = ""; diff --git a/src/google/protobuf/compiler/java/extension.cc b/src/google/protobuf/compiler/java/extension.cc index 24a392edd8..421465b313 100644 --- a/src/google/protobuf/compiler/java/extension.cc +++ b/src/google/protobuf/compiler/java/extension.cc @@ -35,6 +35,7 @@ #include "google/protobuf/compiler/java/extension.h" #include "google/protobuf/io/printer.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -68,8 +69,9 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} void ExtensionGenerator::InitTemplateVars( const FieldDescriptor* descriptor, const std::string& scope, bool immutable, ClassNameResolver* name_resolver, - std::map* vars_pointer, Context* context) { - std::map& vars = *vars_pointer; + absl::flat_hash_map* vars_pointer, + Context* context) { + absl::flat_hash_map& vars = *vars_pointer; vars["scope"] = scope; vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor); vars["containing_type"] = @@ -116,7 +118,7 @@ void ExtensionGenerator::InitTemplateVars( } void ImmutableExtensionGenerator::Generate(io::Printer* printer) { - std::map vars; + absl::flat_hash_map vars; const bool kUseImmutableNames = true; InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, &vars, context_); diff --git a/src/google/protobuf/compiler/java/extension.h b/src/google/protobuf/compiler/java/extension.h index b9dc99597b..15341b74dd 100644 --- a/src/google/protobuf/compiler/java/extension.h +++ b/src/google/protobuf/compiler/java/extension.h @@ -38,6 +38,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/port.h" namespace google { @@ -81,11 +82,11 @@ class ExtensionGenerator { virtual int GenerateRegistrationCode(io::Printer* printer) = 0; protected: - static void InitTemplateVars(const FieldDescriptor* descriptor, - const std::string& scope, bool immutable, - ClassNameResolver* name_resolver, - std::map* vars_pointer, - Context* context); + static void InitTemplateVars( + const FieldDescriptor* descriptor, const std::string& scope, + bool immutable, ClassNameResolver* name_resolver, + absl::flat_hash_map* vars_pointer, + Context* context); }; class ImmutableExtensionGenerator : public ExtensionGenerator { diff --git a/src/google/protobuf/compiler/java/extension_lite.cc b/src/google/protobuf/compiler/java/extension_lite.cc index e18dc6536a..111e51054b 100644 --- a/src/google/protobuf/compiler/java/extension_lite.cc +++ b/src/google/protobuf/compiler/java/extension_lite.cc @@ -30,7 +30,10 @@ #include "google/protobuf/compiler/java/extension_lite.h" +#include + #include "google/protobuf/io/printer.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -60,7 +63,7 @@ ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator( ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {} void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) { - std::map vars; + absl::flat_hash_map vars; const bool kUseImmutableNames = true; InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, &vars, context_); diff --git a/src/google/protobuf/compiler/java/field.cc b/src/google/protobuf/compiler/java/field.cc index 831f88ab2d..449edf7fe4 100644 --- a/src/google/protobuf/compiler/java/field.cc +++ b/src/google/protobuf/compiler/java/field.cc @@ -35,10 +35,12 @@ #include "google/protobuf/compiler/java/field.h" #include +#include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/java/context.h" @@ -241,9 +243,9 @@ template <> FieldGeneratorMap::~FieldGeneratorMap() {} -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - const FieldGeneratorInfo* info, - std::map* variables) { +void SetCommonFieldVariables( + const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, + absl::flat_hash_map* variables) { (*variables)["field_name"] = descriptor->name(); (*variables)["name"] = info->name; (*variables)["classname"] = descriptor->containing_type()->name(); @@ -273,15 +275,16 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["annotation_field_type"] = std::string(FieldTypeName(descriptor->type())) + "_LIST"; if (descriptor->is_packed()) { - (*variables)["annotation_field_type"] = - (*variables)["annotation_field_type"] + "_PACKED"; + variables->insert( + {"annotation_field_type", + absl::StrCat((*variables)["annotation_field_type"], "_PACKED")}); } } } -void SetCommonOneofVariables(const FieldDescriptor* descriptor, - const OneofGeneratorInfo* info, - std::map* variables) { +void SetCommonOneofVariables( + const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, + absl::flat_hash_map* variables) { (*variables)["oneof_name"] = info->name; (*variables)["oneof_capitalized_name"] = info->capitalized_name; (*variables)["oneof_index"] = @@ -294,10 +297,10 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor, info->name + "Case_ == " + absl::StrCat(descriptor->number()); } -void PrintExtraFieldInfo(const std::map& variables, - io::Printer* printer) { - const std::map::const_iterator it = - variables.find("disambiguated_reason"); +void PrintExtraFieldInfo( + const absl::flat_hash_map& variables, + io::Printer* printer) { + auto it = variables.find("disambiguated_reason"); if (it != variables.end() && !it->second.empty()) { printer->Print( variables, diff --git a/src/google/protobuf/compiler/java/field.h b/src/google/protobuf/compiler/java/field.h index 5ac57cd4e1..7926f0821c 100644 --- a/src/google/protobuf/compiler/java/field.h +++ b/src/google/protobuf/compiler/java/field.h @@ -43,6 +43,7 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/descriptor.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/port.h" namespace google { @@ -169,18 +170,19 @@ struct OneofGeneratorInfo { }; // Set some common variables used in variable FieldGenerators. -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - const FieldGeneratorInfo* info, - std::map* variables); +void SetCommonFieldVariables( + const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, + absl::flat_hash_map* variables); // Set some common oneof variables used in OneofFieldGenerators. -void SetCommonOneofVariables(const FieldDescriptor* descriptor, - const OneofGeneratorInfo* info, - std::map* variables); +void SetCommonOneofVariables( + const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, + absl::flat_hash_map* variables); // Print useful comments before a field's accessors. -void PrintExtraFieldInfo(const std::map& variables, - io::Printer* printer); +void PrintExtraFieldInfo( + const absl::flat_hash_map& variables, + io::Printer* printer); } // namespace java } // namespace compiler diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index d13941c6ed..fea72712b5 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -84,11 +84,10 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter, printer->Print(ptemplate.c_str(), "annotation_file", annotation_file); } -void PrintEnumVerifierLogic(io::Printer* printer, - const FieldDescriptor* descriptor, - const std::map& variables, - const char* var_name, - const char* terminating_string, bool enforce_lite) { +void PrintEnumVerifierLogic( + io::Printer* printer, const FieldDescriptor* descriptor, + const absl::flat_hash_map& variables, + const char* var_name, const char* terminating_string, bool enforce_lite) { std::string enum_verifier_string = enforce_lite ? absl::StrCat(var_name, ".internalGetVerifier()") : absl::StrCat( diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 9273ae3c0b..a3eee1a938 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -74,11 +74,10 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$', // If a GeneratedMessageLite contains non-lite enums, then its verifier // must be instantiated inline, rather than retrieved from the enum class. -void PrintEnumVerifierLogic(io::Printer* printer, - const FieldDescriptor* descriptor, - const std::map& variables, - const char* var_name, - const char* terminating_string, bool enforce_lite); +void PrintEnumVerifierLogic( + io::Printer* printer, const FieldDescriptor* descriptor, + const absl::flat_hash_map& variables, + const char* var_name, const char* terminating_string, bool enforce_lite); // Converts a name to camel-case. If cap_first_letter is true, capitalize the // first letter. diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index 2b69bb6e29..4c7715c69e 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -31,6 +31,7 @@ #include "google/protobuf/compiler/java/map_field.h" #include "google/protobuf/io/printer.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" @@ -88,10 +89,10 @@ std::string WireType(const FieldDescriptor* field) { std::string(FieldTypeName(field->type())); } -void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - Context* context, - std::map* variables) { +void SetMessageVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, Context* context, + absl::flat_hash_map* variables) { SetCommonFieldVariables(descriptor, info, variables); ClassNameResolver* name_resolver = context->GetNameResolver(); @@ -133,8 +134,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, if (valueJavaType == JAVATYPE_ENUM) { // We store enums as Integers internally. (*variables)["value_type"] = "int"; - (*variables)["value_type_pass_through_nullness"] = - (*variables)["value_type"]; + variables->insert( + {"value_type_pass_through_nullness", (*variables)["value_type"]}); (*variables)["boxed_value_type"] = "java.lang.Integer"; (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = @@ -143,13 +144,15 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); - (*variables)["value_enum_type_pass_through_nullness"] = - pass_through_nullness + (*variables)["value_enum_type"]; + variables->insert( + {"value_enum_type_pass_through_nullness", + absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])}); if (SupportUnknownEnumValue(descriptor->file())) { // Map unknown values to a special UNRECOGNIZED value if supported. - (*variables)["unrecognized_value"] = - (*variables)["value_enum_type"] + ".UNRECOGNIZED"; + variables->insert( + {"unrecognized_value", + absl::StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED")}); } else { // Map unknown values to the default value if we don't have UNRECOGNIZED. (*variables)["unrecognized_value"] = @@ -158,31 +161,36 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, } else { (*variables)["value_type"] = TypeName(value, name_resolver, false); - (*variables)["value_type_pass_through_nullness"] = - (IsReferenceType(valueJavaType) ? pass_through_nullness : "") + - (*variables)["value_type"]; + variables->insert( + {"value_type_pass_through_nullness", + absl::StrCat( + (IsReferenceType(valueJavaType) ? pass_through_nullness : ""), + (*variables)["value_type"])}); (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = DefaultValue(value, true, name_resolver, context->options()); } - (*variables)["type_parameters"] = - (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; + variables->insert( + {"type_parameters", absl::StrCat((*variables)["boxed_key_type"], ", ", + (*variables)["boxed_value_type"])}); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["on_changed"] = "onChanged();"; - (*variables)["default_entry"] = - (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry"; - (*variables)["map_field_parameter"] = (*variables)["default_entry"]; + variables->insert( + {"default_entry", absl::StrCat((*variables)["capitalized_name"], + "DefaultEntryHolder.defaultEntry")}); + variables->insert({"map_field_parameter", (*variables)["default_entry"]}); (*variables)["descriptor"] = name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; diff --git a/src/google/protobuf/compiler/java/map_field.h b/src/google/protobuf/compiler/java/map_field.h index 434150820b..39cdbde767 100644 --- a/src/google/protobuf/compiler/java/map_field.h +++ b/src/google/protobuf/compiler/java/map_field.h @@ -68,7 +68,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; Context* context_; void GenerateMapGetters(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/java/map_field_lite.cc b/src/google/protobuf/compiler/java/map_field_lite.cc index 22bc306586..94d964fa38 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/src/google/protobuf/compiler/java/map_field_lite.cc @@ -90,10 +90,10 @@ std::string WireType(const FieldDescriptor* field) { std::string(FieldTypeName(field->type())); } -void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - Context* context, - std::map* variables) { +void SetMessageVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, Context* context, + absl::flat_hash_map* variables) { SetCommonFieldVariables(descriptor, info, variables); ClassNameResolver* name_resolver = context->GetNameResolver(); @@ -130,8 +130,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, if (GetJavaType(value) == JAVATYPE_ENUM) { // We store enums as Integers internally. (*variables)["value_type"] = "int"; - (*variables)["value_type_pass_through_nullness"] = - (*variables)["value_type"]; + (*variables)["value_type_pass_through_nullness"] = "int"; (*variables)["boxed_value_type"] = "java.lang.Integer"; (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = @@ -140,13 +139,15 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); - (*variables)["value_enum_type_pass_through_nullness"] = - pass_through_nullness + (*variables)["value_enum_type"]; + variables->insert( + {"value_enum_type_pass_through_nullness", + absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])}); if (SupportUnknownEnumValue(descriptor->file())) { // Map unknown values to a special UNRECOGNIZED value if supported. - (*variables)["unrecognized_value"] = - (*variables)["value_enum_type"] + ".UNRECOGNIZED"; + variables->insert( + {"unrecognized_value", + absl::StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED")}); } else { // Map unknown values to the default value if we don't have UNRECOGNIZED. (*variables)["unrecognized_value"] = @@ -155,31 +156,37 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, } else { (*variables)["value_type"] = TypeName(value, name_resolver, false); - (*variables)["value_type_pass_through_nullness"] = - (IsReferenceType(valueJavaType) ? pass_through_nullness : "") + - (*variables)["value_type"]; + variables->insert( + {"value_type_pass_through_nullness", + absl::StrCat( + (IsReferenceType(valueJavaType) ? pass_through_nullness : ""), + (*variables)["value_type"])}); (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = DefaultValue(value, true, name_resolver, context->options()); } - (*variables)["type_parameters"] = - (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; + variables->insert( + {"type_parameters", absl::StrCat((*variables)["boxed_key_type"], ", ", + (*variables)["boxed_value_type"])}); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; - - (*variables)["default_entry"] = - (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry"; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); + + variables->insert( + {"default_entry", absl::StrCat((*variables)["capitalized_name"], + "DefaultEntryHolder.defaultEntry")}); // { and } variables are used as delimiters when emitting annotations. - (*variables)["{"] = (*variables)["}"] = ""; + (*variables)["{"] = ""; + (*variables)["}"] = ""; } } // namespace diff --git a/src/google/protobuf/compiler/java/map_field_lite.h b/src/google/protobuf/compiler/java/map_field_lite.h index 46a2d9f884..ccb2bc4c3f 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.h +++ b/src/google/protobuf/compiler/java/map_field_lite.h @@ -61,7 +61,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index eae7bb3bcc..9ff8b87aa0 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -36,7 +36,6 @@ #include #include -#include #include #include @@ -115,7 +114,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( // the outermost class in the file. This way, they will be initialized in // a deterministic order. - std::map vars; + absl::flat_hash_map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["index"] = absl::StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); @@ -159,7 +158,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( int ImmutableMessageGenerator::GenerateStaticVariableInitializers( io::Printer* printer) { int bytecode_estimate = 0; - std::map vars; + absl::flat_hash_map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["index"] = absl::StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); @@ -196,7 +195,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers( void ImmutableMessageGenerator::GenerateFieldAccessorTable( io::Printer* printer, int* bytecode_estimate) { - std::map vars; + absl::flat_hash_map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { // We can only make these package-private since the classes that use them @@ -314,7 +313,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { void ImmutableMessageGenerator::Generate(io::Printer* printer) { bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - std::map variables; + absl::flat_hash_map variables; variables["static"] = is_own_file ? "" : "static "; variables["classname"] = descriptor_->name(); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); @@ -426,7 +425,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { } // oneof - std::map vars; + absl::flat_hash_map vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = diff --git a/src/google/protobuf/compiler/java/message_builder.cc b/src/google/protobuf/compiler/java/message_builder.cc index 150c4e6c4c..eb85dd4f76 100644 --- a/src/google/protobuf/compiler/java/message_builder.cc +++ b/src/google/protobuf/compiler/java/message_builder.cc @@ -35,13 +35,13 @@ #include "google/protobuf/compiler/java/message_builder.h" #include -#include #include #include #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -126,7 +126,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { } // oneof - std::map vars; + absl::flat_hash_map vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = diff --git a/src/google/protobuf/compiler/java/message_builder_lite.cc b/src/google/protobuf/compiler/java/message_builder_lite.cc index 1f9d13e9b6..5f047344e2 100644 --- a/src/google/protobuf/compiler/java/message_builder_lite.cc +++ b/src/google/protobuf/compiler/java/message_builder_lite.cc @@ -35,7 +35,6 @@ #include "google/protobuf/compiler/java/message_builder_lite.h" #include -#include #include #include #include @@ -43,6 +42,7 @@ #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/java/context.h" @@ -82,7 +82,7 @@ MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {} void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { WriteMessageDocComment(printer, descriptor_); - std::map vars = { + absl::flat_hash_map vars = { {"{", ""}, {"}", ""}, {"classname", name_resolver_->GetImmutableClassName(descriptor_)}, diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 0e06ed77d8..c77d345e7c 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -34,11 +34,11 @@ #include "google/protobuf/compiler/java/message_field.h" -#include #include #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" @@ -55,16 +55,16 @@ namespace java { namespace { -void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetMessageVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->message_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])}); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->message_type()); (*variables)["group_or_message"] = @@ -74,11 +74,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["on_changed"] = "onChanged();"; (*variables)["ver"] = GeneratedCodeVersionSuffix(); (*variables)["get_parser"] = @@ -106,8 +107,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_has_field_bit_builder"] = ""; (*variables)["clear_has_field_bit_builder"] = ""; - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != null"; + variables->insert({"is_field_present_message", + absl::StrCat((*variables)["name"], "_ != null")}); } // For repeated builders, one bit is used for whether the array is immutable. diff --git a/src/google/protobuf/compiler/java/message_field.h b/src/google/protobuf/compiler/java/message_field.h index 4fe5ac7df4..6510a16e92 100644 --- a/src/google/protobuf/compiler/java/message_field.h +++ b/src/google/protobuf/compiler/java/message_field.h @@ -92,7 +92,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; Context* context_; @@ -165,7 +165,7 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; void PrintNestedBuilderCondition(io::Printer* printer, diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index d01ccc102d..0a27635d7a 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -35,7 +35,6 @@ #include "google/protobuf/compiler/java/message_field_lite.h" #include -#include #include #include "google/protobuf/io/printer.h" @@ -56,16 +55,16 @@ namespace java { namespace { -void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetMessageVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->message_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + variables->insert({"kt_type", EscapeKotlinKeywords((*variables)["type"])}); (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->message_type()); (*variables)["group_or_message"] = @@ -75,11 +74,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; if (HasHasbit(descriptor)) { @@ -97,8 +97,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_has_field_bit_message"] = ""; (*variables)["clear_has_field_bit_message"] = ""; - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != null"; + variables->insert({"is_field_present_message", + absl::StrCat((*variables)["name"], "_ != null")}); } (*variables)["get_has_field_bit_from_local"] = diff --git a/src/google/protobuf/compiler/java/message_field_lite.h b/src/google/protobuf/compiler/java/message_field_lite.h index c5387a6ffe..227d2660ad 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.h +++ b/src/google/protobuf/compiler/java/message_field_lite.h @@ -83,7 +83,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; const int messageBitIndex_; ClassNameResolver* name_resolver_; Context* context_; @@ -136,7 +136,7 @@ class RepeatedImmutableMessageFieldLiteGenerator protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; Context* context_; }; diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 475a30b9f5..64195ecda6 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -44,6 +43,7 @@ #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -117,7 +117,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true, "OrBuilder"); - std::map variables = { + absl::flat_hash_map variables = { {"{", ""}, {"}", ""}, {"deprecation", @@ -173,7 +173,8 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - std::map variables = {{"{", ""}, {"}", ""}}; + absl::flat_hash_map variables = {{"{", ""}, + {"}", ""}}; variables["static"] = is_own_file ? " " : " static "; variables["classname"] = descriptor_->name(); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); @@ -242,7 +243,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { } // oneof - std::map vars = {{"{", ""}, {"}", ""}}; + absl::flat_hash_map vars = {{"{", ""}, + {"}", ""}}; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = diff --git a/src/google/protobuf/compiler/java/name_resolver.cc b/src/google/protobuf/compiler/java/name_resolver.cc index 84e74ffddc..72078bd6b8 100644 --- a/src/google/protobuf/compiler/java/name_resolver.cc +++ b/src/google/protobuf/compiler/java/name_resolver.cc @@ -30,7 +30,6 @@ #include "google/protobuf/compiler/java/name_resolver.h" -#include #include #include "google/protobuf/compiler/code_generator.h" diff --git a/src/google/protobuf/compiler/java/primitive_field.cc b/src/google/protobuf/compiler/java/primitive_field.cc index 87dbdb6a50..36754350b3 100644 --- a/src/google/protobuf/compiler/java/primitive_field.cc +++ b/src/google/protobuf/compiler/java/primitive_field.cc @@ -35,7 +35,6 @@ #include "google/protobuf/compiler/java/primitive_field.h" #include -#include #include #include "google/protobuf/stubs/logging.h" @@ -57,54 +56,55 @@ using internal::WireFormat; namespace { -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); JavaType javaType = GetJavaType(descriptor); (*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType); - (*variables)["field_type"] = (*variables)["type"]; + variables->insert({"field_type", (*variables)["type"]}); + std::string name = (*variables)["name"]; if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE || javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT || javaType == JAVATYPE_LONG) { std::string capitalized_type = UnderscoresToCamelCase( PrimitiveTypeName(javaType), /*cap_first_letter=*/true); (*variables)["field_list_type"] = - "com.google.protobuf.Internal." + capitalized_type + "List"; - (*variables)["empty_list"] = "empty" + capitalized_type + "List()"; - (*variables)["create_list"] = "new" + capitalized_type + "List()"; + absl::StrCat("com.google.protobuf.Internal.", capitalized_type, "List"); + (*variables)["empty_list"] = + absl::StrCat("empty", capitalized_type, "List()"); + (*variables)["create_list"] = + absl::StrCat("new", capitalized_type, "List()"); (*variables)["mutable_copy_list"] = - "mutableCopy(" + (*variables)["name"] + "_)"; + absl::StrCat("mutableCopy(", name, "_)"); (*variables)["name_make_immutable"] = - (*variables)["name"] + "_.makeImmutable()"; + absl::StrCat(name, "_.makeImmutable()"); (*variables)["repeated_get"] = - (*variables)["name"] + "_.get" + capitalized_type; + absl::StrCat(name, "_.get", capitalized_type); (*variables)["repeated_add"] = - (*variables)["name"] + "_.add" + capitalized_type; + absl::StrCat(name, "_.add", capitalized_type); (*variables)["repeated_set"] = - (*variables)["name"] + "_.set" + capitalized_type; + absl::StrCat(name, "_.set", capitalized_type); } else { + std::string boxed_type = (*variables)["boxed_type"]; (*variables)["field_list_type"] = - "java.util.List<" + (*variables)["boxed_type"] + ">"; + absl::StrCat("java.util.List<", boxed_type, ">"); (*variables)["create_list"] = - "new java.util.ArrayList<" + (*variables)["boxed_type"] + ">()"; - (*variables)["mutable_copy_list"] = "new java.util.ArrayList<" + - (*variables)["boxed_type"] + ">(" + - (*variables)["name"] + "_)"; + absl::StrCat("new java.util.ArrayList<", boxed_type, ">()"); + (*variables)["mutable_copy_list"] = + absl::StrCat("new java.util.ArrayList<", boxed_type, ">(", name, "_)"); (*variables)["empty_list"] = "java.util.Collections.emptyList()"; - (*variables)["name_make_immutable"] = - (*variables)["name"] + "_ = java.util.Collections.unmodifiableList(" + - (*variables)["name"] + "_)"; - (*variables)["repeated_get"] = (*variables)["name"] + "_.get"; - (*variables)["repeated_add"] = (*variables)["name"] + "_.add"; - (*variables)["repeated_set"] = (*variables)["name"] + "_.set"; + (*variables)["name_make_immutable"] = absl::StrCat( + name, "_ = java.util.Collections.unmodifiableList(", name, "_)"); + (*variables)["repeated_get"] = absl::StrCat(name, "_.get"); + (*variables)["repeated_add"] = absl::StrCat(name, "_.add"); + (*variables)["repeated_set"] = absl::StrCat(name, "_.set"); } (*variables)["default"] = @@ -134,8 +134,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", name, + " is deprecated\") ") : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { @@ -165,21 +165,20 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, switch (descriptor->type()) { case FieldDescriptor::TYPE_BYTES: (*variables)["is_field_present_message"] = - "!" + (*variables)["name"] + "_.isEmpty()"; + absl::StrCat("!", name, "_.isEmpty()"); break; case FieldDescriptor::TYPE_FLOAT: (*variables)["is_field_present_message"] = - "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] + - "_) != 0"; + absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); break; case FieldDescriptor::TYPE_DOUBLE: - (*variables)["is_field_present_message"] = - "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] + - "_) != 0"; + (*variables)["is_field_present_message"] = absl::StrCat( + "java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); break; default: - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"]; + variables->insert( + {"is_field_present_message", + absl::StrCat(name, "_ != ", (*variables)["default"])}); break; } } diff --git a/src/google/protobuf/compiler/java/primitive_field.h b/src/google/protobuf/compiler/java/primitive_field.h index d8104ba5f6..f81e28da18 100644 --- a/src/google/protobuf/compiler/java/primitive_field.h +++ b/src/google/protobuf/compiler/java/primitive_field.h @@ -92,7 +92,7 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; @@ -155,7 +155,7 @@ class RepeatedImmutablePrimitiveFieldGenerator private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.cc b/src/google/protobuf/compiler/java/primitive_field_lite.cc index e370815326..31fe87dfdf 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/primitive_field_lite.cc @@ -35,12 +35,10 @@ #include "google/protobuf/compiler/java/primitive_field_lite.h" #include -#include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" @@ -66,18 +64,17 @@ bool EnableExperimentalRuntimeForLite() { #endif // !PROTOBUF_EXPERIMENT } -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); JavaType javaType = GetJavaType(descriptor); (*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType); - (*variables)["field_type"] = (*variables)["type"]; + variables->insert({"field_type", (*variables)["type"]}); (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver, context->options()); (*variables)["capitalized_type"] = GetCapitalizedType( @@ -90,43 +87,47 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, std::string capitalized_type = UnderscoresToCamelCase( PrimitiveTypeName(javaType), true /* cap_next_letter */); + std::string name = (*variables)["name"]; switch (javaType) { case JAVATYPE_INT: case JAVATYPE_LONG: case JAVATYPE_FLOAT: case JAVATYPE_DOUBLE: case JAVATYPE_BOOLEAN: - (*variables)["field_list_type"] = - "com.google.protobuf.Internal." + capitalized_type + "List"; - (*variables)["empty_list"] = "empty" + capitalized_type + "List()"; + (*variables)["field_list_type"] = absl::StrCat( + "com.google.protobuf.Internal.", capitalized_type, "List"); + (*variables)["empty_list"] = + absl::StrCat("empty", capitalized_type, "List()"); (*variables)["make_name_unmodifiable"] = - (*variables)["name"] + "_.makeImmutable()"; + absl::StrCat(name, "_.makeImmutable()"); (*variables)["repeated_get"] = - (*variables)["name"] + "_.get" + capitalized_type; + absl::StrCat(name, "_.get", capitalized_type); (*variables)["repeated_add"] = - (*variables)["name"] + "_.add" + capitalized_type; + absl::StrCat(name, "_.add", capitalized_type); (*variables)["repeated_set"] = - (*variables)["name"] + "_.set" + capitalized_type; + absl::StrCat(name, "_.set", capitalized_type); (*variables)["visit_type"] = capitalized_type; - (*variables)["visit_type_list"] = "visit" + capitalized_type + "List"; + (*variables)["visit_type_list"] = + absl::StrCat("visit", capitalized_type, "List"); break; default: - (*variables)["field_list_type"] = - "com.google.protobuf.Internal.ProtobufList<" + - (*variables)["boxed_type"] + ">"; + variables->insert( + {"field_list_type", + absl::StrCat("com.google.protobuf.Internal.ProtobufList<", + (*variables)["boxed_type"], ">")}); (*variables)["empty_list"] = "emptyProtobufList()"; (*variables)["make_name_unmodifiable"] = - (*variables)["name"] + "_.makeImmutable()"; - (*variables)["repeated_get"] = (*variables)["name"] + "_.get"; - (*variables)["repeated_add"] = (*variables)["name"] + "_.add"; - (*variables)["repeated_set"] = (*variables)["name"] + "_.set"; + absl::StrCat(name, "_.makeImmutable()"); + (*variables)["repeated_get"] = absl::StrCat(name, "_.get"); + (*variables)["repeated_add"] = absl::StrCat(name, "_.add"); + (*variables)["repeated_set"] = absl::StrCat(name, "_.set"); (*variables)["visit_type"] = "ByteString"; (*variables)["visit_type_list"] = "visitList"; } if (javaType == JAVATYPE_BYTES) { (*variables)["bytes_default"] = - absl::AsciiStrToUpper((*variables)["name"]) + "_DEFAULT_VALUE"; + absl::AsciiStrToUpper(name) + "_DEFAULT_VALUE"; } if (IsReferenceType(javaType)) { @@ -143,8 +144,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", name, + " is deprecated\") ") : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { @@ -169,21 +170,20 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, switch (descriptor->type()) { case FieldDescriptor::TYPE_BYTES: (*variables)["is_field_present_message"] = - "!" + (*variables)["name"] + "_.isEmpty()"; + absl::StrCat("!", name, "_.isEmpty()"); break; case FieldDescriptor::TYPE_FLOAT: (*variables)["is_field_present_message"] = - "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] + - "_) != 0"; + absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); break; case FieldDescriptor::TYPE_DOUBLE: - (*variables)["is_field_present_message"] = - "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] + - "_) != 0"; + (*variables)["is_field_present_message"] = absl::StrCat( + "java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); break; default: - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"]; + variables->insert( + {"is_field_present_message", + absl::StrCat(name, "_ != " + (*variables)["default"])}); break; } } @@ -193,7 +193,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["set_has_field_bit_to_local"] = GenerateSetBitToLocal(messageBitIndex); // Annotations often use { and } variables to denote ranges. - (*variables)["{"] = (*variables)["}"] = ""; + (*variables)["{"] = ""; + (*variables)["}"] = ""; } } // namespace diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.h b/src/google/protobuf/compiler/java/primitive_field_lite.h index 410b7d608f..95b42432a9 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/primitive_field_lite.h @@ -83,7 +83,7 @@ class ImmutablePrimitiveFieldLiteGenerator protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -133,7 +133,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/service.cc b/src/google/protobuf/compiler/java/service.cc index d0c525b8c4..25fbfe30bf 100644 --- a/src/google/protobuf/compiler/java/service.cc +++ b/src/google/protobuf/compiler/java/service.cc @@ -215,7 +215,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - std::map vars; + absl::flat_hash_map vars; vars["index"] = absl::StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); @@ -262,7 +262,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod( for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - std::map vars; + absl::flat_hash_map vars; vars["index"] = absl::StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); @@ -307,7 +307,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - std::map vars; + absl::flat_hash_map vars; vars["index"] = absl::StrCat(i); vars["type"] = (which == REQUEST) @@ -362,7 +362,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { printer->Print(" {\n"); printer->Indent(); - std::map vars; + absl::flat_hash_map vars; vars["index"] = absl::StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, @@ -426,7 +426,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { printer->Print(" {\n"); printer->Indent(); - std::map vars; + absl::flat_hash_map vars; vars["index"] = absl::StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, @@ -449,7 +449,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { void ImmutableServiceGenerator::GenerateMethodSignature( io::Printer* printer, const MethodDescriptor* method, IsAbstract is_abstract) { - std::map vars; + absl::flat_hash_map vars; vars["name"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); @@ -463,7 +463,7 @@ void ImmutableServiceGenerator::GenerateMethodSignature( void ImmutableServiceGenerator::GenerateBlockingMethodSignature( io::Printer* printer, const MethodDescriptor* method) { - std::map vars; + absl::flat_hash_map vars; vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); diff --git a/src/google/protobuf/compiler/java/string_field.cc b/src/google/protobuf/compiler/java/string_field.cc index 910ee8e0ee..4992ef2bcc 100644 --- a/src/google/protobuf/compiler/java/string_field.cc +++ b/src/google/protobuf/compiler/java/string_field.cc @@ -36,13 +36,13 @@ #include "google/protobuf/compiler/java/string_field.h" #include -#include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -59,12 +59,11 @@ using internal::WireFormatLite; namespace { -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; @@ -96,11 +95,12 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["on_changed"] = "onChanged();"; if (HasHasbit(descriptor)) { @@ -122,8 +122,9 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["set_has_field_bit_builder"] = ""; (*variables)["clear_has_field_bit_builder"] = ""; - (*variables)["is_field_present_message"] = - "!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)"; + variables->insert({"is_field_present_message", + absl::StrCat("!", (*variables)["isStringEmpty"], "(", + (*variables)["name"], "_)")}); } // For repeated builders, one bit is used for whether the array is immutable. diff --git a/src/google/protobuf/compiler/java/string_field.h b/src/google/protobuf/compiler/java/string_field.h index c9b6256d5d..bbe673a1c2 100644 --- a/src/google/protobuf/compiler/java/string_field.h +++ b/src/google/protobuf/compiler/java/string_field.h @@ -91,7 +91,7 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; @@ -152,7 +152,7 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/string_field_lite.cc b/src/google/protobuf/compiler/java/string_field_lite.cc index df86df7876..9b4069a209 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.cc +++ b/src/google/protobuf/compiler/java/string_field_lite.cc @@ -36,13 +36,12 @@ #include "google/protobuf/compiler/java/string_field_lite.h" #include -#include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" @@ -59,12 +58,11 @@ using internal::WireFormatLite; namespace { -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + absl::flat_hash_map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["empty_list"] = @@ -89,11 +87,12 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? absl::StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; if (!context->options().opensource_runtime) { (*variables)["enforce_utf8"] = CheckUtf8(descriptor) ? "true" : "false"; @@ -120,8 +119,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["set_has_field_bit_message"] = ""; (*variables)["clear_has_field_bit_message"] = ""; - (*variables)["is_field_present_message"] = - "!" + (*variables)["name"] + "_.isEmpty()"; + variables->insert({"is_field_present_message", + absl::StrCat("!", (*variables)["name"], "_.isEmpty()")}); } (*variables)["get_has_field_bit_from_local"] = @@ -129,7 +128,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["set_has_field_bit_to_local"] = GenerateSetBitToLocal(messageBitIndex); // Annotations often use { and } variables to denote text ranges. - (*variables)["{"] = (*variables)["}"] = ""; + (*variables)["{"] = ""; + (*variables)["}"] = ""; } } // namespace diff --git a/src/google/protobuf/compiler/java/string_field_lite.h b/src/google/protobuf/compiler/java/string_field_lite.h index f35da288f9..fb9a05abcb 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.h +++ b/src/google/protobuf/compiler/java/string_field_lite.h @@ -84,7 +84,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { protected: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; const int messageBitIndex_; ClassNameResolver* name_resolver_; Context* context_; @@ -133,7 +133,7 @@ class RepeatedImmutableStringFieldLiteGenerator private: const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; Context* context_; }; diff --git a/src/google/protobuf/compiler/objectivec/enum.cc b/src/google/protobuf/compiler/objectivec/enum.cc index c24b0654c8..650d04d31a 100644 --- a/src/google/protobuf/compiler/objectivec/enum.cc +++ b/src/google/protobuf/compiler/objectivec/enum.cc @@ -32,7 +32,6 @@ #include #include -#include #include #include diff --git a/src/google/protobuf/compiler/objectivec/enum_field.cc b/src/google/protobuf/compiler/objectivec/enum_field.cc index cf0a3df498..061033b97d 100644 --- a/src/google/protobuf/compiler/objectivec/enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/enum_field.cc @@ -30,10 +30,10 @@ #include "google/protobuf/compiler/objectivec/enum_field.h" -#include #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" #include "google/protobuf/io/printer.h" @@ -45,22 +45,24 @@ namespace objectivec { namespace { -void SetEnumVariables(const FieldDescriptor* descriptor, - std::map* variables) { - std::string type = EnumName(descriptor->enum_type()); +void SetEnumVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables) { + const std::string type = EnumName(descriptor->enum_type()); + const std::string enum_desc_func = absl::StrCat(type, "_EnumDescriptor"); (*variables)["storage_type"] = type; // For non repeated fields, if it was defined in a different file, the // property decls need to use "enum NAME" rather than just "NAME" to support // the forward declaration of the enums. if (!descriptor->is_repeated() && (descriptor->file() != descriptor->enum_type()->file())) { - (*variables)["property_type"] = "enum " + type; + (*variables)["property_type"] = absl::StrCat("enum ", type); } - (*variables)["enum_verifier"] = type + "_IsValidValue"; - (*variables)["enum_desc_func"] = type + "_EnumDescriptor"; + (*variables)["enum_verifier"] = absl::StrCat(type, "_IsValidValue"); + (*variables)["enum_desc_func"] = enum_desc_func; (*variables)["dataTypeSpecific_name"] = "enumDescFunc"; - (*variables)["dataTypeSpecific_value"] = (*variables)["enum_desc_func"]; + (*variables)["dataTypeSpecific_value"] = enum_desc_func; const Descriptor* msg_descriptor = descriptor->containing_type(); (*variables)["owning_message_class"] = ClassName(msg_descriptor); diff --git a/src/google/protobuf/compiler/objectivec/extension.cc b/src/google/protobuf/compiler/objectivec/extension.cc index 91f008ec61..d8c179b763 100644 --- a/src/google/protobuf/compiler/objectivec/extension.cc +++ b/src/google/protobuf/compiler/objectivec/extension.cc @@ -31,12 +31,12 @@ #include "google/protobuf/compiler/objectivec/extension.h" #include -#include #include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" @@ -64,7 +64,7 @@ ExtensionGenerator::ExtensionGenerator(const std::string& root_class_name, } void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { - std::map vars; + absl::flat_hash_map vars; vars["method_name"] = method_name_; if (IsRetainedName(method_name_)) { vars["storage_attribute"] = " NS_RETURNS_NOT_RETAINED"; @@ -91,7 +91,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { void ExtensionGenerator::GenerateStaticVariablesInitialization( io::Printer* printer) { - std::map vars; + absl::flat_hash_map vars; 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); diff --git a/src/google/protobuf/compiler/objectivec/field.cc b/src/google/protobuf/compiler/objectivec/field.cc index 6274b9d05e..63d71b3cc6 100644 --- a/src/google/protobuf/compiler/objectivec/field.cc +++ b/src/google/protobuf/compiler/objectivec/field.cc @@ -31,12 +31,12 @@ #include "google/protobuf/compiler/objectivec/field.h" #include -#include #include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/enum_field.h" #include "google/protobuf/compiler/objectivec/helpers.h" @@ -53,8 +53,9 @@ namespace objectivec { namespace { -void SetCommonFieldVariables(const FieldDescriptor* descriptor, - std::map* variables) { +void SetCommonFieldVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables) { std::string camel_case_name = FieldName(descriptor); std::string raw_field_name; if (descriptor->type() == FieldDescriptor::TYPE_GROUP) { diff --git a/src/google/protobuf/compiler/objectivec/field.h b/src/google/protobuf/compiler/objectivec/field.h index 07643720ec..f52e7c87f7 100644 --- a/src/google/protobuf/compiler/objectivec/field.h +++ b/src/google/protobuf/compiler/objectivec/field.h @@ -31,12 +31,12 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__ -#include #include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/match.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -104,7 +104,7 @@ class FieldGenerator { bool WantsHasProperty() const; const FieldDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; }; class SingleFieldGenerator : public FieldGenerator { diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index fd7b644579..be711d57b5 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -33,13 +33,13 @@ #include #include #include -#include #include #include #include #include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/enum.h" @@ -626,7 +626,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { // File descriptor only needed if there are messages to use it. if (!message_generators_.empty()) { - std::map vars; + absl::flat_hash_map vars; vars["root_class_name"] = root_class_name_; vars["package"] = file_->package(); vars["objc_prefix"] = FileClassPrefix(file_); diff --git a/src/google/protobuf/compiler/objectivec/import_writer.cc b/src/google/protobuf/compiler/objectivec/import_writer.cc index b276ea5634..ff154a21ec 100644 --- a/src/google/protobuf/compiler/objectivec/import_writer.cc +++ b/src/google/protobuf/compiler/objectivec/import_writer.cc @@ -31,11 +31,11 @@ #include "google/protobuf/compiler/objectivec/import_writer.h" #include -#include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "google/protobuf/compiler/objectivec/line_consumer.h" @@ -55,22 +55,22 @@ namespace { class ProtoFrameworkCollector : public LineConsumer { public: explicit ProtoFrameworkCollector( - std::map* inout_proto_file_to_framework_name) + absl::flat_hash_map* + inout_proto_file_to_framework_name) : map_(inout_proto_file_to_framework_name) {} bool ConsumeLine(absl::string_view line, std::string* out_error) override; private: - std::map* map_; + absl::flat_hash_map* map_; }; bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line, std::string* out_error) { int offset = line.find(':'); if (offset == absl::string_view::npos) { - *out_error = - std::string("Framework/proto file mapping line without colon sign: '") + - std::string(line) + "'."; + *out_error = absl::StrCat( + "Framework/proto file mapping line without colon sign: '", line, "'."); return false; } absl::string_view framework_name = @@ -88,13 +88,11 @@ bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line, absl::string_view proto_file = absl::StripAsciiWhitespace( proto_file_list.substr(start, offset - start)); if (!proto_file.empty()) { - std::map::iterator existing_entry = - map_->find(std::string(proto_file)); + auto existing_entry = map_->find(proto_file); if (existing_entry != map_->end()) { std::cerr << "warning: duplicate proto file reference, replacing " "framework entry for '" - << std::string(proto_file) << "' with '" - << std::string(framework_name) << "' (was '" + << proto_file << "' with '" << framework_name << "' (was '" << existing_entry->second << "')." << std::endl; std::cerr.flush(); } @@ -102,11 +100,11 @@ bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line, if (absl::StrContains(proto_file, ' ')) { std::cerr << "note: framework mapping file had a proto file with a " "space in, hopefully that isn't a missing comma: '" - << std::string(proto_file) << "'" << std::endl; + << proto_file << "'" << std::endl; std::cerr.flush(); } - (*map_)[std::string(proto_file)] = std::string(framework_name); + (*map_)[proto_file] = std::string(framework_name); } start = offset + 1; @@ -147,8 +145,7 @@ void ImportWriter::AddFile(const FileDescriptor* file, ParseFrameworkMappings(); } - std::map::iterator proto_lookup = - proto_file_to_framework_name_.find(file->name()); + auto proto_lookup = proto_file_to_framework_name_.find(file->name()); if (proto_lookup != proto_file_to_framework_name_.end()) { other_framework_imports_.push_back( proto_lookup->second + "/" + FilePathBasename(file) + header_extension); diff --git a/src/google/protobuf/compiler/objectivec/import_writer.h b/src/google/protobuf/compiler/objectivec/import_writer.h index f3fb63b4b7..d36fe34cb2 100644 --- a/src/google/protobuf/compiler/objectivec/import_writer.h +++ b/src/google/protobuf/compiler/objectivec/import_writer.h @@ -35,6 +35,7 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" @@ -68,7 +69,7 @@ class ImportWriter { const std::string named_framework_to_proto_path_mappings_path_; const std::string runtime_import_prefix_; const bool include_wkt_imports_; - std::map proto_file_to_framework_name_; + absl::flat_hash_map proto_file_to_framework_name_; bool need_to_parse_mapping_file_; std::vector protobuf_imports_; diff --git a/src/google/protobuf/compiler/objectivec/map_field.cc b/src/google/protobuf/compiler/objectivec/map_field.cc index 4eff6f3cc4..c5ca768cfc 100644 --- a/src/google/protobuf/compiler/objectivec/map_field.cc +++ b/src/google/protobuf/compiler/objectivec/map_field.cc @@ -30,7 +30,6 @@ #include "google/protobuf/compiler/objectivec/map_field.h" -#include #include #include #include diff --git a/src/google/protobuf/compiler/objectivec/message.cc b/src/google/protobuf/compiler/objectivec/message.cc index 49375713ee..91fd9ed0f2 100644 --- a/src/google/protobuf/compiler/objectivec/message.cc +++ b/src/google/protobuf/compiler/objectivec/message.cc @@ -32,13 +32,13 @@ #include #include -#include #include #include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/enum.h" @@ -517,13 +517,13 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { printer->Outdent(); } - std::map vars; + absl::flat_hash_map vars; vars["classname"] = class_name_; vars["rootclassname"] = root_classname_; vars["fields"] = has_fields ? "fields" : "NULL"; if (has_fields) { - vars["fields_count"] = - "(uint32_t)(sizeof(fields) / sizeof(" + field_description_type + "))"; + vars["fields_count"] = absl::StrCat("(uint32_t)(sizeof(fields) / sizeof(", + field_description_type, "))"); } else { vars["fields_count"] = "0"; } diff --git a/src/google/protobuf/compiler/objectivec/message_field.cc b/src/google/protobuf/compiler/objectivec/message_field.cc index 1f174f6ea4..ddf1f19716 100644 --- a/src/google/protobuf/compiler/objectivec/message_field.cc +++ b/src/google/protobuf/compiler/objectivec/message_field.cc @@ -30,10 +30,10 @@ #include "google/protobuf/compiler/objectivec/message_field.h" -#include #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" @@ -44,8 +44,9 @@ namespace objectivec { namespace { -void SetMessageVariables(const FieldDescriptor* descriptor, - std::map* variables) { +void SetMessageVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables) { const std::string& message_type = ClassName(descriptor->message_type()); const std::string& containing_class = ClassName(descriptor->containing_type()); diff --git a/src/google/protobuf/compiler/objectivec/names.cc b/src/google/protobuf/compiler/objectivec/names.cc index a82f8b2818..2e1c45c4d0 100644 --- a/src/google/protobuf/compiler/objectivec/names.cc +++ b/src/google/protobuf/compiler/objectivec/names.cc @@ -34,13 +34,13 @@ #include #include #include -#include #include #include #include #include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" @@ -83,16 +83,16 @@ class SimpleLineCollector : public LineConsumer { class PackageToPrefixesCollector : public LineConsumer { public: - PackageToPrefixesCollector( - const std::string& usage, - std::map* inout_package_to_prefix_map) + PackageToPrefixesCollector(const std::string& usage, + absl::flat_hash_map* + inout_package_to_prefix_map) : usage_(usage), prefix_map_(inout_package_to_prefix_map) {} bool ConsumeLine(absl::string_view line, std::string* out_error) override; private: const std::string usage_; - std::map* prefix_map_; + absl::flat_hash_map* prefix_map_; }; class PrefixModeStorage { @@ -129,7 +129,7 @@ class PrefixModeStorage { private: bool use_package_name_; - std::map package_to_prefix_map_; + absl::flat_hash_map package_to_prefix_map_; std::string package_to_prefix_mappings_path_; std::string exception_path_; std::string forced_prefix_; @@ -154,6 +154,8 @@ PrefixModeStorage::PrefixModeStorage() { } } +constexpr absl::string_view kNoPackagePrefix = "no_package:"; + std::string PrefixModeStorage::prefix_from_proto_package_mappings( const FileDescriptor* file) { if (!file) { @@ -170,9 +172,9 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings( if (!ParseSimpleFile(package_to_prefix_mappings_path_, &collector, &error_str)) { if (error_str.empty()) { - error_str = std::string("protoc:0: warning: Failed to parse") + - std::string(" prefix to proto package mappings file: ") + - package_to_prefix_mappings_path_; + error_str = absl::StrCat("protoc:0: warning: Failed to parse ", + "prefix to proto package mappings file: ", + package_to_prefix_mappings_path_); } std::cerr << error_str << std::endl; std::cerr.flush(); @@ -183,12 +185,10 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings( const std::string package = file->package(); // For files without packages, the can be registered as "no_package:PATH", // allowing the expected prefixes file. - const std::string no_package_prefix("no_package:"); const std::string lookup_key = - package.empty() ? no_package_prefix + file->name() : package; + package.empty() ? absl::StrCat(kNoPackagePrefix, file->name()) : package; - std::map::const_iterator prefix_lookup = - package_to_prefix_map_.find(lookup_key); + auto prefix_lookup = package_to_prefix_map_.find(lookup_key); if (prefix_lookup != package_to_prefix_map_.end()) { return prefix_lookup->second; @@ -1021,9 +1021,10 @@ bool PackageToPrefixesCollector::ConsumeLine(absl::string_view line, return true; } -bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path, - std::map* prefix_map, - std::string* out_error) { +bool LoadExpectedPackagePrefixes( + const std::string& expected_prefixes_path, + absl::flat_hash_map* prefix_map, + std::string* out_error) { if (expected_prefixes_path.empty()) { return true; } @@ -1034,7 +1035,8 @@ bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path, bool ValidateObjCClassPrefix( const FileDescriptor* file, const std::string& expected_prefixes_path, - const std::map& expected_package_prefixes, + const absl::flat_hash_map& + expected_package_prefixes, bool prefixes_must_be_registered, bool require_prefixes, std::string* out_error) { // Reminder: An explicit prefix option of "" is valid in case the default @@ -1048,17 +1050,15 @@ bool ValidateObjCClassPrefix( const std::string package = file->package(); // For files without packages, the can be registered as "no_package:PATH", // allowing the expected prefixes file. - const std::string no_package_prefix("no_package:"); const std::string lookup_key = - package.empty() ? no_package_prefix + file->name() : package; + package.empty() ? absl::StrCat(kNoPackagePrefix, file->name()) : package; // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for warnings. // Check: Error - See if there was an expected prefix for the package and // report if it doesn't match (wrong or missing). - std::map::const_iterator package_match = - expected_package_prefixes.find(lookup_key); + auto package_match = expected_package_prefixes.find(lookup_key); if (package_match != expected_package_prefixes.end()) { // There was an entry, and... if (has_prefix && package_match->second == prefix) { @@ -1095,14 +1095,13 @@ bool ValidateObjCClassPrefix( if (!prefix.empty() && have_expected_prefix_file) { // For a non empty prefix, look for any other package that uses the prefix. std::string other_package_for_prefix; - for (std::map::const_iterator i = - expected_package_prefixes.begin(); + for (auto i = expected_package_prefixes.begin(); i != expected_package_prefixes.end(); ++i) { if (i->second == prefix) { other_package_for_prefix = i->first; // Stop on the first real package listing, if it was a no_package file // specific entry, keep looking to try and find a package one. - if (!absl::StartsWith(other_package_for_prefix, no_package_prefix)) { + if (!absl::StartsWith(other_package_for_prefix, kNoPackagePrefix)) { break; } } @@ -1115,10 +1114,10 @@ bool ValidateObjCClassPrefix( *out_error = "error: Found 'option objc_class_prefix = \"" + prefix + "\";' in '" + file->name() + "'; that prefix is already used for "; - if (absl::StartsWith(other_package_for_prefix, no_package_prefix)) { + if (absl::StartsWith(other_package_for_prefix, kNoPackagePrefix)) { absl::StrAppend( out_error, "file '", - absl::StripPrefix(other_package_for_prefix, no_package_prefix), + absl::StripPrefix(other_package_for_prefix, kNoPackagePrefix), "'."); } else { absl::StrAppend(out_error, "'package ", @@ -1213,7 +1212,7 @@ bool ValidateObjCClassPrefixes(const std::vector& files, } // Load the expected package prefixes, if available, to validate against. - std::map expected_package_prefixes; + absl::flat_hash_map expected_package_prefixes; if (!LoadExpectedPackagePrefixes(validation_options.expected_prefixes_path, &expected_package_prefixes, out_error)) { return false; diff --git a/src/google/protobuf/compiler/objectivec/oneof.cc b/src/google/protobuf/compiler/objectivec/oneof.cc index 94fee5351f..4dfaf98171 100644 --- a/src/google/protobuf/compiler/objectivec/oneof.cc +++ b/src/google/protobuf/compiler/objectivec/oneof.cc @@ -30,7 +30,6 @@ #include "google/protobuf/compiler/objectivec/oneof.h" -#include #include #include "absl/strings/str_cat.h" diff --git a/src/google/protobuf/compiler/objectivec/oneof.h b/src/google/protobuf/compiler/objectivec/oneof.h index ea79251613..27a1ecbc07 100644 --- a/src/google/protobuf/compiler/objectivec/oneof.h +++ b/src/google/protobuf/compiler/objectivec/oneof.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ -#include #include #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -67,7 +67,7 @@ class OneofGenerator { private: const OneofDescriptor* descriptor_; - std::map variables_; + absl::flat_hash_map variables_; }; } // namespace objectivec diff --git a/src/google/protobuf/compiler/objectivec/primitive_field.cc b/src/google/protobuf/compiler/objectivec/primitive_field.cc index d116ec0462..fa89d2cfa2 100644 --- a/src/google/protobuf/compiler/objectivec/primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/primitive_field.cc @@ -30,9 +30,9 @@ #include "google/protobuf/compiler/objectivec/primitive_field.h" -#include #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/io/printer.h" @@ -111,8 +111,9 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) { return nullptr; } -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - std::map* variables) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, + absl::flat_hash_map* variables) { std::string primitive_name = PrimitiveTypeName(descriptor); (*variables)["type"] = primitive_name; (*variables)["storage_type"] = primitive_name; diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index 0f51a7d2a3..f8a33cc6b4 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -46,7 +46,6 @@ #include #include -#include #include #include #include @@ -54,11 +53,13 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_replace.h" +#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/python/helpers.h" @@ -433,7 +434,7 @@ void Generator::PrintImports() const { // Prints the single file descriptor for this file. void Generator::PrintFileDescriptor() const { - std::map m; + absl::flat_hash_map m; m["descriptor_name"] = kDescriptorKey; m["name"] = file_->name(); m["package"] = file_->package(); @@ -508,7 +509,7 @@ void Generator::PrintAllNestedEnumsInFile() const { // enum name to a Python EnumDescriptor object equivalent to // enum_descriptor. void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { - std::map m; + absl::flat_hash_map m; std::string module_level_descriptor_name = ModuleLevelDescriptorName(enum_descriptor); m["descriptor_name"] = module_level_descriptor_name; @@ -583,7 +584,7 @@ void Generator::PrintServices() const { void Generator::PrintServiceDescriptor( const ServiceDescriptor& descriptor) const { - std::map m; + absl::flat_hash_map m; m["service_name"] = ModuleLevelServiceDescriptorName(descriptor); m["name"] = descriptor.name(); m["file"] = kDescriptorKey; @@ -633,7 +634,7 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { // // Mutually recursive with PrintNestedDescriptors(). void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { - std::map m; + absl::flat_hash_map m; m["name"] = message_descriptor.name(); m["full_name"] = message_descriptor.full_name(); m["file"] = kDescriptorKey; @@ -784,7 +785,7 @@ void Generator::PrintMessage(const Descriptor& message_descriptor, to_register->push_back(qualified_name); PrintNestedMessages(message_descriptor, qualified_name, to_register); - std::map m; + absl::flat_hash_map m; m["descriptor_key"] = kDescriptorKey; m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor); printer_->Print(m, "'$descriptor_key$' : $descriptor_name$,\n"); @@ -839,7 +840,7 @@ void Generator::FixForeignFieldsInDescriptor( FixContainingTypeInDescriptor(enum_descriptor, &descriptor); } for (int i = 0; i < descriptor.oneof_decl_count(); ++i) { - std::map m; + absl::flat_hash_map m; const OneofDescriptor* oneof = descriptor.oneof_decl(i); m["descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["oneof_name"] = oneof->name(); @@ -858,7 +859,7 @@ void Generator::FixForeignFieldsInDescriptor( } void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { - std::map m; + absl::flat_hash_map m; m["descriptor_name"] = kDescriptorKey; m["message_name"] = descriptor.name(); m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor); @@ -870,7 +871,7 @@ void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { void Generator::AddServiceToFileDescriptor( const ServiceDescriptor& descriptor) const { - std::map m; + absl::flat_hash_map m; m["descriptor_name"] = kDescriptorKey; m["service_name"] = descriptor.name(); m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor); @@ -882,7 +883,7 @@ void Generator::AddServiceToFileDescriptor( void Generator::AddEnumToFileDescriptor( const EnumDescriptor& descriptor) const { - std::map m; + absl::flat_hash_map m; m["descriptor_name"] = kDescriptorKey; m["enum_name"] = descriptor.name(); m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor); @@ -894,7 +895,7 @@ void Generator::AddEnumToFileDescriptor( void Generator::AddExtensionToFileDescriptor( const FieldDescriptor& descriptor) const { - std::map m; + absl::flat_hash_map m; m["descriptor_name"] = kDescriptorKey; m["field_name"] = descriptor.name(); m["resolved_name"] = ResolveKeyword(descriptor.name()); @@ -918,7 +919,7 @@ void Generator::FixForeignFieldsInField( const std::string& python_dict_name) const { const std::string field_referencing_expression = FieldReferencingExpression(containing_type, field, python_dict_name); - std::map m; + absl::flat_hash_map m; m["field_ref"] = field_referencing_expression; const Descriptor* foreign_message_type = field.message_type(); if (foreign_message_type) { @@ -1014,7 +1015,7 @@ void Generator::FixForeignFieldsInExtension( const FieldDescriptor& extension_field) const { GOOGLE_CHECK(extension_field.is_extension()); - std::map m; + absl::flat_hash_map m; // Confusingly, for FieldDescriptors that happen to be extensions, // containing_type() means "extended type." // On the other hand, extension_scope() will give us what we normally @@ -1046,7 +1047,7 @@ void Generator::PrintEnumValueDescriptor( // More circular references. ::sigh:: std::string options_string; descriptor.options().SerializeToString(&options_string); - std::map m; + absl::flat_hash_map m; m["name"] = descriptor.name(); m["index"] = absl::StrCat(descriptor.index()); m["number"] = absl::StrCat(descriptor.number()); @@ -1074,7 +1075,7 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field, bool is_extension) const { std::string options_string; field.options().SerializeToString(&options_string); - std::map m; + absl::flat_hash_map m; m["name"] = field.name(); m["full_name"] = field.full_name(); m["index"] = absl::StrCat(field.index()); diff --git a/src/google/protobuf/compiler/python/pyi_generator.cc b/src/google/protobuf/compiler/python/pyi_generator.cc index b09ceb2f69..bc90a6436c 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.cc +++ b/src/google/protobuf/compiler/python/pyi_generator.cc @@ -154,17 +154,19 @@ void PyiGenerator::PrintImportForDescriptor( const FileDescriptor& desc, std::set* seen_aliases) const { const std::string& filename = desc.name(); - std::string module_name = StrippedModuleName(filename); + std::string module_name_owned = StrippedModuleName(filename); + absl::string_view module_name(module_name_owned); size_t last_dot_pos = module_name.rfind('.'); std::string import_statement; if (last_dot_pos == std::string::npos) { - import_statement = "import " + module_name; + import_statement = absl::StrCat("import ", module_name); } else { - import_statement = "from " + module_name.substr(0, last_dot_pos) + - " import " + module_name.substr(last_dot_pos + 1); + import_statement = + absl::StrCat("from ", module_name.substr(0, last_dot_pos), " import ", + module_name.substr(last_dot_pos + 1)); module_name = module_name.substr(last_dot_pos + 1); } - std::string alias = "_" + module_name; + std::string alias = absl::StrCat("_", module_name); // Generate a unique alias by adding _1 suffixes until we get an unused alias. while (seen_aliases->find(alias) != seen_aliases->end()) { alias = alias + "_1"; diff --git a/src/google/protobuf/compiler/python/pyi_generator.h b/src/google/protobuf/compiler/python/pyi_generator.h index 7f1e5d839d..bd7e71f90f 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.h +++ b/src/google/protobuf/compiler/python/pyi_generator.h @@ -35,10 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ -#include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/synchronization/mutex.h" #include "google/protobuf/compiler/code_generator.h" @@ -106,7 +106,7 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera mutable io::Printer* printer_; // Set in Generate(). Under mutex_. // import_map will be a mapping from filename to module alias, e.g. // "google3/foo/bar.py" -> "_bar" - mutable std::map import_map_; + mutable absl::flat_hash_map import_map_; }; } // namespace python diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index acedbd46e1..289f5bfdba 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -469,7 +469,7 @@ void Printer::PrintImpl(absl::string_view format, LookupResult sub; absl::optional same_name_record; - if (opts.allow_digit_substitions && absl::ascii_isdigit(var[0])) { + if (opts.allow_digit_substitutions && absl::ascii_isdigit(var[0])) { PrintRaw(next_chunk); if (!Validate(var.size() == 1u, opts, "expected single-digit variable")) { diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index 450e90ffc8..764e335f1f 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -479,6 +479,27 @@ class PROTOBUF_EXPORT Printer { } }; + // Provide a helper to use heterogeneous lookup when it's available. + template + using void_t = void; + template + struct has_heterogeneous_lookup : std::false_type {}; + template + struct has_heterogeneous_lookup().find( + std::declval()))>> + : std::true_type {}; + + template ::value, int> = 0> + static absl::string_view ToStringKey(absl::string_view x) { + return x; + } + template ::value, int> = 0> + static std::string ToStringKey(absl::string_view x) { + return std::string(x); + } + public: static constexpr char kDefaultVariableDelimiter = '$'; static constexpr absl::string_view kProtocCodegenTrace = @@ -538,7 +559,7 @@ class PROTOBUF_EXPORT Printer { template auto WithVars(const Map* vars) { var_lookups_.emplace_back([vars](absl::string_view var) -> LookupResult { - auto it = vars->find(std::string(var)); + auto it = vars->find(ToStringKey(var)); if (it == vars->end()) { return absl::nullopt; } @@ -558,7 +579,7 @@ class PROTOBUF_EXPORT Printer { auto WithVars(Map&& vars) { var_lookups_.emplace_back([vars = std::forward(vars)]( absl::string_view var) -> LookupResult { - auto it = vars.find(std::string(var)); + auto it = vars.find(ToStringKey(var)); if (it == vars.end()) { return absl::nullopt; } @@ -585,7 +606,7 @@ class PROTOBUF_EXPORT Printer { auto WithAnnotations(const Map* vars) { annotation_lookups_.emplace_back( [vars](absl::string_view var) -> absl::optional { - auto it = vars->find(std::string(var)); + auto it = vars->find(ToStringKey(var)); if (it == vars->end()) { return absl::nullopt; } @@ -605,7 +626,7 @@ class PROTOBUF_EXPORT Printer { annotation_lookups_.emplace_back( [vars = std::forward(vars)]( absl::string_view var) -> absl::optional { - auto it = vars.find(std::string(var)); + auto it = vars.find(ToStringKey(var)); if (it == vars.end()) { return absl::nullopt; } @@ -665,7 +686,7 @@ class PROTOBUF_EXPORT Printer { PrintOptions opts; opts.checks_are_debug_only = true; opts.use_substitution_map = true; - opts.allow_digit_substitions = false; + opts.allow_digit_substitutions = false; auto pop = WithVars(&vars); PrintImpl(text, {}, opts); @@ -678,10 +699,10 @@ class PROTOBUF_EXPORT Printer { // Include an extra arg, since a zero-length array is ill-formed, and // MSVC complains. absl::string_view vars[] = {args..., ""}; - absl::flat_hash_map map; + absl::flat_hash_map map; map.reserve(sizeof...(args) / 2); for (size_t i = 0; i < sizeof...(args); i += 2) { - map.emplace(std::string(vars[i]), std::string(vars[i + 1])); + map.emplace(vars[i], vars[i + 1]); } Print(map, text); @@ -737,8 +758,8 @@ class PROTOBUF_EXPORT Printer { // FormatInternal is a helper function not meant to use directly, use // compiler::cpp::Formatter instead. - void FormatInternal(absl::Span args, - const std::map& vars, + template > + void FormatInternal(absl::Span args, const Map& vars, absl::string_view format) { PrintOptions opts; opts.use_curly_brace_substitutions = true; @@ -764,7 +785,7 @@ class PROTOBUF_EXPORT Printer { bool use_curly_brace_substitutions = false; // If set, the $n$ forms will be substituted, pulling from the `args` // argument to PrintImpl(). - bool allow_digit_substitions = true; + bool allow_digit_substitutions = true; // If set, when a variable substitution with spaces in it, such as $ var$, // is encountered, the spaces are stripped, so that it is as if it was // $var$. If $var$ substitutes to a non-empty string, the removed spaces are From f29dbf01a3210f4e378fcc21696ceb6d80b07f52 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 26 Oct 2022 20:12:46 -0700 Subject: [PATCH 29/29] Fixing merge issues from sync --- src/google/protobuf/compiler/csharp/csharp_map_field.cc | 2 +- src/google/protobuf/json/internal/lexer_test.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index efe87f2a6a..50d8b1d828 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -88,7 +88,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { printer->Print( variables_, - "$name$_.Add(other.$name$_);\n"); + "$name$_.MergeFrom(other.$name$_);\n"); } void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { diff --git a/src/google/protobuf/json/internal/lexer_test.cc b/src/google/protobuf/json/internal/lexer_test.cc index 92a6f3aa2d..6213172f4d 100644 --- a/src/google/protobuf/json/internal/lexer_test.cc +++ b/src/google/protobuf/json/internal/lexer_test.cc @@ -160,6 +160,7 @@ struct Value { return Value{std::move(obj)}; } } + return absl::InternalError("Unrecognized kind in lexer"); } friend std::ostream& operator<<(std::ostream& os, const Value& v) {