From a6da5f7aa4301b8bbd4375a47356fea889d0ec5d Mon Sep 17 00:00:00 2001 From: tony Date: Fri, 15 Jul 2022 14:37:27 +0100 Subject: [PATCH 01/23] issue 8101 fix csharp name starting with digit --- .../csharp/csharp_generator_unittest.cc | 16 ++++++++++++++++ .../protobuf/compiler/csharp/csharp_helpers.cc | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index e21eff17ba..63adaf3110 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -74,6 +74,22 @@ TEST(DescriptorProtoHelpers, IsDescriptorOptionMessage) { EXPECT_FALSE(IsDescriptorOptionMessage(DescriptorProto::descriptor())); } +TEST(CSharpIdentifiers, UnderscoresToCamelCase) { + EXPECT_EQ("FooBar", UnderscoresToCamelCase("Foo_Bar", true)); + EXPECT_EQ("fooBar", UnderscoresToCamelCase("FooBar", false)); + EXPECT_EQ("foo123", UnderscoresToCamelCase("foo_123", false)); + // remove leading underscores + EXPECT_EQ("Foo123", UnderscoresToCamelCase("_Foo_123", true)); + // this one has slight unexpected output as it capitalises the first + // letter after consuming the underscores, but this was the existing + // behaviour so I have to changed it + EXPECT_EQ("FooBar", UnderscoresToCamelCase("___fooBar", false)); + // leave a leading underscore for identifiers that would otherwise + // be invalid because they would start with a digit + EXPECT_EQ("_123Foo", UnderscoresToCamelCase("_123_foo", true)); + EXPECT_EQ("_123Foo", UnderscoresToCamelCase("___123_foo", true)); +} + } // namespace } // namespace csharp } // namespace compiler diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 42d952721e..8109d22eab 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -144,6 +144,7 @@ std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter, bool preserve_period) { std::string result; + // Note: I distrust ctype.h due to locales. for (int i = 0; i < input.size(); i++) { if ('a' <= input[i] && input[i] <= 'z') { @@ -177,6 +178,22 @@ std::string UnderscoresToCamelCase(const std::string& input, if (input.size() > 0 && input[input.size() - 1] == '#') { result += '_'; } + + // https://github.com/protocolbuffers/protobuf/issues/8101 + // To avoid generating invalid identifiers - if the input string + // starts with _ (or multiple underscores then digit) then + // we need to preserve the underscore as an identifier cannot start + // with a digit. + // This check is being done after the loop rather than before + // to handle the case where there are multiple underscores before the + // first digit. We let them all be consumed so we can see if we would + // start with a digit. + // Note: not preserving leading underscores for all otherwise valid identifiers + // so as to not break anything that relies on the existing behaviour + if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9') && input.size() > 0 && input[0] == '_') + { + result.insert(0, 1, '_'); + } return result; } From 69b8686caefe783767ecce275d807d38e800b0d6 Mon Sep 17 00:00:00 2001 From: tony Date: Tue, 19 Jul 2022 10:14:57 +0100 Subject: [PATCH 02/23] Fix typo in comments --- .../protobuf/compiler/csharp/csharp_generator_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index 63adaf3110..56b920dbdf 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -82,7 +82,7 @@ TEST(CSharpIdentifiers, UnderscoresToCamelCase) { EXPECT_EQ("Foo123", UnderscoresToCamelCase("_Foo_123", true)); // this one has slight unexpected output as it capitalises the first // letter after consuming the underscores, but this was the existing - // behaviour so I have to changed it + // behaviour so I have not changed it EXPECT_EQ("FooBar", UnderscoresToCamelCase("___fooBar", false)); // leave a leading underscore for identifiers that would otherwise // be invalid because they would start with a digit From 68de42df88132f97ecdbf183453869a8e25c26c7 Mon Sep 17 00:00:00 2001 From: tony Date: Tue, 19 Jul 2022 13:10:54 +0100 Subject: [PATCH 03/23] tidy up code formatting --- src/google/protobuf/compiler/csharp/csharp_helpers.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 8109d22eab..d40c9d39d7 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -190,7 +190,8 @@ std::string UnderscoresToCamelCase(const std::string& input, // start with a digit. // Note: not preserving leading underscores for all otherwise valid identifiers // so as to not break anything that relies on the existing behaviour - if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9') && input.size() > 0 && input[0] == '_') + if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9') + && input.size() > 0 && input[0] == '_') { result.insert(0, 1, '_'); } From c752a43e1ee48d6f40d3ac564b864e58a4623843 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 26 Jul 2022 18:20:23 -0700 Subject: [PATCH 04/23] fix: fix PHP readonly legacy files for nested messages --- php/tests/GeneratedClassTest.php | 1 + php/tests/proto/test_php_namespace.proto | 2 ++ .../protobuf/compiler/php/php_generator.cc | 33 ++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php index 37c33dfabe..b42649dc18 100644 --- a/php/tests/GeneratedClassTest.php +++ b/php/tests/GeneratedClassTest.php @@ -338,6 +338,7 @@ class GeneratedClassTest extends TestBase { $this->assertTrue(class_exists('\Upper\READONLY')); $this->assertTrue(class_exists('\Lower\readonly')); + $this->assertTrue(class_exists('\Php\Test\TestNamespace\PBEmpty\ReadOnly')); } public function testLegacyReadOnlyEnum() diff --git a/php/tests/proto/test_php_namespace.proto b/php/tests/proto/test_php_namespace.proto index 61085bf75a..eb4a523797 100644 --- a/php/tests/proto/test_php_namespace.proto +++ b/php/tests/proto/test_php_namespace.proto @@ -27,5 +27,7 @@ message TestNamespace { enum NestedEnum { ZERO = 0; }; + // Test previously unreserved name + message ReadOnly {} } } diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 6c824e3733..b2387039e8 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -421,12 +421,17 @@ std::string LegacyGeneratedClassFileName(const DescriptorType* desc, } template -std::string LegacyReadOnlyGeneratedClassFileName(const DescriptorType* desc, - const Options& options) { - std::string php_namespace = RootPhpNamespace(desc, options); +std::string LegacyReadOnlyGeneratedClassFileName(std::string php_namespace, + const DescriptorType* desc) { if (!php_namespace.empty()) { + for (int i = 0; i < php_namespace.size(); i++) { + if (php_namespace[i] == '\\') { + php_namespace[i] = '/'; + } + } return php_namespace + "/" + desc->name() + ".php"; } + return desc->name() + ".php"; } @@ -1316,27 +1321,39 @@ template void LegacyReadOnlyGenerateClassFile(const FileDescriptor* file, const DescriptorType* desc, const Options& options, GeneratorContext* generator_context) { - std::string filename = LegacyReadOnlyGeneratedClassFileName(desc, options); + std::string fullname = FullClassName(desc, options); + std::string php_namespace; + std::string classname; + int lastindex = fullname.find_last_of("\\"); + + if (lastindex != std::string::npos) { + php_namespace = fullname.substr(0, lastindex); + classname = fullname.substr(lastindex + 1); + } else { + php_namespace = ""; + classname = fullname; + } + + std::string filename = LegacyReadOnlyGeneratedClassFileName(php_namespace, desc); std::unique_ptr output( generator_context->Open(filename)); io::Printer printer(output.get(), '^'); GenerateHead(file, &printer); - std::string php_namespace = RootPhpNamespace(desc, options); if (!php_namespace.empty()) { printer.Print( "namespace ^name^;\n\n", "name", php_namespace); } - std::string newname = FullClassName(desc, options); + printer.Print("class_exists(^new^::class); // autoload the new class, which " "will also create an alias to the deprecated class\n", - "new", GeneratedClassNameImpl(desc)); + "new", classname); printer.Print("@trigger_error(__NAMESPACE__ . '\\^old^ is deprecated and will be removed in " "the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n", "old", desc->name(), - "fullname", newname); + "fullname", classname); } void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, From 5999a02891a1936c732b0fb13e2bd0cfb2c446e8 Mon Sep 17 00:00:00 2001 From: NathanGrand Date: Wed, 27 Jul 2022 16:01:55 +0100 Subject: [PATCH 05/23] Fix Timestamps fromDate for negative 'exact second' java.sql.Timestamps --- .../src/main/java/com/google/protobuf/util/Timestamps.java | 2 +- .../test/java/com/google/protobuf/util/TimestampsTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index ea8a9334bc..0b09fccd2a 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -344,7 +344,7 @@ public final class Timestamps { if (date instanceof java.sql.Timestamp) { java.sql.Timestamp sqlTimestamp = (java.sql.Timestamp) date; long time = sqlTimestamp.getTime(); - long integralSeconds = (time < 0) ? time / 1000L - 1 : time / 1000L ; // truncate the fractional seconds + long integralSeconds = (time < 0 && time % 1000 != 0) ? time / 1000L - 1 : time / 1000L ; // truncate the fractional seconds return Timestamp.newBuilder() .setSeconds(integralSeconds) .setNanos(sqlTimestamp.getNanos()) diff --git a/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java b/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java index 7d0d821c3f..51f7a85b49 100644 --- a/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java @@ -483,6 +483,13 @@ public class TimestampsTest { assertThat(Timestamps.toString(timestamp)).isEqualTo("1969-12-31T23:59:58.889Z"); } + @Test + public void testFromSqlTimestamp_beforeEpochWholeSecond() { + Date date = new java.sql.Timestamp(-2000); + Timestamp timestamp = Timestamps.fromDate(date); + assertThat(Timestamps.toString(timestamp)).isEqualTo("1969-12-31T23:59:58Z"); + } + @Test public void testTimeOperations() throws Exception { Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z"); From 05ba39a34f4337c86bfa0ff20f64975bc128c4ac Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Thu, 28 Jul 2022 22:07:59 +0000 Subject: [PATCH 06/23] Revert third_party/benchmark changes from sync --- third_party/benchmark | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/benchmark b/third_party/benchmark index 0baacde361..5b7683f49e 160000 --- a/third_party/benchmark +++ b/third_party/benchmark @@ -1 +1 @@ -Subproject commit 0baacde3618ca617da95375e0af13ce1baadea47 +Subproject commit 5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8 From f3ebd8bb80609cbf8c9a9644baefda40c78a44f1 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Mon, 1 Aug 2022 15:20:44 -0700 Subject: [PATCH 07/23] Add placeholders for further testing (#10336) * Fix comments in cmake test files * Add placeholder tests --- kokoro/linux/cmake/build.sh | 2 +- kokoro/linux/cmake_install/build.sh | 2 +- kokoro/linux/cmake_ninja/build.sh | 2 +- kokoro/linux/cmake_shared/build.sh | 7 +++++++ kokoro/linux/cmake_shared/continuous.cfg | 11 +++++++++++ kokoro/linux/cmake_shared/presubmit.cfg | 11 +++++++++++ kokoro/windows/bazel/build.bat | 4 ++++ kokoro/windows/bazel/continuous.cfg | 5 +++++ kokoro/windows/bazel/presubmit.cfg | 5 +++++ kokoro/windows/cmake_shared/build.bat | 4 ++++ kokoro/windows/cmake_shared/continuous.cfg | 5 +++++ kokoro/windows/cmake_shared/presubmit.cfg | 5 +++++ 12 files changed, 60 insertions(+), 3 deletions(-) create mode 100755 kokoro/linux/cmake_shared/build.sh create mode 100644 kokoro/linux/cmake_shared/continuous.cfg create mode 100644 kokoro/linux/cmake_shared/presubmit.cfg create mode 100644 kokoro/windows/bazel/build.bat create mode 100644 kokoro/windows/bazel/continuous.cfg create mode 100644 kokoro/windows/bazel/presubmit.cfg create mode 100644 kokoro/windows/cmake_shared/build.bat create mode 100644 kokoro/windows/cmake_shared/continuous.cfg create mode 100644 kokoro/windows/cmake_shared/presubmit.cfg diff --git a/kokoro/linux/cmake/build.sh b/kokoro/linux/cmake/build.sh index 1b0ebfc5fa..523253da25 100755 --- a/kokoro/linux/cmake/build.sh +++ b/kokoro/linux/cmake/build.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Build file to set up and run tests based on distribution archive +# Build file to set up and run tests using CMake set -eux diff --git a/kokoro/linux/cmake_install/build.sh b/kokoro/linux/cmake_install/build.sh index 6fdafa557e..7fdf267f74 100755 --- a/kokoro/linux/cmake_install/build.sh +++ b/kokoro/linux/cmake_install/build.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Build file to set up and run tests based on distribution archive +# Build file to build, install, and test using CMake. set -eux diff --git a/kokoro/linux/cmake_ninja/build.sh b/kokoro/linux/cmake_ninja/build.sh index d3a281f9ec..21cc01e56a 100755 --- a/kokoro/linux/cmake_ninja/build.sh +++ b/kokoro/linux/cmake_ninja/build.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Build file to set up and run tests based on distribution archive +# Build file to set up and run tests using CMake with the Ninja generator. set -eux diff --git a/kokoro/linux/cmake_shared/build.sh b/kokoro/linux/cmake_shared/build.sh new file mode 100755 index 0000000000..87dde411c7 --- /dev/null +++ b/kokoro/linux/cmake_shared/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# +# Build file to set up and run tests via CMake using shared libraries + +set -eux + +# TODO(mkruskal) Implement this. \ No newline at end of file diff --git a/kokoro/linux/cmake_shared/continuous.cfg b/kokoro/linux/cmake_shared/continuous.cfg new file mode 100644 index 0000000000..f03bd3945f --- /dev/null +++ b/kokoro/linux/cmake_shared/continuous.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cmake/build.sh" +timeout_mins: 1440 + +action { + define_artifacts { + regex: "**/sponge_log.*" + } +} diff --git a/kokoro/linux/cmake_shared/presubmit.cfg b/kokoro/linux/cmake_shared/presubmit.cfg new file mode 100644 index 0000000000..f03bd3945f --- /dev/null +++ b/kokoro/linux/cmake_shared/presubmit.cfg @@ -0,0 +1,11 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cmake/build.sh" +timeout_mins: 1440 + +action { + define_artifacts { + regex: "**/sponge_log.*" + } +} diff --git a/kokoro/windows/bazel/build.bat b/kokoro/windows/bazel/build.bat new file mode 100644 index 0000000000..52b83f4666 --- /dev/null +++ b/kokoro/windows/bazel/build.bat @@ -0,0 +1,4 @@ +@rem enter repo root +cd /d %~dp0\..\..\.. + +@rem TODO(mkruskal) Implement tests diff --git a/kokoro/windows/bazel/continuous.cfg b/kokoro/windows/bazel/continuous.cfg new file mode 100644 index 0000000000..37e89e068b --- /dev/null +++ b/kokoro/windows/bazel/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/cmake/build.bat" +timeout_mins: 1440 diff --git a/kokoro/windows/bazel/presubmit.cfg b/kokoro/windows/bazel/presubmit.cfg new file mode 100644 index 0000000000..37e89e068b --- /dev/null +++ b/kokoro/windows/bazel/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/cmake/build.bat" +timeout_mins: 1440 diff --git a/kokoro/windows/cmake_shared/build.bat b/kokoro/windows/cmake_shared/build.bat new file mode 100644 index 0000000000..52b83f4666 --- /dev/null +++ b/kokoro/windows/cmake_shared/build.bat @@ -0,0 +1,4 @@ +@rem enter repo root +cd /d %~dp0\..\..\.. + +@rem TODO(mkruskal) Implement tests diff --git a/kokoro/windows/cmake_shared/continuous.cfg b/kokoro/windows/cmake_shared/continuous.cfg new file mode 100644 index 0000000000..37e89e068b --- /dev/null +++ b/kokoro/windows/cmake_shared/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/cmake/build.bat" +timeout_mins: 1440 diff --git a/kokoro/windows/cmake_shared/presubmit.cfg b/kokoro/windows/cmake_shared/presubmit.cfg new file mode 100644 index 0000000000..37e89e068b --- /dev/null +++ b/kokoro/windows/cmake_shared/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/cmake/build.bat" +timeout_mins: 1440 From 86fa35913d309a3293800aab44f320a5fef0647b Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 2 Aug 2022 09:38:35 +0100 Subject: [PATCH 08/23] Add MapField.MergeFrom to merge maps without failing on duplicate keys This will enable message MergeFrom methods to implement the documented behavior. --- .../src/Google.Protobuf/Collections/MapField.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index f0124ee12b..09afb75cdb 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -237,6 +237,21 @@ namespace Google.Protobuf.Collections } } + /// + /// Adds the specified entries to the map, replacing any existing entries with the same keys. + /// The keys and values are not automatically cloned. + /// + /// This method primarily exists to be called from MergeFrom methods in generated classes for messages. + /// The entries to add to the map. + public void MergeFrom(IDictionary entries) + { + ProtoPreconditions.CheckNotNull(entries, nameof(entries)); + foreach (var pair in entries) + { + this[pair.Key] = pair.Value; + } + } + /// /// Returns an enumerator that iterates through the collection. /// From 1d990dcb9c517a850829e413c741a73b3382f07a Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 2 Aug 2022 09:39:02 +0100 Subject: [PATCH 09/23] Make the C# generator use the new MapField.MergeFrom method in generated code --- src/google/protobuf/compiler/csharp/csharp_map_field.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index a13b995da8..9efd3d524f 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -90,7 +90,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { printer->Print( variables_, - "$name$_.Add(other.$name$_);\n"); + "$name$_.MergeFrom(other.$name$_);\n"); } void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { From a7dcf1b6c1572ebe2f8ab326f61630a00fdeec15 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 2 Aug 2022 09:40:40 +0100 Subject: [PATCH 10/23] Regenerate C# protos The only change is in generated MergeFrom methods for messages with map fields, which now call MapField.MergeFrom instead of Add. --- .../MapUnittestProto3.cs | 74 +++++++++---------- .../TestMessagesProto2.cs | 38 +++++----- .../TestMessagesProto3.cs | 38 +++++----- .../Unittest.cs | 4 +- .../UnittestWellKnownTypes.cs | 36 ++++----- .../Google.Protobuf/WellKnownTypes/Struct.cs | 2 +- 6 files changed, 96 insertions(+), 96 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs index 57e59a9ac3..d3284a40f6 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs @@ -580,23 +580,23 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - mapInt32Int32_.Add(other.mapInt32Int32_); - mapInt64Int64_.Add(other.mapInt64Int64_); - mapUint32Uint32_.Add(other.mapUint32Uint32_); - mapUint64Uint64_.Add(other.mapUint64Uint64_); - mapSint32Sint32_.Add(other.mapSint32Sint32_); - mapSint64Sint64_.Add(other.mapSint64Sint64_); - mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); - mapInt32Float_.Add(other.mapInt32Float_); - mapInt32Double_.Add(other.mapInt32Double_); - mapBoolBool_.Add(other.mapBoolBool_); - mapStringString_.Add(other.mapStringString_); - mapInt32Bytes_.Add(other.mapInt32Bytes_); - mapInt32Enum_.Add(other.mapInt32Enum_); - mapInt32ForeignMessage_.Add(other.mapInt32ForeignMessage_); + mapInt32Int32_.MergeFrom(other.mapInt32Int32_); + mapInt64Int64_.MergeFrom(other.mapInt64Int64_); + mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); + mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); + mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); + mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); + mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); + mapInt32Float_.MergeFrom(other.mapInt32Float_); + mapInt32Double_.MergeFrom(other.mapInt32Double_); + mapBoolBool_.MergeFrom(other.mapBoolBool_); + mapStringString_.MergeFrom(other.mapStringString_); + mapInt32Bytes_.MergeFrom(other.mapInt32Bytes_); + mapInt32Enum_.MergeFrom(other.mapInt32Enum_); + mapInt32ForeignMessage_.MergeFrom(other.mapInt32ForeignMessage_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -1100,7 +1100,7 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - mapInt32Message_.Add(other.mapInt32Message_); + mapInt32Message_.MergeFrom(other.mapInt32Message_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -1298,8 +1298,8 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - map1_.Add(other.map1_); - map2_.Add(other.map2_); + map1_.MergeFrom(other.map1_); + map2_.MergeFrom(other.map2_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -1723,21 +1723,21 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - mapInt32Int32_.Add(other.mapInt32Int32_); - mapInt64Int64_.Add(other.mapInt64Int64_); - mapUint32Uint32_.Add(other.mapUint32Uint32_); - mapUint64Uint64_.Add(other.mapUint64Uint64_); - mapSint32Sint32_.Add(other.mapSint32Sint32_); - mapSint64Sint64_.Add(other.mapSint64Sint64_); - mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); - mapInt32Float_.Add(other.mapInt32Float_); - mapInt32Double_.Add(other.mapInt32Double_); - mapBoolBool_.Add(other.mapBoolBool_); - mapInt32Enum_.Add(other.mapInt32Enum_); - mapInt32ForeignMessage_.Add(other.mapInt32ForeignMessage_); + mapInt32Int32_.MergeFrom(other.mapInt32Int32_); + mapInt64Int64_.MergeFrom(other.mapInt64Int64_); + mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); + mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); + mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); + mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); + mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); + mapInt32Float_.MergeFrom(other.mapInt32Float_); + mapInt32Double_.MergeFrom(other.mapInt32Double_); + mapBoolBool_.MergeFrom(other.mapBoolBool_); + mapInt32Enum_.MergeFrom(other.mapInt32Enum_); + mapInt32ForeignMessage_.MergeFrom(other.mapInt32ForeignMessage_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -2031,7 +2031,7 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - type_.Add(other.type_); + type_.MergeFrom(other.type_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -2224,7 +2224,7 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - entry_.Add(other.entry_); + entry_.MergeFrom(other.entry_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs index 08b1aaf80c..d5734552c0 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs @@ -4344,25 +4344,25 @@ namespace ProtobufTestMessages.Proto2 { unpackedDouble_.Add(other.unpackedDouble_); unpackedBool_.Add(other.unpackedBool_); unpackedNestedEnum_.Add(other.unpackedNestedEnum_); - mapInt32Int32_.Add(other.mapInt32Int32_); - mapInt64Int64_.Add(other.mapInt64Int64_); - mapUint32Uint32_.Add(other.mapUint32Uint32_); - mapUint64Uint64_.Add(other.mapUint64Uint64_); - mapSint32Sint32_.Add(other.mapSint32Sint32_); - mapSint64Sint64_.Add(other.mapSint64Sint64_); - mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); - mapInt32Float_.Add(other.mapInt32Float_); - mapInt32Double_.Add(other.mapInt32Double_); - mapBoolBool_.Add(other.mapBoolBool_); - mapStringString_.Add(other.mapStringString_); - mapStringBytes_.Add(other.mapStringBytes_); - mapStringNestedMessage_.Add(other.mapStringNestedMessage_); - mapStringForeignMessage_.Add(other.mapStringForeignMessage_); - mapStringNestedEnum_.Add(other.mapStringNestedEnum_); - mapStringForeignEnum_.Add(other.mapStringForeignEnum_); + mapInt32Int32_.MergeFrom(other.mapInt32Int32_); + mapInt64Int64_.MergeFrom(other.mapInt64Int64_); + mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); + mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); + mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); + mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); + mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); + mapInt32Float_.MergeFrom(other.mapInt32Float_); + mapInt32Double_.MergeFrom(other.mapInt32Double_); + mapBoolBool_.MergeFrom(other.mapBoolBool_); + mapStringString_.MergeFrom(other.mapStringString_); + mapStringBytes_.MergeFrom(other.mapStringBytes_); + mapStringNestedMessage_.MergeFrom(other.mapStringNestedMessage_); + mapStringForeignMessage_.MergeFrom(other.mapStringForeignMessage_); + mapStringNestedEnum_.MergeFrom(other.mapStringNestedEnum_); + mapStringForeignEnum_.MergeFrom(other.mapStringForeignEnum_); if (other.HasData) { if (!HasData) { Data = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.Data(); diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs index 520216fdf5..74e2a57680 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs @@ -3753,25 +3753,25 @@ namespace ProtobufTestMessages.Proto3 { unpackedDouble_.Add(other.unpackedDouble_); unpackedBool_.Add(other.unpackedBool_); unpackedNestedEnum_.Add(other.unpackedNestedEnum_); - mapInt32Int32_.Add(other.mapInt32Int32_); - mapInt64Int64_.Add(other.mapInt64Int64_); - mapUint32Uint32_.Add(other.mapUint32Uint32_); - mapUint64Uint64_.Add(other.mapUint64Uint64_); - mapSint32Sint32_.Add(other.mapSint32Sint32_); - mapSint64Sint64_.Add(other.mapSint64Sint64_); - mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); - mapInt32Float_.Add(other.mapInt32Float_); - mapInt32Double_.Add(other.mapInt32Double_); - mapBoolBool_.Add(other.mapBoolBool_); - mapStringString_.Add(other.mapStringString_); - mapStringBytes_.Add(other.mapStringBytes_); - mapStringNestedMessage_.Add(other.mapStringNestedMessage_); - mapStringForeignMessage_.Add(other.mapStringForeignMessage_); - mapStringNestedEnum_.Add(other.mapStringNestedEnum_); - mapStringForeignEnum_.Add(other.mapStringForeignEnum_); + mapInt32Int32_.MergeFrom(other.mapInt32Int32_); + mapInt64Int64_.MergeFrom(other.mapInt64Int64_); + mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); + mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); + mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); + mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); + mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); + mapInt32Float_.MergeFrom(other.mapInt32Float_); + mapInt32Double_.MergeFrom(other.mapInt32Double_); + mapBoolBool_.MergeFrom(other.mapBoolBool_); + mapStringString_.MergeFrom(other.mapStringString_); + mapStringBytes_.MergeFrom(other.mapStringBytes_); + mapStringNestedMessage_.MergeFrom(other.mapStringNestedMessage_); + mapStringForeignMessage_.MergeFrom(other.mapStringForeignMessage_); + mapStringNestedEnum_.MergeFrom(other.mapStringNestedEnum_); + mapStringForeignEnum_.MergeFrom(other.mapStringForeignEnum_); if (other.optionalBoolWrapper_ != null) { if (optionalBoolWrapper_ == null || other.OptionalBoolWrapper != false) { OptionalBoolWrapper = other.OptionalBoolWrapper; diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs index c1f43ce0f8..7f1aca1b92 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs @@ -24112,7 +24112,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - foo_.Add(other.foo_); + foo_.MergeFrom(other.foo_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -30708,7 +30708,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } OptionalGroup.MergeFrom(other.OptionalGroup); } - stringStringMap_.Add(other.stringStringMap_); + stringStringMap_.MergeFrom(other.stringStringMap_); switch (other.OneofFieldCase) { case OneofFieldOneofCase.OneofUint32: OneofUint32 = other.OneofUint32; diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs index 3ec8d3556f..50b9046a3b 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs @@ -3258,24 +3258,24 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - anyField_.Add(other.anyField_); - apiField_.Add(other.apiField_); - durationField_.Add(other.durationField_); - emptyField_.Add(other.emptyField_); - fieldMaskField_.Add(other.fieldMaskField_); - sourceContextField_.Add(other.sourceContextField_); - structField_.Add(other.structField_); - timestampField_.Add(other.timestampField_); - typeField_.Add(other.typeField_); - doubleField_.Add(other.doubleField_); - floatField_.Add(other.floatField_); - int64Field_.Add(other.int64Field_); - uint64Field_.Add(other.uint64Field_); - int32Field_.Add(other.int32Field_); - uint32Field_.Add(other.uint32Field_); - boolField_.Add(other.boolField_); - stringField_.Add(other.stringField_); - bytesField_.Add(other.bytesField_); + anyField_.MergeFrom(other.anyField_); + apiField_.MergeFrom(other.apiField_); + durationField_.MergeFrom(other.durationField_); + emptyField_.MergeFrom(other.emptyField_); + fieldMaskField_.MergeFrom(other.fieldMaskField_); + sourceContextField_.MergeFrom(other.sourceContextField_); + structField_.MergeFrom(other.structField_); + timestampField_.MergeFrom(other.timestampField_); + typeField_.MergeFrom(other.typeField_); + doubleField_.MergeFrom(other.doubleField_); + floatField_.MergeFrom(other.floatField_); + int64Field_.MergeFrom(other.int64Field_); + uint64Field_.MergeFrom(other.uint64Field_); + int32Field_.MergeFrom(other.int32Field_); + uint32Field_.MergeFrom(other.uint32Field_); + boolField_.MergeFrom(other.boolField_); + stringField_.MergeFrom(other.stringField_); + bytesField_.MergeFrom(other.bytesField_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs index 8c1eec53b4..aa25686dee 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs @@ -212,7 +212,7 @@ namespace Google.Protobuf.WellKnownTypes { if (other == null) { return; } - fields_.Add(other.fields_); + fields_.MergeFrom(other.fields_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } From 71f4d7e682140748f52713949d43b5e2fe66be96 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 2 Aug 2022 09:41:29 +0100 Subject: [PATCH 11/23] Tests for new MapField behavior in generated messages Before the change, one test passed (merging from a stream) and one failed (merging from another message object) --- .../GeneratedMessageTest.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 8387291956..17c5249140 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -36,6 +36,7 @@ using Google.Protobuf.TestProtos; using NUnit.Framework; using System.Linq; using Google.Protobuf.WellKnownTypes; +using Google.Protobuf.Collections; namespace Google.Protobuf { @@ -795,5 +796,44 @@ namespace Google.Protobuf EqualityTester.AssertInequality(message1, message2); EqualityTester.AssertEquality(message1, message3); } + + [Test] + [TestCase(false)] + [TestCase(true)] + public void MapFieldMerging(bool direct) + { + var message1 = new TestMap + { + MapStringString = + { + { "x1", "y1" }, + { "common", "message1" } + } + }; + var message2 = new TestMap + { + MapStringString = + { + { "x2", "y2" }, + { "common", "message2" } + } + }; + if (direct) + { + message1.MergeFrom(message2); + } + else + { + message1.MergeFrom(message2.ToByteArray()); + } + + var expected = new MapField + { + { "x1", "y1" }, + { "x2", "y2" }, + { "common", "message2" } + }; + Assert.AreEqual(expected, message1.MapStringString); + } } } \ No newline at end of file From 7beb116549cf37f97e3a35d4a38598116f98ce2e Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 2 Aug 2022 14:57:29 +0100 Subject: [PATCH 12/23] Clarify C# MessageParser and JSON parsing behavior Addresses #8316 as far as we want to. --- csharp/src/Google.Protobuf/MessageParser.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs index 66907d46fa..57102920ef 100644 --- a/csharp/src/Google.Protobuf/MessageParser.cs +++ b/csharp/src/Google.Protobuf/MessageParser.cs @@ -171,6 +171,10 @@ namespace Google.Protobuf /// /// Parses a message from the given JSON. /// + /// This method always uses the default JSON parser; it is not affected by . + /// To ignore unknown fields when parsing JSON, create a using a + /// with set to true and call directly. + /// /// The JSON to parse. /// The parsed message. /// The JSON does not comply with RFC 7159 @@ -203,6 +207,9 @@ namespace Google.Protobuf /// /// Creates a new message parser which optionally discards unknown fields when parsing. /// + /// Note that this does not affect the behavior of + /// at all. To ignore unknown fields when parsing JSON, create a using a + /// with set to true and call directly. /// Whether or not to discard unknown fields when parsing. /// A newly configured message parser. public MessageParser WithDiscardUnknownFields(bool discardUnknownFields) => From e031663f291ec89bbb13c708fad284eebdc429af Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Tue, 2 Aug 2022 14:08:02 -0400 Subject: [PATCH 13/23] Re-reremove extract_includes.bat.in --- cmake/extract_includes.bat.in | 144 ---------------------------------- 1 file changed, 144 deletions(-) delete mode 100644 cmake/extract_includes.bat.in diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in deleted file mode 100644 index 1292829219..0000000000 --- a/cmake/extract_includes.bat.in +++ /dev/null @@ -1,144 +0,0 @@ -mkdir include -mkdir include\google -mkdir include\google\protobuf -mkdir include\google\protobuf\compiler -mkdir include\google\protobuf\compiler\cpp -mkdir include\google\protobuf\compiler\csharp -mkdir include\google\protobuf\compiler\java -mkdir include\google\protobuf\compiler\objectivec -mkdir include\google\protobuf\compiler\php -mkdir include\google\protobuf\compiler\python -mkdir include\google\protobuf\compiler\ruby -mkdir include\google\protobuf\io -mkdir include\google\protobuf\stubs -mkdir include\google\protobuf\util -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.h" include\google\protobuf\any.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.pb.h" include\google\protobuf\any.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.pb.h" include\google\protobuf\api.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena.h" include\google\protobuf\arena.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena_impl.h" include\google\protobuf\arena_impl.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenastring.h" include\google\protobuf\arenastring.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenaz_sampler.h" include\google\protobuf\arenaz_sampler.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\code_generator.h" include\google\protobuf\compiler\code_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_interface.h" include\google\protobuf\compiler\command_line_interface.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\file.h" include\google\protobuf\compiler\cpp\file.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h" include\google\protobuf\compiler\cpp\cpp_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\generator.h" include\google\protobuf\compiler\cpp\generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\helpers.h" include\google\protobuf\compiler\cpp\helpers.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\names.h" include\google\protobuf\compiler\cpp\names.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_doc_comment.h" include\google\protobuf\compiler\csharp\csharp_doc_comment.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h" include\google\protobuf\compiler\csharp\csharp_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_names.h" include\google\protobuf\compiler\csharp\csharp_names.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_options.h" include\google\protobuf\compiler\csharp\csharp_options.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h" include\google\protobuf\compiler\importer.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\generator.h" include\google\protobuf\compiler\java\generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h" include\google\protobuf\compiler\java\java_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\kotlin_generator.h" include\google\protobuf\compiler\java\kotlin_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\names.h" include\google\protobuf\compiler\java\names.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_generator.h" include\google\protobuf\compiler\objectivec\objectivec_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_helpers.h" include\google\protobuf\compiler\objectivec\objectivec_helpers.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\parser.h" include\google\protobuf\compiler\parser.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\php\php_generator.h" include\google\protobuf\compiler\php\php_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h" include\google\protobuf\compiler\plugin.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h" include\google\protobuf\compiler\plugin.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\generator.h" include\google\protobuf\compiler\python\generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\pyi_generator.h" include\google\protobuf\compiler\python\pyi_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h" include\google\protobuf\compiler\python\python_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h" include\google\protobuf\compiler\ruby\ruby_generator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h" include\google\protobuf\descriptor.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.pb.h" include\google\protobuf\descriptor.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor_database.h" include\google\protobuf\descriptor_database.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.pb.h" include\google\protobuf\duration.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\dynamic_message.h" include\google\protobuf\dynamic_message.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.pb.h" include\google\protobuf\empty.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\endian.h" include\google\protobuf\endian.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\explicitly_constructed.h" include\google\protobuf\explicitly_constructed.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set.h" include\google\protobuf\extension_set.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set_inl.h" include\google\protobuf\extension_set_inl.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_access_listener.h" include\google\protobuf\field_access_listener.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.pb.h" include\google\protobuf\field_mask.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_reflection.h" include\google\protobuf\generated_enum_reflection.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h" include\google\protobuf\generated_enum_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_bases.h" include\google\protobuf\generated_message_bases.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_reflection.h" include\google\protobuf\generated_message_reflection.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_tctable_decl.h" include\google\protobuf\generated_message_tctable_decl.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_tctable_impl.h" include\google\protobuf\generated_message_tctable_impl.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_util.h" include\google\protobuf\generated_message_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\has_bits.h" include\google\protobuf\has_bits.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\implicit_weak_message.h" include\google\protobuf\implicit_weak_message.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\inlined_string_field.h" include\google\protobuf\inlined_string_field.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\coded_stream.h" include\google\protobuf\io\coded_stream.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\gzip_stream.h" include\google\protobuf\io\gzip_stream.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\io_win32.h" include\google\protobuf\io\io_win32.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\printer.h" include\google\protobuf\io\printer.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\strtod.h" include\google\protobuf\io\strtod.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\tokenizer.h" include\google\protobuf\io\tokenizer.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream.h" include\google\protobuf\io\zero_copy_stream.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl.h" include\google\protobuf\io\zero_copy_stream_impl.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl_lite.h" include\google\protobuf\io\zero_copy_stream_impl_lite.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map.h" include\google\protobuf\map.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry.h" include\google\protobuf\map_entry.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry_lite.h" include\google\protobuf\map_entry_lite.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field.h" include\google\protobuf\map_field.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_inl.h" include\google\protobuf\map_field_inl.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_lite.h" include\google\protobuf\map_field_lite.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_type_handler.h" include\google\protobuf\map_type_handler.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h" include\google\protobuf\message.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h" include\google\protobuf\message_lite.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h" include\google\protobuf\metadata.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata_lite.h" include\google\protobuf\metadata_lite.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\parse_context.h" include\google\protobuf\parse_context.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port.h" include\google\protobuf\port.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_def.inc" include\google\protobuf\port_def.inc -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_undef.inc" include\google\protobuf\port_undef.inc -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection.h" include\google\protobuf\reflection.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection_ops.h" include\google\protobuf\reflection_ops.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field.h" include\google\protobuf\repeated_field.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_ptr_field.h" include\google\protobuf\repeated_ptr_field.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\service.h" include\google\protobuf\service.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.pb.h" include\google\protobuf\source_context.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.pb.h" include\google\protobuf\struct.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\bytestream.h" include\google\protobuf\stubs\bytestream.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\callback.h" include\google\protobuf\stubs\callback.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\casts.h" include\google\protobuf\stubs\casts.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h" include\google\protobuf\stubs\common.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h" include\google\protobuf\stubs\hash.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\logging.h" include\google\protobuf\stubs\logging.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\macros.h" include\google\protobuf\stubs\macros.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\map_util.h" include\google\protobuf\stubs\map_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\mutex.h" include\google\protobuf\stubs\mutex.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h" include\google\protobuf\stubs\once.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h" include\google\protobuf\stubs\platform_macros.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\port.h" include\google\protobuf\stubs\port.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\status.h" include\google\protobuf\stubs\status.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h" include\google\protobuf\stubs\stl_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stringpiece.h" include\google\protobuf\stubs\stringpiece.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\strutil.h" include\google\protobuf\stubs\strutil.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h" include\google\protobuf\stubs\template_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h" include\google\protobuf\text_format.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h" include\google\protobuf\timestamp.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.pb.h" include\google\protobuf\type.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\unknown_field_set.h" include\google\protobuf\unknown_field_set.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\delimited_message_util.h" include\google\protobuf\util\delimited_message_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_comparator.h" include\google\protobuf\util\field_comparator.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_mask_util.h" include\google\protobuf\util\field_mask_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\json_util.h" include\google\protobuf\util\json_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\message_differencer.h" include\google\protobuf\util\message_differencer.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\time_util.h" include\google\protobuf\util\time_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver.h" include\google\protobuf\util\type_resolver.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver_util.h" include\google\protobuf\util\type_resolver_util.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format.h" include\google\protobuf\wire_format.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite.h" include\google\protobuf\wire_format_lite.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.pb.h" include\google\protobuf\wrappers.pb.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.proto" include\google\protobuf\any.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.proto" include\google\protobuf\api.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.proto" include\google\protobuf\compiler\plugin.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.proto" include\google\protobuf\descriptor.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.proto" include\google\protobuf\duration.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.proto" include\google\protobuf\empty.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.proto" include\google\protobuf\field_mask.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.proto" include\google\protobuf\source_context.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.proto" include\google\protobuf\struct.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.proto" include\google\protobuf\timestamp.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.proto" include\google\protobuf\type.proto -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.proto" include\google\protobuf\wrappers.proto From 9b7ab18a135e4f2c313ce0b04bf55feb0296bbfd Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Tue, 2 Aug 2022 20:16:12 +0200 Subject: [PATCH 14/23] docs: add protoc-gen-bq-schema Add protoc-gen-bq-schema to the list of third party add-ons. --- docs/third_party.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/third_party.md b/docs/third_party.md index d8478e9ada..d9ff970227 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -203,3 +203,4 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d * [vim-protolint: A protobuf linter for Vim](https://github.com/yoheimuta/vim-protolint) * [super-linter: Protocol Buffer lint as GitHub Action](https://github.com/github/super-linter) * [protoc-gen-fieldmask - A plugin to generate static type fieldmask paths](https://github.com/idodod/protoc-gen-fieldmask) +* [protoc-gen-bq-schema - A protoc plugin to generate BigQuery schema files](https://github.com/GoogleCloudPlatform/protoc-gen-bq-schema) From 8448ab9fcf1baca8bbe453823b806710bded4a0c Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 3 Aug 2022 11:26:33 +0100 Subject: [PATCH 16/23] Fix XML comment warnings for JsonFormatter --- csharp/src/Google.Protobuf/JsonFormatter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 4482c8790b..9cecb6a2d2 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -154,7 +154,7 @@ namespace Google.Protobuf /// /// The message to format. /// Indentation level to start at. - /// To keep consistent indentation when embedding a message inside another JSON string, set . E.g: + /// To keep consistent indentation when embedding a message inside another JSON string, set . E.g: /// /// var response = $@"{{ /// ""data"": { Format(message, indentationLevel: 1) } @@ -178,12 +178,12 @@ namespace Google.Protobuf public void Format(IMessage message, TextWriter writer) => Format(message, writer, indentationLevel: 0); /// - /// Formats the specified message as JSON. When is not null, start indenting at the specified . + /// Formats the specified message as JSON. When is not null, start indenting at the specified . /// /// The message to format. /// The TextWriter to write the formatted message to. /// Indentation level to start at. - /// To keep consistent indentation when embedding a message inside another JSON string, set . + /// To keep consistent indentation when embedding a message inside another JSON string, set . public void Format(IMessage message, TextWriter writer, int indentationLevel) { ProtoPreconditions.CheckNotNull(message, nameof(message)); From 8d3a7327606b115dda871be54c8b8cb66d41ff90 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Wed, 3 Aug 2022 10:02:48 -0700 Subject: [PATCH 17/23] Adding shared library build test (#10351) --- kokoro/linux/cmake_shared/build.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kokoro/linux/cmake_shared/build.sh b/kokoro/linux/cmake_shared/build.sh index 87dde411c7..1fda3dfca4 100755 --- a/kokoro/linux/cmake_shared/build.sh +++ b/kokoro/linux/cmake_shared/build.sh @@ -4,4 +4,23 @@ set -eux -# TODO(mkruskal) Implement this. \ No newline at end of file +# Change to repo root +cd $(dirname $0)/../../.. +GIT_REPO_ROOT=`pwd` + +CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671 + +# Update git submodules +git submodule update --init --recursive + +tmpfile=$(mktemp -u) + +docker run \ + --cidfile $tmpfile \ + -v $GIT_REPO_ROOT:/workspace \ + $CONTAINER_IMAGE \ + /test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_SHARED_LIBS=ON + +# Save logs for Kokoro +docker cp \ + `cat $tmpfile`:/workspace/logs $KOKORO_ARTIFACTS_DIR From 763f08c6209e61585cf135988f6056f2091fd530 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 3 Aug 2022 19:04:39 +0000 Subject: [PATCH 18/23] [PHP] Added getContainingOneof and getRealContainingOneof to descriptor. --- php/ext/google/protobuf/def.c | 41 ++++++++++++++++++++++++++ php/tests/DescriptorsTest.php | 18 ++++++++++- php/tests/proto/test_descriptors.proto | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 018dac19ac..8c3266eb07 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -456,6 +456,44 @@ PHP_METHOD(FieldDescriptor, getEnumType) { RETURN_COPY_VALUE(&ret); } +/* + * FieldDescriptor::getContainingOneof() + * + * Returns the OneofDescriptor for this field, or null if it is not inside + * a oneof. + */ +PHP_METHOD(FieldDescriptor, getContainingOneof) { + FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis()); + const upb_OneofDef *o = upb_FieldDef_ContainingOneof(intern->fielddef); + zval ret; + + if (!o) { + RETURN_NULL(); + } + + OneofDescriptor_FromOneofDef(&ret, o); + RETURN_COPY_VALUE(&ret); +} + +/* + * FieldDescriptor::getRealContainingOneof() + * + * Returns the non-synthetic OneofDescriptor for this field, or null if it is + * not inside a oneof. + */ +PHP_METHOD(FieldDescriptor, getRealContainingOneof) { + FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis()); + const upb_OneofDef *o = upb_FieldDef_RealContainingOneof(intern->fielddef); + zval ret; + + if (!o) { + RETURN_NULL(); + } + + OneofDescriptor_FromOneofDef(&ret, o); + RETURN_COPY_VALUE(&ret); +} + /* * FieldDescriptor::getMessageType() * @@ -482,6 +520,8 @@ static zend_function_entry FieldDescriptor_methods[] = { PHP_ME(FieldDescriptor, getType, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(FieldDescriptor, isMap, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(FieldDescriptor, getEnumType, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(FieldDescriptor, getContainingOneof, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(FieldDescriptor, getRealContainingOneof, arginfo_void, ZEND_ACC_PUBLIC) PHP_ME(FieldDescriptor, getMessageType, arginfo_void, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -516,6 +556,7 @@ static zend_class_entry *Descriptor_GetGeneratedClass(const upb_MessageDef *m) { char *classname = GetPhpClassname(upb_MessageDef_File(m), upb_MessageDef_FullName(m), false); zend_error(E_ERROR, "Couldn't load generated class %s", classname); + return NULL; } void Descriptor_FromMessageDef(zval *val, const upb_MessageDef *m) { diff --git a/php/tests/DescriptorsTest.php b/php/tests/DescriptorsTest.php index 4f17a49571..07d4a9b243 100644 --- a/php/tests/DescriptorsTest.php +++ b/php/tests/DescriptorsTest.php @@ -83,7 +83,7 @@ class DescriptorsTest extends TestBase $this->assertSame($class, $desc->getClass()); $this->assertInstanceOf('\Google\Protobuf\FieldDescriptor', $desc->getField(0)); - $this->assertSame(7, $desc->getFieldCount()); + $this->assertSame(8, $desc->getFieldCount()); $this->assertInstanceOf('\Google\Protobuf\OneofDescriptor', $desc->getOneofDecl(0)); $this->assertSame(1, $desc->getOneofDeclCount()); @@ -180,6 +180,7 @@ class DescriptorsTest extends TestBase $this->assertSame(self::GPBTYPE_MESSAGE, $fieldDesc->getType()); $this->assertInstanceOf('\Google\Protobuf\Descriptor', $fieldDesc->getMessageType()); $this->assertFalse($fieldDesc->isMap()); + $this->assertNull($fieldDesc->getContainingOneof()); // Oneof int field // Tested further in testOneofDescriptor() @@ -189,6 +190,21 @@ class DescriptorsTest extends TestBase $this->assertSame(self::GPBLABEL_OPTIONAL, $fieldDesc->getLabel()); $this->assertSame(self::GPBTYPE_INT32, $fieldDesc->getType()); $this->assertFalse($fieldDesc->isMap()); + $this->assertSame($fieldDesc->getContainingOneof(), $fieldDesc->getRealContainingOneof()); + + $oneofDesc = $fieldDesc->getContainingOneof(); + $this->assertSame('my_oneof', $oneofDesc->getName()); + + // Proto3 optional it field. + // Tested further in testOneofDescriptor() + $fieldDesc = $fieldDescMap[52]; + $this->assertSame('proto3_optional_int32', $fieldDesc->getName()); + $this->assertSame(52, $fieldDesc->getNumber()); + $this->assertSame(self::GPBLABEL_OPTIONAL, $fieldDesc->getLabel()); + $this->assertSame(self::GPBTYPE_INT32, $fieldDesc->getType()); + $this->assertFalse($fieldDesc->isMap()); + $this->assertNull($fieldDesc->getRealContainingOneof()); + $this->assertNotNull($fieldDesc->getContainingOneof()); // Map int-enum field $fieldDesc = $fieldDescMap[71]; diff --git a/php/tests/proto/test_descriptors.proto b/php/tests/proto/test_descriptors.proto index d42aec7cec..b0956c6edd 100644 --- a/php/tests/proto/test_descriptors.proto +++ b/php/tests/proto/test_descriptors.proto @@ -14,6 +14,7 @@ message TestDescriptorsMessage { oneof my_oneof { int32 oneof_int32 = 51; } + optional int32 proto3_optional_int32 = 52; map map_int32_enum = 71; From a8c600f9008da0161270d0f2fc10cdc4eb7231bb Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 3 Aug 2022 19:35:39 +0000 Subject: [PATCH 19/23] Updated oneof count. --- php/tests/DescriptorsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/tests/DescriptorsTest.php b/php/tests/DescriptorsTest.php index 07d4a9b243..336d979428 100644 --- a/php/tests/DescriptorsTest.php +++ b/php/tests/DescriptorsTest.php @@ -86,7 +86,7 @@ class DescriptorsTest extends TestBase $this->assertSame(8, $desc->getFieldCount()); $this->assertInstanceOf('\Google\Protobuf\OneofDescriptor', $desc->getOneofDecl(0)); - $this->assertSame(1, $desc->getOneofDeclCount()); + $this->assertSame(2, $desc->getOneofDeclCount()); } public function testDescriptorForIncludedMessage() From 8b49ff0000d68ea1f8f5f1b390ecfb9cb6354485 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 3 Aug 2022 18:48:26 -0700 Subject: [PATCH 20/23] Remove bogus IWYU pragma Pragma points at a directory that's not in the github repo, only internally. It's throwing gRPC's IWYU analysis and causing it to recommend bad paths. --- src/google/protobuf/repeated_ptr_field.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index acdbee3afc..8a9c9e6c73 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -41,8 +41,6 @@ // // This header covers RepeatedPtrField. -// IWYU pragma: private, include "net/proto2/public/repeated_field.h" - #ifndef GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__ #define GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__ From a99b5feaf6fbb07320fdc8109c6ea97af35debe4 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Thu, 4 Aug 2022 15:41:24 -0400 Subject: [PATCH 21/23] add release notes --- CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index a7d74a7eee..d8ed3e99bb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,7 @@ 2022-07-01 Unreleased version C++ + * cpp_generated_lib_linked support is removed in protoc * Reduced .pb.o object file size slightly by explicitly instantiating InternalMetadata templates in the runtime. * Add C++20 keywords guarded by PROTOBUF_FUTURE_CPP20_KEYWORDS @@ -11,6 +12,7 @@ * Hide C++ RepeatedField::UnsafeArenaSwap Kotlin + * Suppress deprecation warnings in Kotlin generated code. * Kotlin generated code comments now use kdoc format instead of javadoc. * Escape keywords in package names in proto generated code * Add Kotlin enum int value getters and setters From 79c3d07c63e711255e0d566c9b876706e978686a Mon Sep 17 00:00:00 2001 From: zhangskz <89936743+zhangskz@users.noreply.github.com> Date: Thu, 4 Aug 2022 14:17:49 -0700 Subject: [PATCH 22/23] Update README.md (#10363) Previous line about checking Protocol Buffers version didn't make grammatical sense --- ruby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/README.md b/ruby/README.md index 42a1ffaad4..be8d6bc8b1 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -9,7 +9,7 @@ install protoc as well to have Ruby code generation functionality. Installation from Gem --------------------- -In Gemfile (Please check a version of Protocol Buffers you needed [RubyGems](https://rubygems.org/gems/google-protobuf)): +In Gemfile (Please check which version of Protocol Buffers you need: [RubyGems](https://rubygems.org/gems/google-protobuf)): gem 'google-protobuf' From 9c02fff2559f1c7cd93924af27a28a546ad4e197 Mon Sep 17 00:00:00 2001 From: Kiyoshi Mizumaru Date: Sat, 6 Aug 2022 03:17:23 +0900 Subject: [PATCH 23/23] Fix rule for java target in examples/Makefile --- examples/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index 1ed7f67fd1..2a64b64fe3 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -13,13 +13,14 @@ python: add_person_python list_people_python clean: rm -f add_person_cpp list_people_cpp add_person_java list_people_java add_person_python list_people_python - rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class - rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java + rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/protos/*.class + rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/protos/*.java rm -f *.pyc rm -f go/tutorialpb/*.pb.go add_person_go list_people_go rm -f protoc_middleman_dart dart_tutorial/*.pb*.dart rmdir dart_tutorial 2>/dev/null || true rmdir tutorial 2>/dev/null || true + rmdir com/example/tutorial/protos 2>/dev/null || true rmdir com/example/tutorial 2>/dev/null || true rmdir com/example 2>/dev/null || true rmdir com 2>/dev/null || true @@ -63,7 +64,7 @@ list_people_gotest: go/tutorialpb/addressbook.pb.go cd go && go test ./cmd/list_people javac_middleman: AddPerson.java ListPeople.java protoc_middleman - javac -cp $$CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java + javac -cp $$CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/protos/*.java @touch javac_middleman add_person_java: javac_middleman