From 34ba95bb71946936e087986f5fe7eea7d96c7016 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Fri, 26 Aug 2022 16:36:36 -0400 Subject: [PATCH 01/39] json_name and default pseudo-options have source code info consistent with options --- src/google/protobuf/compiler/parser.cc | 40 +++++++++++++++---- src/google/protobuf/compiler/parser.h | 4 ++ .../protobuf/compiler/parser_unittest.cc | 7 ++-- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index f220fad8be..2ab823981e 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -408,6 +408,11 @@ Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent) { Init(parent, parent.source_code_info_); } +Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent, + SourceCodeInfo* source_code_info) { + Init(parent, source_code_info); +} + Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent, int path1, SourceCodeInfo* source_code_info) { @@ -1237,13 +1242,22 @@ bool Parser::ParseDefaultAssignment( field->clear_default_value(); } + LocationRecorder location(field_location, + FieldDescriptorProto::kDefaultValueFieldNumber); + DO(Consume("default")); DO(Consume("=")); - LocationRecorder location(field_location, - FieldDescriptorProto::kDefaultValueFieldNumber); - location.RecordLegacyLocation(field, - DescriptorPool::ErrorCollector::DEFAULT_VALUE); + // We don't need to create separate spans in source code info for name and value, + // since there's no way to represent them distinctly in a location path. But we will + // want a separate recorder for the value, just to have more precise location info + // in error messages. So we let it create a location in no_op, so it doesn't add a + // span to the file descriptor. + SourceCodeInfo no_op; + LocationRecorder value_location(location, &no_op); + value_location.RecordLegacyLocation( + field, DescriptorPool::ErrorCollector::DEFAULT_VALUE); + std::string* default_value = field->mutable_default_value(); if (!field->has_type()) { @@ -1377,13 +1391,23 @@ bool Parser::ParseJsonName(FieldDescriptorProto* field, LocationRecorder location(field_location, FieldDescriptorProto::kJsonNameFieldNumber); - location.RecordLegacyLocation(field, - DescriptorPool::ErrorCollector::OPTION_NAME); - DO(Consume("json_name")); + // We don't need to create separate spans in source code info for name and value, + // since there's no way to represent them distinctly in a location path. But we will + // want a separate recorder for them, just to have more precise location info + // in error messages. So we let them create a location in no_op, so they don't + // add a span to the file descriptor. + SourceCodeInfo no_op; + { + LocationRecorder name_location(location, &no_op); + name_location.RecordLegacyLocation( + field, DescriptorPool::ErrorCollector::OPTION_NAME); + + DO(Consume("json_name")); + } DO(Consume("=")); - LocationRecorder value_location(location); + LocationRecorder value_location(location, &no_op); value_location.RecordLegacyLocation( field, DescriptorPool::ErrorCollector::OPTION_VALUE); diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index d4eb76302c..8b05d0e4ad 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -237,6 +237,10 @@ class PROTOBUF_EXPORT Parser { LocationRecorder(const LocationRecorder& parent, int path1, int path2); // Creates a recorder that generates locations into given source code info. + LocationRecorder(const LocationRecorder& parent, + SourceCodeInfo* source_code_info); + // Creates a recorder that generates locations into given source code info + // and calls AddPath() one time. LocationRecorder(const LocationRecorder& parent, int path1, SourceCodeInfo* source_code_info); diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 55ed7acb6f..a164d7d54a 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -3415,18 +3415,19 @@ TEST_F(SourceInfoTest, FieldOptions) { EXPECT_TRUE( Parse("message Foo {" " optional int32 bar = 1 " - "$a$[default=$b$123$c$,$d$opt1=123$e$," - "$f$opt2='hi'$g$]$h$;" + "$a$[$b$default=123$c$, $d$opt1=123$e$, " + "$f$opt2='hi'$g$, $h$json_name='barBar'$i$]$j$;" "}\n")); const FieldDescriptorProto& field = file_.message_type(0).field(0); const UninterpretedOption& option1 = field.options().uninterpreted_option(0); const UninterpretedOption& option2 = field.options().uninterpreted_option(1); - EXPECT_TRUE(HasSpan('a', 'h', field.options())); + EXPECT_TRUE(HasSpan('a', 'j', field.options())); EXPECT_TRUE(HasSpan('b', 'c', field, "default_value")); EXPECT_TRUE(HasSpan('d', 'e', option1)); EXPECT_TRUE(HasSpan('f', 'g', option2)); + EXPECT_TRUE(HasSpan('h', 'i', field, "json_name")); // Ignore these. EXPECT_TRUE(HasSpan(file_)); From 40847c7ee5848f41c505a1ece1f27ec4a687837b Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Tue, 30 Aug 2022 09:39:21 -0400 Subject: [PATCH 02/39] Fix Kokoro tests to work on Monterey machines (#10473) * Disabling broken mac php tests * Fix ruby permissions after Monterey upgrade * Install m4 via Homebrew * Adding ruby/python fixes to presubmits * Adding homebrew prefix command * More fixes for objc, python, and benchmark build * Properly disabling C++ benchmark warning * Use python 2 for testing * Splitting venv and python 2 * Setup tox-pyenv * Silencing more warnings * Cleanup * Upgrade python tests to 3.7 on mac * Switch to python 2 by default (googletest requires it) * Remove venv for python tests, use python 3.7 * Disable all compiler warnings for benchmark builds * Enable benchmark LTO to silence warnings * Fix locale issues in cocoapods * Remove benchmark build from C++ tests * Removing deprecated use_bazel command Removing python 3.6 mac build, since Monterey doesn't support it --- benchmarks/Makefile.am | 4 +-- kokoro/macos/prepare_build_macos_rc | 35 +++++++++++-------- kokoro/macos/ruby31/build.sh | 3 ++ .../release/python/macos/build_artifacts.sh | 1 - kokoro/release/ruby/macos/build_artifacts.sh | 3 -- kokoro/release/ruby/macos/ruby/ruby_build.sh | 1 - .../ruby/macos/ruby/ruby_build_environment.sh | 4 +++ tests.sh | 11 ------ 8 files changed, 29 insertions(+), 33 deletions(-) diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am index 3ab35e37ca..ed5797880d 100644 --- a/benchmarks/Makefile.am +++ b/benchmarks/Makefile.am @@ -91,8 +91,8 @@ $(benchmarks_protoc_outputs_proto2_header): protoc_middleman2 initialize_submodule: oldpwd=`pwd` - cd $(top_srcdir) && git submodule update --init -r third_party/benchmark && \ - cd third_party/benchmark && cmake -DCMAKE_BUILD_TYPE=Release && make + cd $(top_srcdir) && git submodule update --init -r third_party/benchmark && cd third_party/benchmark \ + && cmake -DCMAKE_BUILD_TYPE=Release && make cd $$oldpwd touch initialize_submodule diff --git a/kokoro/macos/prepare_build_macos_rc b/kokoro/macos/prepare_build_macos_rc index 8e0a87edbb..75b50c09f9 100755 --- a/kokoro/macos/prepare_build_macos_rc +++ b/kokoro/macos/prepare_build_macos_rc @@ -4,14 +4,15 @@ set -eux +export HOMEBREW_PREFIX=$(brew --prefix) + ## # Select Xcode version -# Remember to update the Xcode version when Xcode_11.3.app is not available. -# If xcode is not available, it will probably encounter the failure for -# "autom4te: need GNU m4 1.4 or later: /usr/bin/m4" -# go/kokoro/userdocs/macos/selecting_xcode.md for more information. -export DEVELOPER_DIR=/Applications/Xcode_11.3.app/Contents/Developer +## +# Select Xcode version +export DEVELOPER_DIR=/Applications/Xcode_13.3.1.app/Contents/Developer +sudo xcode-select -s "${DEVELOPER_DIR}" ## # Select C/C++ compilers @@ -19,22 +20,26 @@ export DEVELOPER_DIR=/Applications/Xcode_11.3.app/Contents/Developer export CC=gcc export CXX=g++ +## +# Install Python 2 by default + +eval "$(pyenv init -)" +pyenv install -v -s 2.7.18 && pyenv global 2.7.18 + ## # Install Tox if [[ "${KOKORO_INSTALL_TOX:-}" == "yes" ]] ; then - sudo python3 -m pip install --upgrade pip tox + pyenv install -v -s 3.7.13 + pyenv global 3.7.13 + sudo python -m pip install --upgrade pip tox tox-pyenv fi ## -# Install RVM - +# Setup RVM if [[ "${KOKORO_INSTALL_RVM:-}" == "yes" ]] ; then - curl -sSL https://rvm.io/mpapis.asc | gpg --import - - curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - - - # Old OpenSSL versions cannot handle the SSL certificate used by - # https://get.rvm.io, so as a workaround we download RVM directly from - # GitHub. See this issue for details: https://github.com/rvm/rvm/issues/5133 - curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s master --ruby + git config --global --add safe.directory $HOMEBREW_PREFIX/Library/Taps/homebrew/homebrew-cask + git config --global --add safe.directory $HOMEBREW_PREFIX/Library/Taps/homebrew/homebrew-core + git config --global --add safe.directory $HOMEBREW_PREFIX/Library/Taps/homebrew/homebrew-services + sudo chown -R $(whoami) $HOME/.rvm/ fi diff --git a/kokoro/macos/ruby31/build.sh b/kokoro/macos/ruby31/build.sh index 1b5a5a5a60..3cf61f60f6 100644 --- a/kokoro/macos/ruby31/build.sh +++ b/kokoro/macos/ruby31/build.sh @@ -5,6 +5,9 @@ # Change to repo root cd $(dirname $0)/../../.. +# Fix locale issues in Monterey. +export LC_ALL=en_US.UTF-8 + # Prepare worker environment to run tests KOKORO_INSTALL_RVM=yes source kokoro/macos/prepare_build_macos_rc diff --git a/kokoro/release/python/macos/build_artifacts.sh b/kokoro/release/python/macos/build_artifacts.sh index aeb4242a6b..a72ee6733f 100755 --- a/kokoro/release/python/macos/build_artifacts.sh +++ b/kokoro/release/python/macos/build_artifacts.sh @@ -58,7 +58,6 @@ build_artifact_version() { } export MB_PYTHON_OSX_VER=10.9 -build_artifact_version 3.6 build_artifact_version 3.7 build_artifact_version 3.8 build_artifact_version 3.9 diff --git a/kokoro/release/ruby/macos/build_artifacts.sh b/kokoro/release/ruby/macos/build_artifacts.sh index c68b63cc43..a109d45b61 100755 --- a/kokoro/release/ruby/macos/build_artifacts.sh +++ b/kokoro/release/ruby/macos/build_artifacts.sh @@ -12,8 +12,5 @@ export ARTIFACT_DIR=$(pwd)/artifacts # ruby environment bash kokoro/release/ruby/macos/ruby/ruby_build_environment.sh -gem install rubygems-update -update_rubygems - # build artifacts bash kokoro/release/ruby/macos/ruby/ruby_build.sh diff --git a/kokoro/release/ruby/macos/ruby/ruby_build.sh b/kokoro/release/ruby/macos/ruby/ruby_build.sh index 55773b21a9..bbfc631197 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build.sh @@ -3,7 +3,6 @@ set -ex # Build protoc -use_bazel.sh 5.1.1 bazel build //:protoc export PROTOC=$PWD/bazel-bin/protoc diff --git a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index 2a9cb1687b..29066427f2 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -2,6 +2,10 @@ set -ex +# Fix permissions +sudo chown -R $(whoami) $HOME/.rvm/ +sudo chown -R $(whoami) /Library/Ruby/ + set +ex # rvm script is very verbose and exits with errorcode curl -sSL https://rvm.io/mpapis.asc | gpg --import - diff --git a/tests.sh b/tests.sh index e82265c895..180b870210 100755 --- a/tests.sh +++ b/tests.sh @@ -23,17 +23,6 @@ build_cpp() { internal_build_cpp make check -j$(nproc) || (cat src/test-suite.log; false) cd conformance && make test_cpp && cd .. - - # The benchmark code depends on cmake, so test if it is installed before - # trying to do the build. - if [[ $(type cmake 2>/dev/null) ]]; then - # Verify benchmarking code can build successfully. - cd benchmarks && make cpp-benchmark && cd .. - else - echo "" - echo "WARNING: Skipping validation of the benchmarking code, cmake isn't installed." - echo "" - fi } build_cpp_tcmalloc() { From aafacb09c75d521b11500970827214f2247dd4aa Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Wed, 7 Sep 2022 09:59:22 -0700 Subject: [PATCH 03/39] Remove broken use_bazel.sh (#10511) --- kokoro/release/python/macos/config.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/kokoro/release/python/macos/config.sh b/kokoro/release/python/macos/config.sh index 91e62d6c79..74e65691cb 100644 --- a/kokoro/release/python/macos/config.sh +++ b/kokoro/release/python/macos/config.sh @@ -26,7 +26,6 @@ function pre_build { pushd protobuf # Build protoc and protobuf libraries - use_bazel.sh 5.1.1 bazel build //:protoc export PROTOC=$PWD/bazel-bin/protoc mkdir src/.libs From ea2f20498e2853a58875f247b06edcb567ccd86b Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Thu, 8 Sep 2022 10:57:01 -0700 Subject: [PATCH 04/39] Uninstall system protobuf to prevent version conflicts (#10522) --- kokoro/macos/prepare_build_macos_rc | 4 ++++ kokoro/release/python/macos/build_artifacts.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/kokoro/macos/prepare_build_macos_rc b/kokoro/macos/prepare_build_macos_rc index 75b50c09f9..8f99f105fa 100755 --- a/kokoro/macos/prepare_build_macos_rc +++ b/kokoro/macos/prepare_build_macos_rc @@ -6,6 +6,10 @@ set -eux export HOMEBREW_PREFIX=$(brew --prefix) +## +# Remove any pre-existing protobuf installation. +brew uninstall protobuf + ## # Select Xcode version diff --git a/kokoro/release/python/macos/build_artifacts.sh b/kokoro/release/python/macos/build_artifacts.sh index a72ee6733f..296bd9aef3 100755 --- a/kokoro/release/python/macos/build_artifacts.sh +++ b/kokoro/release/python/macos/build_artifacts.sh @@ -2,6 +2,9 @@ set -ex +# Remove any pre-existing protobuf installation. +brew uninstall protobuf + # change to repo root pushd $(dirname $0)/../../../.. From fc1dbc6fac87d6c6307d055e50bc5a57c8143e4e Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 7 Sep 2022 18:25:00 +0100 Subject: [PATCH 05/39] Fix 32-bit floating point JSON parsing of maximal values for C# Fixes #10509. --- .../src/Google.Protobuf.Test/JsonParserTest.cs | 10 ++++++++-- csharp/src/Google.Protobuf/JsonParser.cs | 16 ++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index b5d6c0bbe3..c03b326c08 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -576,6 +576,10 @@ namespace Google.Protobuf [TestCase("-3.402823e38", -3.402823e38f)] [TestCase("1.5e1", 15f)] [TestCase("15e-1", 1.5f)] + [TestCase("3.4028235e38", float.MaxValue)] + [TestCase("-3.4028235e38", float.MinValue)] + [TestCase("3.4028235e+38", float.MaxValue)] + [TestCase("-3.4028235e+38", float.MinValue)] public void NumberToFloat_Valid(string jsonValue, float expectedParsedValue) { string json = "{ \"singleFloat\": " + jsonValue + "}"; @@ -584,8 +588,10 @@ namespace Google.Protobuf } [Test] - [TestCase("3.402824e38", typeof(InvalidProtocolBufferException))] - [TestCase("-3.402824e38", typeof(InvalidProtocolBufferException))] + [TestCase("3.4028236e38", typeof(InvalidProtocolBufferException))] + [TestCase("-3.4028236e38", typeof(InvalidProtocolBufferException))] + [TestCase("3.4028236e+38", typeof(InvalidProtocolBufferException))] + [TestCase("-3.4028236e+38", typeof(InvalidProtocolBufferException))] [TestCase("1,0", typeof(InvalidJsonException))] [TestCase("1.0.0", typeof(InvalidJsonException))] [TestCase("+1", typeof(InvalidJsonException))] diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs index 3575e2529e..6cb98d6e24 100644 --- a/csharp/src/Google.Protobuf/JsonParser.cs +++ b/csharp/src/Google.Protobuf/JsonParser.cs @@ -642,19 +642,15 @@ namespace Google.Protobuf { return float.NaN; } - if (value > float.MaxValue || value < float.MinValue) + float converted = (float) value; + // If the value is out of range of float, the cast representation will be infinite. + // If the original value was infinite as well, that's fine - we'll return the 32-bit + // version (with the correct sign). + if (float.IsInfinity(converted) && !double.IsInfinity(value)) { - if (double.IsPositiveInfinity(value)) - { - return float.PositiveInfinity; - } - if (double.IsNegativeInfinity(value)) - { - return float.NegativeInfinity; - } throw new InvalidProtocolBufferException($"Value out of range: {value}"); } - return (float) value; + return converted; case FieldType.Enum: CheckInteger(value); // Just return it as an int, and let the CLR convert it. From cd0ee8f45d0d749a1e4deb9847e53efb62c04d7b Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 13 Sep 2022 16:38:34 +0000 Subject: [PATCH 06/39] Apply patch --- src/google/protobuf/extension_set_inl.h | 27 +++-- src/google/protobuf/wire_format.cc | 26 +++-- src/google/protobuf/wire_format_lite.h | 27 +++-- src/google/protobuf/wire_format_unittest.inc | 104 +++++++++++++++++-- 4 files changed, 149 insertions(+), 35 deletions(-) diff --git a/src/google/protobuf/extension_set_inl.h b/src/google/protobuf/extension_set_inl.h index 95936cc243..e4e711721d 100644 --- a/src/google/protobuf/extension_set_inl.h +++ b/src/google/protobuf/extension_set_inl.h @@ -206,16 +206,21 @@ const char* ExtensionSet::ParseMessageSetItemTmpl( const char* ptr, const Msg* extendee, internal::InternalMetadata* metadata, internal::ParseContext* ctx) { std::string payload; - uint32_t type_id = 0; - bool payload_read = false; + uint32_t type_id; + enum class State { kNoTag, kHasType, kHasPayload, kDone }; + State state = State::kNoTag; + while (!ctx->Done(&ptr)) { uint32_t tag = static_cast(*ptr++); if (tag == WireFormatLite::kMessageSetTypeIdTag) { uint64_t tmp; ptr = ParseBigVarint(ptr, &tmp); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - type_id = tmp; - if (payload_read) { + if (state == State::kNoTag) { + type_id = tmp; + state = State::kHasType; + } else if (state == State::kHasPayload) { + type_id = tmp; ExtensionInfo extension; bool was_packed_on_wire; if (!FindExtension(2, type_id, extendee, ctx, &extension, @@ -241,20 +246,24 @@ const char* ExtensionSet::ParseMessageSetItemTmpl( GOOGLE_PROTOBUF_PARSER_ASSERT(value->_InternalParse(p, &tmp_ctx) && tmp_ctx.EndedAtLimit()); } - type_id = 0; + state = State::kDone; } } else if (tag == WireFormatLite::kMessageSetMessageTag) { - if (type_id != 0) { + if (state == State::kHasType) { ptr = ParseFieldMaybeLazily(static_cast(type_id) * 8 + 2, ptr, extendee, metadata, ctx); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr != nullptr); - type_id = 0; + state = State::kDone; } else { + std::string tmp; int32_t size = ReadSize(&ptr); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - ptr = ctx->ReadString(ptr, size, &payload); + ptr = ctx->ReadString(ptr, size, &tmp); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - payload_read = true; + if (state == State::kNoTag) { + payload = std::move(tmp); + state = State::kHasPayload; + } } } else { ptr = ReadTag(ptr - 1, &tag); diff --git a/src/google/protobuf/wire_format.cc b/src/google/protobuf/wire_format.cc index e44c6ebeee..6fe63c86ce 100644 --- a/src/google/protobuf/wire_format.cc +++ b/src/google/protobuf/wire_format.cc @@ -657,9 +657,11 @@ struct WireFormat::MessageSetParser { const char* _InternalParse(const char* ptr, internal::ParseContext* ctx) { // Parse a MessageSetItem auto metadata = reflection->MutableInternalMetadata(msg); + enum class State { kNoTag, kHasType, kHasPayload, kDone }; + State state = State::kNoTag; + std::string payload; uint32_t type_id = 0; - bool payload_read = false; while (!ctx->Done(&ptr)) { // We use 64 bit tags in order to allow typeid's that span the whole // range of 32 bit numbers. @@ -668,8 +670,11 @@ struct WireFormat::MessageSetParser { uint64_t tmp; ptr = ParseBigVarint(ptr, &tmp); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - type_id = tmp; - if (payload_read) { + if (state == State::kNoTag) { + type_id = tmp; + state = State::kHasType; + } else if (state == State::kHasPayload) { + type_id = tmp; const FieldDescriptor* field; if (ctx->data().pool == nullptr) { field = reflection->FindKnownExtensionByNumber(type_id); @@ -696,17 +701,17 @@ struct WireFormat::MessageSetParser { GOOGLE_PROTOBUF_PARSER_ASSERT(value->_InternalParse(p, &tmp_ctx) && tmp_ctx.EndedAtLimit()); } - type_id = 0; + state = State::kDone; } continue; } else if (tag == WireFormatLite::kMessageSetMessageTag) { - if (type_id == 0) { + if (state == State::kNoTag) { int32_t size = ReadSize(&ptr); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ptr = ctx->ReadString(ptr, size, &payload); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - payload_read = true; - } else { + state = State::kHasPayload; + } else if (state == State::kHasType) { // We're now parsing the payload const FieldDescriptor* field = nullptr; if (descriptor->IsExtensionNumber(type_id)) { @@ -720,7 +725,12 @@ struct WireFormat::MessageSetParser { ptr = WireFormat::_InternalParseAndMergeField( msg, ptr, ctx, static_cast(type_id) * 8 + 2, reflection, field); - type_id = 0; + state = State::kDone; + } else { + int32_t size = ReadSize(&ptr); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); + ptr = ctx->Skip(ptr, size); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); } } else { // An unknown field in MessageSetItem. diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index a7e64bf1e4..80d396156f 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -1831,6 +1831,9 @@ bool ParseMessageSetItemImpl(io::CodedInputStream* input, MS ms) { // we can parse it later. std::string message_data; + enum class State { kNoTag, kHasType, kHasPayload, kDone }; + State state = State::kNoTag; + while (true) { const uint32_t tag = input->ReadTagNoLastTag(); if (tag == 0) return false; @@ -1839,26 +1842,34 @@ bool ParseMessageSetItemImpl(io::CodedInputStream* input, MS ms) { case WireFormatLite::kMessageSetTypeIdTag: { uint32_t type_id; if (!input->ReadVarint32(&type_id)) return false; - last_type_id = type_id; - - if (!message_data.empty()) { + if (state == State::kNoTag) { + last_type_id = type_id; + state = State::kHasType; + } else if (state == State::kHasPayload) { // We saw some message data before the type_id. Have to parse it // now. io::CodedInputStream sub_input( reinterpret_cast(message_data.data()), static_cast(message_data.size())); sub_input.SetRecursionLimit(input->RecursionBudget()); - if (!ms.ParseField(last_type_id, &sub_input)) { + if (!ms.ParseField(type_id, &sub_input)) { return false; } message_data.clear(); + state = State::kDone; } break; } case WireFormatLite::kMessageSetMessageTag: { - if (last_type_id == 0) { + if (state == State::kHasType) { + // Already saw type_id, so we can parse this directly. + if (!ms.ParseField(last_type_id, input)) { + return false; + } + state = State::kDone; + } else if (state == State::kNoTag) { // We haven't seen a type_id yet. Append this data to message_data. uint32_t length; if (!input->ReadVarint32(&length)) return false; @@ -1869,11 +1880,9 @@ bool ParseMessageSetItemImpl(io::CodedInputStream* input, MS ms) { auto ptr = reinterpret_cast(&message_data[0]); ptr = io::CodedOutputStream::WriteVarint32ToArray(length, ptr); if (!input->ReadRaw(ptr, length)) return false; + state = State::kHasPayload; } else { - // Already saw type_id, so we can parse this directly. - if (!ms.ParseField(last_type_id, input)) { - return false; - } + if (!ms.SkipField(tag, input)) return false; } break; diff --git a/src/google/protobuf/wire_format_unittest.inc b/src/google/protobuf/wire_format_unittest.inc index d583ddde19..0e3869cbef 100644 --- a/src/google/protobuf/wire_format_unittest.inc +++ b/src/google/protobuf/wire_format_unittest.inc @@ -581,28 +581,54 @@ TEST(WireFormatTest, ParseMessageSet) { EXPECT_EQ(message_set.DebugString(), dynamic_message_set.DebugString()); } -TEST(WireFormatTest, ParseMessageSetWithReverseTagOrder) { +namespace { +std::string BuildMessageSetItemStart() { std::string data; { - UNITTEST::TestMessageSetExtension1 message; - message.set_i(123); - // Build a MessageSet manually with its message content put before its - // type_id. io::StringOutputStream output_stream(&data); io::CodedOutputStream coded_output(&output_stream); coded_output.WriteTag(WireFormatLite::kMessageSetItemStartTag); + } + return data; +} +std::string BuildMessageSetItemEnd() { + std::string data; + { + io::StringOutputStream output_stream(&data); + io::CodedOutputStream coded_output(&output_stream); + coded_output.WriteTag(WireFormatLite::kMessageSetItemEndTag); + } + return data; +} +std::string BuildMessageSetTestExtension1(int value = 123) { + std::string data; + { + UNITTEST::TestMessageSetExtension1 message; + message.set_i(value); + io::StringOutputStream output_stream(&data); + io::CodedOutputStream coded_output(&output_stream); // Write the message content first. WireFormatLite::WriteTag(WireFormatLite::kMessageSetMessageNumber, WireFormatLite::WIRETYPE_LENGTH_DELIMITED, &coded_output); coded_output.WriteVarint32(message.ByteSizeLong()); message.SerializeWithCachedSizes(&coded_output); - // Write the type id. - uint32_t type_id = message.GetDescriptor()->extension(0)->number(); + } + return data; +} +std::string BuildMessageSetItemTypeId(int extension_number) { + std::string data; + { + io::StringOutputStream output_stream(&data); + io::CodedOutputStream coded_output(&output_stream); WireFormatLite::WriteUInt32(WireFormatLite::kMessageSetTypeIdNumber, - type_id, &coded_output); - coded_output.WriteTag(WireFormatLite::kMessageSetItemEndTag); + extension_number, &coded_output); } + return data; +} +void ValidateTestMessageSet(const std::string& test_case, + const std::string& data) { + SCOPED_TRACE(test_case); { PROTO2_WIREFORMAT_UNITTEST::TestMessageSet message_set; ASSERT_TRUE(message_set.ParseFromString(data)); @@ -612,6 +638,11 @@ TEST(WireFormatTest, ParseMessageSetWithReverseTagOrder) { .GetExtension( UNITTEST::TestMessageSetExtension1::message_set_extension) .i()); + + // Make sure it does not contain anything else. + message_set.ClearExtension( + UNITTEST::TestMessageSetExtension1::message_set_extension); + EXPECT_EQ(message_set.SerializeAsString(), ""); } { // Test parse the message via Reflection. @@ -627,6 +658,61 @@ TEST(WireFormatTest, ParseMessageSetWithReverseTagOrder) { UNITTEST::TestMessageSetExtension1::message_set_extension) .i()); } + { + // Test parse the message via DynamicMessage. + DynamicMessageFactory factory; + std::unique_ptr msg( + factory + .GetPrototype( + PROTO2_WIREFORMAT_UNITTEST::TestMessageSet::descriptor()) + ->New()); + msg->ParseFromString(data); + auto* reflection = msg->GetReflection(); + std::vector fields; + reflection->ListFields(*msg, &fields); + ASSERT_EQ(fields.size(), 1); + const auto& sub = reflection->GetMessage(*msg, fields[0]); + reflection = sub.GetReflection(); + EXPECT_EQ(123, reflection->GetInt32( + sub, sub.GetDescriptor()->FindFieldByName("i"))); + } +} +} // namespace + +TEST(WireFormatTest, ParseMessageSetWithAnyTagOrder) { + std::string start = BuildMessageSetItemStart(); + std::string end = BuildMessageSetItemEnd(); + std::string id = BuildMessageSetItemTypeId( + UNITTEST::TestMessageSetExtension1::descriptor()->extension(0)->number()); + std::string message = BuildMessageSetTestExtension1(); + + ValidateTestMessageSet("id + message", start + id + message + end); + ValidateTestMessageSet("message + id", start + message + id + end); +} + +TEST(WireFormatTest, ParseMessageSetWithDuplicateTags) { + std::string start = BuildMessageSetItemStart(); + std::string end = BuildMessageSetItemEnd(); + std::string id = BuildMessageSetItemTypeId( + UNITTEST::TestMessageSetExtension1::descriptor()->extension(0)->number()); + std::string other_id = BuildMessageSetItemTypeId(123456); + std::string message = BuildMessageSetTestExtension1(); + std::string other_message = BuildMessageSetTestExtension1(321); + + // Double id + ValidateTestMessageSet("id + other_id + message", + start + id + other_id + message + end); + ValidateTestMessageSet("id + message + other_id", + start + id + message + other_id + end); + ValidateTestMessageSet("message + id + other_id", + start + message + id + other_id + end); + // Double message + ValidateTestMessageSet("id + message + other_message", + start + id + message + other_message + end); + ValidateTestMessageSet("message + id + other_message", + start + message + id + other_message + end); + ValidateTestMessageSet("message + other_message + id", + start + message + other_message + id + end); } void SerializeReverseOrder( From 24487dd1045c7f3d64a21f38a3f0c06cc4cf2edb Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 13 Sep 2022 13:50:08 -0700 Subject: [PATCH 07/39] Updating version.json and repo version numbers to: 21.6 --- 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 2043adbdec..8ab70d04ac 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.5' + s.version = '3.21.6' 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 eb87a8f81a..b3e843485e 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.5' + s.version = '3.21.6' 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 375a79d93a..c42fbc21ba 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.5],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.21.6],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 5b71f9f040..096d0a47c1 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.5 + 3.21.6 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 35248481f2..33db8a8e0b 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.5 + 3.21.6 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 3a022f0929..6a23c0d9e8 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.5 + 3.21.6 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.21.5 + 3.21.6 ``` @@ -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.5' + implementation 'com.google.protobuf:protobuf-java:3.21.6' ``` 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 4504729f9c..1196d3685c 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.21.5 + 3.21.6 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 9315004516..7e5e8df1d7 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.5 + 3.21.6 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 03f28f5901..52bc1b3675 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.5 + 3.21.6 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index f2d034e9c8..ee949ddb4b 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.5 + 3.21.6 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 2445ec3a88..6f003ed543 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.5 + 3.21.6 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index c5ef4abc0d..ba65f5cbf4 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.5 + 3.21.6 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index c086992432..6f1059f8d9 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.5 + 3.21.6 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 987163247d..0f02bb84df 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.5 + 3.21.6 protobuf-java-util diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index ccf1d414fd..4f0b8b4277 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-08-09 - + 2022-09-13 + - 3.21.5 - 3.21.5 + 3.21.6 + 3.21.6 stable @@ -1403,5 +1403,20 @@ G A release. + + + 3.21.6 + 3.21.6 + + + stable + stable + + 2022-09-13 + + BSD-3-Clause + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 836bb8b74e..4f14ab526a 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.5" +#define PHP_PROTOBUF_VERSION "3.21.6" // 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 253aaac46d..fdd9b5fe57 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,3 +1,3 @@ -PROTOC_VERSION = '21.5' -PROTOBUF_JAVA_VERSION = '3.21.5' -PROTOBUF_PYTHON_VERSION = '4.21.5' +PROTOC_VERSION = '21.6' +PROTOBUF_JAVA_VERSION = '3.21.6' +PROTOBUF_PYTHON_VERSION = '4.21.6' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index bdbf3fc334..8e81909771 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.21.5 + 3.21.6 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 4d288e20d0..9ba2b78c85 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.5' +__version__ = '4.21.6' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 3d776fecea..9dc373ca3b 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.5" + s.version = "3.21.6" 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 d56c99d785..4e07f84022 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.21.5 + 3.21.6 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.5 + 3.21.6 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index e6a7dc7fdd..3a6ecdc42e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 32:5:0 +PROTOBUF_VERSION = 32:6: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 41ee5c2a90..ac51c9bcac 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 31c09b5c5f..348bac8882 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 f2cff45738..97bf2f02b5 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 4129d0d2d5..2d9c790f57 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 83e780e2b3..c4a94c5394 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 ca821f91a8..00a4481544 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 ff9424f0f4..ecc6edee9a 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 e4b07537fb..8943a4454f 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 3021005 +#define PROTOBUF_VERSION 3021006 #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 784fe1cdf3..e9c41bdea7 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 cf7416c121..ac2d9716dd 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 427df67d4f..ebb1ca0e67 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 3021005 +#define GOOGLE_PROTOBUF_VERSION 3021006 // 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 14efcf185f..6633822791 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 19247b337c..0f11e6cd1b 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 1766742722..cc42a8ba5c 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 3021005 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021006 < 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 25df6c1044..eed0a2a14b 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "21.x": { - "protoc_version": "21.6-dev", + "protoc_version": "21.6", "lts": false, - "date": "2022-08-09", + "date": "2022-09-13", "languages": { - "cpp": "3.21.6-dev", - "csharp": "3.21.6-dev", - "java": "3.21.6-dev", - "javascript": "3.21.6-dev", - "objectivec": "3.21.6-dev", - "php": "3.21.6-dev", - "python": "4.21.6-dev", - "ruby": "3.21.6-dev" + "cpp": "3.21.6", + "csharp": "3.21.6", + "java": "3.21.6", + "javascript": "3.21.6", + "objectivec": "3.21.6", + "php": "3.21.6", + "python": "4.21.6", + "ruby": "3.21.6" } } } \ No newline at end of file From aa8c73d845339c8e477df4a9ca5731ffc7c023c8 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 13 Sep 2022 21:21:48 +0000 Subject: [PATCH 08/39] Updating changelog --- CHANGES.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 264c72853b..4be9411211 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,8 @@ +2022-09-13 version 21.6 (C++/Java/Python/PHP/Objective-C/C#/Ruby) + +C++ +* Reduce memory consumption of MessageSet parsing + 2022-08-09 version 21.5 (C++/Java/Python/PHP/Objective-C/C#/Ruby) PHP From de7597e577320e3737b7585b0f9740adff423a4f Mon Sep 17 00:00:00 2001 From: zhangskz <89936743+zhangskz@users.noreply.github.com> Date: Wed, 27 Jul 2022 19:53:14 +0000 Subject: [PATCH 09/39] Update python/release.sh to handle delay between twine upload and pip install (#10324) --- python/release.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/python/release.sh b/python/release.sh index 15a70db31f..87fcf8cfee 100755 --- a/python/release.sh +++ b/python/release.sh @@ -19,11 +19,24 @@ function run_install_test() { chmod +x test-venv/bin/protoc source test-venv/bin/activate - pip install -i ${PYPI} protobuf==${VERSION} --no-cache-dir + (pip install -i ${PYPI} protobuf==${VERSION} --no-cache-dir) || (retry_pip_install ${PYPI} ${VERSION}) deactivate rm -fr test-venv } +function retry_pip_install() { + local PYPI=$1 + local VERSION=$2 + + read -p "pip install failed, possibly due to delay between upload and availability on pip. Retry? [y/n]" -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + + (pip install -i ${PYPI} protobuf==${VERSION} --no-cache-dir) || (retry_pip_install ${PYPI} ${VERSION}) +} + [ $# -lt 1 ] && { echo "Usage: $0 VERSION [" @@ -86,13 +99,16 @@ python3 setup.py test python3 setup.py sdist twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/* -# Test locally with different python versions. +# Sleep to allow time for distribution to be available on pip. +sleep 5m + +# Test locally. run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple # Deploy egg/wheel packages to testing PyPI and test again. python3 setup.py clean build bdist_wheel twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/* - +sleep 5m run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple echo "All install tests have passed using testing PyPI." From b1924e1de96f1e7bc617fe8b4dd52a29be6edaa2 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 14 Sep 2022 21:40:15 +0000 Subject: [PATCH 10/39] Update version.json to: 21.7-dev --- version.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/version.json b/version.json index eed0a2a14b..ade50a1b8a 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "21.x": { - "protoc_version": "21.6", + "protoc_version": "21.7-dev", "lts": false, - "date": "2022-09-13", + "date": "2022-09-14", "languages": { - "cpp": "3.21.6", - "csharp": "3.21.6", - "java": "3.21.6", - "javascript": "3.21.6", - "objectivec": "3.21.6", - "php": "3.21.6", - "python": "4.21.6", - "ruby": "3.21.6" + "cpp": "3.21.7-dev", + "csharp": "3.21.7-dev", + "java": "3.21.7-dev", + "javascript": "3.21.7-dev", + "objectivec": "3.21.7-dev", + "php": "3.21.7-dev", + "python": "4.21.7-dev", + "ruby": "3.21.7-dev" } } } \ No newline at end of file From 2270d3f93ce3040380fa470807ce60db28c1339f Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Tue, 13 Sep 2022 16:17:10 -0400 Subject: [PATCH 11/39] allow excessively large int literal values (that would otherwise overflow uint64 or underflow int64) to be used as float/double values --- src/google/protobuf/compiler/parser.cc | 43 +++++++++++++++++--------- src/google/protobuf/compiler/parser.h | 3 ++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 4cae1a1187..e5f42c4506 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -288,6 +288,16 @@ bool Parser::ConsumeInteger64(uint64_t max_value, uint64_t* output, } } +bool Parser::TryConsumeInteger64(uint64_t max_value, uint64_t* output) { + if (LookingAtType(io::Tokenizer::TYPE_INTEGER) && + io::Tokenizer::ParseInteger(input_->current().text, max_value, + output)) { + input_->Next(); + return true; + } + return false; +} + bool Parser::ConsumeNumber(double* output, const char* error) { if (LookingAtType(io::Tokenizer::TYPE_FLOAT)) { *output = io::Tokenizer::ParseFloat(input_->current().text); @@ -296,13 +306,14 @@ bool Parser::ConsumeNumber(double* output, const char* error) { } else if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { // Also accept integers. uint64_t value = 0; - if (!io::Tokenizer::ParseInteger(input_->current().text, + if (io::Tokenizer::ParseInteger(input_->current().text, std::numeric_limits::max(), &value)) { - AddError("Integer out of range."); - // We still return true because we did, in fact, parse a number. + *output = value; + } else { + // out of int range, treat as double literal + *output = io::Tokenizer::ParseFloat(input_->current().text); } - *output = value; input_->Next(); return true; } else if (LookingAt("inf")) { @@ -1551,18 +1562,20 @@ bool Parser::ParseOption(Message* options, is_negative ? static_cast(std::numeric_limits::max()) + 1 : std::numeric_limits::max(); - DO(ConsumeInteger64(max_value, &value, "Expected integer.")); - if (is_negative) { - value_location.AddPath( - UninterpretedOption::kNegativeIntValueFieldNumber); - uninterpreted_option->set_negative_int_value( - static_cast(0 - value)); - } else { - value_location.AddPath( - UninterpretedOption::kPositiveIntValueFieldNumber); - uninterpreted_option->set_positive_int_value(value); + if (TryConsumeInteger64(max_value, &value)) { + if (is_negative) { + value_location.AddPath( + UninterpretedOption::kNegativeIntValueFieldNumber); + uninterpreted_option->set_negative_int_value( + static_cast(0 - value)); + } else { + value_location.AddPath( + UninterpretedOption::kPositiveIntValueFieldNumber); + uninterpreted_option->set_positive_int_value(value); + } + break; } - break; + // value too large for an integer; fall through below to treat as floating point } case io::Tokenizer::TYPE_FLOAT: { diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index ccd3e5a5f7..a5649fd587 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -180,6 +180,9 @@ class PROTOBUF_EXPORT Parser { // is greater than max_value, an error will be reported. bool ConsumeInteger64(uint64_t max_value, uint64_t* output, const char* error); + // Try to consume a 64-bit integer and store its value in "output". No + // error is reported on failure, allowing caller to consume token another way. + bool TryConsumeInteger64(uint64_t max_value, uint64_t* output); // Consume a number and store its value in "output". This will accept // tokens of either INTEGER or FLOAT type. bool ConsumeNumber(double* output, const char* error); From 87f24e47595ef5e382949346e50a81150d35c230 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Tue, 13 Sep 2022 16:32:48 -0400 Subject: [PATCH 12/39] add allowed ranges to error messages --- src/google/protobuf/descriptor.cc | 18 ++++++++---------- src/google/protobuf/descriptor_unittest.cc | 16 ++++++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index ddebcf6184..0e43bc3af6 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -7683,7 +7683,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError("Value out of range for int32 option \"" + + return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" + option_field->full_name() + "\"."); } else { SetInt32(option_field->number(), @@ -7693,7 +7693,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } else if (uninterpreted_option_->has_negative_int_value()) { if (uninterpreted_option_->negative_int_value() < static_cast(std::numeric_limits::min())) { - return AddValueError("Value out of range for int32 option \"" + + return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" + option_field->full_name() + "\"."); } else { SetInt32(option_field->number(), @@ -7701,7 +7701,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( option_field->type(), unknown_fields); } } else { - return AddValueError("Value must be integer for int32 option \"" + + return AddValueError("Value must be integer, from -2,147,483,648 to 2,147,483,647, for int32 option \"" + option_field->full_name() + "\"."); } break; @@ -7710,7 +7710,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError("Value out of range for int64 option \"" + + return AddValueError("Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" + option_field->full_name() + "\"."); } else { SetInt64(option_field->number(), @@ -7722,7 +7722,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError("Value must be integer for int64 option \"" + + return AddValueError("Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" + option_field->full_name() + "\"."); } break; @@ -7731,7 +7731,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > std::numeric_limits::max()) { - return AddValueError("Value out of range for uint32 option \"" + + return AddValueError("Value out of range, 0 to 4,294,967,295, for uint32 option \"" + option_field->name() + "\"."); } else { SetUInt32(option_field->number(), @@ -7740,8 +7740,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } } else { return AddValueError( - "Value must be non-negative integer for uint32 " - "option \"" + + "Value must be integer, from 0 to 4,294,967,295, for uint32 option \"" + option_field->full_name() + "\"."); } break; @@ -7753,8 +7752,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( option_field->type(), unknown_fields); } else { return AddValueError( - "Value must be non-negative integer for uint64 " - "option \"" + + "Value must be integer, from 0 to 18,446,744,073,709,551,615, for uint64 option \"" + option_field->full_name() + "\"."); } break; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index a2900454f6..33d4299fb6 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -5557,7 +5557,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfPositiveRange) { " positive_int_value: 0x80000000 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, " "for int32 option \"foo\".\n"); } @@ -5574,7 +5574,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfNegativeRange) { " negative_int_value: -0x80000001 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, " "for int32 option \"foo\".\n"); } @@ -5590,7 +5590,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueIsNotPositiveInt) { " is_extension: true } " " string_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -2,147,483,648 to 2,147,483,647, " "for int32 option \"foo\".\n"); } @@ -5608,7 +5608,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueOutOfRange) { "} " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, " "for int64 option \"foo\".\n"); } @@ -5624,7 +5624,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueIsNotPositiveInt) { " is_extension: true } " " identifier_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, " "for int64 option \"foo\".\n"); } @@ -5640,7 +5640,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueOutOfRange) { " is_extension: true } " " positive_int_value: 0x100000000 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, 0 to 4,294,967,295, " "for uint32 option \"foo\".\n"); } @@ -5656,7 +5656,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueIsNotPositiveInt) { " is_extension: true } " " double_value: -5.6 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 4,294,967,295, " "for uint32 option \"foo\".\n"); } @@ -5672,7 +5672,7 @@ TEST_F(ValidationErrorTest, UInt64OptionValueIsNotPositiveInt) { " is_extension: true } " " negative_int_value: -5 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 18,446,744,073,709,551,615, " "for uint64 option \"foo\".\n"); } From 4e54ec20d12aaf6868638ceaab4d1c8c17f4d4e8 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 14 Sep 2022 15:16:51 -0400 Subject: [PATCH 13/39] change format of int range in error message; use macro to make DRY --- src/google/protobuf/descriptor.cc | 35 +++++++++++----------- src/google/protobuf/descriptor_unittest.cc | 16 +++++----- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 0e43bc3af6..cd40584b37 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -58,6 +58,7 @@ #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_format.h" #include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" @@ -7675,6 +7676,14 @@ bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet( return true; } +#define VALUE_OUT_OF_RANGE(T, NAME) absl::StrFormat( \ + "Value out of range, %d to %d, for " #T " option \"%s\".", \ + std::numeric_limits::min(), std::numeric_limits::max(), NAME) + +#define VALUE_MUST_BE_INT(T, NAME) absl::StrFormat( \ + "Value must be integer, from %d to %d, for " #T " option \"%s\".", \ + std::numeric_limits::min(), std::numeric_limits::max(), NAME) + bool DescriptorBuilder::OptionInterpreter::SetOptionValue( const FieldDescriptor* option_field, UnknownFieldSet* unknown_fields) { // We switch on the CppType to validate. @@ -7683,8 +7692,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_OUT_OF_RANGE(int32, option_field->full_name())); } else { SetInt32(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7693,16 +7701,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } else if (uninterpreted_option_->has_negative_int_value()) { if (uninterpreted_option_->negative_int_value() < static_cast(std::numeric_limits::min())) { - return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_OUT_OF_RANGE(int32, option_field->full_name())); } else { SetInt32(option_field->number(), uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError("Value must be integer, from -2,147,483,648 to 2,147,483,647, for int32 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_MUST_BE_INT(int32, option_field->full_name())); } break; @@ -7710,8 +7716,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError("Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_OUT_OF_RANGE(int64, option_field->full_name())); } else { SetInt64(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7722,8 +7727,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError("Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_MUST_BE_INT(int64, option_field->full_name())); } break; @@ -7731,17 +7735,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > std::numeric_limits::max()) { - return AddValueError("Value out of range, 0 to 4,294,967,295, for uint32 option \"" + - option_field->name() + "\"."); + return AddValueError(VALUE_OUT_OF_RANGE(uint32, option_field->full_name())); } else { SetUInt32(option_field->number(), uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError( - "Value must be integer, from 0 to 4,294,967,295, for uint32 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_MUST_BE_INT(uint32, option_field->full_name())); } break; @@ -7751,9 +7752,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError( - "Value must be integer, from 0 to 18,446,744,073,709,551,615, for uint64 option \"" + - option_field->full_name() + "\"."); + return AddValueError(VALUE_MUST_BE_INT(uint64, option_field->full_name())); } break; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 33d4299fb6..8079a26895 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -5557,7 +5557,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfPositiveRange) { " positive_int_value: 0x80000000 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2147483648 to 2147483647, " "for int32 option \"foo\".\n"); } @@ -5574,7 +5574,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfNegativeRange) { " negative_int_value: -0x80000001 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2147483648 to 2147483647, " "for int32 option \"foo\".\n"); } @@ -5590,7 +5590,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueIsNotPositiveInt) { " is_extension: true } " " string_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -2,147,483,648 to 2,147,483,647, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -2147483648 to 2147483647, " "for int32 option \"foo\".\n"); } @@ -5608,7 +5608,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueOutOfRange) { "} " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -9223372036854775808 to 9223372036854775807, " "for int64 option \"foo\".\n"); } @@ -5624,7 +5624,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueIsNotPositiveInt) { " is_extension: true } " " identifier_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -9223372036854775808 to 9223372036854775807, " "for int64 option \"foo\".\n"); } @@ -5640,7 +5640,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueOutOfRange) { " is_extension: true } " " positive_int_value: 0x100000000 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, 0 to 4,294,967,295, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, 0 to 4294967295, " "for uint32 option \"foo\".\n"); } @@ -5656,7 +5656,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueIsNotPositiveInt) { " is_extension: true } " " double_value: -5.6 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 4,294,967,295, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 4294967295, " "for uint32 option \"foo\".\n"); } @@ -5672,7 +5672,7 @@ TEST_F(ValidationErrorTest, UInt64OptionValueIsNotPositiveInt) { " is_extension: true } " " negative_int_value: -5 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 18,446,744,073,709,551,615, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 18446744073709551615, " "for uint64 option \"foo\".\n"); } From 35dd193f4787983a69911cb5f0afd6a7763b820a Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 14 Sep 2022 16:25:14 -0400 Subject: [PATCH 14/39] add test to verify parsing of extremely large decimal integers to double values --- .../protobuf/compiler/parser_unittest.cc | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 3b32451916..7685371c14 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -592,6 +592,56 @@ TEST_F(ParseMessageTest, FieldOptions) { "}"); } +TEST_F(ParseMessageTest, FieldOptionsSupportLargeDecimalLiteral) { + // decimal integer literal > uint64 max + ExpectParsesTo( + "import \"google/protobuf/descriptor.proto\";\n" + "extend google.protobuf.FieldOptions {\n" + " optional double f = 10101;\n" + "}\n" + "message TestMessage {\n" + " optional double a = 1 [default = 18446744073709551616];\n" + " optional double b = 2 [default = -18446744073709551616];\n" + " optional double c = 3 [(f) = 18446744073709551616];\n" + " optional double d = 4 [(f) = -18446744073709551616];\n" + "}\n", + + "dependency: \"google/protobuf/descriptor.proto\"" + "extension {" + " name: \"f\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 10101" + " extendee: \"google.protobuf.FieldOptions\"" + "}" + "message_type {" + " name: \"TestMessage\"" + " field {" + " name: \"a\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 1" + " default_value: \"1.8446744073709552e+19\"" + " }" + " field {" + " name: \"b\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 2" + " default_value: \"-1.8446744073709552e+19\"" + " }" + " field {" + " name: \"c\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 3" + " options{" + " uninterpreted_option{" + " name{ name_part: \"f\" is_extension: true }" + " double_value: 1.8446744073709552e+19" + " }" + " }" + " }" + " field {" + " name: \"d\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 4" + " options{" + " uninterpreted_option{" + " name{ name_part: \"f\" is_extension: true }" + " double_value: -1.8446744073709552e+19" + " }" + " }" + " }" + "}"); +} + TEST_F(ParseMessageTest, Oneof) { ExpectParsesTo( "message TestMessage {\n" From 4c69337faab5cd7a6bd040dbae841e21873004c0 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 14 Sep 2022 20:11:19 -0400 Subject: [PATCH 15/39] use template instead of macro --- src/google/protobuf/descriptor.cc | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index cd40584b37..b2841ce6ef 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -7676,13 +7676,21 @@ bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet( return true; } -#define VALUE_OUT_OF_RANGE(T, NAME) absl::StrFormat( \ - "Value out of range, %d to %d, for " #T " option \"%s\".", \ - std::numeric_limits::min(), std::numeric_limits::max(), NAME) +template std::string ValueOutOfRange( + std::string type_name, std::string option_name) { + return absl::StrFormat( + "Value out of range, %d to %d, for %s option \"%s\".", \ + std::numeric_limits::min(), std::numeric_limits::max(), + type_name, option_name); +} -#define VALUE_MUST_BE_INT(T, NAME) absl::StrFormat( \ - "Value must be integer, from %d to %d, for " #T " option \"%s\".", \ - std::numeric_limits::min(), std::numeric_limits::max(), NAME) +template std::string ValueMustBeInt( + std::string type_name, std::string option_name) { + return absl::StrFormat( + "Value must be integer, from %d to %d, for %s option \"%s\".", \ + std::numeric_limits::min(), std::numeric_limits::max(), + type_name, option_name); +} bool DescriptorBuilder::OptionInterpreter::SetOptionValue( const FieldDescriptor* option_field, UnknownFieldSet* unknown_fields) { @@ -7692,7 +7700,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError(VALUE_OUT_OF_RANGE(int32, option_field->full_name())); + return AddValueError(ValueOutOfRange("int32", option_field->full_name())); } else { SetInt32(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7701,14 +7709,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } else if (uninterpreted_option_->has_negative_int_value()) { if (uninterpreted_option_->negative_int_value() < static_cast(std::numeric_limits::min())) { - return AddValueError(VALUE_OUT_OF_RANGE(int32, option_field->full_name())); + return AddValueError(ValueOutOfRange("int32", option_field->full_name())); } else { SetInt32(option_field->number(), uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError(VALUE_MUST_BE_INT(int32, option_field->full_name())); + return AddValueError(ValueMustBeInt("int32", option_field->full_name())); } break; @@ -7716,7 +7724,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError(VALUE_OUT_OF_RANGE(int64, option_field->full_name())); + return AddValueError(ValueOutOfRange("int64", option_field->full_name())); } else { SetInt64(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7727,7 +7735,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError(VALUE_MUST_BE_INT(int64, option_field->full_name())); + return AddValueError(ValueMustBeInt("int64", option_field->full_name())); } break; @@ -7735,14 +7743,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > std::numeric_limits::max()) { - return AddValueError(VALUE_OUT_OF_RANGE(uint32, option_field->full_name())); + return AddValueError(ValueOutOfRange("uint32", option_field->full_name())); } else { SetUInt32(option_field->number(), uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError(VALUE_MUST_BE_INT(uint32, option_field->full_name())); + return AddValueError(ValueMustBeInt("uint32", option_field->full_name())); } break; @@ -7752,7 +7760,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError(VALUE_MUST_BE_INT(uint64, option_field->full_name())); + return AddValueError(ValueMustBeInt("uint64", option_field->full_name())); } break; From 7702355b9cc9ab7a1fcc851ecaac372debbc25f6 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Thu, 15 Sep 2022 09:44:15 -0400 Subject: [PATCH 16/39] address latest review comments --- src/google/protobuf/descriptor.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index b2841ce6ef..ffc8cd628e 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -7677,7 +7677,7 @@ bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet( } template std::string ValueOutOfRange( - std::string type_name, std::string option_name) { + absl::string_view type_name, absl::string_view option_name) { return absl::StrFormat( "Value out of range, %d to %d, for %s option \"%s\".", \ std::numeric_limits::min(), std::numeric_limits::max(), @@ -7685,7 +7685,7 @@ template std::string ValueOutOfRange( } template std::string ValueMustBeInt( - std::string type_name, std::string option_name) { + absl::string_view type_name, absl::string_view option_name) { return absl::StrFormat( "Value must be integer, from %d to %d, for %s option \"%s\".", \ std::numeric_limits::min(), std::numeric_limits::max(), @@ -7724,7 +7724,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError(ValueOutOfRange("int64", option_field->full_name())); + return AddValueError(ValueOutOfRange("int64", option_field->full_name())); } else { SetInt64(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7735,7 +7735,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError(ValueMustBeInt("int64", option_field->full_name())); + return AddValueError(ValueMustBeInt("int64", option_field->full_name())); } break; @@ -7743,14 +7743,14 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > std::numeric_limits::max()) { - return AddValueError(ValueOutOfRange("uint32", option_field->full_name())); + return AddValueError(ValueOutOfRange("uint32", option_field->full_name())); } else { SetUInt32(option_field->number(), uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError(ValueMustBeInt("uint32", option_field->full_name())); + return AddValueError(ValueMustBeInt("uint32", option_field->full_name())); } break; @@ -7760,7 +7760,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError(ValueMustBeInt("uint64", option_field->full_name())); + return AddValueError(ValueMustBeInt("uint64", option_field->full_name())); } break; From 0bc90b189cb6d6f6f66f263dcd0afc84daf12e0d Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Thu, 15 Sep 2022 10:36:26 -0400 Subject: [PATCH 17/39] put helpers into anon namespace --- src/google/protobuf/descriptor.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index ffc8cd628e..81412ffc6c 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -7676,6 +7676,9 @@ bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet( return true; } +namespace { +// Helpers for method below + template std::string ValueOutOfRange( absl::string_view type_name, absl::string_view option_name) { return absl::StrFormat( @@ -7692,6 +7695,8 @@ template std::string ValueMustBeInt( type_name, option_name); } +} // namespace + bool DescriptorBuilder::OptionInterpreter::SetOptionValue( const FieldDescriptor* option_field, UnknownFieldSet* unknown_fields) { // We switch on the CppType to validate. From 9b64c403f6e8a7d03ce53521ad629eec23301d96 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 15 Sep 2022 10:36:44 -0400 Subject: [PATCH 18/39] [ObjC] Clean up includes. - Sort things. - Remove the duplicate (not sure if some automation went wrong at some point). --- .../compiler/objectivec/objectivec_enum.cc | 14 ++++------- .../objectivec/objectivec_extension.cc | 12 ++++------ .../compiler/objectivec/objectivec_field.cc | 14 ++++------- .../compiler/objectivec/objectivec_file.cc | 23 ++++++++----------- .../objectivec/objectivec_generator.cc | 15 +++++------- .../compiler/objectivec/objectivec_helpers.cc | 12 +++++----- .../objectivec/objectivec_map_field.h | 1 + .../compiler/objectivec/objectivec_message.cc | 20 +++++++--------- .../objectivec/objectivec_message_field.h | 1 + .../compiler/objectivec/objectivec_oneof.cc | 12 ++++------ .../compiler/objectivec/objectivec_oneof.h | 3 ++- .../objectivec/objectivec_primitive_field.cc | 12 ++++------ 12 files changed, 56 insertions(+), 83 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index 7e1283b841..28ef44cace 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -28,22 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include #include #include -#include "google/protobuf/compiler/objectivec/objectivec_enum.h" -#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" #include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include // std::find() +#include "google/protobuf/compiler/objectivec/objectivec_enum.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index c70766a6ef..3c20a13ad2 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -30,19 +30,15 @@ #include -#include "google/protobuf/compiler/objectivec/objectivec_extension.h" -#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" #include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" +#include "google/protobuf/compiler/objectivec/objectivec_extension.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index f11cbde086..4397231c58 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -30,22 +30,18 @@ #include +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_replace.h" +#include "absl/strings/str_split.h" +#include "google/protobuf/compiler/objectivec/objectivec_enum_field.h" #include "google/protobuf/compiler/objectivec/objectivec_field.h" #include "google/protobuf/compiler/objectivec/objectivec_helpers.h" -#include "google/protobuf/compiler/objectivec/objectivec_enum_field.h" #include "google/protobuf/compiler/objectivec/objectivec_map_field.h" #include "google/protobuf/compiler/objectivec/objectivec_message_field.h" #include "google/protobuf/compiler/objectivec/objectivec_primitive_field.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index a420c2c69b..72caa47d4f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -28,27 +28,24 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "google/protobuf/compiler/objectivec/objectivec_file.h" +#include +#include +#include + +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_replace.h" +#include "absl/strings/str_split.h" +#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/objectivec/objectivec_enum.h" #include "google/protobuf/compiler/objectivec/objectivec_extension.h" +#include "google/protobuf/compiler/objectivec/objectivec_file.h" #include "google/protobuf/compiler/objectivec/objectivec_helpers.h" #include "google/protobuf/compiler/objectivec/objectivec_message.h" -#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/stubs/stl_util.h" #include "google/protobuf/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include // std::find() -#include -#include // 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 errors. diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index e2efe29b20..9c7acabc63 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -32,20 +32,17 @@ #include #include #include -#include "google/protobuf/compiler/objectivec/objectivec_generator.h" + +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_replace.h" +#include "absl/strings/str_split.h" #include "google/protobuf/compiler/objectivec/objectivec_file.h" +#include "google/protobuf/compiler/objectivec/objectivec_generator.h" #include "google/protobuf/compiler/objectivec/objectivec_helpers.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 1dbff83749..87a5685a4d 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -41,21 +41,21 @@ #include #include +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_replace.h" +#include "absl/strings/str_split.h" #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/objectivec/objectivec_helpers.h" #include "google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/io_win32.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/io_win32.h" #include "google/protobuf/port.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" // 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 errors. @@ -199,7 +199,7 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDesc if (prefix_lookup != package_to_prefix_map_.end()) { return prefix_lookup->second; - } + } return ""; } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index c16e818e2e..20c538e3bb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -33,6 +33,7 @@ #include #include + #include "google/protobuf/compiler/objectivec/objectivec_field.h" namespace google { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 945d095b7e..dd3eacb1d1 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -32,24 +32,20 @@ #include #include -#include "google/protobuf/compiler/objectivec/objectivec_message.h" -#include "google/protobuf/compiler/objectivec/objectivec_enum.h" -#include "google/protobuf/compiler/objectivec/objectivec_extension.h" -#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" -#include "google/protobuf/stubs/stl_util.h" -#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" #include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/io/printer.h" +#include "google/protobuf/compiler/objectivec/objectivec_enum.h" +#include "google/protobuf/compiler/objectivec/objectivec_extension.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_message.h" +#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/stubs/stl_util.h" +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index 12e191eed2..19f23a29e7 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -33,6 +33,7 @@ #include #include + #include "google/protobuf/compiler/objectivec/objectivec_field.h" namespace google { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc b/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc index 269cd52660..dc218dff9f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc @@ -31,18 +31,14 @@ #include #include -#include "google/protobuf/compiler/objectivec/objectivec_oneof.h" -#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" #include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_oneof.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h index 27e9c2a423..c89cdd91b4 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h @@ -31,9 +31,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ -#include #include +#include #include + #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index 2c30d6bac5..824bdbfa8b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -31,18 +31,14 @@ #include #include -#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" -#include "google/protobuf/compiler/objectivec/objectivec_primitive_field.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" #include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_primitive_field.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { From f82be688318afe5f46ea877a576a208d70d83d9d Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Thu, 15 Sep 2022 11:26:13 -0400 Subject: [PATCH 19/39] avoid possible exception; error if octal or hex literal that is too large --- src/google/protobuf/compiler/parser.cc | 11 ++++++++--- .../protobuf/compiler/parser_unittest.cc | 16 ++++++++++++++++ src/google/protobuf/io/tokenizer.cc | 19 ++++++++++++------- src/google/protobuf/io/tokenizer.h | 4 ++++ 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index e5f42c4506..4381307624 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -310,9 +310,14 @@ bool Parser::ConsumeNumber(double* output, const char* error) { std::numeric_limits::max(), &value)) { *output = value; - } else { - // out of int range, treat as double literal - *output = io::Tokenizer::ParseFloat(input_->current().text); + } else if (input_->current().text[0] == '0') { + // octal or hexadecimal; don't bother parsing as float + AddError("Integer out of range."); + // We still return true because we did, in fact, parse a number. + } else if (!io::Tokenizer::TryParseFloat(input_->current().text, output)) { + // out of int range, and not valid float? 🤷 + AddError("Integer out of range."); + // We still return true because we did, in fact, parse a number. } input_->Next(); return true; diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 7685371c14..39d5b60744 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -1941,6 +1941,22 @@ TEST_F(ParserValidationErrorTest, FieldDefaultValueError) { "2:32: Enum type \"Baz\" has no value named \"NO_SUCH_VALUE\".\n"); } +TEST_F(ParserValidationErrorTest, FieldDefaultIntegerOutOfRange) { + ExpectHasErrors( + "message Foo {\n" + " optional double bar = 1 [default = 0x10000000000000000];\n" + "}\n", + "1:37: Integer out of range.\n"); +} + +TEST_F(ParserValidationErrorTest, FieldOptionOutOfRange) { + ExpectHasErrors( + "message Foo {\n" + " optional double bar = 1 [foo = 0x10000000000000000];\n" + "}\n", + "1:33: Integer out of range.\n"); +} + TEST_F(ParserValidationErrorTest, FileOptionNameError) { ExpectHasValidationErrors( "option foo = 5;", diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc index 7bc0820dd8..127fb5a402 100644 --- a/src/google/protobuf/io/tokenizer.cc +++ b/src/google/protobuf/io/tokenizer.cc @@ -1002,9 +1002,19 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value, } double Tokenizer::ParseFloat(const std::string& text) { + double result; + GOOGLE_LOG_IF(DFATAL, + !TryParseFloat(text, &result)) + << " Tokenizer::ParseFloat() passed text that could not have been" + " tokenized as a float: " + << absl::CEscape(text); + return result; +} + +bool Tokenizer::TryParseFloat(const std::string& text, double* result) { const char* start = text.c_str(); char* end; - double result = NoLocaleStrtod(start, &end); + *result = NoLocaleStrtod(start, &end); // "1e" is not a valid float, but if the tokenizer reads it, it will // report an error but still return it as a valid token. We need to @@ -1020,12 +1030,7 @@ double Tokenizer::ParseFloat(const std::string& text) { ++end; } - GOOGLE_LOG_IF(DFATAL, - static_cast(end - start) != text.size() || *start == '-') - << " Tokenizer::ParseFloat() passed text that could not have been" - " tokenized as a float: " - << absl::CEscape(text); - return result; + return static_cast(end - start) == text.size() && *start != '-'; } // Helper to append a Unicode code point to a string as UTF8, without bringing diff --git a/src/google/protobuf/io/tokenizer.h b/src/google/protobuf/io/tokenizer.h index cab1faf917..73877ccc24 100644 --- a/src/google/protobuf/io/tokenizer.h +++ b/src/google/protobuf/io/tokenizer.h @@ -214,6 +214,10 @@ class PROTOBUF_EXPORT Tokenizer { // result is undefined (possibly an assert failure). static double ParseFloat(const std::string& text); + // Parses given text as if it were a TYPE_FLOAT token. Returns false if the + // given text is not actually a valid float literal. + static bool TryParseFloat(const std::string& text, double* result); + // Parses a TYPE_STRING token. This never fails, so long as the text actually // comes from a TYPE_STRING token parsed by Tokenizer. If it doesn't, the // result is undefined (possibly an assert failure). From b67bd3309b8a92a279fc43653d3a7d4a698ea11c Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 15 Sep 2022 10:05:11 -0400 Subject: [PATCH 20/39] [ObjC] Add helper for IsCreateName for the CF Create Rule. Also add tests for all of the Is*Name helpers. --- .../compiler/objectivec/objectivec_helpers.cc | 49 +++++++++-- .../compiler/objectivec/objectivec_helpers.h | 4 + .../objectivec/objectivec_helpers_unittest.cc | 84 +++++++++++++++++++ 3 files changed, 129 insertions(+), 8 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 87a5685a4d..f4a36936c0 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -513,13 +513,14 @@ void PathSplit(const std::string& path, std::string* directory, } } -bool IsSpecialName(const std::string& name, const std::string* special_names, - size_t count) { +bool IsSpecialNamePrefix(const std::string& name, + const std::string* special_names, + size_t count) { for (size_t i = 0; i < count; ++i) { - size_t length = special_names[i].length(); + const size_t length = special_names[i].length(); if (name.compare(0, length, special_names[i]) == 0) { if (name.length() > length) { - // If name is longer than the retained_name[i] that it matches + // If name is longer than the special_names[i] that it matches // the next character must be not lower case (newton vs newTon vs // new_ton). return !absl::ascii_islower(name[length]); @@ -589,14 +590,46 @@ bool IsRetainedName(const std::string& name) { // http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html static const std::string retained_names[] = {"new", "alloc", "copy", "mutableCopy"}; - return IsSpecialName(name, retained_names, - sizeof(retained_names) / sizeof(retained_names[0])); + return IsSpecialNamePrefix(name, retained_names, + sizeof(retained_names) / sizeof(retained_names[0])); } bool IsInitName(const std::string& name) { static const std::string init_names[] = {"init"}; - return IsSpecialName(name, init_names, - sizeof(init_names) / sizeof(init_names[0])); + return IsSpecialNamePrefix(name, init_names, + sizeof(init_names) / sizeof(init_names[0])); +} + +bool IsCreateName(const std::string& name) { + // List of segments from + // https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029 + static const std::string create_names[] = {"Create", "Copy"}; + const size_t count = sizeof(create_names) / sizeof(create_names[0]); + + for (size_t i = 0; i < count; ++i) { + const size_t length = create_names[i].length(); + size_t pos = name.find(create_names[i]); + if (pos != std::string::npos) { + // The above docs don't actually call out anything about the characters + // before the special words. So it's not clear if something like + // "FOOCreate" would or would not match the "The Create Rule", but by not + // checking, and claiming it does match, then callers will annotate with + // `cf_returns_not_retained` which will ensure things work as desired. + // + // The footnote here is the docs do have a passing reference to "NoCopy", + // but again, not looking for that and just returning `true` will cause + // callers to annotate the api as not being a Create Rule function. + + // If name is longer than the create_names[i] that it matches the next + // character must be not lower case (Copyright vs CopyFoo vs Copy_Foo). + if (name.length() > pos + length) { + return !absl::ascii_islower(name[pos + length]); + } else { + return true; + } + } + } + return false; } std::string BaseFileName(const FileDescriptor* file) { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 9cee305080..79a9643c17 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -92,6 +92,10 @@ bool PROTOC_EXPORT IsRetainedName(const std::string& name); // handling under ARC. bool PROTOC_EXPORT IsInitName(const std::string& name); +// Returns true if the name requires a cf_returns_not_retained attribute applied +// to it. +bool PROTOC_EXPORT IsCreateName(const std::string& name); + // Gets the objc_class_prefix or the prefix made from the proto package. std::string PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 7ad11f04cb..0ae2451464 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -369,6 +369,90 @@ TEST(ObjCHelper, ParseSimple_RejectLinesNoMessage) { } } +TEST(ObjCHelper, IsRetainedName) { + EXPECT_TRUE(IsRetainedName("new")); + EXPECT_TRUE(IsRetainedName("alloc")); + EXPECT_TRUE(IsRetainedName("copy")); + EXPECT_TRUE(IsRetainedName("mutableCopy")); + EXPECT_TRUE(IsRetainedName("newFoo")); + EXPECT_TRUE(IsRetainedName("allocFoo")); + EXPECT_TRUE(IsRetainedName("copyFoo")); + EXPECT_TRUE(IsRetainedName("mutableCopyFoo")); + EXPECT_TRUE(IsRetainedName("new_foo")); + EXPECT_TRUE(IsRetainedName("alloc_foo")); + EXPECT_TRUE(IsRetainedName("copy_foo")); + EXPECT_TRUE(IsRetainedName("mutableCopy_foo")); + + EXPECT_FALSE(IsRetainedName("")); + EXPECT_FALSE(IsRetainedName("ne")); + EXPECT_FALSE(IsRetainedName("all")); + EXPECT_FALSE(IsRetainedName("co")); + EXPECT_FALSE(IsRetainedName("mutable")); + EXPECT_FALSE(IsRetainedName("New")); + EXPECT_FALSE(IsRetainedName("Alloc")); + EXPECT_FALSE(IsRetainedName("Copy")); + EXPECT_FALSE(IsRetainedName("MutableCopy")); + EXPECT_FALSE(IsRetainedName("newer")); + EXPECT_FALSE(IsRetainedName("alloced")); + EXPECT_FALSE(IsRetainedName("copying")); + EXPECT_FALSE(IsRetainedName("mutableCopying")); + + EXPECT_FALSE(IsRetainedName("init")); + EXPECT_FALSE(IsRetainedName("Create")); + EXPECT_FALSE(IsRetainedName("Copy")); +} + +TEST(ObjCHelper, IsInitName) { + EXPECT_TRUE(IsInitName("init")); + EXPECT_TRUE(IsInitName("initFoo")); + EXPECT_TRUE(IsInitName("init_foo")); + + EXPECT_FALSE(IsInitName("")); + EXPECT_FALSE(IsInitName("in")); + EXPECT_FALSE(IsInitName("Init")); + EXPECT_FALSE(IsInitName("inIt")); + EXPECT_FALSE(IsInitName("initial")); + EXPECT_FALSE(IsInitName("initiAl")); + EXPECT_FALSE(IsInitName("fooInit")); + EXPECT_FALSE(IsInitName("foo_init")); + + EXPECT_FALSE(IsInitName("new")); + EXPECT_FALSE(IsInitName("alloc")); + EXPECT_FALSE(IsInitName("copy")); + EXPECT_FALSE(IsInitName("mutableCopy")); + EXPECT_FALSE(IsInitName("Create")); + EXPECT_FALSE(IsInitName("Copy")); +} + +TEST(ObjCHelper, IsCreateName) { + EXPECT_TRUE(IsCreateName("Create")); + EXPECT_TRUE(IsCreateName("Copy")); + EXPECT_TRUE(IsCreateName("CreateFoo")); + EXPECT_TRUE(IsCreateName("CopyFoo")); + EXPECT_TRUE(IsCreateName("Create_foo")); + EXPECT_TRUE(IsCreateName("Copy_foo")); + EXPECT_TRUE(IsCreateName("ReCreate")); + EXPECT_TRUE(IsCreateName("ReCopy")); + EXPECT_TRUE(IsCreateName("FOOCreate")); + EXPECT_TRUE(IsCreateName("FOOCopy")); + EXPECT_TRUE(IsCreateName("CreateWithCopy")); + + EXPECT_FALSE(IsCreateName("")); + EXPECT_FALSE(IsCreateName("Crea")); + EXPECT_FALSE(IsCreateName("Co")); + EXPECT_FALSE(IsCreateName("create")); + EXPECT_FALSE(IsCreateName("recreate")); + EXPECT_FALSE(IsCreateName("recopy")); + EXPECT_FALSE(IsCreateName("ReCreated")); + EXPECT_FALSE(IsCreateName("ReCopying")); + + EXPECT_FALSE(IsCreateName("init")); + EXPECT_FALSE(IsCreateName("new")); + EXPECT_FALSE(IsCreateName("alloc")); + EXPECT_FALSE(IsCreateName("copy")); + EXPECT_TRUE(IsCreateName("mutableCopy")); +} + // TODO(thomasvl): Should probably add some unittests for all the special cases // of name mangling (class name, field name, enum names). Rather than doing // this with an ObjC test in the objectivec directory, we should be able to From 3c01924679c4a96b7fb8ded2b0333c7c8dc1c3cb Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 14 Sep 2022 09:55:55 -0400 Subject: [PATCH 21/39] [ObjC] Move generation options out to their own file. This will make it easier to pass the option down in the future to the other parts (message, enum, extension, etc. generators) as needed. --- src/file_lists.cmake | 1 + .../protobuf/compiler/objectivec/BUILD.bazel | 1 + .../compiler/objectivec/objectivec_file.h | 12 +--- .../objectivec/objectivec_generator.cc | 2 +- .../compiler/objectivec/objectivec_options.h | 56 +++++++++++++++++++ 5 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/google/protobuf/compiler/objectivec/objectivec_options.h diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 0d6a9f850e..be3d61ee14 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -456,6 +456,7 @@ set(libprotoc_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_oneof.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_options.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h diff --git a/src/google/protobuf/compiler/objectivec/BUILD.bazel b/src/google/protobuf/compiler/objectivec/BUILD.bazel index defcf29183..ee2ef1f0e0 100644 --- a/src/google/protobuf/compiler/objectivec/BUILD.bazel +++ b/src/google/protobuf/compiler/objectivec/BUILD.bazel @@ -35,6 +35,7 @@ cc_library( "objectivec_message_field.h", "objectivec_nsobject_methods.h", "objectivec_oneof.h", + "objectivec_options.h", "objectivec_primitive_field.h", ], copts = COPTS, diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h index 842ddff154..5063611923 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -35,6 +35,7 @@ #include #include #include +#include "google/protobuf/compiler/objectivec/objectivec_options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -49,17 +50,6 @@ class MessageGenerator; class FileGenerator { public: - struct GenerationOptions { - GenerationOptions() - // TODO(thomasvl): Eventually flip this default to false for better - // interop with Swift if proto usages span modules made from ObjC sources. - : headers_use_forward_declarations(true) {} - std::string generate_for_named_framework; - std::string named_framework_to_proto_path_mappings_path; - std::string runtime_import_prefix; - bool headers_use_forward_declarations; - }; - // Wrapper for some common state that is shared between file generations to // improve performance when more than one file is generated at a time. struct CommonState { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 9c7acabc63..225a7d207e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -100,7 +100,7 @@ bool ObjectiveCGenerator::GenerateAll( // e.g. protoc ... --objc_opt=expected_prefixes=file.txt,generate_for_named_framework=MyFramework Options validation_options; - FileGenerator::GenerationOptions generation_options; + GenerationOptions generation_options; std::vector > options; ParseGeneratorParameter(parameter, &options); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_options.h b/src/google/protobuf/compiler/objectivec/objectivec_options.h new file mode 100644 index 0000000000..07b90b3d69 --- /dev/null +++ b/src/google/protobuf/compiler/objectivec/objectivec_options.h @@ -0,0 +1,56 @@ +// 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. + +#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_OPTIONS_H__ +#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_OPTIONS_H__ + +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace objectivec { + +// Generation options, documented within objectivec_generator.cc. +struct GenerationOptions { + std::string generate_for_named_framework; + std::string named_framework_to_proto_path_mappings_path; + std::string runtime_import_prefix; + // TODO(thomasvl): Eventually flip this default to false for better interop + // with Swift if proto usages span modules made from ObjC sources. + bool headers_use_forward_declarations = true; +}; + +} // namespace objectivec +} // namespace compiler +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_OPTIONS_H__ From d6acffba7bf67e8f928acf1cc676056919ad19e3 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Thu, 15 Sep 2022 13:37:59 -0400 Subject: [PATCH 22/39] use normal conditional --- src/google/protobuf/io/tokenizer.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc index 127fb5a402..d14c5a1926 100644 --- a/src/google/protobuf/io/tokenizer.cc +++ b/src/google/protobuf/io/tokenizer.cc @@ -1003,11 +1003,12 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value, double Tokenizer::ParseFloat(const std::string& text) { double result; - GOOGLE_LOG_IF(DFATAL, - !TryParseFloat(text, &result)) - << " Tokenizer::ParseFloat() passed text that could not have been" - " tokenized as a float: " - << absl::CEscape(text); + if (!TryParseFloat(text, &result)) { + LOG(DFATAL) + << " Tokenizer::ParseFloat() passed text that could not have been" + " tokenized as a float: " + << absl::CEscape(text); + } return result; } From 0362a1204f269161fe20e53ff1184440bdeeb792 Mon Sep 17 00:00:00 2001 From: Joshua Humphries Date: Thu, 15 Sep 2022 14:01:43 -0400 Subject: [PATCH 23/39] initialize var to avoid undefined return val --- src/google/protobuf/io/tokenizer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc index d14c5a1926..d7f100dbbd 100644 --- a/src/google/protobuf/io/tokenizer.cc +++ b/src/google/protobuf/io/tokenizer.cc @@ -1002,7 +1002,7 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value, } double Tokenizer::ParseFloat(const std::string& text) { - double result; + double result = 0; if (!TryParseFloat(text, &result)) { LOG(DFATAL) << " Tokenizer::ParseFloat() passed text that could not have been" From 7e745c4910630f49b243c7f8d1db2050bdb4ff01 Mon Sep 17 00:00:00 2001 From: Joshua Humphries Date: Thu, 15 Sep 2022 15:24:48 -0400 Subject: [PATCH 24/39] oops, fix name: LOG -> GOOGLE_LOG --- src/google/protobuf/io/tokenizer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc index d7f100dbbd..4fcf81b3dc 100644 --- a/src/google/protobuf/io/tokenizer.cc +++ b/src/google/protobuf/io/tokenizer.cc @@ -1004,7 +1004,7 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value, double Tokenizer::ParseFloat(const std::string& text) { double result = 0; if (!TryParseFloat(text, &result)) { - LOG(DFATAL) + GOOGLE_LOG(DFATAL) << " Tokenizer::ParseFloat() passed text that could not have been" " tokenized as a float: " << absl::CEscape(text); From b6a3f6eb98ab0fc96d6ff7d66d4b77dc12cbb827 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 16 Sep 2022 17:55:33 +0000 Subject: [PATCH 25/39] Add public modifier --- .../protobuf/compiler/java/enum_field.cc | 22 +++++----- .../protobuf/compiler/java/enum_field_lite.cc | 22 +++++----- .../protobuf/compiler/java/map_field.cc | 12 +++--- .../protobuf/compiler/java/map_field_lite.cc | 14 +++---- src/google/protobuf/compiler/java/message.cc | 38 +++++++++--------- .../protobuf/compiler/java/message_field.cc | 24 +++++------ .../compiler/java/message_field_lite.cc | 24 +++++------ .../protobuf/compiler/java/message_lite.cc | 40 +++++++++---------- .../protobuf/compiler/java/primitive_field.cc | 22 +++++----- .../compiler/java/primitive_field_lite.cc | 22 +++++----- .../protobuf/compiler/java/string_field.cc | 22 +++++----- .../compiler/java/string_field_lite.cc | 22 +++++----- 12 files changed, 142 insertions(+), 142 deletions(-) diff --git a/src/google/protobuf/compiler/java/enum_field.cc b/src/google/protobuf/compiler/java/enum_field.cc index ea74d8bc6f..ab799f026c 100644 --- a/src/google/protobuf/compiler/java/enum_field.cc +++ b/src/google/protobuf/compiler/java/enum_field.cc @@ -276,7 +276,7 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ var $kt_name$: $kt_type$\n" + "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -299,7 +299,7 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -308,7 +308,7 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); } @@ -1085,12 +1085,12 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -1103,7 +1103,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "add(value: $kt_type$) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -1115,7 +1115,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(value: $kt_type$) {\n" " add(value)\n" @@ -1126,7 +1126,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -1139,7 +1139,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n" " addAll(values)\n" @@ -1151,7 +1151,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "set(index: kotlin.Int, value: $kt_type$) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -1162,7 +1162,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/enum_field_lite.cc b/src/google/protobuf/compiler/java/enum_field_lite.cc index 713f805f98..c221a33368 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -311,7 +311,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: $kt_type$\n" + "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -334,7 +334,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -343,7 +343,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); } @@ -870,12 +870,12 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -888,7 +888,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "add(value: $kt_type$) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -900,7 +900,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(value: $kt_type$) {\n" " add(value)\n" @@ -911,7 +911,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -924,7 +924,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n" " addAll(values)\n" @@ -936,7 +936,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "set(index: kotlin.Int, value: $kt_type$) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -947,7 +947,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index 66d7fbb9c5..d741ca472e 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -727,13 +727,13 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print( variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -746,7 +746,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( printer->Print( variables_, "@JvmName(\"put$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .put(key: $kt_key_type$, value: $kt_value_type$) {\n" " $kt_dsl_builder$.${$put$capitalized_name$$}$(key, value)\n" @@ -758,7 +758,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"set$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslMap" + "public inline operator fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .set(key: $kt_key_type$, value: $kt_value_type$) {\n" " put(key, value)\n" @@ -769,7 +769,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"remove$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .remove(key: $kt_key_type$) {\n" " $kt_dsl_builder$.${$remove$capitalized_name$$}$(key)\n" @@ -780,7 +780,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"putAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .putAll(map: kotlin.collections.Map<$kt_key_type$, $kt_value_type$>) " "{\n" diff --git a/src/google/protobuf/compiler/java/map_field_lite.cc b/src/google/protobuf/compiler/java/map_field_lite.cc index e116d1ebb6..471bbdaab9 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/src/google/protobuf/compiler/java/map_field_lite.cc @@ -871,13 +871,13 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print( variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -890,7 +890,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print( variables_, "@JvmName(\"put$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .put(key: $kt_key_type$, value: $kt_value_type$) {\n" " $kt_dsl_builder$.${$put$capitalized_name$$}$(key, value)\n" @@ -902,7 +902,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"set$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslMap" + "public inline operator fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .set(key: $kt_key_type$, value: $kt_value_type$) {\n" " put(key, value)\n" @@ -913,7 +913,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"remove$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .remove(key: $kt_key_type$) {\n" " $kt_dsl_builder$.${$remove$capitalized_name$$}$(key)\n" @@ -924,7 +924,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"putAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .putAll(map: kotlin.collections.Map<$kt_key_type$, $kt_value_type$>) " "{\n" @@ -936,7 +936,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index 52768bb477..55f486e3ee 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -1409,10 +1409,10 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const { "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" "@com.google.protobuf.kotlin.ProtoDslMarker\n"); printer->Print( - "class Dsl private constructor(\n" + "public class Dsl private constructor(\n" " private val _builder: $message$.Builder\n" ") {\n" - " companion object {\n" + " public companion object {\n" " @kotlin.jvm.JvmSynthetic\n" " @kotlin.PublishedApi\n" " internal fun _create(builder: $message$.Builder): Dsl = " @@ -1435,10 +1435,10 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const { for (auto oneof : oneofs_) { printer->Print( - "val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n" + "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n" " @JvmName(\"get$oneof_capitalized_name$Case\")\n" " get() = _builder.get$oneof_capitalized_name$Case()\n\n" - "fun clear$oneof_capitalized_name$() {\n" + "public fun clear$oneof_capitalized_name$() {\n" " _builder.clear$oneof_capitalized_name$()\n" "}\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name, @@ -1466,7 +1466,7 @@ void ImmutableMessageGenerator::GenerateKotlinMembers( } printer->Print( - "inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> " + "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> " "kotlin.Unit): " "$message$ " "=\n" @@ -1480,7 +1480,7 @@ void ImmutableMessageGenerator::GenerateKotlinMembers( EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); WriteMessageDocComment(printer, descriptor_, /* kdoc */ true); - printer->Print("object $name$Kt {\n", "name", descriptor_->name()); + printer->Print("public object $name$Kt {\n", "name", descriptor_->name()); printer->Indent(); GenerateKotlinDsl(printer); for (int i = 0; i < descriptor_->nested_type_count(); i++) { @@ -1501,7 +1501,7 @@ void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers( } printer->Print( - "inline fun $message$.copy(block: $message_kt$.Dsl.() -> " + "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> " "kotlin.Unit): $message$ =\n" " $message_kt$.Dsl._create(this.toBuilder()).apply { block() " "}._build()\n\n", @@ -1546,7 +1546,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@Suppress(\"UNCHECKED_CAST\")\n" "@kotlin.jvm.JvmSynthetic\n" - "operator fun get(extension: " + "public operator fun get(extension: " "com.google.protobuf.ExtensionLite<$message$, T>): T {\n" " return if (extension.isRepeated) {\n" " get(extension as com.google.protobuf.ExtensionLite<$message$, " @@ -1562,7 +1562,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" "@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n" - "operator fun get(\n" + "public operator fun get(\n" " extension: com.google.protobuf.ExtensionLite<$message$, List>\n" "): com.google.protobuf.kotlin.ExtensionList {\n" " return com.google.protobuf.kotlin.ExtensionList(extension, " @@ -1572,7 +1572,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "operator fun contains(extension: " + "public operator fun contains(extension: " "com.google.protobuf.ExtensionLite<$message$, *>): " "Boolean {\n" " return _builder.hasExtension(extension)\n" @@ -1581,7 +1581,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "fun clear(extension: " + "public fun clear(extension: " "com.google.protobuf.ExtensionLite<$message$, *>) " "{\n" " _builder.clearExtension(extension)\n" @@ -1601,7 +1601,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun > set(\n" + "public inline operator fun > set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n" " value: T\n" ") {\n" @@ -1612,7 +1612,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun set(\n" + "public inline operator fun set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, " "com.google.protobuf.ByteString>,\n" " value: com.google.protobuf.ByteString\n" @@ -1634,7 +1634,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.add(value: E) {\n" " _builder.addExtension(this.extension, value)\n" "}\n\n", @@ -1643,7 +1643,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign" "(value: E) {\n" @@ -1653,7 +1653,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.addAll(values: Iterable) {\n" " for (value in values) {\n" " add(value)\n" @@ -1664,7 +1664,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign(values: " "Iterable) {\n" @@ -1674,7 +1674,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "operator fun " + "public operator fun " "com.google.protobuf.kotlin.ExtensionList.set(index: Int, value: " "E) {\n" @@ -1685,7 +1685,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline fun com.google.protobuf.kotlin.ExtensionList<*, " + "public inline fun com.google.protobuf.kotlin.ExtensionList<*, " "$message$>.clear() {\n" " clear(extension)\n" "}\n\n", diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 32da1b74eb..c51c71a020 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -426,7 +426,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: $kt_type$\n" + "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -437,7 +437,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -445,7 +445,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); @@ -455,7 +455,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( void ImmutableMessageFieldGenerator::GenerateKotlinOrNull(io::Printer* printer) const { if (descriptor_->has_optional_keyword()) { printer->Print(variables_, - "val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" + "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" " get() = $kt_dsl_builder$.$name$OrNull\n"); } } @@ -1425,12 +1425,12 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -1443,7 +1443,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "add(value: $kt_type$) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -1455,7 +1455,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(value: $kt_type$) {\n" " add(value)\n" @@ -1466,7 +1466,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -1479,7 +1479,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n" " addAll(values)\n" @@ -1491,7 +1491,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "set(index: kotlin.Int, value: $kt_type$) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -1502,7 +1502,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index ad685eb26d..5a05939c95 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -293,7 +293,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: $kt_type$\n" + "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -304,7 +304,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -312,7 +312,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); GenerateKotlinOrNull(printer); @@ -321,7 +321,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( void ImmutableMessageFieldLiteGenerator::GenerateKotlinOrNull(io::Printer* printer) const { if (descriptor_->has_optional_keyword()) { printer->Print(variables_, - "val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" + "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" " get() = $kt_dsl_builder$.$name$OrNull\n"); } } @@ -819,12 +819,12 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -837,7 +837,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "add(value: $kt_type$) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -849,7 +849,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(value: $kt_type$) {\n" " add(value)\n" @@ -860,7 +860,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -873,7 +873,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n" " addAll(values)\n" @@ -885,7 +885,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "set(index: kotlin.Int, value: $kt_type$) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -896,7 +896,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index fc98ef5009..504e072bee 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -746,10 +746,10 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl( "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" "@com.google.protobuf.kotlin.ProtoDslMarker\n"); printer->Print( - "class Dsl private constructor(\n" + "public class Dsl private constructor(\n" " private val _builder: $message$.Builder\n" ") {\n" - " companion object {\n" + " public companion object {\n" " @kotlin.jvm.JvmSynthetic\n" " @kotlin.PublishedApi\n" " internal fun _create(builder: $message$.Builder): Dsl = " @@ -772,10 +772,10 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl( for (auto oneof : oneofs_) { printer->Print( - "val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n" + "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n" " @JvmName(\"get$oneof_capitalized_name$Case\")\n" " get() = _builder.get$oneof_capitalized_name$Case()\n\n" - "fun clear$oneof_capitalized_name$() {\n" + "public fun clear$oneof_capitalized_name$() {\n" " _builder.clear$oneof_capitalized_name$()\n" "}\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name, @@ -802,7 +802,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinMembers( printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n"); } printer->Print( - "inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> " + "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> " "kotlin.Unit): $message$ =\n" " $message_kt$.Dsl._create($message$.newBuilder()).apply { block() " "}._build()\n", @@ -814,7 +814,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinMembers( EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); WriteMessageDocComment(printer, descriptor_, /* kdoc */ true); - printer->Print("object $name$Kt {\n", "name", descriptor_->name()); + printer->Print("public object $name$Kt {\n", "name", descriptor_->name()); printer->Indent(); GenerateKotlinDsl(printer); for (int i = 0; i < descriptor_->nested_type_count(); i++) { @@ -832,7 +832,7 @@ void ImmutableMessageLiteGenerator::GenerateTopLevelKotlinMembers( printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n"); } printer->Print( - "inline fun $message$.copy(block: $message_kt$.Dsl.() -> " + "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> " "kotlin.Unit): $message$ =\n" " $message_kt$.Dsl._create(this.toBuilder()).apply { block() " "}._build()\n\n", @@ -879,7 +879,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@Suppress(\"UNCHECKED_CAST\")\n" "@kotlin.jvm.JvmSynthetic\n" - "operator fun get(extension: " + "public operator fun get(extension: " "com.google.protobuf.ExtensionLite<$message$, T>): T {\n" " return if (extension.isRepeated) {\n" " get(extension as com.google.protobuf.ExtensionLite<$message$, " @@ -895,7 +895,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" "@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n" - "operator fun get(\n" + "public operator fun get(\n" " extension: com.google.protobuf.ExtensionLite<$message$, List>\n" "): com.google.protobuf.kotlin.ExtensionList {\n" " return com.google.protobuf.kotlin.ExtensionList(extension, " @@ -905,7 +905,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "operator fun contains(extension: " + "public operator fun contains(extension: " "com.google.protobuf.ExtensionLite<$message$, *>): " "Boolean {\n" " return _builder.hasExtension(extension)\n" @@ -914,7 +914,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "fun clear(extension: " + "public fun clear(extension: " "com.google.protobuf.ExtensionLite<$message$, *>) " "{\n" " _builder.clearExtension(extension)\n" @@ -934,7 +934,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun > set(\n" + "public inline operator fun > set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n" " value: T\n" ") {\n" @@ -945,7 +945,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun set(\n" + "public inline operator fun set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, " "com.google.protobuf.ByteString>,\n" " value: com.google.protobuf.ByteString\n" @@ -957,7 +957,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun set(\n" + "public inline operator fun set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n" " value: T\n" ") {\n" @@ -967,7 +967,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.add(value: E) {\n" " _builder.addExtension(this.extension, value)\n" "}\n\n", @@ -976,7 +976,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign" "(value: E) {\n" @@ -986,7 +986,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.addAll(values: Iterable) {\n" " for (value in values) {\n" " add(value)\n" @@ -997,7 +997,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign(values: " "Iterable) {\n" @@ -1007,7 +1007,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "operator fun " + "public operator fun " "com.google.protobuf.kotlin.ExtensionList.set(index: Int, value: " "E) {\n" @@ -1018,7 +1018,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline fun com.google.protobuf.kotlin.ExtensionList<*, " + "public inline fun com.google.protobuf.kotlin.ExtensionList<*, " "$message$>.clear() {\n" " clear(extension)\n" "}\n\n", diff --git a/src/google/protobuf/compiler/java/primitive_field.cc b/src/google/protobuf/compiler/java/primitive_field.cc index 3706ef164f..aae9b324d7 100644 --- a/src/google/protobuf/compiler/java/primitive_field.cc +++ b/src/google/protobuf/compiler/java/primitive_field.cc @@ -324,7 +324,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: $kt_type$\n" + "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -335,7 +335,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -344,7 +344,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); } @@ -854,12 +854,12 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -872,7 +872,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "add(value: $kt_type$) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -884,7 +884,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(value: $kt_type$) {\n" " add(value)\n" @@ -895,7 +895,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -908,7 +908,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n" " addAll(values)\n" @@ -920,7 +920,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "set(index: kotlin.Int, value: $kt_type$) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -931,7 +931,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.cc b/src/google/protobuf/compiler/java/primitive_field_lite.cc index 28066bb6b2..b7ff8912c3 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/primitive_field_lite.cc @@ -344,7 +344,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: $kt_type$\n" + "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -355,7 +355,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -364,7 +364,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); } @@ -691,12 +691,12 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " @kotlin.jvm.JvmSynthetic\n" @@ -709,7 +709,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "add(value: $kt_type$) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -721,7 +721,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(value: $kt_type$) {\n" " add(value)\n" @@ -732,7 +732,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -745,7 +745,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n" " addAll(values)\n" @@ -757,7 +757,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "set(index: kotlin.Int, value: $kt_type$) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -768,7 +768,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/string_field.cc b/src/google/protobuf/compiler/java/string_field.cc index d8b5d4ef6f..a40d473149 100644 --- a/src/google/protobuf/compiler/java/string_field.cc +++ b/src/google/protobuf/compiler/java/string_field.cc @@ -383,7 +383,7 @@ void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: kotlin.String\n" + "$kt_deprecation$public var $kt_name$: kotlin.String\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -394,7 +394,7 @@ void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -403,7 +403,7 @@ void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); } @@ -968,14 +968,14 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); // property for List WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "\n" " @kotlin.jvm.JvmSynthetic\n" @@ -989,7 +989,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "." "add(value: kotlin.String) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -1002,7 +1002,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(value: kotlin.String) {\n" " add(value)\n" @@ -1015,7 +1015,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "." "addAll(values: kotlin.collections.Iterable) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -1029,7 +1029,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(values: kotlin.collections.Iterable) {\n" " addAll(values)\n" @@ -1042,7 +1042,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "." "set(index: kotlin.Int, value: kotlin.String) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -1053,7 +1053,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" diff --git a/src/google/protobuf/compiler/java/string_field_lite.cc b/src/google/protobuf/compiler/java/string_field_lite.cc index 2551d395cc..73e849917a 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.cc +++ b/src/google/protobuf/compiler/java/string_field_lite.cc @@ -342,7 +342,7 @@ void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); printer->Print(variables_, - "$kt_deprecation$var $kt_name$: kotlin.String\n" + "$kt_deprecation$public var $kt_name$: kotlin.String\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" " get() = $kt_dsl_builder$.${$get$capitalized_name$$}$()\n" " @JvmName(\"${$set$kt_capitalized_name$$}$\")\n" @@ -353,7 +353,7 @@ void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ false, /* kdoc */ true); printer->Print(variables_, - "fun ${$clear$kt_capitalized_name$$}$() {\n" + "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); @@ -362,7 +362,7 @@ void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" + "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" " return $kt_dsl_builder$.${$has$capitalized_name$$}$()\n" "}\n"); } @@ -788,7 +788,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( " */\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - "class ${$$kt_capitalized_name$Proxy$}$ private constructor()" + "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); // property for List @@ -796,7 +796,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print( variables_, - "$kt_deprecation$ val $kt_name$: " + "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "\n" "@kotlin.OptIn" @@ -811,7 +811,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "." "add(value: kotlin.String) {\n" " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" @@ -824,7 +824,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(value: kotlin.String) {\n" " add(value)\n" @@ -837,7 +837,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "." "addAll(values: kotlin.collections.Iterable) {\n" " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" @@ -851,7 +851,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun com.google.protobuf.kotlin.DslList" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(values: kotlin.collections.Iterable) {\n" " addAll(values)\n" @@ -864,7 +864,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"set$kt_capitalized_name$\")\n" - "operator fun com.google.protobuf.kotlin.DslList" + "public operator fun com.google.protobuf.kotlin.DslList" "." "set(index: kotlin.Int, value: kotlin.String) {\n" " $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n" @@ -875,7 +875,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslList" + "public fun com.google.protobuf.kotlin.DslList" "." "clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" From 47a3ccf75666cd588d1c9b69beef3660e4d0bbc3 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 16 Sep 2022 17:59:00 +0000 Subject: [PATCH 26/39] Add missing public --- src/google/protobuf/compiler/java/map_field.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index d741ca472e..0a59a32e35 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -792,7 +792,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( variables_, "@kotlin.jvm.JvmSynthetic\n" "@JvmName(\"clear$kt_capitalized_name$\")\n" - "fun com.google.protobuf.kotlin.DslMap" + "public fun com.google.protobuf.kotlin.DslMap" "<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n" " .clear() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" From 42ce332a5f4cd471c2f35e07fb9fea6251e20cbb Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 16 Sep 2022 18:07:52 +0000 Subject: [PATCH 27/39] Add missing modifier --- src/google/protobuf/compiler/java/message.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index 55f486e3ee..af64911e97 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -1624,7 +1624,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "inline operator fun set(\n" + "public inline operator fun set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n" " value: T\n" ") {\n" From 2202cc8d3302c2a7bf9624bc1fda63e7a5557a6d Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 16 Sep 2022 12:39:56 -0400 Subject: [PATCH 28/39] Add clang-format for some things are well formatted already. The sources haven't yet been reformatted, there are lots of Print() calls that end up worse, but those should probably get revisit to Emit() instead. --- .../protobuf/compiler/objectivec/objectivec_generator.h | 2 ++ .../protobuf/compiler/objectivec/objectivec_helpers.h | 2 ++ .../compiler/objectivec/objectivec_helpers_unittest.cc | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.h b/src/google/protobuf/compiler/objectivec/objectivec_generator.h index f863fc8686..acd9ce895f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.h @@ -37,7 +37,9 @@ #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/descriptor.h" +// clang-format off #include "google/protobuf/port_def.inc" +// clang-format on namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 79a9643c17..a0a8d5b6e8 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -40,7 +40,9 @@ #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/zero_copy_stream.h" +// clang-format off #include "google/protobuf/port_def.inc" +// clang-format on namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 0ae2451464..e6d0a7c613 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -101,10 +101,12 @@ TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_ByteCodes) { // Long name so multiple decode ops are needed. + // clang-format off input_for_decode = "longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000"; desired_output_for_decode = "long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000"; + // clang-format on expected = std::string("\x04\xA5\xA4\xA2\xBF\x1F\x0E\x84\x0", 9); result = TextFormatDecodeData::DecodeDataForString(input_for_decode, desired_output_for_decode); @@ -154,11 +156,13 @@ TEST(ObjCHelper, TextFormatDecodeData_RawStrings) { EXPECT_EQ(4, decode_data.num_entries()); uint8_t expected_data[] = { + // clang-format off 0x4, 0x1, 0x0, 'z', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 0x0, 0x3, 0x0, 'a', 'b', 'c', 'd', 'e', 'z', 'g', 'h', 'I', 'J', 0x0, 0x2, 0x0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 0x0, 0x4, 0x0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 'z', 0x0, + // clang-format on }; std::string expected((const char*)expected_data, sizeof(expected_data)); @@ -172,12 +176,15 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) { decode_data.AddString(3, "abcdefghIJ", "_AbcdefghIJ"); decode_data.AddString(2, "abcdefghIJ", "Abcd_EfghIJ"); decode_data.AddString(4, "abcdefghIJ", "ABCD__EfghI_j"); + // clang-format off decode_data.AddString(1000, "longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000", "long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000"); + // clang-format on EXPECT_EQ(5, decode_data.num_entries()); + // clang-format off uint8_t expected_data[] = { 0x5, // All as is (00 op) @@ -196,6 +203,7 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) { // underscore, as is + 3 (00 op) 0xE8, 0x07, 0x04, 0xA5, 0xA4, 0xA2, 0xBF, 0x1F, 0x0E, 0x84, 0x0, }; + // clang-format on std::string expected((const char*)expected_data, sizeof(expected_data)); EXPECT_EQ(expected, decode_data.Data()); From 805812ec90ea06a1c81b1915bbdf6419c00a7f1a Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 16 Sep 2022 15:11:30 -0700 Subject: [PATCH 29/39] Auto-generate CMake file lists in GitHub action (#10592) This GitHub action will run after each pull request merge and will auto-update the file lists in in src/file_lists.cmake. The action will run as our bot account. I realized that if a bug somehow made the file generation non-idempotent, this could trigger an infinite loop of commits, so I put in an extra safeguard against that. If the previous commit was by "Protobuf Team Bot", the GitHub action will revert any local changes to ensure that no new commit will be made. --- .github/workflows/generated_cmake.yml | 30 +++++++++++--------- cmake/push_auto_update.sh | 41 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 13 deletions(-) create mode 100755 cmake/push_auto_update.sh diff --git a/.github/workflows/generated_cmake.yml b/.github/workflows/generated_cmake.yml index 91dcd4f1e7..b63f16c0cc 100644 --- a/.github/workflows/generated_cmake.yml +++ b/.github/workflows/generated_cmake.yml @@ -1,8 +1,13 @@ -name: Generated CMake File Lists +name: Generate CMake File Lists on: - - push - - pull_request + push: + branches: + - main + - '[0-9]+.x' + # The 21.x branch predates support for auto-generation of the CMake file + # lists, so we make sure to exclude it. + - '!21.x' jobs: cmake: @@ -12,13 +17,12 @@ jobs: fail-fast: false # Don't cancel all jobs if one fails. steps: - - uses: actions/checkout@v2 - - name: Set up Bazel read-only caching - run: echo "BAZEL_CACHE_AUTH=--remote_upload_local_results=false" >> $GITHUB_ENV - - name: Generate CMake files - run: cd ${{ github.workspace }} && bazel build //pkg:gen_src_file_lists --test_output=errors $BAZEL_CACHE $BAZEL_CACHE_AUTH - - name: Compare to Golden file - run: diff -du bazel-bin/pkg/src_file_lists.cmake src/file_lists.cmake - - name: Report - run: echo "::error file=cmake/update_file_lists.sh::CMake files are stale, please run cmake/update_file_lists.sh" - if: failure() + - uses: actions/checkout@v3 + with: + # Note: this token has an expiration date, so if the workflow starts + # failing then you may need to generate a fresh token. + token: ${{ secrets.BOT_ACCESS_TOKEN }} + - name: Configure name and email address in Git + run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com" + - name: Commit and push update + run: cd ${{ github.workspace }} && ./cmake/push_auto_update.sh diff --git a/cmake/push_auto_update.sh b/cmake/push_auto_update.sh new file mode 100755 index 0000000000..abae4f4c0c --- /dev/null +++ b/cmake/push_auto_update.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# This script updates the CMake file lists (i.e. src/file_lists.cmake), commits +# the resulting change, and pushes it. This does not do anything useful when +# run manually, but should be run by our GitHub action instead. + +set -ex + +# Exit early if the previous commit was made by the bot. This reduces the risk +# of a bug causing an infinite loop of auto-generated commits. +if (git log -1 --pretty=format:'%an' | grep -q "Protobuf Team Bot"); then + echo "Previous commit was authored by bot" + exit 0 +fi + +$(dirname -- "$0")/update_file_lists.sh + +# Try to determine the most recent pull request number. +title=$(git log -1 --pretty='%s') +pr_from_merge=$(echo "$title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p') +pr_from_squash=$(echo "$title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p') + +pr="" +if [ ! -z "$pr_from_merge" ]; then + pr="$pr_from_merge" +elif [ ! -z "$pr_from_squash" ]; then + pr="$pr_from_squash" +fi + +if [ ! -z "$pr" ]; then + commit_message="Auto-generate CMake file lists after PR #$pr" +else + # If we are unable to determine the pull request number, we fall back on this + # default commit message. Typically this should not occur, but could happen + # if a pull request was merged via a rebase. + commit_message="Auto-generate CMake file lists" +fi + +git add -A +git diff --staged --quiet || git commit -am "$commit_message" +git push From 6be96e7a20801e70ef8f2a964e73eb47d09cd815 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 16 Sep 2022 15:20:52 -0700 Subject: [PATCH 30/39] Run CMake file auto-generation only on the main protobuf repo (#10611) This workflow will otherwise fail on forks, so let's make sure to do it only on the main repo where we need it. --- .github/workflows/generated_cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/generated_cmake.yml b/.github/workflows/generated_cmake.yml index b63f16c0cc..640bd137ec 100644 --- a/.github/workflows/generated_cmake.yml +++ b/.github/workflows/generated_cmake.yml @@ -11,6 +11,7 @@ on: jobs: cmake: + if: github.repository == 'protocolbuffers/protobuf' runs-on: ubuntu-latest strategy: From 975ed9f7045a32c5abf3014cb62fe61f9a9201bb Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 16 Sep 2022 15:55:16 -0700 Subject: [PATCH 31/39] Make slight change to ordering in src/file_lists.cmake (#10612) This change does not directly do anything useful, but the goal is to confirm that the GitHub action for auto-generating file_lists.cmake will quickly rewrite the file in its canonical form. --- src/file_lists.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index be3d61ee14..0b15b8cc1c 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -11,8 +11,8 @@ endif() # //pkg:protobuf set(libprotobuf_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.cc From fe9db54cedabf8ccb09c241c2477d7953d777844 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 16 Sep 2022 22:55:52 +0000 Subject: [PATCH 32/39] Auto-generate CMake file lists after PR #10612 --- src/file_lists.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 0b15b8cc1c..be3d61ee14 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -11,8 +11,8 @@ endif() # //pkg:protobuf set(libprotobuf_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.cc From e18aa2eda7835007c805c07cb3c4025aebda7b94 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Fri, 16 Sep 2022 18:56:59 -0700 Subject: [PATCH 33/39] Fix broken examples build (#10614) * Add .bazelrc for examples repo * Include examples in some of our basic tests --- examples/.bazelrc | 1 + kokoro/linux/bazel/common.cfg | 2 +- kokoro/linux/cmake/build.sh | 2 +- kokoro/windows/bazel/build.bat | 2 +- kokoro/windows/cmake/build.bat | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 examples/.bazelrc diff --git a/examples/.bazelrc b/examples/.bazelrc new file mode 100644 index 0000000000..554440cfe3 --- /dev/null +++ b/examples/.bazelrc @@ -0,0 +1 @@ +build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 diff --git a/kokoro/linux/bazel/common.cfg b/kokoro/linux/bazel/common.cfg index 6d35d8bbaa..cd41cb2cb8 100644 --- a/kokoro/linux/bazel/common.cfg +++ b/kokoro/linux/bazel/common.cfg @@ -6,7 +6,7 @@ timeout_mins: 15 env_vars { key: "BAZEL_TARGETS" - value: "//src/..." + value: "//src/... @com_google_protobuf_examples//..." } action { diff --git a/kokoro/linux/cmake/build.sh b/kokoro/linux/cmake/build.sh index 523253da25..ee06d95cf9 100755 --- a/kokoro/linux/cmake/build.sh +++ b/kokoro/linux/cmake/build.sh @@ -19,7 +19,7 @@ docker run \ --cidfile $tmpfile \ -v $GIT_REPO_ROOT:/workspace \ $CONTAINER_IMAGE \ - /test.sh -Dprotobuf_BUILD_CONFORMANCE=ON + /test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_EXAMPLES=ON # Save logs for Kokoro docker cp \ diff --git a/kokoro/windows/bazel/build.bat b/kokoro/windows/bazel/build.bat index 0b2ba9fc13..55fba16579 100644 --- a/kokoro/windows/bazel/build.bat +++ b/kokoro/windows/bazel/build.bat @@ -24,7 +24,7 @@ bazel %BAZEL_STARTUP% build //:protoc //:protobuf //:protobuf_lite %BAZEL_FLAGS% @rem TODO(b/241484899) Enable conformance tests on windows. bazel %BAZEL_STARTUP% test %BAZEL_FLAGS% ^ --test_tag_filters=-conformance --build_tag_filters=-conformance ^ - //src/... || goto :error + //src/... @com_google_protobuf_examples//... || goto :error goto :EOF diff --git a/kokoro/windows/cmake/build.bat b/kokoro/windows/cmake/build.bat index 29d012ba1c..49c89d3c84 100644 --- a/kokoro/windows/cmake/build.bat +++ b/kokoro/windows/cmake/build.bat @@ -13,6 +13,7 @@ cd build cmake .. ^ -G "Visual Studio 15 2017" -A x64 ^ + -Dprotobuf_BUILD_EXAMPLES=ON ^ -Dprotobuf_BUILD_CONFORMANCE=OFF ^ -Dprotobuf_WITH_ZLIB=OFF ^ -Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error From f191ab0f35432c76fff0763509a4cc6439183d49 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 15 Sep 2022 14:40:15 -0400 Subject: [PATCH 34/39] Provide a protocol for GPBExtensionRegistry's lookup support. This allows some to use an alternative registry if they have a different implementation. This is really just wiring though the change to use the GPBExtensionRegistry protocol vs the concrete GPBExtensionRegistry through the other apis. --- objectivec/GPBCodedInputStream.h | 4 +-- objectivec/GPBCodedInputStream.m | 6 ++-- .../GPBCodedInputStream_PackagePrivate.h | 4 +-- objectivec/GPBDictionary.m | 4 +-- objectivec/GPBDictionary_PackagePrivate.h | 4 +-- objectivec/GPBExtensionInternals.h | 4 +-- objectivec/GPBExtensionInternals.m | 6 ++-- objectivec/GPBExtensionRegistry.h | 32 +++++++++++-------- objectivec/GPBMessage.h | 14 ++++---- objectivec/GPBMessage.m | 24 +++++++------- objectivec/GPBMessage_PackagePrivate.h | 4 +-- 11 files changed, 56 insertions(+), 50 deletions(-) diff --git a/objectivec/GPBCodedInputStream.h b/objectivec/GPBCodedInputStream.h index 1886ccf61b..73b65581d7 100644 --- a/objectivec/GPBCodedInputStream.h +++ b/objectivec/GPBCodedInputStream.h @@ -31,7 +31,7 @@ #import @class GPBMessage; -@class GPBExtensionRegistry; +@protocol GPBExtensionRegistry; NS_ASSUME_NONNULL_BEGIN @@ -184,7 +184,7 @@ CF_EXTERN_C_END * extensions for message. **/ - (void)readMessage:(GPBMessage *)message - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; + extensionRegistry:(nullable id)extensionRegistry; /** * Reads and discards a single field, given its tag value. diff --git a/objectivec/GPBCodedInputStream.m b/objectivec/GPBCodedInputStream.m index c459391e08..25dde75320 100644 --- a/objectivec/GPBCodedInputStream.m +++ b/objectivec/GPBCodedInputStream.m @@ -434,7 +434,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, - (void)readGroup:(int32_t)fieldNumber message:(GPBMessage *)message - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { + extensionRegistry:(id)extensionRegistry { CheckRecursionLimit(&state_); ++state_.recursionDepth; [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; @@ -454,7 +454,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, } - (void)readMessage:(GPBMessage *)message - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { + extensionRegistry:(id)extensionRegistry { CheckRecursionLimit(&state_); int32_t length = ReadRawVarint32(&state_); size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); @@ -466,7 +466,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, } - (void)readMapEntry:(id)mapDictionary - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(id)extensionRegistry field:(GPBFieldDescriptor *)field parentMessage:(GPBMessage *)parentMessage { CheckRecursionLimit(&state_); diff --git a/objectivec/GPBCodedInputStream_PackagePrivate.h b/objectivec/GPBCodedInputStream_PackagePrivate.h index 43ec6e79b2..cdfb0dcc3f 100644 --- a/objectivec/GPBCodedInputStream_PackagePrivate.h +++ b/objectivec/GPBCodedInputStream_PackagePrivate.h @@ -61,7 +61,7 @@ typedef struct GPBCodedInputStreamState { // support for older data. - (void)readGroup:(int32_t)fieldNumber message:(GPBMessage *)message - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry; + extensionRegistry:(id)extensionRegistry; // Reads a group field value from the stream and merges it into the given // UnknownFieldSet. @@ -70,7 +70,7 @@ typedef struct GPBCodedInputStreamState { // Reads a map entry. - (void)readMapEntry:(id)mapDictionary - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(id)extensionRegistry field:(GPBFieldDescriptor *)field parentMessage:(GPBMessage *)parentMessage; @end diff --git a/objectivec/GPBDictionary.m b/objectivec/GPBDictionary.m index 187a97092f..77642c27f9 100644 --- a/objectivec/GPBDictionary.m +++ b/objectivec/GPBDictionary.m @@ -386,7 +386,7 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescri static void ReadValue(GPBCodedInputStream *stream, GPBGenericValue *valueToFill, GPBDataType type, - GPBExtensionRegistry *registry, + idregistry, GPBFieldDescriptor *field) { switch (type) { case GPBDataTypeBool: @@ -454,7 +454,7 @@ static void ReadValue(GPBCodedInputStream *stream, void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, - GPBExtensionRegistry *registry, + idregistry, GPBFieldDescriptor *field, GPBMessage *parentMessage) { GPBDataType keyDataType = field.mapKeyDataType; diff --git a/objectivec/GPBDictionary_PackagePrivate.h b/objectivec/GPBDictionary_PackagePrivate.h index 15e4283264..d494b7ee88 100644 --- a/objectivec/GPBDictionary_PackagePrivate.h +++ b/objectivec/GPBDictionary_PackagePrivate.h @@ -34,7 +34,7 @@ @class GPBCodedInputStream; @class GPBCodedOutputStream; -@class GPBExtensionRegistry; +@protocol GPBExtensionRegistry; @class GPBFieldDescriptor; @protocol GPBDictionaryInternalsProtocol @@ -493,7 +493,7 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, // Helper to read a map instead. void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, - GPBExtensionRegistry *registry, + idregistry, GPBFieldDescriptor *field, GPBMessage *parentMessage); diff --git a/objectivec/GPBExtensionInternals.h b/objectivec/GPBExtensionInternals.h index 2b980aefa4..854b57fe89 100644 --- a/objectivec/GPBExtensionInternals.h +++ b/objectivec/GPBExtensionInternals.h @@ -34,12 +34,12 @@ @class GPBCodedInputStream; @class GPBCodedOutputStream; -@class GPBExtensionRegistry; +@protocol GPBExtensionRegistry; void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, BOOL isPackedOnStream, GPBCodedInputStream *input, - GPBExtensionRegistry *extensionRegistry, + idextensionRegistry, GPBMessage *message); size_t GPBComputeExtensionSerializedSizeIncludingTag( diff --git a/objectivec/GPBExtensionInternals.m b/objectivec/GPBExtensionInternals.m index bacec5740a..b74591e0a0 100644 --- a/objectivec/GPBExtensionInternals.m +++ b/objectivec/GPBExtensionInternals.m @@ -40,7 +40,7 @@ static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, GPBCodedInputStream *input, - GPBExtensionRegistry *extensionRegistry, + idextensionRegistry, GPBMessage *existingValue) __attribute__((ns_returns_retained)); @@ -273,7 +273,7 @@ static void WriteArrayIncludingTagsToCodedOutputStream( void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, BOOL isPackedOnStream, GPBCodedInputStream *input, - GPBExtensionRegistry *extensionRegistry, + idextensionRegistry, GPBMessage *message) { GPBExtensionDescription *description = extension->description_; GPBCodedInputStreamState *state = &input->state_; @@ -334,7 +334,7 @@ size_t GPBComputeExtensionSerializedSizeIncludingTag( // Note that this returns a retained value intentionally. static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, GPBCodedInputStream *input, - GPBExtensionRegistry *extensionRegistry, + idextensionRegistry, GPBMessage *existingValue) { GPBExtensionDescription *description = extension->description_; GPBCodedInputStreamState *state = &input->state_; diff --git a/objectivec/GPBExtensionRegistry.h b/objectivec/GPBExtensionRegistry.h index d79632d28b..b1850568d9 100644 --- a/objectivec/GPBExtensionRegistry.h +++ b/objectivec/GPBExtensionRegistry.h @@ -41,6 +41,24 @@ NS_ASSUME_NONNULL_BEGIN * GPBExtensionRegistry in which you have registered any extensions that you * want to be able to parse. Otherwise, those extensions will just be treated * like unknown fields. + **/ +@protocol GPBExtensionRegistry + +/** + * Looks for the extension registered for the given field number on a given + * GPBDescriptor. + * + * @param descriptor The descriptor to look for a registered extension on. + * @param fieldNumber The field number of the extension to look for. + * + * @return The registered GPBExtensionDescriptor or nil if none was found. + **/ +- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor + fieldNumber:(NSInteger)fieldNumber; +@end + +/** + * A concrete implementation of `GPBExtensionRegistry`. * * The *Root classes provide `+extensionRegistry` for the extensions defined * in a given file *and* all files it imports. You can also create a @@ -54,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN * MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError]; * ``` **/ -@interface GPBExtensionRegistry : NSObject +@interface GPBExtensionRegistry : NSObject /** * Adds the given GPBExtensionDescriptor to this registry. @@ -70,18 +88,6 @@ NS_ASSUME_NONNULL_BEGIN **/ - (void)addExtensions:(GPBExtensionRegistry *)registry; -/** - * Looks for the extension registered for the given field number on a given - * GPBDescriptor. - * - * @param descriptor The descriptor to look for a registered extension on. - * @param fieldNumber The field number of the extension to look for. - * - * @return The registered GPBExtensionDescriptor or nil if none was found. - **/ -- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor - fieldNumber:(NSInteger)fieldNumber; - @end NS_ASSUME_NONNULL_END diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index 01253a4afc..990a796faf 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -36,7 +36,7 @@ @class GPBCodedInputStream; @class GPBCodedOutputStream; @class GPBExtensionDescriptor; -@class GPBExtensionRegistry; +@protocol GPBExtensionRegistry; @class GPBFieldDescriptor; @class GPBUnknownFieldSet; @@ -147,7 +147,7 @@ CF_EXTERN_C_END * @return A new instance of the generated class. **/ + (nullable instancetype)parseFromData:(NSData *)data - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(nullable id)extensionRegistry error:(NSError **)errorPtr; /** @@ -171,7 +171,7 @@ CF_EXTERN_C_END **/ + (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (nullable GPBExtensionRegistry *)extensionRegistry + (nullable id)extensionRegistry error:(NSError **)errorPtr; /** @@ -196,7 +196,7 @@ CF_EXTERN_C_END **/ + (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (nullable GPBExtensionRegistry *)extensionRegistry + (nullable id)extensionRegistry error:(NSError **)errorPtr; /** @@ -239,7 +239,7 @@ CF_EXTERN_C_END * @return An initialized instance of the generated class. **/ - (nullable instancetype)initWithData:(NSData *)data - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(nullable id)extensionRegistry error:(NSError **)errorPtr; /** @@ -264,7 +264,7 @@ CF_EXTERN_C_END **/ - (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (nullable GPBExtensionRegistry *)extensionRegistry + (nullable id)extensionRegistry error:(NSError **)errorPtr; /** @@ -278,7 +278,7 @@ CF_EXTERN_C_END * unsuccessful. **/ - (void)mergeFromData:(NSData *)data - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; + extensionRegistry:(nullable id)extensionRegistry; /** * Merges the fields from another message (of the same type) into this diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index ee94dee8ed..b293604608 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -881,7 +881,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (instancetype)initWithData:(NSData *)data - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(id)extensionRegistry error:(NSError **)errorPtr { if ((self = [self init])) { @try { @@ -912,7 +912,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { - (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (GPBExtensionRegistry *)extensionRegistry + (id)extensionRegistry error:(NSError **)errorPtr { if ((self = [self init])) { @try { @@ -1973,7 +1973,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { #pragma mark - mergeFrom - (void)mergeFromData:(NSData *)data - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { + extensionRegistry:(id)extensionRegistry { GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data]; [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]; [input checkLastTagWas:0]; @@ -1983,7 +1983,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { #pragma mark - mergeDelimitedFrom - (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { + extensionRegistry:(id)extensionRegistry { GPBCodedInputStreamState *state = &input->state_; if (GPBCodedInputStreamIsAtEnd(state)) { return; @@ -2003,7 +2003,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } + (instancetype)parseFromData:(NSData *)data - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(id)extensionRegistry error:(NSError **)errorPtr { return [[[self alloc] initWithData:data extensionRegistry:extensionRegistry @@ -2011,7 +2011,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } + (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(id)extensionRegistry error:(NSError **)errorPtr { return [[[self alloc] initWithCodedInputStream:input @@ -2023,7 +2023,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { + (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (GPBExtensionRegistry *)extensionRegistry + (id)extensionRegistry error:(NSError **)errorPtr { GPBMessage *message = [[[self alloc] init] autorelease]; @try { @@ -2065,7 +2065,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (void)parseMessageSet:(GPBCodedInputStream *)input - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { + extensionRegistry:(id)extensionRegistry { uint32_t typeId = 0; NSData *rawBytes = nil; GPBExtensionDescriptor *extension = nil; @@ -2117,7 +2117,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (BOOL)parseUnknownField:(GPBCodedInputStream *)input - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry + extensionRegistry:(id)extensionRegistry tag:(uint32_t)tag { GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag); int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag); @@ -2170,7 +2170,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { static void MergeSingleFieldFromCodedInputStream( GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax, - GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) { + GPBCodedInputStream *input, idextensionRegistry) { GPBDataType fieldDataType = GPBGetFieldDataType(field); switch (fieldDataType) { #define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \ @@ -2306,7 +2306,7 @@ static void MergeRepeatedPackedFieldFromCodedInputStream( static void MergeRepeatedNotPackedFieldFromCodedInputStream( GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax, - GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) { + GPBCodedInputStream *input, idextensionRegistry) { GPBCodedInputStreamState *state = &input->state_; id genericArray = GetOrCreateArrayIvarWithField(self, field); switch (GPBGetFieldDataType(field)) { @@ -2371,7 +2371,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( } - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { + extensionRegistry:(id)extensionRegistry { GPBDescriptor *descriptor = [self descriptor]; GPBFileSyntax syntax = descriptor.file.syntax; GPBCodedInputStreamState *state = &input->state_; diff --git a/objectivec/GPBMessage_PackagePrivate.h b/objectivec/GPBMessage_PackagePrivate.h index ca10983b3c..a8755a29ce 100644 --- a/objectivec/GPBMessage_PackagePrivate.h +++ b/objectivec/GPBMessage_PackagePrivate.h @@ -78,13 +78,13 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; // or zero for EOF. // NOTE: This will throw if there is an error while parsing. - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(GPBExtensionRegistry *)extensionRegistry; + extensionRegistry:(id)extensionRegistry; // Parses the next delimited message of this type from the input and merges it // with this message. - (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (GPBExtensionRegistry *)extensionRegistry; + (id)extensionRegistry; - (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data; From 01c340d0bb9abb2654554afc732df2c89774ce81 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Mon, 19 Sep 2022 09:50:19 -0700 Subject: [PATCH 35/39] Adding full build to 32 bit tests (#10589) * Adding full build to 32 bit tests * Running C++ tests in 32 bit builds * Patching static assert test failure * Test fixes for 32-bit architectures * Cleanup after CMake build * Save protoc before cleanup * Route protoc better --- kokoro/linux/32-bit/test_php.sh | 11 ++++++-- php/generate_descriptor_protos.sh | 4 ++- php/generate_test_protos.sh | 4 ++- .../compiler/cpp/message_size_unittest.cc | 2 +- src/google/protobuf/extension_set_unittest.cc | 6 ++-- .../protobuf/io/zero_copy_stream_unittest.cc | 3 ++ .../protobuf/repeated_field_unittest.cc | 4 +-- src/google/protobuf/util/time_util_test.cc | 28 +++++++++++-------- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/kokoro/linux/32-bit/test_php.sh b/kokoro/linux/32-bit/test_php.sh index 3770b84af3..739467b20c 100644 --- a/kokoro/linux/32-bit/test_php.sh +++ b/kokoro/linux/32-bit/test_php.sh @@ -36,9 +36,13 @@ build_php_c() { test_php_c } -cmake . -cmake --build . --target protoc -- -j20 +mkdir build +pushd build +cmake .. +cmake --build . -- -j20 +ctest --verbose --parallel 20 export PROTOC=$(pwd)/protoc +popd build_php 7.0 build_php 7.1 @@ -49,3 +53,6 @@ build_php_c 7.4 build_php_c 7.1-zts build_php_c 7.2-zts build_php_c 7.5-zts + +# Cleanup after CMake build +rm -rf build diff --git a/php/generate_descriptor_protos.sh b/php/generate_descriptor_protos.sh index 1a600abc63..0e5be35e24 100755 --- a/php/generate_descriptor_protos.sh +++ b/php/generate_descriptor_protos.sh @@ -5,7 +5,9 @@ set -e -PROTOC=$(realpath protoc) +if [[ -z "${PROTOC}" ]]; then + PROTOC=$(realpath protoc) +fi if [ ! -f $PROTOC ]; then bazel build -c opt //:protoc PROTOC=$(realpath bazel-bin/protoc) diff --git a/php/generate_test_protos.sh b/php/generate_test_protos.sh index 565c7ec1cd..6d06f959b9 100755 --- a/php/generate_test_protos.sh +++ b/php/generate_test_protos.sh @@ -4,7 +4,9 @@ set -ex cd `dirname $0`/.. -PROTOC=$(pwd)/protoc +if [[ -z "${PROTOC}" ]]; then + PROTOC=$(pwd)/protoc +fi if [ ! -f $PROTOC ]; then bazel build -c opt //:protoc PROTOC=$(pwd)/bazel-bin/protoc diff --git a/src/google/protobuf/compiler/cpp/message_size_unittest.cc b/src/google/protobuf/compiler/cpp/message_size_unittest.cc index a75d77a70c..ed4a90e223 100644 --- a/src/google/protobuf/compiler/cpp/message_size_unittest.cc +++ b/src/google/protobuf/compiler/cpp/message_size_unittest.cc @@ -139,9 +139,9 @@ TEST(GeneratedMessageTest, OneStringSize) { TEST(GeneratedMessageTest, MoreStringSize) { struct MockGenerated : public MockMessageBase { // 16 bytes - int has_bits[1]; // 4 bytes int cached_size; // 4 bytes MockRepeatedPtrField data; // 24 bytes + // + 4 bytes padding }; GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 48); EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated)); diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index 8b436bc20c..84da3c5465 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -855,8 +855,10 @@ TEST(ExtensionSetTest, SpaceUsedExcludingSelf) { const size_t old_capacity = \ message->GetRepeatedExtension(unittest::repeated_##type##_extension) \ .Capacity(); \ - EXPECT_GE(old_capacity, \ - (RepeatedFieldLowerClampLimit())); \ + EXPECT_GE( \ + old_capacity, \ + (RepeatedFieldLowerClampLimit())); \ for (int i = 0; i < 16; ++i) { \ message->AddExtension(unittest::repeated_##type##_extension, value); \ } \ diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index d82354e571..d656da5f13 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -720,6 +720,9 @@ TEST_F(IoTest, StringIo) { // Verifies that outputs up to kint32max can be created. TEST_F(IoTest, LargeOutput) { + // Filter out this test on 32-bit architectures. + if(sizeof(void*) < 8) return; + std::string str; StringOutputStream output(&str); void* unused_data; diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index eb0b9091cf..3baf6f25bb 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -429,14 +429,14 @@ TEST(RepeatedField, ReserveNothing) { TEST(RepeatedField, ReserveLowerClamp) { int clamped_value = internal::CalculateReserveSize(0, 1); - EXPECT_GE(clamped_value, 8 / sizeof(bool)); + EXPECT_GE(clamped_value, sizeof(void*) / sizeof(bool)); EXPECT_EQ((internal::RepeatedFieldLowerClampLimit()), clamped_value); // EXPECT_EQ(clamped_value, (internal::CalculateReserveSize( clamped_value, 2))); clamped_value = internal::CalculateReserveSize(0, 1); - EXPECT_GE(clamped_value, 8 / sizeof(int)); + EXPECT_GE(clamped_value, sizeof(void*) / sizeof(int)); EXPECT_EQ((internal::RepeatedFieldLowerClampLimit()), clamped_value); // EXPECT_EQ(clamped_value, (internal::CalculateReserveSize= sizeof(uint64_t)) { + Timestamp begin, end; + EXPECT_TRUE(TimeUtil::FromString("0001-01-01T00:00:00Z", &begin)); + EXPECT_EQ(TimeUtil::kTimestampMinSeconds, begin.seconds()); + EXPECT_EQ(0, begin.nanos()); + EXPECT_TRUE(TimeUtil::FromString("9999-12-31T23:59:59.999999999Z", &end)); + EXPECT_EQ(TimeUtil::kTimestampMaxSeconds, end.seconds()); + EXPECT_EQ(999999999, end.nanos()); + EXPECT_EQ("0001-01-01T00:00:00Z", TimeUtil::ToString(begin)); + EXPECT_EQ("9999-12-31T23:59:59.999999999Z", TimeUtil::ToString(end)); + } // Test negative timestamps. Timestamp time = TimeUtil::NanosecondsToTimestamp(-1); @@ -94,9 +97,12 @@ TEST(TimeUtilTest, DurationStringFormat) { EXPECT_TRUE(TimeUtil::FromString("0001-01-01T00:00:00Z", &begin)); EXPECT_TRUE(TimeUtil::FromString("9999-12-31T23:59:59.999999999Z", &end)); - EXPECT_EQ("315537897599.999999999s", TimeUtil::ToString(end - begin)); + // These these are out of bounds for 32-bit architectures. + if(sizeof(time_t) >= sizeof(uint64_t)) { + EXPECT_EQ("315537897599.999999999s", TimeUtil::ToString(end - begin)); + EXPECT_EQ("-315537897599.999999999s", TimeUtil::ToString(begin - end)); + } EXPECT_EQ(999999999, (end - begin).nanos()); - EXPECT_EQ("-315537897599.999999999s", TimeUtil::ToString(begin - end)); EXPECT_EQ(-999999999, (begin - end).nanos()); // Generated output should contain 3, 6, or 9 fractional digits. From 81e35132bff7c6752462f4b606af821b80ee7b98 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Mon, 19 Sep 2022 11:08:21 -0700 Subject: [PATCH 36/39] Improve CMake installation tests (#10615) * Using glob to remove headers instead of cyclic file_lists * Simplify CMake config and include missing files * Don't remove generated proto headers * Fix broken CMake proto dependencies instead of opting out pb.h files. * Fixing cyclic dependency --- BUILD.bazel | 6 + cmake/conformance.cmake | 17 +- cmake/tests.cmake | 43 +++-- kokoro/windows/cmake/build.bat | 4 +- kokoro/windows/cmake_install/build.bat | 4 +- kokoro/windows/cmake_nmake/build.bat | 4 +- kokoro/windows/cmake_shared/build.bat | 4 +- pkg/BUILD.bazel | 40 +++-- src/file_lists.cmake | 158 ++++--------------- src/google/protobuf/BUILD.bazel | 10 +- src/google/protobuf/compiler/cpp/BUILD.bazel | 1 + 11 files changed, 113 insertions(+), 178 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index b63b7bf984..fd9ee70aeb 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -324,6 +324,12 @@ alias( # Test protos ################################################################################ +alias( + name = "lite_test_proto_srcs", + actual = "//src/google/protobuf:lite_test_proto_srcs", # proto_library + visibility = ["//:__subpackages__"], +) + alias( name = "lite_test_protos", actual = "//src/google/protobuf:lite_test_protos", # proto_library diff --git a/cmake/conformance.cmake b/cmake/conformance.cmake index fa5c479bc6..056250ebe9 100644 --- a/cmake/conformance.cmake +++ b/cmake/conformance.cmake @@ -1,6 +1,8 @@ add_custom_command( - OUTPUT ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc + OUTPUT + ${protobuf_SOURCE_DIR}/conformance/conformance.pb.h + ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc DEPENDS ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/conformance/conformance.proto COMMAND ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/conformance/conformance.proto --proto_path=${protobuf_SOURCE_DIR}/conformance @@ -8,8 +10,11 @@ add_custom_command( ) add_custom_command( - OUTPUT ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc + OUTPUT + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc DEPENDS ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.proto COMMAND ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto @@ -21,6 +26,7 @@ add_custom_command( add_executable(conformance_test_runner ${protobuf_SOURCE_DIR}/conformance/binary_json_conformance_suite.cc ${protobuf_SOURCE_DIR}/conformance/binary_json_conformance_suite.h + ${protobuf_SOURCE_DIR}/conformance/conformance.pb.h ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc ${protobuf_SOURCE_DIR}/conformance/conformance_test.cc ${protobuf_SOURCE_DIR}/conformance/conformance_test_runner.cc @@ -29,14 +35,19 @@ add_executable(conformance_test_runner ${protobuf_SOURCE_DIR}/conformance/text_format_conformance_suite.h ${protobuf_SOURCE_DIR}/conformance/third_party/jsoncpp/json.h ${protobuf_SOURCE_DIR}/conformance/third_party/jsoncpp/jsoncpp.cpp + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc ) add_executable(conformance_cpp + ${protobuf_SOURCE_DIR}/conformance/conformance.pb.h ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc ${protobuf_SOURCE_DIR}/conformance/conformance_cpp.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc ) diff --git a/cmake/tests.cmake b/cmake/tests.cmake index a9fdd524ca..530a66ba8b 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -43,19 +43,20 @@ endif() include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) set(lite_test_protos - ${protobuf_lite_test_protos_proto_srcs} + ${protobuf_lite_test_protos_files} ) set(tests_protos - ${protobuf_test_protos_proto_srcs} + ${protobuf_test_protos_files} ${compiler_test_protos_files} ${util_test_protos_files} ) macro(compile_proto_file filename) - string(REPLACE .proto .pb.cc pb_file ${filename}) + string(REPLACE .proto .pb.h pb_hdr ${filename}) + string(REPLACE .proto .pb.cc pb_src ${filename}) add_custom_command( - OUTPUT ${pb_file} + OUTPUT ${pb_hdr} ${pb_src} DEPENDS ${protobuf_PROTOC_EXE} ${filename} COMMAND ${protobuf_PROTOC_EXE} ${filename} --proto_path=${protobuf_SOURCE_DIR}/src @@ -67,13 +68,13 @@ endmacro(compile_proto_file) set(lite_test_proto_files) foreach(proto_file ${lite_test_protos}) compile_proto_file(${proto_file}) - set(lite_test_proto_files ${lite_test_proto_files} ${pb_file}) + set(lite_test_proto_files ${lite_test_proto_files} ${pb_src} ${pb_hdr}) endforeach(proto_file) set(tests_proto_files) foreach(proto_file ${tests_protos}) compile_proto_file(${proto_file}) - set(tests_proto_files ${tests_proto_files} ${pb_file}) + set(tests_proto_files ${tests_proto_files} ${pb_src} ${pb_hdr}) endforeach(proto_file) add_library(protobuf-lite-test-common STATIC @@ -85,8 +86,8 @@ target_link_libraries(protobuf-lite-test-common set(common_test_files ${test_util_hdrs} ${test_util_srcs} - ${mock_code_generator_srcs} - ${testing_srcs} + ${common_test_hdrs} + ${common_test_srcs} ) add_library(protobuf-test-common STATIC @@ -138,8 +139,8 @@ target_link_libraries(tests protobuf-lite-test-common protobuf-test-common ${pro set(test_plugin_files ${test_plugin_files} - ${mock_code_generator_srcs} - ${testing_srcs} + ${common_test_hdrs} + ${common_test_srcs} ) add_executable(test_plugin ${test_plugin_files}) @@ -172,13 +173,23 @@ add_custom_target(save-installed-headers) add_custom_target(remove-installed-headers) add_custom_target(restore-installed-headers) -# Explicitly skip the bootstrapping headers as it's directly used in tests -set(_installed_hdrs ${libprotobuf_hdrs} ${libprotoc_hdrs}) -list(REMOVE_ITEM _installed_hdrs +file(GLOB_RECURSE _local_hdrs + "${PROJECT_SOURCE_DIR}/src/*.h" + "${PROJECT_SOURCE_DIR}/src/*.inc") + +# Exclude the bootstrapping that are directly used by tests. +set(_exclude_hdrs "${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.h" "${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.h") -foreach(_hdr ${_installed_hdrs}) +# Exclude test library headers. +list(APPEND _exclude_hdrs ${test_util_hdrs} ${lite_test_util_hdrs} ${common_test_hdrs} + ${compiler_test_utils_hdrs}) +foreach(_hdr ${_exclude_hdrs}) + list(REMOVE_ITEM _local_hdrs ${_hdr}) +endforeach() + +foreach(_hdr ${_local_hdrs}) string(REPLACE "${protobuf_SOURCE_DIR}/src" "" _file ${_hdr}) set(_tmp_file "${CMAKE_BINARY_DIR}/tmp-install-test/${_file}") add_custom_command(TARGET remove-installed-headers PRE_BUILD @@ -193,6 +204,6 @@ endforeach() add_dependencies(remove-installed-headers save-installed-headers) if(protobuf_REMOVE_INSTALLED_HEADERS) - add_dependencies(protobuf-lite-test-common remove-installed-headers) - add_dependencies(protobuf-test-common remove-installed-headers) + # Make sure we remove all the headers *before* any codegen occurs. + add_dependencies(${protobuf_PROTOC_EXE} remove-installed-headers) endif() diff --git a/kokoro/windows/cmake/build.bat b/kokoro/windows/cmake/build.bat index 49c89d3c84..d24e635d24 100644 --- a/kokoro/windows/cmake/build.bat +++ b/kokoro/windows/cmake/build.bat @@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error @rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241484899) Run conformance tests in windows. -md build -ea 0 -md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 +md build +md %KOKORO_ARTIFACTS_DIR%\logs cd build diff --git a/kokoro/windows/cmake_install/build.bat b/kokoro/windows/cmake_install/build.bat index 5392f9e664..c5878de338 100644 --- a/kokoro/windows/cmake_install/build.bat +++ b/kokoro/windows/cmake_install/build.bat @@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error @rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241484899) Run conformance tests in windows. -md build -ea 0 -md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 +md build +md %KOKORO_ARTIFACTS_DIR%\logs cd build diff --git a/kokoro/windows/cmake_nmake/build.bat b/kokoro/windows/cmake_nmake/build.bat index a0807714fc..7b03678dbc 100644 --- a/kokoro/windows/cmake_nmake/build.bat +++ b/kokoro/windows/cmake_nmake/build.bat @@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error @rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241484899) Run conformance tests in windows. -md build -ea 0 -md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 +md build +md %KOKORO_ARTIFACTS_DIR%\logs cd build diff --git a/kokoro/windows/cmake_shared/build.bat b/kokoro/windows/cmake_shared/build.bat index bcd5244608..d4bb2b16ee 100644 --- a/kokoro/windows/cmake_shared/build.bat +++ b/kokoro/windows/cmake_shared/build.bat @@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error @rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241484899) Run conformance tests in windows. -md build -ea 0 -md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 +md build +md %KOKORO_ARTIFACTS_DIR%\logs cd build diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 65dc37c0c6..4eda549da5 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -314,20 +314,18 @@ gen_file_lists( "//src/google/protobuf:descriptor_proto": "descriptor_proto", "//src/google/protobuf/compiler:plugin_proto": "plugin_proto", # Test libraries: + ":common_test": "common_test", ":lite_test_util": "lite_test_util", ":test_util": "test_util", # Tests and test-only protos: "//src/google/protobuf:full_test_srcs": "protobuf_test", - "//src/google/protobuf:test_protos": "protobuf_test_protos", + "//src/google/protobuf:test_proto_srcs": "protobuf_test_protos", "//src/google/protobuf:lite_test_srcs": "protobuf_lite_test", - "//src/google/protobuf:lite_test_protos": "protobuf_lite_test_protos", + "//src/google/protobuf:lite_test_proto_srcs": "protobuf_lite_test_protos", "//src/google/protobuf/compiler:test_srcs": "compiler_test", - ":compiler_annotation_test_util": "annotation_test_util", - ":compiler_mock_code_generator": "mock_code_generator", "//src/google/protobuf/compiler:test_proto_srcs": "compiler_test_protos", "//src/google/protobuf/compiler:test_plugin_srcs": "test_plugin", "//src/google/protobuf/io:test_srcs": "io_test", - ":testinglib": "testing", "//src/google/protobuf/util:test_srcs": "util_test", "//src/google/protobuf/util:test_proto_srcs": "util_test_protos", "//src/google/protobuf/stubs:test_srcs": "stubs_test", @@ -369,6 +367,7 @@ cc_dist_library( "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf:arena", "//src/google/protobuf:protobuf_lite", + "//src/google/protobuf:port_def", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/io", "//src/google/protobuf/io:gzip_stream", @@ -384,6 +383,7 @@ cc_dist_library( "//src/google/protobuf/util:json_util", "//src/google/protobuf/util:time_util", "//src/google/protobuf/util:type_resolver_util", + "//src/google/protobuf/util/internal:constants", "//src/google/protobuf/util/internal:datapiece", "//src/google/protobuf/util/internal:default_value", "//src/google/protobuf/util/internal:field_mask_utility", @@ -422,29 +422,27 @@ cc_dist_library( name = "test_util", testonly = 1, tags = ["manual"], - deps = ["//src/google/protobuf:test_util"], -) - -cc_dist_library( - name = "compiler_annotation_test_util", - testonly = 1, - tags = ["manual"], - deps = ["//src/google/protobuf/compiler:annotation_test_util"], + deps = [ + "//src/google/protobuf:test_util", + "//src/google/protobuf:test_util2", + "//src/google/protobuf/util/internal:expecting_objectwriter", + "//src/google/protobuf/util/internal:mock_error_listener", + "//src/google/protobuf/util/internal:type_info_test_helper", + "//src/google/protobuf/compiler:annotation_test_util", + "//src/google/protobuf/compiler/cpp:unittest_lib", + ], ) cc_dist_library( - name = "compiler_mock_code_generator", + name = "common_test", testonly = 1, tags = ["manual"], - deps = ["//src/google/protobuf/compiler:mock_code_generator"], + deps = [ + "//src/google/protobuf/testing", + "//src/google/protobuf/compiler:mock_code_generator", + ], ) -cc_dist_library( - name = "testinglib", - testonly = 1, - tags = ["manual"], - deps = ["//src/google/protobuf/testing"], -) ################################################################################ # Distribution sources diff --git a/src/file_lists.cmake b/src/file_lists.cmake index be3d61ee14..2a76933de4 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -157,6 +157,8 @@ set(libprotobuf_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.h ${protobuf_SOURCE_DIR}/src/google/protobuf/port.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/port_def.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/port_undef.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection.h ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_internal.h ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops.h @@ -179,6 +181,7 @@ set(libprotobuf_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/constants.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/datapiece.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/default_value_objectwriter.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/error_listener.h @@ -524,6 +527,20 @@ set(plugin_proto_files ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin_proto-descriptor-set.proto.bin ) +# //pkg:common_test +set(common_test_srcs + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.cc +) + +# //pkg:common_test +set(common_test_hdrs + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.h +) + # //pkg:lite_test_util set(lite_test_util_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_test_util.cc @@ -542,12 +559,17 @@ set(lite_test_util_hdrs # //pkg:test_util set(test_util_srcs + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/type_info_test_helper.cc ) # //pkg:test_util set(test_util_hdrs + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util.inc @@ -555,7 +577,11 @@ set(test_util_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util2.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/expecting_objectwriter.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/mock_error_listener.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/type_info_test_helper.h ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.inc ) @@ -590,8 +616,8 @@ set(protobuf_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.cc ) -# //src/google/protobuf:test_protos -set(protobuf_test_protos_proto_srcs +# //src/google/protobuf:test_proto_srcs +set(protobuf_test_protos_files ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.proto ${protobuf_SOURCE_DIR}/src/google/protobuf/map_proto2_unittest.proto ${protobuf_SOURCE_DIR}/src/google/protobuf/map_unittest.proto @@ -623,112 +649,20 @@ set(protobuf_test_protos_proto_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_well_known_types.proto ) -# //src/google/protobuf:test_protos -set(protobuf_test_protos_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_proto2_unittest.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_unittest.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_arena.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_custom_options.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_drop_unknown_fields.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_embed_optimize_for.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_empty.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_enormous_descriptor.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_enum.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite_imports_nonlite.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset_wire_format.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_field_presence.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_generic_services.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_optimize_for.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum2.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena_lite.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_lite.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_optional.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_well_known_types.proto.pb.cc -) - -# //src/google/protobuf:test_protos -set(protobuf_test_protos_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_proto2_unittest.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_unittest.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_arena.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_custom_options.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_drop_unknown_fields.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_embed_optimize_for.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_empty.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_enormous_descriptor.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_enum.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite_imports_nonlite.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset_wire_format.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_field_presence.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_generic_services.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_optimize_for.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum2.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena_lite.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_lite.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_optional.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_well_known_types.proto.pb.h -) - -# //src/google/protobuf:test_protos -set(protobuf_test_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_protos-descriptor-set.proto.bin -) - # //src/google/protobuf:lite_test_srcs set(protobuf_lite_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_arena_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_unittest.cc ) -# //src/google/protobuf:lite_test_protos -set(protobuf_lite_test_protos_proto_srcs +# //src/google/protobuf:lite_test_proto_srcs +set(protobuf_lite_test_protos_files ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_unittest.proto ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_lite.proto ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public_lite.proto ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite.proto ) -# //src/google/protobuf:lite_test_protos -set(protobuf_lite_test_protos_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_unittest.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_lite.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public_lite.proto.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite.proto.pb.cc -) - -# //src/google/protobuf:lite_test_protos -set(protobuf_lite_test_protos_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_unittest.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_lite.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public_lite.proto.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite.proto.pb.h -) - -# //src/google/protobuf:lite_test_protos -set(protobuf_lite_test_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_test_protos-descriptor-set.proto.bin -) - # //src/google/protobuf/compiler:test_srcs set(compiler_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -750,26 +684,6 @@ set(compiler_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc ) -# //pkg:compiler_annotation_test_util -set(annotation_test_util_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.cc -) - -# //pkg:compiler_annotation_test_util -set(annotation_test_util_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.h -) - -# //pkg:compiler_mock_code_generator -set(mock_code_generator_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc -) - -# //pkg:compiler_mock_code_generator -set(mock_code_generator_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.h -) - # //src/google/protobuf/compiler:test_proto_srcs set(compiler_test_protos_files ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto @@ -792,18 +706,6 @@ set(io_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_unittest.cc ) -# //pkg:testinglib -set(testing_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.cc -) - -# //pkg:testinglib -set(testing_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.h -) - # //src/google/protobuf/util:test_srcs set(util_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util_test.cc diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 91aaab9e30..8eaa0113e1 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -392,14 +392,20 @@ filegroup( ], ) -proto_library( - name = "lite_test_protos", +filegroup( + name = "lite_test_proto_srcs", srcs = [ "map_lite_unittest.proto", "unittest_import_lite.proto", "unittest_import_public_lite.proto", "unittest_lite.proto", ], + visibility = ["//:__subpackages__"], +) + +proto_library( + name = "lite_test_protos", + srcs = [":lite_test_proto_srcs"], strip_import_prefix = "/src", visibility = ["//:__subpackages__"], deps = [ diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel index 4a17bc10f0..8d6657d2f4 100644 --- a/src/google/protobuf/compiler/cpp/BUILD.bazel +++ b/src/google/protobuf/compiler/cpp/BUILD.bazel @@ -97,6 +97,7 @@ cc_library( "unittest.inc", ], strip_include_prefix = "/src", + visibility = ["//pkg:__pkg__"], ) cc_test( From 6a28393f089d9f3ab2242d0207ef216dd5171ca2 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 19 Sep 2022 12:44:31 -0400 Subject: [PATCH 37/39] Keep the class forward declaration also. Some users might be depended on these, so until everything is flipped to explicit imports, need to still provide the class declaration so the proto isn't a breaking change. --- objectivec/GPBCodedInputStream.h | 1 + objectivec/GPBMessage.h | 1 + 2 files changed, 2 insertions(+) diff --git a/objectivec/GPBCodedInputStream.h b/objectivec/GPBCodedInputStream.h index 73b65581d7..2b95cc9ae2 100644 --- a/objectivec/GPBCodedInputStream.h +++ b/objectivec/GPBCodedInputStream.h @@ -31,6 +31,7 @@ #import @class GPBMessage; +@class GPBExtensionRegistry; @protocol GPBExtensionRegistry; NS_ASSUME_NONNULL_BEGIN diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index 990a796faf..ddd5de7c9f 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -36,6 +36,7 @@ @class GPBCodedInputStream; @class GPBCodedOutputStream; @class GPBExtensionDescriptor; +@class GPBExtensionRegistry; @protocol GPBExtensionRegistry; @class GPBFieldDescriptor; @class GPBUnknownFieldSet; From 99955470e098aa79d6572f057d430f89c75bbc56 Mon Sep 17 00:00:00 2001 From: Ted Pudlik Date: Mon, 19 Sep 2022 19:12:05 +0000 Subject: [PATCH 38/39] Add reserved extension number for Pigweed The extension number will be used for providing custom options to the Pigweed protobuf compiler. Support for this is added in https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/110632. --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index dc19688235..87f7dca50b 100644 --- a/docs/options.md +++ b/docs/options.md @@ -344,3 +344,7 @@ with info about your project (name and website) so we can add an entry for you. 1. mypy-protobuf * Website: https://github.com/nipunn1313/mypy-protobuf * Extension: 1151-1154 + +1. Pigweed protobuf compiler + * Website: https://pigweed.dev/pw_protobuf + * Extension: 1155 From 5392dc1dd4f6542598d8717a84ee2db678c4aeee Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 19 Sep 2022 16:06:12 -0400 Subject: [PATCH 39/39] [ObjC] Use a real import for GPBExtensionRegistry. The fwd decls can lead to ambiguity for downstream users, so use a full import to avoid the potential issues. --- objectivec/GPBCodedInputStream.h | 4 ++-- objectivec/GPBMessage.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/objectivec/GPBCodedInputStream.h b/objectivec/GPBCodedInputStream.h index 2b95cc9ae2..b7e1c7e6ab 100644 --- a/objectivec/GPBCodedInputStream.h +++ b/objectivec/GPBCodedInputStream.h @@ -30,9 +30,9 @@ #import +#import "GPBExtensionRegistry.h" + @class GPBMessage; -@class GPBExtensionRegistry; -@protocol GPBExtensionRegistry; NS_ASSUME_NONNULL_BEGIN diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index ddd5de7c9f..f80778bc39 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -31,13 +31,12 @@ #import #import "GPBBootstrap.h" +#import "GPBExtensionRegistry.h" @class GPBDescriptor; @class GPBCodedInputStream; @class GPBCodedOutputStream; @class GPBExtensionDescriptor; -@class GPBExtensionRegistry; -@protocol GPBExtensionRegistry; @class GPBFieldDescriptor; @class GPBUnknownFieldSet;