From dd8f748c3d7a8e97e03884958d6147d0970bcb62 Mon Sep 17 00:00:00 2001 From: Martin Landsem Date: Wed, 10 Jun 2020 22:53:56 +0200 Subject: [PATCH 01/80] Changed parameter type from long to integer PHP does not have a long type, and IDEs don't necessarily understand that long is the same as integer. E.g. PhpStorm will give an error like this: `Expected parameter of type '\Google\Protobuf\Internal\long', 'int' provided` --- php/src/Google/Protobuf/Internal/RepeatedField.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index ec7a3a6d07..350bbb592e 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -67,7 +67,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable /** * Constructs an instance of RepeatedField. * - * @param long $type Type of the stored element. + * @param integer $type Type of the stored element. * @param string $klass Message/Enum class name (message/enum fields only). * @ignore */ @@ -116,7 +116,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * This will also be called for: $ele = $arr[0] * - * @param long $offset The index of the element to be fetched. + * @param integer $offset The index of the element to be fetched. * @return object The stored element at given index. * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. @@ -131,7 +131,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * This will also be called for: $arr []= $ele and $arr[0] = ele * - * @param long $offset The index of the element to be assigned. + * @param integer $offset The index of the element to be assigned. * @param object $value The element to be assigned. * @return void * @throws \ErrorException Invalid type for index. @@ -204,7 +204,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * This will also be called for: unset($arr) * - * @param long $offset The index of the element to be removed. + * @param integer $offset The index of the element to be removed. * @return void * @throws \ErrorException Invalid type for index. * @throws \ErrorException The element to be removed is not at the end of the @@ -227,7 +227,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * This will also be called for: isset($arr) * - * @param long $offset The index of the element to be removed. + * @param integer $offset The index of the element to be removed. * @return bool True if the element at the given offset exists. * @throws \ErrorException Invalid type for index. */ From bd08f755862ae7f827829f37c38a2fd77525cd34 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 27 Jan 2021 11:31:54 -0700 Subject: [PATCH 02/80] fix: README supported PHP version for C extension --- php/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/README.md b/php/README.md index 16757be58b..b8cec1e3fd 100644 --- a/php/README.md +++ b/php/README.md @@ -16,7 +16,7 @@ generation functionality. To use PHP runtime library requires: -- C extension: PHP 5.5, 5.6, or 7. +- C extension: PHP 7 - [PHP package](http://php.net/downloads.php): PHP 5.5, 5.6 or 7. ## Installation From e75f5525872c04ee2e76e3b810990aa14909ee35 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 2 Feb 2021 09:47:48 -0800 Subject: [PATCH 03/80] Update README.md --- php/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/README.md b/php/README.md index b8cec1e3fd..c4292cf778 100644 --- a/php/README.md +++ b/php/README.md @@ -16,8 +16,8 @@ generation functionality. To use PHP runtime library requires: -- C extension: PHP 7 -- [PHP package](http://php.net/downloads.php): PHP 5.5, 5.6 or 7. +- C extension: PHP 7.x, 8.0 +- [PHP package](http://php.net/downloads.php): PHP 5.5, 5.6, 7.x, or 8.0. ## Installation From 8932446d9e2033bad04088446926fb7a10d89066 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 16 Dec 2020 12:56:14 +1300 Subject: [PATCH 04/80] Improve WriteString perf with SIMD --- csharp/install_dotnet_sdk.ps1 | 2 +- .../Google.Protobuf.Benchmarks.csproj | 2 +- .../Buffers/ArrayBufferWriter.cs | 12 +- .../CodedOutputStreamTest.cs | 61 ++++++++-- .../Google.Protobuf.Test.csproj | 2 +- .../Google.Protobuf.Test/JsonParserTest.cs | 2 + .../Google.Protobuf.Test/JsonTokenizerTest.cs | 2 + .../LegacyGeneratedCodeTest.cs | 2 +- .../MessageParsingHelpers.cs | 6 +- .../Google.Protobuf/Google.Protobuf.csproj | 16 ++- .../src/Google.Protobuf/WritingPrimitives.cs | 112 ++++++++++++++++-- global.json | 2 +- .../linux/dockerfile/test/csharp/Dockerfile | 2 +- 13 files changed, 186 insertions(+), 37 deletions(-) diff --git a/csharp/install_dotnet_sdk.ps1 b/csharp/install_dotnet_sdk.ps1 index 8bc967c9f4..c78655cc02 100755 --- a/csharp/install_dotnet_sdk.ps1 +++ b/csharp/install_dotnet_sdk.ps1 @@ -17,4 +17,4 @@ Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath # The SDK versions to install should be kept in sync with versions # installed by kokoro/linux/dockerfile/test/csharp/Dockerfile &$InstallScriptPath -Version 2.1.802 -&$InstallScriptPath -Version 3.1.301 +&$InstallScriptPath -Version 5.0.102 diff --git a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj index 73042f358c..ac8e009adc 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj +++ b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 ../../keys/Google.Protobuf.snk true False diff --git a/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs b/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs index 5b9913b290..a36a9513c7 100644 --- a/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs +++ b/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs @@ -42,7 +42,7 @@ namespace Google.Protobuf.Buffers /// ArrayBufferWriter is originally from corefx, and has been contributed to Protobuf /// https://github.com/dotnet/runtime/blob/071da4c41aa808c949a773b92dca6f88de9d11f3/src/libraries/Common/src/System/Buffers/ArrayBufferWriter.cs /// - internal sealed class ArrayBufferWriter : IBufferWriter + internal sealed class TestArrayBufferWriter : IBufferWriter { private T[] _buffer; private int _index; @@ -50,10 +50,10 @@ namespace Google.Protobuf.Buffers private const int DefaultInitialBufferSize = 256; /// - /// Creates an instance of an , in which data can be written to, + /// Creates an instance of an , in which data can be written to, /// with the default initial capacity. /// - public ArrayBufferWriter() + public TestArrayBufferWriter() { _buffer = new T[0]; _index = 0; @@ -66,14 +66,14 @@ namespace Google.Protobuf.Buffers public int? MaxGrowBy { get; set; } /// - /// Creates an instance of an , in which data can be written to, + /// Creates an instance of an , in which data can be written to, /// with an initial capacity specified. /// /// The minimum capacity with which to initialize the underlying buffer. /// /// Thrown when is not positive (i.e. less than or equal to 0). /// - public ArrayBufferWriter(int initialCapacity) + public TestArrayBufferWriter(int initialCapacity) { if (initialCapacity <= 0) throw new ArgumentException(nameof(initialCapacity)); @@ -111,7 +111,7 @@ namespace Google.Protobuf.Buffers /// Clears the data written to the underlying buffer. /// /// - /// You must clear the before trying to re-use it. + /// You must clear the before trying to re-use it. /// public void Clear() { diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 1e5333c965..14440098f1 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -58,7 +58,7 @@ namespace Google.Protobuf Assert.AreEqual(data, rawOutput.ToArray()); // IBufferWriter - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteUInt32((uint) value); ctx.Flush(); @@ -77,7 +77,7 @@ namespace Google.Protobuf Assert.AreEqual(data, rawOutput.ToArray()); // IBufferWriter - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteUInt64(value); ctx.Flush(); @@ -100,7 +100,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); bufferWriter.MaxGrowBy = bufferSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteUInt32((uint) value); @@ -115,7 +115,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); bufferWriter.MaxGrowBy = bufferSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteUInt64(value); @@ -174,7 +174,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteFixed32(value); ctx.Flush(); @@ -190,7 +190,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); bufferWriter.MaxGrowBy = bufferSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteFixed32(value); @@ -212,7 +212,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteFixed64(value); ctx.Flush(); @@ -228,7 +228,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); bufferWriter.MaxGrowBy = blockSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteFixed64(value); @@ -270,7 +270,7 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(rawBytes, rawOutput.ToArray()); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); bufferWriter.MaxGrowBy = blockSize; message.WriteTo(bufferWriter); Assert.AreEqual(rawBytes, bufferWriter.WrittenSpan.ToArray()); @@ -292,7 +292,7 @@ namespace Google.Protobuf output.Flush(); byte[] expectedBytes2 = expectedOutput.ToArray(); - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteMessage(message); ctx.Flush(); @@ -519,7 +519,21 @@ namespace Google.Protobuf } [Test] - public void WriteStringsOfDifferentSizes() + public void WriteString_AsciiSmall_MaxUtf8SizeExceedsBuffer() + { + var buffer = new byte[5]; + var output = new CodedOutputStream(buffer); + output.WriteString("ABC"); + + output.Flush(); + + // Verify written content + var input = new CodedInputStream(buffer); + Assert.AreEqual("ABC", input.ReadString()); + } + + [Test] + public void WriteStringsOfDifferentSizes_Ascii() { for (int i = 1; i <= 1024; i++) { @@ -540,5 +554,30 @@ namespace Google.Protobuf Assert.AreEqual(s, input.ReadString()); } } + + [Test] + public void WriteStringsOfDifferentSizes_Unicode() + { + for (int i = 1; i <= 1024; i++) + { + var buffer = new byte[4096]; + var output = new CodedOutputStream(buffer); + var sb = new StringBuilder(); + for (int j = 0; j < i; j++) + { + char c = (char)((j % 10) + 10112); + sb.Append(c.ToString()); // incrementing unicode numbers, repeating + } + var s = sb.ToString(); + output.WriteString(s); + + output.Flush(); + + // Verify written content + var input = new CodedInputStream(buffer); + + Assert.AreEqual(s, input.ReadString()); + } + } } } \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 7bd3f84e45..cdfa98e098 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -1,7 +1,7 @@  - net451;netcoreapp2.1 + net451;netcoreapp2.1;net50 ../../keys/Google.Protobuf.snk true False diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index e170fcc5a0..87a389aecb 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -551,9 +551,11 @@ namespace Google.Protobuf } [Test] +#if !NET5_0 [TestCase("1.7977e308")] [TestCase("-1.7977e308")] [TestCase("1e309")] +#endif [TestCase("1,0")] [TestCase("1.0.0")] [TestCase("+1")] diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index df43effd4f..55ec02ea02 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -199,8 +199,10 @@ namespace Google.Protobuf [TestCase("1e-")] [TestCase("--")] [TestCase("--1")] +#if !NET5_0 [TestCase("-1.7977e308")] [TestCase("1.7977e308")] +#endif public void InvalidNumberValue(string json) { AssertThrowsAfter(json); diff --git a/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs b/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs index da7b4a8c07..22adcaa95d 100644 --- a/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs +++ b/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs @@ -141,7 +141,7 @@ namespace Google.Protobuf }; var exception = Assert.Throws(() => { - WriteContext.Initialize(new ArrayBufferWriter(), out WriteContext writeCtx); + WriteContext.Initialize(new TestArrayBufferWriter(), out WriteContext writeCtx); ((IBufferMessage)message).InternalWriteTo(ref writeCtx); }); Assert.AreEqual($"Message {typeof(LegacyGeneratedCodeMessageA).Name} doesn't provide the generated method that enables WriteContext-based serialization. You might need to regenerate the generated protobuf code.", exception.Message); diff --git a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs index 36a2f02229..65d2fe0395 100644 --- a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs +++ b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs @@ -83,7 +83,7 @@ namespace Google.Protobuf var bytes = message.ToByteArray(); // also serialize using IBufferWriter and check it leads to the same data - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); message.WriteTo(bufferWriter); Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray(), "Both serialization approaches need to result in the same data."); @@ -112,7 +112,7 @@ namespace Google.Protobuf Assert.AreEqual(message.CalculateSize(), bytes.Length); // serialize using IBufferWriter and check it leads to the same output - var bufferWriter = new ArrayBufferWriter(); + var bufferWriter = new TestArrayBufferWriter(); message.WriteTo(bufferWriter); Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray()); @@ -124,7 +124,7 @@ namespace Google.Protobuf // test for different IBufferWriter.GetSpan() segment sizes for (int blockSize = 1; blockSize < 256; blockSize *= 2) { - var segmentedBufferWriter = new ArrayBufferWriter(); + var segmentedBufferWriter = new TestArrayBufferWriter(); segmentedBufferWriter.MaxGrowBy = blockSize; message.WriteTo(segmentedBufferWriter); Assert.AreEqual(bytes, segmentedBufferWriter.WrittenSpan.ToArray()); diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index f16063418b..4dbb349307 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -1,4 +1,4 @@ - + C# runtime library for Protocol Buffers - Google's data interchange format. @@ -8,7 +8,7 @@ 7.2 Google Inc. - netstandard1.1;netstandard2.0;net45 + netstandard1.1;netstandard2.0;net45;net50 true ../../keys/Google.Protobuf.snk true @@ -27,15 +27,23 @@ $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING + + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING;GOOGLE_PROTOBUF_SIMD + + - - + + + + + + diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index cf8fc7ba71..d33a298d3e 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -32,8 +32,14 @@ using System; using System.Buffers.Binary; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +#if GOOGLE_PROTOBUF_SIMD +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; +using System.Runtime.Intrinsics.X86; +#endif using System.Security; using System.Text; @@ -45,8 +51,11 @@ namespace Google.Protobuf [SecuritySafeCritical] internal static class WritingPrimitives { - // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.) - internal static readonly Encoding Utf8Encoding = Encoding.UTF8; +#if NET5_0 + internal static Encoding Utf8Encoding => Encoding.UTF8; // allows JIT to devirtualize +#else + internal static readonly Encoding Utf8Encoding = Encoding.UTF8; // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.) +#endif #region Writing of values (not including tags) @@ -186,11 +195,7 @@ namespace Google.Protobuf { if (length == value.Length) // Must be all ASCII... { - for (int i = 0; i < length; i++) - { - buffer[state.position + i] = (byte)value[i]; - } - state.position += length; + WriteAsciiStringToBuffer(buffer, ref state, value, length); } else { @@ -208,6 +213,99 @@ namespace Google.Protobuf } } + private static void WriteAsciiStringToBuffer(Span buffer, ref WriterInternalState state, string value, int length) + { + ref char sourceChars = ref MemoryMarshal.GetReference(value.AsSpan()); + ref byte destinationBytes = ref MemoryMarshal.GetReference(buffer.Slice(state.position)); + + int currentIndex = 0; + // If 64bit, process 4 chars at a time. + // The logic inside this check will be elided by JIT in 32bit programs. + if (IntPtr.Size == 8) + { + // Need at least 4 chars available to use this optimization. + if (length >= 4) + { + ref byte sourceBytes = ref Unsafe.As(ref sourceChars); + + // Process 4 chars at a time until there are less than 4 remaining. + // We already know all characters are ASCII so there is no need to validate the source. + int lastIndexWhereCanReadFourChars = value.Length - 4; + do + { + NarrowFourUtf16CharsToAsciiAndWriteToBuffer( + ref Unsafe.AddByteOffset(ref destinationBytes, (IntPtr)currentIndex), + Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref sourceBytes, (IntPtr)(currentIndex * 2)))); + + } while ((currentIndex += 4) <= lastIndexWhereCanReadFourChars); + } + } + + // Process any remaining, 1 char at a time. + // Avoid bounds checking with ref + Unsafe + for (; currentIndex < length; currentIndex++) + { + Unsafe.AddByteOffset(ref destinationBytes, (IntPtr)currentIndex) = (byte)Unsafe.AddByteOffset(ref sourceChars, (IntPtr)(currentIndex * 2)); + } + + state.position += length; + } + + // Copied with permission from https://github.com/dotnet/runtime/blob/1cdafd27e4afd2c916af5df949c13f8b373c4335/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs#L1119-L1171 + // + /// + /// Given a QWORD which represents a buffer of 4 ASCII chars in machine-endian order, + /// narrows each WORD to a BYTE, then writes the 4-byte result to the output buffer + /// also in machine-endian order. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputBuffer, ulong value) + { +#if GOOGLE_PROTOBUF_SIMD + if (Sse2.X64.IsSupported) + { + // Narrows a vector of words [ w0 w1 w2 w3 ] to a vector of bytes + // [ b0 b1 b2 b3 b0 b1 b2 b3 ], then writes 4 bytes (32 bits) to the destination. + + Vector128 vecWide = Sse2.X64.ConvertScalarToVector128UInt64(value).AsInt16(); + Vector128 vecNarrow = Sse2.PackUnsignedSaturate(vecWide, vecWide).AsUInt32(); + Unsafe.WriteUnaligned(ref outputBuffer, Sse2.ConvertToUInt32(vecNarrow)); + } + else if (AdvSimd.IsSupported) + { + // Narrows a vector of words [ w0 w1 w2 w3 ] to a vector of bytes + // [ b0 b1 b2 b3 * * * * ], then writes 4 bytes (32 bits) to the destination. + + Vector128 vecWide = Vector128.CreateScalarUnsafe(value).AsInt16(); + Vector64 lower = AdvSimd.ExtractNarrowingSaturateUnsignedLower(vecWide); + Unsafe.WriteUnaligned(ref outputBuffer, lower.AsUInt32().ToScalar()); + } + else +#endif + { + if (BitConverter.IsLittleEndian) + { + outputBuffer = (byte)value; + value >>= 16; + Unsafe.Add(ref outputBuffer, 1) = (byte)value; + value >>= 16; + Unsafe.Add(ref outputBuffer, 2) = (byte)value; + value >>= 16; + Unsafe.Add(ref outputBuffer, 3) = (byte)value; + } + else + { + Unsafe.Add(ref outputBuffer, 3) = (byte)value; + value >>= 16; + Unsafe.Add(ref outputBuffer, 2) = (byte)value; + value >>= 16; + Unsafe.Add(ref outputBuffer, 1) = (byte)value; + value >>= 16; + outputBuffer = (byte)value; + } + } + } + private static int WriteStringToBuffer(Span buffer, ref WriterInternalState state, string value) { #if NETSTANDARD1_1 diff --git a/global.json b/global.json index 16f71a741f..d29e29a3ea 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "3.0.100", + "version": "5.0.102", "rollForward": "latestMinor" } } diff --git a/kokoro/linux/dockerfile/test/csharp/Dockerfile b/kokoro/linux/dockerfile/test/csharp/Dockerfile index 95bd653152..0bbadba40a 100644 --- a/kokoro/linux/dockerfile/test/csharp/Dockerfile +++ b/kokoro/linux/dockerfile/test/csharp/Dockerfile @@ -29,7 +29,7 @@ RUN apt-get update && apt-get install -y libunwind8 libicu57 && apt-get clean RUN wget -q https://dot.net/v1/dotnet-install.sh && \ chmod u+x dotnet-install.sh && \ ./dotnet-install.sh --version 2.1.802 && \ - ./dotnet-install.sh --version 3.1.301 && \ + ./dotnet-install.sh --version 5.0.102 && \ ln -s /root/.dotnet/dotnet /usr/local/bin RUN wget -q www.nuget.org/NuGet.exe -O /usr/local/bin/nuget.exe From d9889a4a1579c348105986426306792247a36288 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 4 Feb 2021 07:35:47 +1300 Subject: [PATCH 05/80] Fix 5.0 SDK Linux restore issue --- kokoro/linux/dockerfile/test/csharp/Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kokoro/linux/dockerfile/test/csharp/Dockerfile b/kokoro/linux/dockerfile/test/csharp/Dockerfile index 0bbadba40a..0e3538fbe5 100644 --- a/kokoro/linux/dockerfile/test/csharp/Dockerfile +++ b/kokoro/linux/dockerfile/test/csharp/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:stretch +FROM debian:buster # Install dependencies. We start with the basic ones require to build protoc # and the C++ build @@ -22,8 +22,12 @@ RUN apt-get update && apt-get install -y \ wget \ && apt-get clean +# Update ca-certificates to fix known buster + .NET 5 issue +# https://github.com/NuGet/Announcements/issues/49 +RUN apt-get update && apt-get install -y ca-certificates && apt-get clean + # dotnet SDK prerequisites -RUN apt-get update && apt-get install -y libunwind8 libicu57 && apt-get clean +RUN apt-get update && apt-get install -y libunwind8 && apt-get clean # Install dotnet SDK via install script RUN wget -q https://dot.net/v1/dotnet-install.sh && \ From ee05cc11db9dca7a97e53f27ec206d4edad0ab62 Mon Sep 17 00:00:00 2001 From: s1341 Date: Thu, 11 Feb 2021 10:38:48 +0200 Subject: [PATCH 06/80] Fix missing -llog when compiling for android --- configure.ac | 13 +++++++++++++ src/Makefile.am | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index eb70a76e16..5188e305d1 100644 --- a/configure.ac +++ b/configure.ac @@ -223,6 +223,19 @@ case "$target_os" in esac AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1]) +AC_MSG_CHECKING(whether -llog is needed) +ANDROID_TEST=no +case "$target_os" in + *android*) + ANDROID_TEST=yes + ;; +esac +AC_MSG_RESULT($ANDROID_TEST) +if test "x$ANDROID_TEST" = xyes; then + LIBLOG_LIBS="-llog" +fi +AC_SUBST([LIBLOG_LIBS]) + # HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS, # since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock # too. diff --git a/src/Makefile.am b/src/Makefile.am index 5940ce187e..503ed2ec54 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,7 +30,7 @@ endif AM_CXXFLAGS = $(NO_OPT_CXXFLAGS) $(PROTOBUF_OPT_FLAG) -AM_LDFLAGS = $(PTHREAD_CFLAGS) +AM_LDFLAGS = $(PTHREAD_CFLAGS) ${LIBLOG_LIBS} # If I say "dist_include_DATA", automake complains that $(includedir) is not # a "legitimate" directory for DATA. Screw you, automake. From 01dcb9484636f1178bf709aaa16bbcef66641189 Mon Sep 17 00:00:00 2001 From: Upils <5464641+upils@users.noreply.github.com> Date: Fri, 12 Feb 2021 01:00:49 +0100 Subject: [PATCH 07/80] Expand reserved IDs for protoc-gen-psql and protoc-gen-sanititize (#8270) Fix for 59b3d97. --- docs/options.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/options.md b/docs/options.md index 361216f1bd..907fe5aa02 100644 --- a/docs/options.md +++ b/docs/options.md @@ -263,8 +263,8 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-psql * Website: https://github.com/Intrinsec/protoc-gen-psql - * Extension: 1091 + * Extension: 1091-1101 1. Protoc-gen-sanitize * Website: https://github.com/Intrinsec/protoc-gen-sanitize - * Extension: 1092 + * Extension: 1102-1106 From 0894247c2197f0924af1a0a61c195b8423022f41 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Thu, 11 Feb 2021 16:15:30 -0800 Subject: [PATCH 08/80] Add autotools to release languages. --- .github/mergeable.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/mergeable.yml b/.github/mergeable.yml index 8577f086ee..4027cf5a9f 100644 --- a/.github/mergeable.yml +++ b/.github/mergeable.yml @@ -11,8 +11,8 @@ mergeable: regex: 'release notes: yes' message: 'Please include release notes: yes' - must_include: - regex: '^(c#|c\+\+|cleanup|conformance tests|integration|java|javascript|go|objective-c|php|python|ruby|bazel|cmake|protoc)' - message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: bazel, cmake, cleanup, conformance tests, integration, protoc.' + regex: '^(autotools|bazel|c#|c\+\+|cleanup|cmake|conformance tests|integration|go|java|javascript|objective-c|php|protoc|python|ruby)' + message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: autotools, bazel, cmake, cleanup, conformance tests, integration, protoc.' - must_include: regex: 'release notes: no' message: 'Please include release notes: no' From e1b26fe4a12c37ce4e17a4587eabd8f4251e9890 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 12 Feb 2021 00:28:10 +0000 Subject: [PATCH 09/80] deps: update to Guava 30.1 (#8209) This release includes a minor security fix. --- java/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 2ce55db1bf..024536cd26 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -93,12 +93,12 @@ com.google.guava guava - 30.0-android + 30.1-android com.google.guava guava-testlib - 30.0-android + 30.1-android test From 0ef575beff5a627a4a1e8e15e462039d3aed2ad3 Mon Sep 17 00:00:00 2001 From: Abhishek Jain <75967352+akjain2052@users.noreply.github.com> Date: Fri, 12 Feb 2021 05:59:47 +0530 Subject: [PATCH 10/80] Fix compiler warnings issue found in conformance_test_runner#8189 (#8190) --- conformance/binary_json_conformance_suite.cc | 2 +- conformance/conformance_test_runner.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 4a0d8e8480..48bfa9660f 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -300,7 +300,7 @@ const FieldDescriptor* GetFieldForOneofType(FieldDescriptor::Type type, } string UpperCase(string str) { - for (int i = 0; i < str.size(); i++) { + for (size_t i = 0; i < str.size(); i++) { str[i] = toupper(str[i]); } return str; diff --git a/conformance/conformance_test_runner.cc b/conformance/conformance_test_runner.cc index 9f893cb8e7..1572ac03b5 100644 --- a/conformance/conformance_test_runner.cc +++ b/conformance/conformance_test_runner.cc @@ -297,7 +297,7 @@ void ForkPipeRunner::SpawnTestProgram() { std::vector argv; argv.push_back(executable.get()); - for (int i = 0; i < executable_args_.size(); ++i) { + for (size_t i = 0; i < executable_args_.size(); ++i) { argv.push_back(executable_args_[i].c_str()); } argv.push_back(nullptr); @@ -307,7 +307,7 @@ void ForkPipeRunner::SpawnTestProgram() { } void ForkPipeRunner::CheckedWrite(int fd, const void *buf, size_t len) { - if (write(fd, buf, len) != len) { + if (static_cast(write(fd, buf, len)) != len) { GOOGLE_LOG(FATAL) << current_test_name_ << ": error writing to test program: " << strerror(errno); } From a25474ed45f86c9bfa3e4fcc4c16a205e09bc8a0 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Thu, 11 Feb 2021 16:35:00 -0800 Subject: [PATCH 11/80] Remove the (unused) Python all-versions Kokoro config. (#8288) --- kokoro/linux/python/build.sh | 17 ----------------- kokoro/linux/python/continuous.cfg | 11 ----------- kokoro/linux/python/presubmit.cfg | 11 ----------- 3 files changed, 39 deletions(-) delete mode 100755 kokoro/linux/python/build.sh delete mode 100644 kokoro/linux/python/continuous.cfg delete mode 100644 kokoro/linux/python/presubmit.cfg diff --git a/kokoro/linux/python/build.sh b/kokoro/linux/python/build.sh deleted file mode 100755 index 86964f55ef..0000000000 --- a/kokoro/linux/python/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERFILE_DIR=kokoro/linux/64-bit -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="python" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python/continuous.cfg b/kokoro/linux/python/continuous.cfg deleted file mode 100644 index e2fc4136f0..0000000000 --- a/kokoro/linux/python/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/python/presubmit.cfg b/kokoro/linux/python/presubmit.cfg deleted file mode 100644 index e2fc4136f0..0000000000 --- a/kokoro/linux/python/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} From fe6339389609d9f1a4c1fe547dd5dc9a17ae7d20 Mon Sep 17 00:00:00 2001 From: Brecht Sanders Date: Thu, 11 Feb 2021 17:33:33 +0100 Subject: [PATCH 12/80] Update coded_stream.h Fix for Windows build with MinGW-w64 compiler. Windows is assumed to always be little endian. --- src/google/protobuf/io/coded_stream.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index a4d5f960a3..df8c4499ad 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -120,12 +120,12 @@ #include #include -#ifdef _MSC_VER +#ifdef _WIN32 // Assuming windows is always little-endian. #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) #define PROTOBUF_LITTLE_ENDIAN 1 #endif -#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) +#if defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) // If MSVC has "/RTCc" set, it will complain about truncating casts at // runtime. This file contains some intentional truncating casts. #pragma runtime_checks("c", off) From aee143afe8c17a3d2c7e88b70ffa6e08a73e2683 Mon Sep 17 00:00:00 2001 From: Brecht Sanders Date: Thu, 11 Feb 2021 17:35:33 +0100 Subject: [PATCH 13/80] Update port_def.inc Fix for Windows build with MinGW-w64 compiler which has __has_attribute but has issues with __attribute__((weak)). --- src/google/protobuf/port_def.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index d15073a41f..11e01601ca 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -615,7 +615,7 @@ #define PROTOBUF_PRAGMA_INIT_SEG #endif -#if defined(__has_attribute) +#if defined(__has_attribute) && !defined(__MINGW32__) #if __has_attribute(weak) #define PROTOBUF_ATTRIBUTE_WEAK __attribute__((weak)) #endif From 818c2ba077f515e080f3c3245a83c0a5528ee22d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 15 Feb 2021 11:02:41 +0100 Subject: [PATCH 14/80] add libicu63 to C# dockerfile --- kokoro/linux/dockerfile/test/csharp/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kokoro/linux/dockerfile/test/csharp/Dockerfile b/kokoro/linux/dockerfile/test/csharp/Dockerfile index 0e3538fbe5..37edbfda99 100644 --- a/kokoro/linux/dockerfile/test/csharp/Dockerfile +++ b/kokoro/linux/dockerfile/test/csharp/Dockerfile @@ -27,7 +27,7 @@ RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y ca-certificates && apt-get clean # dotnet SDK prerequisites -RUN apt-get update && apt-get install -y libunwind8 && apt-get clean +RUN apt-get update && apt-get install -y libunwind8 libicu63 && apt-get clean # Install dotnet SDK via install script RUN wget -q https://dot.net/v1/dotnet-install.sh && \ From e4cd821f21e63358551c734bbd81474f2885f2ad Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 16 Feb 2021 10:44:04 +1300 Subject: [PATCH 15/80] Add comments --- csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 2 ++ csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs | 2 ++ csharp/src/Google.Protobuf/WritingPrimitives.cs | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index 87a389aecb..69c9eb6e99 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -551,6 +551,8 @@ namespace Google.Protobuf } [Test] + // Skip these test cases in .NET 5 because floating point parsing supports bigger values. + // These big values won't throw an error in the test. #if !NET5_0 [TestCase("1.7977e308")] [TestCase("-1.7977e308")] diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 55ec02ea02..0cbc0a4ff8 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -199,6 +199,8 @@ namespace Google.Protobuf [TestCase("1e-")] [TestCase("--")] [TestCase("--1")] + // Skip these test cases in .NET 5 because floating point parsing supports bigger values. + // These big values won't throw an error in the test. #if !NET5_0 [TestCase("-1.7977e308")] [TestCase("1.7977e308")] diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index d33a298d3e..8beefc54c5 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -213,6 +213,8 @@ namespace Google.Protobuf } } + // Calling this method with non-ASCII content will break. + // Content must be verified to be all ASCII before using this method. private static void WriteAsciiStringToBuffer(Span buffer, ref WriterInternalState state, string value, int length) { ref char sourceChars = ref MemoryMarshal.GetReference(value.AsSpan()); @@ -283,6 +285,9 @@ namespace Google.Protobuf else #endif { + // Fallback to non-SIMD approach when SIMD is not available. + // This could happen either because the APIs are not available, or hardware doesn't support it. + // Processing 4 chars at a time in this fallback is still faster than casting one char at a time. if (BitConverter.IsLittleEndian) { outputBuffer = (byte)value; From 893e2d7fd8513f3b7b30d863b05416bd6cf5f432 Mon Sep 17 00:00:00 2001 From: Yuhanun Citgez Date: Sun, 14 Feb 2021 16:08:49 +0100 Subject: [PATCH 16/80] Resolved an issue where NO_DESTROY and CONSTINIT were in incorrect order --- src/google/protobuf/compiler/cpp/cpp_file.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 6d4412b22a..70941d8b9b 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -454,7 +454,7 @@ void FileGenerator::GenerateSourceDefaultInstance(int idx, // enough. However, the empty destructor fails to be elided in some // configurations (like non-opt or with certain sanitizers). NO_DESTROY is // there just to improve performance and binary size in these builds. - format("PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY $1$ $2$;\n", + format("PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT $1$ $2$;\n", DefaultInstanceType(generator->descriptor_, options_), DefaultInstanceName(generator->descriptor_, options_)); From 8a39e13de9653e3be63877ae5a60c39372af5878 Mon Sep 17 00:00:00 2001 From: Yuhanun Citgez Date: Sun, 14 Feb 2021 19:14:38 +0100 Subject: [PATCH 17/80] Resovled issue in the .pb.cc files --- src/google/protobuf/any.pb.cc | 2 +- src/google/protobuf/api.pb.cc | 6 +-- src/google/protobuf/compiler/plugin.pb.cc | 8 ++-- src/google/protobuf/descriptor.pb.cc | 54 +++++++++++------------ src/google/protobuf/duration.pb.cc | 2 +- src/google/protobuf/empty.pb.cc | 2 +- src/google/protobuf/field_mask.pb.cc | 2 +- src/google/protobuf/source_context.pb.cc | 2 +- src/google/protobuf/struct.pb.cc | 8 ++-- src/google/protobuf/timestamp.pb.cc | 2 +- src/google/protobuf/type.pb.cc | 10 ++--- src/google/protobuf/wrappers.pb.cc | 18 ++++---- 12 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index dea9cd648d..aea98c08f6 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -30,7 +30,7 @@ struct AnyDefaultTypeInternal { Any _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY AnyDefaultTypeInternal _Any_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT AnyDefaultTypeInternal _Any_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fany_2eproto[1]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 64aa6c0af0..c26b2130ec 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -35,7 +35,7 @@ struct ApiDefaultTypeInternal { Api _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY ApiDefaultTypeInternal _Api_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ApiDefaultTypeInternal _Api_default_instance_; constexpr Method::Method( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : options_() @@ -54,7 +54,7 @@ struct MethodDefaultTypeInternal { Method _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY MethodDefaultTypeInternal _Method_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT MethodDefaultTypeInternal _Method_default_instance_; constexpr Mixin::Mixin( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -67,7 +67,7 @@ struct MixinDefaultTypeInternal { Mixin _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY MixinDefaultTypeInternal _Mixin_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT MixinDefaultTypeInternal _Mixin_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fapi_2eproto[3]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 84a90f6963..f59504d00f 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -32,7 +32,7 @@ struct VersionDefaultTypeInternal { Version _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY VersionDefaultTypeInternal _Version_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT VersionDefaultTypeInternal _Version_default_instance_; constexpr CodeGeneratorRequest::CodeGeneratorRequest( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : file_to_generate_() @@ -47,7 +47,7 @@ struct CodeGeneratorRequestDefaultTypeInternal { CodeGeneratorRequest _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; constexpr CodeGeneratorResponse_File::CodeGeneratorResponse_File( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -62,7 +62,7 @@ struct CodeGeneratorResponse_FileDefaultTypeInternal { CodeGeneratorResponse_File _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; constexpr CodeGeneratorResponse::CodeGeneratorResponse( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : file_() @@ -76,7 +76,7 @@ struct CodeGeneratorResponseDefaultTypeInternal { CodeGeneratorResponse _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; } // namespace compiler PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto[4]; diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 443a8bfa2d..8ceaa19718 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -28,7 +28,7 @@ struct FileDescriptorSetDefaultTypeInternal { FileDescriptorSet _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; constexpr FileDescriptorProto::FileDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : dependency_() @@ -51,7 +51,7 @@ struct FileDescriptorProtoDefaultTypeInternal { FileDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; constexpr DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : options_(nullptr) @@ -65,7 +65,7 @@ struct DescriptorProto_ExtensionRangeDefaultTypeInternal { DescriptorProto_ExtensionRange _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; constexpr DescriptorProto_ReservedRange::DescriptorProto_ReservedRange( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : start_(0) @@ -78,7 +78,7 @@ struct DescriptorProto_ReservedRangeDefaultTypeInternal { DescriptorProto_ReservedRange _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; constexpr DescriptorProto::DescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : field_() @@ -99,7 +99,7 @@ struct DescriptorProtoDefaultTypeInternal { DescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; constexpr ExtensionRangeOptions::ExtensionRangeOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_(){} @@ -111,7 +111,7 @@ struct ExtensionRangeOptionsDefaultTypeInternal { ExtensionRangeOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY ExtensionRangeOptionsDefaultTypeInternal _ExtensionRangeOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ExtensionRangeOptionsDefaultTypeInternal _ExtensionRangeOptions_default_instance_; constexpr FieldDescriptorProto::FieldDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -135,7 +135,7 @@ struct FieldDescriptorProtoDefaultTypeInternal { FieldDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; constexpr OneofDescriptorProto::OneofDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -148,7 +148,7 @@ struct OneofDescriptorProtoDefaultTypeInternal { OneofDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; constexpr EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : start_(0) @@ -161,7 +161,7 @@ struct EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal { EnumDescriptorProto_EnumReservedRange _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal _EnumDescriptorProto_EnumReservedRange_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal _EnumDescriptorProto_EnumReservedRange_default_instance_; constexpr EnumDescriptorProto::EnumDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_() @@ -177,7 +177,7 @@ struct EnumDescriptorProtoDefaultTypeInternal { EnumDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; constexpr EnumValueDescriptorProto::EnumValueDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -191,7 +191,7 @@ struct EnumValueDescriptorProtoDefaultTypeInternal { EnumValueDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; constexpr ServiceDescriptorProto::ServiceDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : method_() @@ -205,7 +205,7 @@ struct ServiceDescriptorProtoDefaultTypeInternal { ServiceDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; constexpr MethodDescriptorProto::MethodDescriptorProto( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -222,7 +222,7 @@ struct MethodDescriptorProtoDefaultTypeInternal { MethodDescriptorProto _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; constexpr FileOptions::FileOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -255,7 +255,7 @@ struct FileOptionsDefaultTypeInternal { FileOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FileOptionsDefaultTypeInternal _FileOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FileOptionsDefaultTypeInternal _FileOptions_default_instance_; constexpr MessageOptions::MessageOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -271,7 +271,7 @@ struct MessageOptionsDefaultTypeInternal { MessageOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; constexpr FieldOptions::FieldOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -291,7 +291,7 @@ struct FieldOptionsDefaultTypeInternal { FieldOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; constexpr OneofOptions::OneofOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_(){} @@ -303,7 +303,7 @@ struct OneofOptionsDefaultTypeInternal { OneofOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; constexpr EnumOptions::EnumOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -317,7 +317,7 @@ struct EnumOptionsDefaultTypeInternal { EnumOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; constexpr EnumValueOptions::EnumValueOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -330,7 +330,7 @@ struct EnumValueOptionsDefaultTypeInternal { EnumValueOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; constexpr ServiceOptions::ServiceOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -343,7 +343,7 @@ struct ServiceOptionsDefaultTypeInternal { ServiceOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; constexpr MethodOptions::MethodOptions( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : uninterpreted_option_() @@ -358,7 +358,7 @@ struct MethodOptionsDefaultTypeInternal { MethodOptions _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; constexpr UninterpretedOption_NamePart::UninterpretedOption_NamePart( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_part_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -371,7 +371,7 @@ struct UninterpretedOption_NamePartDefaultTypeInternal { UninterpretedOption_NamePart _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; constexpr UninterpretedOption::UninterpretedOption( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_() @@ -389,7 +389,7 @@ struct UninterpretedOptionDefaultTypeInternal { UninterpretedOption _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; constexpr SourceCodeInfo_Location::SourceCodeInfo_Location( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : path_() @@ -407,7 +407,7 @@ struct SourceCodeInfo_LocationDefaultTypeInternal { SourceCodeInfo_Location _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; constexpr SourceCodeInfo::SourceCodeInfo( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : location_(){} @@ -419,7 +419,7 @@ struct SourceCodeInfoDefaultTypeInternal { SourceCodeInfo _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; constexpr GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : path_() @@ -435,7 +435,7 @@ struct GeneratedCodeInfo_AnnotationDefaultTypeInternal { GeneratedCodeInfo_Annotation _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; constexpr GeneratedCodeInfo::GeneratedCodeInfo( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : annotation_(){} @@ -447,7 +447,7 @@ struct GeneratedCodeInfoDefaultTypeInternal { GeneratedCodeInfo _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[27]; static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[6]; diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index d7e4e0035a..d04e32b0af 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -29,7 +29,7 @@ struct DurationDefaultTypeInternal { Duration _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY DurationDefaultTypeInternal _Duration_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT DurationDefaultTypeInternal _Duration_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fduration_2eproto[1]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 22328bda38..42d7f3be06 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -27,7 +27,7 @@ struct EmptyDefaultTypeInternal { Empty _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EmptyDefaultTypeInternal _Empty_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EmptyDefaultTypeInternal _Empty_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fempty_2eproto[1]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index d1f5698ff1..5a23fc7f2b 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -28,7 +28,7 @@ struct FieldMaskDefaultTypeInternal { FieldMask _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FieldMaskDefaultTypeInternal _FieldMask_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FieldMaskDefaultTypeInternal _FieldMask_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2ffield_5fmask_2eproto[1]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 3d84017647..641862ef39 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -28,7 +28,7 @@ struct SourceContextDefaultTypeInternal { SourceContext _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY SourceContextDefaultTypeInternal _SourceContext_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT SourceContextDefaultTypeInternal _SourceContext_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fsource_5fcontext_2eproto[1]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 1458a9bed5..61e9f80190 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -27,7 +27,7 @@ struct Struct_FieldsEntry_DoNotUseDefaultTypeInternal { Struct_FieldsEntry_DoNotUse _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_FieldsEntry_DoNotUse_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_FieldsEntry_DoNotUse_default_instance_; constexpr Struct::Struct( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : fields_(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}){} @@ -39,7 +39,7 @@ struct StructDefaultTypeInternal { Struct _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY StructDefaultTypeInternal _Struct_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT StructDefaultTypeInternal _Struct_default_instance_; constexpr Value::Value( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : _oneof_case_{}{} @@ -51,7 +51,7 @@ struct ValueDefaultTypeInternal { Value _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY ValueDefaultTypeInternal _Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ValueDefaultTypeInternal _Value_default_instance_; constexpr ListValue::ListValue( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : values_(){} @@ -63,7 +63,7 @@ struct ListValueDefaultTypeInternal { ListValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY ListValueDefaultTypeInternal _ListValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ListValueDefaultTypeInternal _ListValue_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fstruct_2eproto[4]; static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fstruct_2eproto[1]; diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 2c81eb4582..ac920a1612 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -29,7 +29,7 @@ struct TimestampDefaultTypeInternal { Timestamp _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY TimestampDefaultTypeInternal _Timestamp_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TimestampDefaultTypeInternal _Timestamp_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2ftimestamp_2eproto[1]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index a4a3c27069..e2f7a8fc53 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -34,7 +34,7 @@ struct TypeDefaultTypeInternal { Type _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY TypeDefaultTypeInternal _Type_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TypeDefaultTypeInternal _Type_default_instance_; constexpr Field::Field( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : options_() @@ -57,7 +57,7 @@ struct FieldDefaultTypeInternal { Field _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FieldDefaultTypeInternal _Field_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FieldDefaultTypeInternal _Field_default_instance_; constexpr Enum::Enum( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : enumvalue_() @@ -74,7 +74,7 @@ struct EnumDefaultTypeInternal { Enum _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumDefaultTypeInternal _Enum_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumDefaultTypeInternal _Enum_default_instance_; constexpr EnumValue::EnumValue( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : options_() @@ -88,7 +88,7 @@ struct EnumValueDefaultTypeInternal { EnumValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY EnumValueDefaultTypeInternal _EnumValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT EnumValueDefaultTypeInternal _EnumValue_default_instance_; constexpr Option::Option( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string) @@ -101,7 +101,7 @@ struct OptionDefaultTypeInternal { Option _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY OptionDefaultTypeInternal _Option_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT OptionDefaultTypeInternal _Option_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2ftype_2eproto[5]; static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[3]; diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index d1a956175b..eb691be511 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -28,7 +28,7 @@ struct DoubleValueDefaultTypeInternal { DoubleValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY DoubleValueDefaultTypeInternal _DoubleValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT DoubleValueDefaultTypeInternal _DoubleValue_default_instance_; constexpr FloatValue::FloatValue( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(0){} @@ -40,7 +40,7 @@ struct FloatValueDefaultTypeInternal { FloatValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY FloatValueDefaultTypeInternal _FloatValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT FloatValueDefaultTypeInternal _FloatValue_default_instance_; constexpr Int64Value::Int64Value( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(PROTOBUF_LONGLONG(0)){} @@ -52,7 +52,7 @@ struct Int64ValueDefaultTypeInternal { Int64Value _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY Int64ValueDefaultTypeInternal _Int64Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT Int64ValueDefaultTypeInternal _Int64Value_default_instance_; constexpr UInt64Value::UInt64Value( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(PROTOBUF_ULONGLONG(0)){} @@ -64,7 +64,7 @@ struct UInt64ValueDefaultTypeInternal { UInt64Value _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; constexpr Int32Value::Int32Value( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(0){} @@ -76,7 +76,7 @@ struct Int32ValueDefaultTypeInternal { Int32Value _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY Int32ValueDefaultTypeInternal _Int32Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT Int32ValueDefaultTypeInternal _Int32Value_default_instance_; constexpr UInt32Value::UInt32Value( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(0u){} @@ -88,7 +88,7 @@ struct UInt32ValueDefaultTypeInternal { UInt32Value _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_; constexpr BoolValue::BoolValue( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(false){} @@ -100,7 +100,7 @@ struct BoolValueDefaultTypeInternal { BoolValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY BoolValueDefaultTypeInternal _BoolValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT BoolValueDefaultTypeInternal _BoolValue_default_instance_; constexpr StringValue::StringValue( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){} @@ -112,7 +112,7 @@ struct StringValueDefaultTypeInternal { StringValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY StringValueDefaultTypeInternal _StringValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT StringValueDefaultTypeInternal _StringValue_default_instance_; constexpr BytesValue::BytesValue( ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized) : value_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){} @@ -124,7 +124,7 @@ struct BytesValueDefaultTypeInternal { BytesValue _instance; }; }; -PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY BytesValueDefaultTypeInternal _BytesValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT BytesValueDefaultTypeInternal _BytesValue_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[9]; static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; From c908fdbd0ce66585d49fcf94ed2aef59b8d55285 Mon Sep 17 00:00:00 2001 From: Christopher Hunt Date: Thu, 18 Feb 2021 11:10:42 +1100 Subject: [PATCH 18/80] Some doc on AOT compilation and protobuf (#8294) * Create jvm_native_images.md Some initial text pertaining to the use of protobuf with AOT compilation tools such as the one provided by GraalVM native-image. * Update jvm_native_images.md Fixed spelling * Update and rename jvm_native_images.md to jvm_aot.md --- docs/jvm_aot.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 docs/jvm_aot.md diff --git a/docs/jvm_aot.md b/docs/jvm_aot.md new file mode 100644 index 0000000000..4eb682f54b --- /dev/null +++ b/docs/jvm_aot.md @@ -0,0 +1,18 @@ +# Ahead Of Time (AOT) compilation for the Java Virtual Machine (JVM)" + +Ahead Of Time (AOT) compilation build tools such as those provided by [GraalVM's `native-image`](https://www.graalvm.org/reference-manual/native-image/) can require some configuration when using protobuf. +Protobuf for the JVM uses reflection and some of its target classes are not possible to determine in advance. +Historically, there were good reasons to use reflection based on APIs that were published effectively requiring them, and this situation is unlikely to change. + +[The Lite version of protobuf for the JVM](https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md) +avoids reflection and may be better suited for use with AOT compilation tooling. This Lite version was originally targeted for use on Android which has similar AOT compilation +goals as GraalVM's native-image tool. + +## GraalVM native-image + +This section addresses GraalVM's `native-image` configuration specifically as this AOT compilation tool due to its popularity. The `native-image` tool can be configured +with respect to: the [Java Native Interface](https://en.wikipedia.org/wiki/Java_Native_Interface) (JNI), http proxying, reflection, and other resources. While these +considerations can be manually declared as JSON files, we recommend that a JVM application is exercised along with +[the assisted configuration agent](https://www.graalvm.org/reference-manual/native-image/BuildConfiguration/#assisted-configuration-of-native-image-builds). The agent +will generate files that you can then subsequently point at when invoking `native-image`. We recommend that the generated files are retained with a project's source +code. From ac9218c5d9fc5c1e877dcbd0b93f13c3fd0ba51c Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 5 Feb 2021 14:18:49 -0800 Subject: [PATCH 19/80] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 27 ++++++++++++++----- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 4 +-- src/google/protobuf/api.pb.h | 4 +-- src/google/protobuf/compiler/plugin.pb.h | 4 +-- src/google/protobuf/descriptor.pb.h | 4 +-- src/google/protobuf/duration.pb.h | 4 +-- src/google/protobuf/empty.pb.h | 4 +-- src/google/protobuf/field_mask.pb.h | 4 +-- src/google/protobuf/port_def.inc | 10 +++---- src/google/protobuf/source_context.pb.h | 4 +-- src/google/protobuf/struct.pb.h | 4 +-- src/google/protobuf/stubs/common.h | 10 +++---- src/google/protobuf/timestamp.pb.h | 4 +-- src/google/protobuf/type.pb.h | 4 +-- src/google/protobuf/wrappers.pb.h | 4 +-- 31 files changed, 71 insertions(+), 56 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 3f250e2f2a..f3f463d93f 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.14.0' + s.version = '3.15.0-rc1' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 7a7363aaf0..1777c08f59 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.14.0' + s.version = '3.15.0-rc1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index eb70a76e16..2c33819c6b 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.14.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.15.0-rc-1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 0fb4b15093..d39e39cf78 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.14.0 + 3.15.0-rc1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4dbb349307..ec64544986 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.14.0 + 3.15.0-rc1 7.2 Google Inc. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 209a4b555b..8fd539f64c 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.14.0 + 3.15.0-rc-1 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 6c0732a358..449678de9c 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.14.0 + 3.15.0-rc-1 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 104c5c1676..cabe335729 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.14.0 + 3.15.0-rc-1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 024536cd26..ea00c6b173 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.14.0 + 3.15.0-rc-1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 75457fbc8e..45cbbe10f8 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.14.0 + 3.15.0-rc-1 protobuf-java-util diff --git a/js/package.json b/js/package.json index 6bbc115c04..2f3ba35341 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.14.0", + "version": "3.15.0-rc.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 557f8ffc23..a1d2cc1678 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,15 +10,15 @@ protobuf-opensource@google.com yes - 2020-11-12 - + 2021-02-05 + - 3.14.0 - 3.14.0 + 3.15.0RC1 + 3.15.0 - stable - stable + beta + beta 3-Clause BSD License PHP protobuf @@ -750,5 +750,20 @@ G A release. + + + 3.15.0RC1 + 3.15.0 + + + beta + beta + + 2021-02-05 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 232528288a..fa9e35ecf6 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -76,7 +76,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.14.0" +#define PHP_PROTOBUF_VERSION "3.15.0RC1" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 97fd11e700..45ae2384cd 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.14.0 + 3.15.0-rc-1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 97ac28028b..f6e7d2850a 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__ = '3.14.0' +__version__ = '3.15.0rc1' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 4852f7d587..bb689baaa5 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.14.0" + s.version = "3.15.0.rc.1" 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/src/Makefile.am b/src/Makefile.am index 5940ce187e..2f0f92ab98 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 25:0:0 +PROTOBUF_VERSION = 26:0: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 a91d4565ff..98d4890439 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 3aea532804..863b9da67d 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 208b8ef5e9..e2932deac0 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 cd4caa53aa..c9d47546c4 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 2065a85bb8..65c5d264a3 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 3b59d1630f..8de6f1c0f4 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 e7668ba903..af25a03cab 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 11e01601ca..b3583c67e5 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -335,14 +335,14 @@ // Shared google3/opensource definitions. ////////////////////////////////////// -#define PROTOBUF_VERSION 3014000 -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3014000 -#define PROTOBUF_MIN_PROTOC_VERSION 3014000 -#define PROTOBUF_VERSION_SUFFIX "" +#define PROTOBUF_VERSION 3015000 +#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3015000 +#define PROTOBUF_MIN_PROTOC_VERSION 3015000 +#define PROTOBUF_VERSION_SUFFIX "-rc1" // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3014000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3015000 #if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI #define PROTOBUF_RTTI 0 diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 12d4655da0..a5e9db67a9 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 315c473330..ac33ab601e 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 2d210d727c..dc4c515024 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,23 +82,23 @@ 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 3014000 +#define GOOGLE_PROTOBUF_VERSION 3015000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. -#define GOOGLE_PROTOBUF_VERSION_SUFFIX "" +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc1" // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 3014000; +static const int kMinHeaderVersionForLibrary = 3015000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3014000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3015000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 3014000; +static const int kMinHeaderVersionForProtoc = 3015000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 1105edb6bb..bae459137c 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 a47a5fbcb7..7188ed3609 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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 2efd56091c..569bde0f67 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3014000 +#if PROTOBUF_VERSION < 3015000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3014000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3015000 < 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. From 983ea052cedc6fd1f253932f60b8553a46ea4924 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 5 Feb 2021 16:09:24 -0800 Subject: [PATCH 20/80] Updated CHANGES.txt for the 3.15.0 release --- CHANGES.txt | 55 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6658bcdbd1..476ed7601e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) +2021-02-05 version 3.15.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Protocol Compiler * Optional fields for proto3 are enabled by default, and no longer require @@ -27,7 +27,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) output (does not affect comparison logic) and stop printing 'value' in the path. The modified print functionality is in the MessageDifferencer::StreamReporter. - * Fixes https://github.com/protocolbuffers/protobuf/issues/8129 + * Fixed https://github.com/protocolbuffers/protobuf/issues/8129 * Ensure that null char symbol, package and file names do not result in a crash. * Constant initialize the global message instances @@ -35,6 +35,43 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Removed remaining instances of std::is_pod, which is deprecated in C++20. * Changes to reduce code size for unknown field handling by making uncommon cases out of line. + * Fix std::is_pod deprecated in C++20 (#7180) + * Fix some -Wunused-parameter warnings (#8053) + * Fix detecting file as directory on zOS issue #8051 (#8052) + * Don't include sys/param.h for _BYTE_ORDER (#8106) + * remove CMAKE_THREAD_LIBS_INIT from pkgconfig CFLAGS (#8154) + * Fix TextFormatMapTest.DynamicMessage issue#5136 (#8159) + * Fix for compiler warning issue#8145 (#8160) + * fix: support deprecated enums for GCC < 6 (#8164) + * Fix some warning when compiling with Visual Studio 2019 on x64 target (#8125) + + Python + * Provided an override for the reverse() method that will reverse the internal + collection directly instead of using the other methods of the BaseContainer. + * MessageFactory.CreateProtoype can be overridden to customize class creation. + * Fix PyUnknownFields memory leak (#7928) + * Add macOS big sur compatibility (#8126) + + JavaScript + * Generate `getDescriptor` methods with `*` as their `this` type. + * Enforce `let/const` for generated messages. + * js/binary/utils.js: Fix jspb.utils.joinUnsignedDecimalString to work with negative bitsLow and low but non-zero bitsHigh parameter. (#8170) + + PHP + * unregister INI entries and fix invalid read on shutdown (#8042) + * Fix PhpDoc comments for message accessors to include "|null". (#8136) + * fix: convert native PHP floats to single precision (#8187) + * Fixed PHP to support field numbers >=2**28. (#8235) + * feat: add support for deprecated fields to PHP compiler (#8223) + * Protect against stack overflow if the user derives from Message. (#8248) + * Fixed clone for Message, RepeatedField, and MapField. (#8245) + * Updated upb to allow nonzero offset minutes in JSON timestamps. (#8258) + + Ruby + * Fill out JRuby support (#7923) + * [Ruby] Fix: (SIGSEGV) gRPC-Ruby issue on Windows. memory alloc infinite recursion/run out of memory (#8195) + * Ported Ruby extension to upb_msg (#8184) + * Fix jruby support to handle messages nested more than 1 level deep (#8194) Java * Avoid possible UnsupportedOperationException when using CodedInputSteam @@ -49,14 +86,12 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Annotates Java proto generated *_FIELD_NUMBER constants. * Add -assumevalues to remove JvmMemoryAccessor on Android. - Python - * Provided an override for the reverse() method that will reverse the internal - collection directly instead of using the other methods of the BaseContainer. - * MessageFactory.CreateProtoype can be overridden to customize class creation. - - Javascript - * Generate `getDescriptor` methods with `*` as their `this` type. - * Enforce `let/const` for generated messages. + C# + * Fix parsing negative Int32Value that crosses segment boundary (#8035) + * Change ByteString to use memory and support unsafe create without copy (#7645) + * Optimize MapField serialization by removing MessageAdapter (#8143) + * Allow FileDescriptors to be parsed with extension registries (#8220) + * Optimize writing small strings (#8149) 2020-11-11 version 3.14.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From 76bfd890904943e5f73fd9126562d3381fb4e73e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 9 Feb 2021 14:10:10 -0800 Subject: [PATCH 21/80] Added PHP changes for 3.15.0 into package.xml --- php/ext/google/protobuf/package.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index a1d2cc1678..44fe74475f 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -21,7 +21,17 @@ beta 3-Clause BSD License - PHP protobuf + + New changes in 3.15.0: + * unregister INI entries and fix invalid read on shutdown (#8042) + * Fix PhpDoc comments for message accessors to include "|null". (#8136) + * fix: convert native PHP floats to single precision (#8187) + * Fixed PHP to support field numbers >=2**28. (#8235) + * feat: add support for deprecated fields to PHP compiler (#8223) + * Protect against stack overflow if the user derives from Message. (#8248) + * Fixed clone for Message, RepeatedField, and MapField. (#8245) + * Updated upb to allow nonzero offset minutes in JSON timestamps. (#8258) + From a94870872c29861c2330a15645c187b046e7aa86 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 9 Feb 2021 17:44:30 -0800 Subject: [PATCH 22/80] Added more information to "file already loaded" warning. Also changed it to zend_error() so it is more easily suppressed. --- php/ext/google/protobuf/def.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 9accb1da36..6e1a7e4e43 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -916,7 +916,10 @@ static void add_descriptor(DescriptorPool *pool, if (upb_symtab_lookupfile2(pool->symtab, name.data, name.size)) { // Already added. - fprintf(stderr, "WARNING: file was already added\n"); + zend_error(E_USER_WARNING, + "proto descriptor was previously loaded (included in multiple " + "metadata bundles?): " UPB_STRVIEW_FORMAT, + UPB_STRVIEW_ARGS(name)); return; } From 8aa0063befd9c380a4660f0f9ed464125b270ad1 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 10 Feb 2021 11:43:36 -0800 Subject: [PATCH 23/80] Updated collect_all_artifacts.sh to avoid installing apt-transport-https The installation of apt-transport-https is failing and causing this script to exit early. I suspect the package is no longer needed since recent versions have moved it into the apt package, so this change updates the script to stop trying to install apt-transport-https. --- kokoro/release/collect_all_artifacts.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/kokoro/release/collect_all_artifacts.sh b/kokoro/release/collect_all_artifacts.sh index 8f6e9db9a0..56f9eaeb19 100755 --- a/kokoro/release/collect_all_artifacts.sh +++ b/kokoro/release/collect_all_artifacts.sh @@ -49,7 +49,6 @@ cp ${INPUT_ARTIFACTS_DIR}/build64/src/protoc protoc/macosx_x64/protoc # Install nuget (will also install mono) # TODO(jtattermusch): use "mono:5.14" docker image instead so we don't have to apt-get install sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF -sudo apt install apt-transport-https echo "deb https://download.mono-project.com/repo/ubuntu stable-trusty main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list sudo apt update sudo apt-get install -y nuget From 37229350548659bb0d25c2a2ed439426c3ad6ee1 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 10 Feb 2021 15:06:29 -0800 Subject: [PATCH 24/80] Added to the changelog entries for Ruby & PHP. --- CHANGES.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 476ed7601e..9be4173739 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -58,6 +58,7 @@ * js/binary/utils.js: Fix jspb.utils.joinUnsignedDecimalString to work with negative bitsLow and low but non-zero bitsHigh parameter. (#8170) PHP + * Added support for PHP 8. (#8105) * unregister INI entries and fix invalid read on shutdown (#8042) * Fix PhpDoc comments for message accessors to include "|null". (#8136) * fix: convert native PHP floats to single precision (#8187) @@ -68,9 +69,13 @@ * Updated upb to allow nonzero offset minutes in JSON timestamps. (#8258) Ruby + * Added support for Ruby 3. (#8184) + * Rewrote the data storage layer to be based on upb_msg objects from the + upb library. This should lead to much better parsing performance, + particularly for large messages. (#8184). * Fill out JRuby support (#7923) - * [Ruby] Fix: (SIGSEGV) gRPC-Ruby issue on Windows. memory alloc infinite recursion/run out of memory (#8195) - * Ported Ruby extension to upb_msg (#8184) + * [Ruby] Fix: (SIGSEGV) gRPC-Ruby issue on Windows. memory alloc infinite + recursion/run out of memory (#8195) * Fix jruby support to handle messages nested more than 1 level deep (#8194) Java From 0533d042b33258c0c62a6752d95d0e8cf132eeff Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 10 Feb 2021 16:29:44 -0800 Subject: [PATCH 25/80] Delete root-owned files in Kokoro builds Some of our Kokoro builds have been failing because Kokoro is unable to copy root-owned files when the build is complete. This commit fixes the problem by deleting these files at the end. --- kokoro/linux/cpp_distcheck/build.sh | 4 ++++ kokoro/release/python/linux/build_artifacts.sh | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kokoro/linux/cpp_distcheck/build.sh b/kokoro/linux/cpp_distcheck/build.sh index 42ac88caff..a28843e9cb 100755 --- a/kokoro/linux/cpp_distcheck/build.sh +++ b/kokoro/linux/cpp_distcheck/build.sh @@ -16,6 +16,10 @@ until docker pull $DOCKER_IMAGE_NAME; do sleep 10; done docker run -v $(pwd):/var/local/protobuf --rm $DOCKER_IMAGE_NAME \ bash -l /var/local/protobuf/tests.sh cpp || FAILED="true" +# This directory is owned by root. We need to delete it, because otherwise +# Kokoro will attempt to rsync it and fail with a permission error. +rm -rf src/core + if [ "$FAILED" = "true" ]; then exit 1 fi diff --git a/kokoro/release/python/linux/build_artifacts.sh b/kokoro/release/python/linux/build_artifacts.sh index 6b1836f407..a35fc6f427 100755 --- a/kokoro/release/python/linux/build_artifacts.sh +++ b/kokoro/release/python/linux/build_artifacts.sh @@ -30,10 +30,6 @@ cp kokoro/release/python/linux/config.sh config.sh build_artifact_version() { MB_PYTHON_VERSION=$1 - - # Clean up env - rm -rf venv - sudo rm -rf $REPO_DIR cp -R $STAGE_DIR $REPO_DIR source multibuild/common_utils.sh @@ -47,6 +43,10 @@ build_artifact_version() { build_wheel $REPO_DIR/python $PLAT mv wheelhouse/* $ARTIFACT_DIR + + # Clean up env + rm -rf venv + sudo rm -rf $REPO_DIR } build_artifact_version 2.7 From ea2412e6edce2233acb3e95b4c32dad990c52d6c Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 16 Feb 2021 16:13:07 -0800 Subject: [PATCH 26/80] Updated collect_all_artifacts.sh for Ubuntu Xenial --- kokoro/release/collect_all_artifacts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kokoro/release/collect_all_artifacts.sh b/kokoro/release/collect_all_artifacts.sh index 56f9eaeb19..3372a01975 100755 --- a/kokoro/release/collect_all_artifacts.sh +++ b/kokoro/release/collect_all_artifacts.sh @@ -49,7 +49,7 @@ cp ${INPUT_ARTIFACTS_DIR}/build64/src/protoc protoc/macosx_x64/protoc # Install nuget (will also install mono) # TODO(jtattermusch): use "mono:5.14" docker image instead so we don't have to apt-get install sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF -echo "deb https://download.mono-project.com/repo/ubuntu stable-trusty main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list +echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list sudo apt update sudo apt-get install -y nuget From de701c660b78b307f0bbab7b71e61a04e4bcad79 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 17 Feb 2021 09:13:54 -0800 Subject: [PATCH 27/80] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 25 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/stubs/common.h | 2 +- 18 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index f3f463d93f..2020d507f7 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.15.0-rc1' + s.version = '3.15.0-rc2' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 1777c08f59..88bcbe701d 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.15.0-rc1' + s.version = '3.15.0-rc2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 2c33819c6b..1d15829a1d 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.15.0-rc-1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.15.0-rc-2],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index d39e39cf78..ec7fedf43e 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.15.0-rc1 + 3.15.0-rc2 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index ec64544986..4e0de6d997 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.15.0-rc1 + 3.15.0-rc2 7.2 Google Inc. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 8fd539f64c..4f6d400d34 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.15.0-rc-1 + 3.15.0-rc-2 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 449678de9c..ab75b577f0 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-1 + 3.15.0-rc-2 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index cabe335729..53f05e6469 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-1 + 3.15.0-rc-2 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index ea00c6b173..d783603024 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-1 + 3.15.0-rc-2 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 45cbbe10f8..c63a6fbbed 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-1 + 3.15.0-rc-2 protobuf-java-util diff --git a/js/package.json b/js/package.json index 2f3ba35341..a992b3964a 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.15.0-rc.1", + "version": "3.15.0-rc.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 44fe74475f..77005b3d0a 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,10 +10,10 @@ protobuf-opensource@google.com yes - 2021-02-05 - + 2021-02-17 + - 3.15.0RC1 + 3.15.0RC2 3.15.0 @@ -24,9 +24,9 @@ New changes in 3.15.0: * unregister INI entries and fix invalid read on shutdown (#8042) - * Fix PhpDoc comments for message accessors to include "|null". (#8136) + * Fix PhpDoc comments for message accessors to include "|null". (#8136) * fix: convert native PHP floats to single precision (#8187) - * Fixed PHP to support field numbers >=2**28. (#8235) + * Fixed PHP to support field numbers >=2**28. (#8235) * feat: add support for deprecated fields to PHP compiler (#8223) * Protect against stack overflow if the user derives from Message. (#8248) * Fixed clone for Message, RepeatedField, and MapField. (#8245) @@ -775,5 +775,20 @@ G A release. + + + 3.15.0RC2 + 3.15.0 + + + beta + beta + + 2021-02-17 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index fa9e35ecf6..16887b965b 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -76,7 +76,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.15.0RC1" +#define PHP_PROTOBUF_VERSION "3.15.0RC2" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 45ae2384cd..0916f713ef 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.15.0-rc-1 + 3.15.0-rc-2 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index f6e7d2850a..f9190c4ba1 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__ = '3.15.0rc1' +__version__ = '3.15.0rc2' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index bb689baaa5..99c1d14fba 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.15.0.rc.1" + s.version = "3.15.0.rc.2" 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/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index b3583c67e5..41b428412f 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -338,7 +338,7 @@ #define PROTOBUF_VERSION 3015000 #define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3015000 #define PROTOBUF_MIN_PROTOC_VERSION 3015000 -#define PROTOBUF_VERSION_SUFFIX "-rc1" +#define PROTOBUF_VERSION_SUFFIX "-rc2" // The minimum library version which works with the current version of the // headers. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index dc4c515024..b24da744d5 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -85,7 +85,7 @@ namespace internal { #define GOOGLE_PROTOBUF_VERSION 3015000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. -#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc1" +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc2" // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code From 133e5e75263be696c06599ab97614a1e1e6d9c66 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 18 Feb 2021 10:36:22 -0800 Subject: [PATCH 28/80] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 25 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/stubs/common.h | 2 +- 18 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 2020d507f7..e794cb2a49 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.15.0-rc2' + s.version = '3.15.0' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 88bcbe701d..d982b9de8b 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.15.0-rc2' + s.version = '3.15.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 1d15829a1d..fed7095bbd 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.15.0-rc-2],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.15.0],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index ec7fedf43e..0e8b54d9ab 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.15.0-rc2 + 3.15.0 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4e0de6d997..9c2c028507 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.15.0-rc2 + 3.15.0 7.2 Google Inc. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 4f6d400d34..7fbd41da5e 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.15.0-rc-2 + 3.15.0 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index ab75b577f0..79b967bb0e 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-2 + 3.15.0 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 53f05e6469..fd313daf51 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-2 + 3.15.0 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index d783603024..79850b17d3 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-2 + 3.15.0 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index c63a6fbbed..9c089dfb72 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.0-rc-2 + 3.15.0 protobuf-java-util diff --git a/js/package.json b/js/package.json index a992b3964a..768b37a4d0 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.15.0-rc.2", + "version": "3.15.0", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 77005b3d0a..805c071f75 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,15 +10,15 @@ protobuf-opensource@google.com yes - 2021-02-17 - + 2021-02-18 + - 3.15.0RC2 + 3.15.0 3.15.0 - beta - beta + stable + stable 3-Clause BSD License @@ -790,5 +790,20 @@ G A release. + + + 3.15.0 + 3.15.0 + + + stable + stable + + 2021-02-18 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 16887b965b..7e63ca095b 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -76,7 +76,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.15.0RC2" +#define PHP_PROTOBUF_VERSION "3.15.0" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 0916f713ef..cbe84bb434 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.15.0-rc-2 + 3.15.0 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index f9190c4ba1..6c20545fae 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__ = '3.15.0rc2' +__version__ = '3.15.0' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 99c1d14fba..6420dfc051 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.15.0.rc.2" + s.version = "3.15.0" 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/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 41b428412f..3dc0ca7f97 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -338,7 +338,7 @@ #define PROTOBUF_VERSION 3015000 #define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3015000 #define PROTOBUF_MIN_PROTOC_VERSION 3015000 -#define PROTOBUF_VERSION_SUFFIX "-rc2" +#define PROTOBUF_VERSION_SUFFIX "" // The minimum library version which works with the current version of the // headers. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index b24da744d5..c2edf7c9c5 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -85,7 +85,7 @@ namespace internal { #define GOOGLE_PROTOBUF_VERSION 3015000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. -#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc2" +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "" // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code From 947e2e189a9948fee8a624a7ff12802dc3d12e28 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 19 Feb 2021 21:36:09 +0000 Subject: [PATCH 29/80] deps: update JUnit and Truth --- java/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 79850b17d3..592a251b6a 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -75,7 +75,7 @@ junit junit - 4.13.1 + 4.13.2 test @@ -104,7 +104,7 @@ com.google.truth truth - 1.0.1 + 1.1.2 test From 2e47e3bc6476bbf40ee2834f493d58b2a729c195 Mon Sep 17 00:00:00 2001 From: Yuriy Chernyshov Date: Sat, 20 Feb 2021 12:09:52 +0300 Subject: [PATCH 30/80] Fix PROTOBUF_CONSTINIT macro redifinition The #ifdef block is duplicated with the above (which was fixed in 3.15.1). It would be great to have this fix backported to 3.15.1 (and released as 3.15.2). --- src/google/protobuf/port_def.inc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 3dc0ca7f97..d3cf42f39e 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -573,17 +573,6 @@ #define PROTOBUF_CONSTINIT #endif -#if defined(__cpp_constinit) -#define PROTOBUF_CONSTINIT constinit -#elif defined(__has_cpp_attribute) -#if __has_cpp_attribute(clang::require_constant_initialization) -#define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] -#endif -#endif -#ifndef PROTOBUF_CONSTINIT -#define PROTOBUF_CONSTINIT -#endif - // Some globals with an empty non-trivial destructor are annotated with // no_destroy for performance reasons. It reduces the cost of these globals in // non-opt mode and under sanitizers. From 5911099659dc1d15dd6b1967a6b5afbdc8563db8 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 19 Feb 2021 09:10:47 -0500 Subject: [PATCH 31/80] Move the class map to a CFDictionary. Since the keys are `Class`-s, there's no need to hash/copy/etc. them. This avoids causing `+initialize` on the classes just when building up a registry. --- objectivec/GPBExtensionRegistry.m | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/objectivec/GPBExtensionRegistry.m b/objectivec/GPBExtensionRegistry.m index b056a52d95..e3ff7c4059 100644 --- a/objectivec/GPBExtensionRegistry.m +++ b/objectivec/GPBExtensionRegistry.m @@ -34,18 +34,20 @@ #import "GPBDescriptor.h" @implementation GPBExtensionRegistry { - NSMutableDictionary *mutableClassMap_; + CFMutableDictionaryRef mutableClassMap_; } - (instancetype)init { if ((self = [super init])) { - mutableClassMap_ = [[NSMutableDictionary alloc] init]; + // The keys are ObjC classes, so straight up ptr comparisons are fine. + mutableClassMap_ = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, + &kCFTypeDictionaryValueCallBacks); } return self; } - (void)dealloc { - [mutableClassMap_ release]; + CFRelease(mutableClassMap_); [super dealloc]; } @@ -68,14 +70,13 @@ Class containingMessageClass = extension.containingMessageClass; CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) - [mutableClassMap_ objectForKey:containingMessageClass]; + CFDictionaryGetValue(mutableClassMap_, containingMessageClass); if (extensionMap == nil) { // Use a custom dictionary here because the keys are numbers and conversion // back and forth from NSNumber isn't worth the cost. extensionMap = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks); - [mutableClassMap_ setObject:(id)extensionMap - forKey:(id)containingMessageClass]; + CFDictionarySetValue(mutableClassMap_, containingMessageClass, extensionMap); CFRelease(extensionMap); } @@ -87,7 +88,7 @@ fieldNumber:(NSInteger)fieldNumber { Class messageClass = descriptor.messageClass; CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) - [mutableClassMap_ objectForKey:messageClass]; + CFDictionaryGetValue(mutableClassMap_, messageClass); ssize_t key = fieldNumber; GPBExtensionDescriptor *result = (extensionMap @@ -101,28 +102,28 @@ static void CopyKeyValue(const void *key, const void *value, void *context) { CFDictionarySetValue(extensionMap, key, value); } +static void CopySubDictionary(const void *key, const void *value, void *context) { + CFMutableDictionaryRef mutableClassMap = (CFMutableDictionaryRef)context; + Class containingMessageClass = key; + CFMutableDictionaryRef otherExtensionMap = (CFMutableDictionaryRef)value; + + CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) + CFDictionaryGetValue(mutableClassMap, containingMessageClass); + if (extensionMap == nil) { + extensionMap = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, otherExtensionMap); + CFDictionarySetValue(mutableClassMap, containingMessageClass, extensionMap); + CFRelease(extensionMap); + } else { + CFDictionaryApplyFunction(otherExtensionMap, CopyKeyValue, extensionMap); + } +} + - (void)addExtensions:(GPBExtensionRegistry *)registry { if (registry == nil) { // In the case where there are no extensions just ignore. return; } - NSMutableDictionary *otherClassMap = registry->mutableClassMap_; - [otherClassMap enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL * stop) { -#pragma unused(stop) - Class containingMessageClass = key; - CFMutableDictionaryRef otherExtensionMap = (CFMutableDictionaryRef)value; - - CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) - [mutableClassMap_ objectForKey:containingMessageClass]; - if (extensionMap == nil) { - extensionMap = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, otherExtensionMap); - [mutableClassMap_ setObject:(id)extensionMap - forKey:(id)containingMessageClass]; - CFRelease(extensionMap); - } else { - CFDictionaryApplyFunction(otherExtensionMap, CopyKeyValue, extensionMap); - } - }]; + CFDictionaryApplyFunction(registry->mutableClassMap_, CopySubDictionary, mutableClassMap_); } #pragma clang diagnostic pop From d6f0c9b18727809ca6fe2bf22a34fe2a4786e6c8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 26 Feb 2021 10:45:41 -0800 Subject: [PATCH 32/80] Updated changelog. --- CHANGES.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index d73ef274c5..14b9b3a7ae 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,18 @@ +Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + C++ + * Allow MessageDifferencer::TreatAsSet() (and friends) to override previous + calls instead of crashing. + * Reduce the size of generated proto headers for protos with `string` or + `bytes` fields. + * Move arena() operation on uncommon path to out-of-line routine + * For iterator-pair function parameter types, take both iterators by value. + * Code-space savings and perhaps some modest performance improvements in + RepeatedPtrField. + + Java: + * Exceptions thrown while reading from an InputStream in parseFrom are now included as causes. + 2021-02-25 version 3.15.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Ruby From f645c7ed07d2d82c8b2356245957d681cd7adbd2 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 26 Feb 2021 10:54:13 -0800 Subject: [PATCH 33/80] Fixed spelling errors surfaced by CodeSpell. --- .../com/google/protobuf/InvalidProtocolBufferException.java | 2 +- src/google/protobuf/compiler/cpp/cpp_file.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index b47eeefe28..4b4303374c 100644 --- a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java @@ -78,7 +78,7 @@ public class InvalidProtocolBufferException extends IOException { /* This write can be racy if the same exception is stored and then thrown by multiple custom * InputStreams on different threads. But since it only ever moves from false->true, there's no * problem. A thread checking this condition after catching this exception from a delegate - * stram of CodedInputStream is guaranteed to always observe true, because a write on the same + * stream of CodedInputStream is guaranteed to always observe true, because a write on the same * thread set the value when the exception left the delegate. A thread checking the same * condition with an exception created by CodedInputStream is guaranteed to always see false, * because the exception has not been exposed to any code that could publish it to other threads diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index d47a0d6fee..9a0c7ab651 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -856,8 +856,8 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) { "};\n" // This function exists to be marked as weak. // It can significantly speed up compilation by breaking up LLVM's SCC in - // the .pb.cc tranlation units. Large translation units see a reduction of - // more than 35% of walltime for optimized builds. + // the .pb.cc translation units. Large translation units see a reduction + // of more than 35% of walltime for optimized builds. // Without the weak attribute all the messages in the file, including all // the vtables and everything they use become part of the same SCC through // a cycle like: From e9091e6d8c0adaa83bcb260aa47c316024f1c97a Mon Sep 17 00:00:00 2001 From: Yuriy Chernyshov Date: Mon, 1 Mar 2021 23:59:39 +0300 Subject: [PATCH 34/80] Fix some constness / char literal issues being found by MSVC standard conforming mode (#8344) * Fix some constness / char literal issues being found by MSVC standard conforming mode * Switch to const_cast from C-style casts --- python/google/protobuf/pyext/descriptor_pool.cc | 4 ++-- python/google/protobuf/pyext/map_container.cc | 8 ++++---- python/google/protobuf/pyext/message.cc | 10 +++++----- python/google/protobuf/pyext/message.h | 2 +- python/google/protobuf/pyext/message_factory.cc | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index 6f1464e321..a24d45d834 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -176,9 +176,9 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase( // The public DescriptorPool constructor. static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { - static char* kwlist[] = {"descriptor_db", 0}; + static const char* kwlist[] = {"descriptor_db", 0}; PyObject* py_database = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &py_database)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", const_cast(kwlist), &py_database)) { return NULL; } DescriptorDatabase* database = NULL; diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index a0ee16fe86..711c30472c 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -462,10 +462,10 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key, static PyObject* ScalarMapGet(PyObject* self, PyObject* args, PyObject* kwargs) { - static char* kwlist[] = {"key", "default", nullptr}; + static const char* kwlist[] = {"key", "default", nullptr}; PyObject* key; PyObject* default_value = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &key, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", const_cast(kwlist), &key, &default_value)) { return NULL; } @@ -757,10 +757,10 @@ PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) { } PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) { - static char* kwlist[] = {"key", "default", nullptr}; + static const char* kwlist[] = {"key", "default", nullptr}; PyObject* key; PyObject* default_value = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &key, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", const_cast(kwlist), &key, &default_value)) { return NULL; } diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 4e74386e2d..e8e1a17b97 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -196,12 +196,12 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) { } static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { - static char *kwlist[] = {"name", "bases", "dict", 0}; + static const char *kwlist[] = {"name", "bases", "dict", 0}; PyObject *bases, *dict; const char* name; // Check arguments: (name, bases, dict) - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!O!:type", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!O!:type", const_cast(kwlist), &name, &PyTuple_Type, &bases, &PyDict_Type, &dict)) { @@ -546,7 +546,7 @@ PyObject* PickleError_class; // Format an error message for unexpected types. // Always return with an exception set. -void FormatTypeError(PyObject* arg, char* expected_types) { +void FormatTypeError(PyObject* arg, const char* expected_types) { // This function is often called with an exception set. // Clear it to call PyObject_Repr() in good conditions. PyErr_Clear(); @@ -1679,9 +1679,9 @@ static PyObject* InternalSerializeToString( CMessage* self, PyObject* args, PyObject* kwargs, bool require_initialized) { // Parse the "deterministic" kwarg; defaults to False. - static char* kwlist[] = { "deterministic", 0 }; + static const char* kwlist[] = { "deterministic", 0 }; PyObject* deterministic_obj = Py_None; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", const_cast(kwlist), &deterministic_obj)) { return NULL; } diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index a1e8326512..96e06e5a3d 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -329,7 +329,7 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg); #define FULL_MODULE_NAME "google.protobuf.pyext._message" -void FormatTypeError(PyObject* arg, char* expected_types); +void FormatTypeError(PyObject* arg, const char* expected_types); template bool CheckAndGetInteger(PyObject* arg, T* value); bool CheckAndGetDouble(PyObject* arg, double* value); diff --git a/python/google/protobuf/pyext/message_factory.cc b/python/google/protobuf/pyext/message_factory.cc index 5fed13b943..5a10c3dc24 100644 --- a/python/google/protobuf/pyext/message_factory.cc +++ b/python/google/protobuf/pyext/message_factory.cc @@ -77,9 +77,9 @@ PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool) } PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { - static char* kwlist[] = {"pool", 0}; + static const char* kwlist[] = {"pool", 0}; PyObject* pool = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &pool)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", const_cast(kwlist), &pool)) { return NULL; } ScopedPyObjectPtr owned_pool; From 88367afa1ff1c178e33ce9e1214050638a05f4d4 Mon Sep 17 00:00:00 2001 From: Yannic Date: Tue, 2 Mar 2021 00:29:00 +0000 Subject: [PATCH 35/80] [C++] Delete StringPiecePod (#8353) Protobuf no longer supports C++ < 11, so this type is no longer required. --- src/google/protobuf/stubs/stringpiece.h | 43 ------------------- src/google/protobuf/stubs/strutil.h | 3 -- src/google/protobuf/util/internal/datapiece.h | 8 ++-- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/google/protobuf/stubs/stringpiece.h b/src/google/protobuf/stubs/stringpiece.h index fbcb20afc4..0a426fec34 100644 --- a/src/google/protobuf/stubs/stringpiece.h +++ b/src/google/protobuf/stubs/stringpiece.h @@ -426,49 +426,6 @@ inline bool operator>=(StringPiece x, StringPiece y) { // allow StringPiece to be logged extern std::ostream& operator<<(std::ostream& o, StringPiece piece); -namespace internal { -// StringPiece is not a POD and can not be used in an union (pre C++11). We -// need a POD version of it. -struct StringPiecePod { - // Create from a StringPiece. - static StringPiecePod CreateFromStringPiece(StringPiece str) { - StringPiecePod pod; - pod.data_ = str.data(); - pod.size_ = str.size(); - return pod; - } - - // Cast to StringPiece. - operator StringPiece() const { return StringPiece(data_, size_); } - - bool operator==(const char* value) const { - return StringPiece(data_, size_) == StringPiece(value); - } - - char operator[](stringpiece_ssize_type i) const { - assert(0 <= i); - assert(i < size_); - return data_[i]; - } - - const char* data() const { return data_; } - - stringpiece_ssize_type size() const { - return size_; - } - - std::string ToString() const { - return std::string(data_, static_cast(size_)); - } - - explicit operator std::string() const { return ToString(); } - - private: - const char* data_; - stringpiece_ssize_type size_; -}; - -} // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 8ce81f28c3..31c548982e 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -664,9 +664,6 @@ struct PROTOBUF_EXPORT AlphaNum { AlphaNum(StringPiece str) : piece_data_(str.data()), piece_size_(str.size()) {} - AlphaNum(internal::StringPiecePod str) - : piece_data_(str.data()), piece_size_(str.size()) {} - size_t size() const { return piece_size_; } const char *data() const { return piece_data_; } diff --git a/src/google/protobuf/util/internal/datapiece.h b/src/google/protobuf/util/internal/datapiece.h index 03ea128bdb..a8fe717457 100644 --- a/src/google/protobuf/util/internal/datapiece.h +++ b/src/google/protobuf/util/internal/datapiece.h @@ -93,12 +93,12 @@ class PROTOBUF_EXPORT DataPiece { : type_(TYPE_BOOL), bool_(value), use_strict_base64_decoding_(false) {} DataPiece(StringPiece value, bool use_strict_base64_decoding) : type_(TYPE_STRING), - str_(StringPiecePod::CreateFromStringPiece(value)), + str_(value), use_strict_base64_decoding_(use_strict_base64_decoding) {} // Constructor for bytes. The second parameter is not used. DataPiece(StringPiece value, bool dummy, bool use_strict_base64_decoding) : type_(TYPE_BYTES), - str_(StringPiecePod::CreateFromStringPiece(value)), + str_(value), use_strict_base64_decoding_(use_strict_base64_decoding) {} DataPiece(const DataPiece& r) : type_(r.type_) { InternalCopy(r); } @@ -191,8 +191,6 @@ class PROTOBUF_EXPORT DataPiece { // Data type for this piece of data. Type type_; - typedef ::google::protobuf::internal::StringPiecePod StringPiecePod; - // Stored piece of data. union { int32 i32_; @@ -202,7 +200,7 @@ class PROTOBUF_EXPORT DataPiece { double double_; float float_; bool bool_; - StringPiecePod str_; + StringPiece str_; }; // Uses a stricter version of base64 decoding for byte fields. From 9d203953a9950a2f2054b9029490940859ba153f Mon Sep 17 00:00:00 2001 From: Romain Geissler Date: Thu, 18 Feb 2021 23:34:41 +0000 Subject: [PATCH 36/80] Fix gcc error: comparison of unsigned expression in '>= 0' is always true [-Werror=type-limits] This fixes the following build error: In file included from no_warning_test.cc:7: ../../src/google/protobuf/parse_context.h: In instantiation of 'const char* google::protobuf::internal::EpsCopyInputStream::AppendUntilEnd(const char*, const A&) [with A = google::protobuf::internal::EpsCopyInputStream::AppendString(const char*, std::string*)::]': ../../src/google/protobuf/parse_context.h:366:70: required from here ../../src/google/protobuf/stubs/logging.h:161:48: error: comparison of unsigned expression in '>= 0' is always true [-Werror=type-limits] 161 | #define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B)) | ^ ../../src/google/protobuf/stubs/logging.h:151:5: note: in definition of macro 'GOOGLE_LOG_IF' 151 | !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL) | ^~~~~~~~~ ../../src/google/protobuf/stubs/logging.h:161:31: note: in expansion of macro 'GOOGLE_CHECK' 161 | #define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B)) | ^~~~~~~~~~~~ ../../src/google/protobuf/stubs/logging.h:201:26: note: in expansion of macro 'GOOGLE_CHECK_GE' 201 | #define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE | ^~~~~~~~~~~~~~~ ../../src/google/protobuf/parse_context.h:351:7: note: in expansion of macro 'GOOGLE_DCHECK_GE' 351 | GOOGLE_DCHECK_GE(chunk_size, static_cast(0)); | ^~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors --- src/google/protobuf/parse_context.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 7966d99d57..3754f983b1 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -348,7 +348,6 @@ class PROTOBUF_EXPORT EpsCopyInputStream { if (ptr - buffer_end_ > limit_) return nullptr; while (limit_ > kSlopBytes) { size_t chunk_size = buffer_end_ + kSlopBytes - ptr; - GOOGLE_DCHECK_GE(chunk_size, static_cast(0)); append(ptr, chunk_size); ptr = Next(); if (ptr == nullptr) return limit_end_; From 630028a4c6442cfcfabf9c770870a441b3096da8 Mon Sep 17 00:00:00 2001 From: Anton Danielsson Date: Tue, 16 Feb 2021 20:59:54 +0100 Subject: [PATCH 37/80] Fix cmake install on iOS Fixes: INSTALL TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE executable --- cmake/install.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 9dd6e7710f..ef5bb13068 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -30,7 +30,9 @@ endforeach() if (protobuf_BUILD_PROTOC_BINARIES) install(TARGETS protoc EXPORT protobuf-targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT protoc) if (UNIX AND NOT APPLE) set_property(TARGET protoc PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") From a4e7b97bd609acf2b8b0eb7c936d37f2eda367ff Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 25 Feb 2021 15:11:40 -0500 Subject: [PATCH 38/80] Create a CMake option to control whether or not RTTI is enabled This is useful for Conan recipes that build Protobuf, in which whatever we want to enable has to be enabled in the initial command line. Without this, the people maintaining the recipe have to patch the CMake setup of Protobuf before building the binaries. Closes #5541 --- cmake/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 52661f522d..83bbb40164 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -40,6 +40,7 @@ endif() if(WITH_PROTOC) set(protobuf_PROTOC_EXE ${WITH_PROTOC} CACHE FILEPATH "Protocol Buffer Compiler executable" FORCE) endif() +option(protobuf_DISABLE_RTTI "Remove runtime type information in the binaries" ON) option(protobuf_BUILD_TESTS "Build tests" ON) option(protobuf_BUILD_CONFORMANCE "Build conformance tests" OFF) option(protobuf_BUILD_EXAMPLES "Build examples" OFF) @@ -117,6 +118,10 @@ endif() add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) +if (protobuf_DISABLE_RTTI) + add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1) +endif() + find_package(Threads REQUIRED) if (CMAKE_USE_PTHREADS_INIT) add_definitions(-DHAVE_PTHREAD) From 3172ab8ff97aab005d7734627409faa166174232 Mon Sep 17 00:00:00 2001 From: Po-Chuan Hsieh Date: Fri, 26 Feb 2021 10:26:56 +0000 Subject: [PATCH 39/80] Fix endian.h location on FreeBSD --- src/google/protobuf/io/coded_stream.h | 2 ++ src/google/protobuf/stubs/port.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index df8c4499ad..dcbb7834a7 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -133,6 +133,8 @@ #else #ifdef __APPLE__ #include // __BYTE_ORDER +#elif defined(__FreeBSD__) +#include // __BYTE_ORDER #else #include // __BYTE_ORDER #endif diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index b7aab404ca..0f3b5aa628 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -59,6 +59,8 @@ #else #ifdef __APPLE__ #include // __BYTE_ORDER +#elif defined(__FreeBSD__) +#include // __BYTE_ORDER #else #include // __BYTE_ORDER #endif From 85e5204517779bbb6b3523ab516359f581bf0bab Mon Sep 17 00:00:00 2001 From: Yannic Date: Sat, 27 Feb 2021 15:00:59 +0100 Subject: [PATCH 40/80] [bazel] Flip --incompatible_use_com_google_googletest --- BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 1124321602..1dee9af93d 100644 --- a/BUILD +++ b/BUILD @@ -17,7 +17,7 @@ exports_files(["LICENSE"]) # TODO(yannic): Remove in 3.14.0. string_flag( name = "incompatible_use_com_google_googletest", - build_setting_default = "true", + build_setting_default = "false", values = ["true", "false"] ) From 2e7771d7a05a9416c530332f0ebd2c0522c4e6e6 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Tue, 2 Mar 2021 22:49:24 +0300 Subject: [PATCH 41/80] read_property() handler is not supposed to return NULL NULL is never expected as a result of read_property() handler, it should return &EG(uninitialized_zval) if there is no such property in the object --- php/ext/google/protobuf/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 7f27670320..0f1f4c964e 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -334,7 +334,7 @@ static zval *Message_read_property(PROTO_VAL *obj, PROTO_STR *member, Message* intern = PROTO_VAL_P(obj); const upb_fielddef *f = get_field(intern, member); - if (!f) return NULL; + if (!f) return &EG(uninitialized_zval); Message_get(intern, f, rv); return rv; } From 88243e45fc3300e7f0c50b1a1c70834249ad974d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 2 Mar 2021 13:37:47 -0800 Subject: [PATCH 42/80] [Ruby] Fixed quadratic memory usage when appending to arrays. The code mistakenly called realloc() instead of resize() on every array append, causing quadratic memory usage. --- ruby/ext/google/protobuf_c/ruby-upb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index a7aeda2df2..61762fcd99 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6663,10 +6663,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { } bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { - if (!_upb_array_realloc(arr, arr->len + 1, arena)) { + if (!upb_array_resize(arr, arr->len + 1, arena)) { return false; } - arr->len++; upb_array_set(arr, arr->len - 1, val); return true; } From 33905ec87bd49e257cba21888e99ea0278705d10 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 3 Mar 2021 12:36:13 -0800 Subject: [PATCH 43/80] Fixed the Java Lite build. --- java/lite/generate-test-sources-build.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 62bca93c86..65e62ce4fb 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -4,6 +4,7 @@ + From 82f5ecd955391bf6fe35ed08214dd7287764a60d Mon Sep 17 00:00:00 2001 From: Yannic Date: Wed, 3 Mar 2021 23:07:10 +0100 Subject: [PATCH 44/80] Revert "[bazel] Flip --incompatible_use_com_google_googletest" This reverts commit 85e5204517779bbb6b3523ab516359f581bf0bab. --- BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 1dee9af93d..1124321602 100644 --- a/BUILD +++ b/BUILD @@ -17,7 +17,7 @@ exports_files(["LICENSE"]) # TODO(yannic): Remove in 3.14.0. string_flag( name = "incompatible_use_com_google_googletest", - build_setting_default = "false", + build_setting_default = "true", values = ["true", "false"] ) From 5d0c30934bb6a6c1d387b549f5af3a4efcebe2ef Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Thu, 4 Mar 2021 13:25:55 +0300 Subject: [PATCH 45/80] Added abilty to pass options to protoc executable from cmake --- cmake/protobuf-config.cmake.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index fac5efe440..9197625dc2 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -15,7 +15,7 @@ function(protobuf_generate) if(COMMAND target_sources) list(APPEND _singleargs TARGET) endif() - set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS) + set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS PROTOC_OPTIONS) cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") @@ -130,9 +130,9 @@ function(protobuf_generate) add_custom_command( OUTPUT ${_generated_srcs} COMMAND protobuf::protoc - ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} + ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} DEPENDS ${_abs_file} protobuf::protoc - COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}" + COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}. Custom options: ${protobuf_generate_PROTOC_OPTIONS}" VERBATIM ) endforeach() From b6facc69ea0f1515b9bf522634bb6ab19031729d Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 1 Mar 2021 10:01:35 -0500 Subject: [PATCH 46/80] docs: update version --- java/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/README.md b/java/README.md index c8050893e0..c3434144b1 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.11.0 + 3.15.3 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.11.0 + 3.15.3 ``` From 87dd07b4367b7676af42105d0d102f4e536c248b Mon Sep 17 00:00:00 2001 From: Alexander Shadchin Date: Thu, 4 Mar 2021 22:00:41 +0300 Subject: [PATCH 47/80] Switch on "new" buffer API (#8339) "Old" buffer API will removed in Python 3.10. This is also fix #7930. --- python/google/protobuf/internal/message_test.py | 9 +-------- python/google/protobuf/internal/python_message.py | 6 ------ python/google/protobuf/pyext/descriptor.cc | 2 +- python/google/protobuf/pyext/message.cc | 12 ++++++------ python/tox.ini | 7 +++---- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index feff228fb6..77122a2875 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -841,8 +841,7 @@ class MessageTest(unittest.TestCase): m1.MergeFromString(m2.SerializeToString()) self.assertEqual(1, m1.optional_nested_message.bb) - @unittest.skipIf(six.PY2, 'memoryview objects are not supported on py2') - def testMergeFromStringUsingMemoryViewWorksInPy3(self, message_module): + def testMergeFromStringUsingMemoryView(self, message_module): m2 = message_module.TestAllTypes() m2.optional_string = 'scalar string' m2.repeated_string.append('repeated string') @@ -864,12 +863,6 @@ class MessageTest(unittest.TestCase): self.assertIsInstance(m1.optional_string, six.text_type) self.assertIsInstance(m1.repeated_string[0], six.text_type) - @unittest.skipIf(six.PY3, 'memoryview is supported by py3') - def testMergeFromStringUsingMemoryViewIsPy2Error(self, message_module): - memview = memoryview(b'') - with self.assertRaises(TypeError): - message_module.TestAllTypes.FromString(memview) - def testMergeFromEmpty(self, message_module): m1 = message_module.TestAllTypes() # Cpp extension will lazily create a sub message which is immutable. diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index d1f4dcde8e..99d2f078de 100644 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -1133,12 +1133,6 @@ def _AddSerializePartialToStringMethod(message_descriptor, cls): def _AddMergeFromStringMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" def MergeFromString(self, serialized): - if isinstance(serialized, memoryview) and six.PY2: - raise TypeError( - 'memoryview not supported in Python 2 with the pure Python proto ' - 'implementation: this is to maintain compatibility with the C++ ' - 'implementation') - serialized = memoryview(serialized) length = len(serialized) try: diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 75f1760ccf..ab482da32f 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -248,7 +248,7 @@ static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) { return NULL; } ScopedPyObjectPtr value( - PyEval_CallObject(message_class->AsPyObject(), NULL)); + PyObject_Call(message_class->AsPyObject(), NULL, NULL)); Py_DECREF(message_class); if (value == NULL) { return NULL; diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index e8e1a17b97..d3fc477d0f 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -1927,9 +1927,8 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg) { } static PyObject* MergeFromString(CMessage* self, PyObject* arg) { - const void* data; - Py_ssize_t data_length; - if (PyObject_AsReadBuffer(arg, &data, &data_length) < 0) { + Py_buffer data; + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) < 0) { return NULL; } @@ -1942,7 +1941,8 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { const char* ptr; internal::ParseContext ctx( depth, false, &ptr, - StringPiece(static_cast(data), data_length)); + StringPiece(static_cast(data.buf), data.len)); + PyBuffer_Release(&data); ctx.data().pool = factory->pool->pool; ctx.data().factory = factory->message_factory; @@ -1968,9 +1968,9 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { // TODO(jieluo): Raise error and return NULL instead. // b/27494216 PyErr_Warn(nullptr, "Unexpected end-group tag: Not all data was converted"); - return PyInt_FromLong(data_length - ctx.BytesUntilLimit(ptr)); + return PyInt_FromLong(data.len - ctx.BytesUntilLimit(ptr)); } - return PyInt_FromLong(data_length); + return PyInt_FromLong(data.len); } static PyObject* ParseFromString(CMessage* self, PyObject* arg) { diff --git a/python/tox.ini b/python/tox.ini index 9fabb6ddbb..f9eee920fd 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -14,10 +14,9 @@ setenv = commands = python setup.py -q build_py python: python setup.py -q build - # --warnings_as_errors disabled until we update the Python C extension. See: - # https://github.com/protocolbuffers/protobuf/issues/7930 - # cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension - cpp: python setup.py -q build --cpp_implementation --compile_static_extension + # --warnings_as_errors disabled for Python 2.7 because _POSIX_C_SOURCE and _XOPEN_SOURCE are redefined + py27-cpp: python setup.py -q build --cpp_implementation --compile_static_extension + py{33,34,35,36,37,38,39}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension python: python setup.py -q test -q cpp: python setup.py -q test -q --cpp_implementation python: python setup.py -q test_conformance From 8d1d530c511dcfa502fba0ef9a58e8971d2b62a4 Mon Sep 17 00:00:00 2001 From: Jiro Nishiguchi Date: Mon, 8 Mar 2021 15:40:03 +0900 Subject: [PATCH 48/80] Fix typo in docs/implementing_proto3_presence.md --- docs/implementing_proto3_presence.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/implementing_proto3_presence.md b/docs/implementing_proto3_presence.md index 73f21a3829..ae8b369579 100644 --- a/docs/implementing_proto3_presence.md +++ b/docs/implementing_proto3_presence.md @@ -261,7 +261,7 @@ bool FieldHasPresence(const google::protobuf::FieldDescriptor* field) { Old: ```c++ -bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { +bool FieldIsInOneof(const google::protobuf::FieldDescriptor* field) { return field->containing_oneof() != nullptr; } ``` @@ -269,7 +269,7 @@ bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { New: ```c++ -bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { +bool FieldIsInOneof(const google::protobuf::FieldDescriptor* field) { // real_containing_oneof() returns nullptr for synthetic oneofs. return field->real_containing_oneof() != nullptr; } From 6f4573afbd3f01958d5c2898d8b75c17f323ad11 Mon Sep 17 00:00:00 2001 From: Galen Warren Date: Sat, 6 Mar 2021 10:47:58 -0500 Subject: [PATCH 49/80] docs: register Coach Client Connect extension number (1107) --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index 907fe5aa02..d186a52234 100644 --- a/docs/options.md +++ b/docs/options.md @@ -268,3 +268,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-sanitize * Website: https://github.com/Intrinsec/protoc-gen-sanitize * Extension: 1102-1106 + +1. Coach Client Connect (planned release in March 2021) + * Website: https://www.coachclientconnect.com + * Extension: 1107 From 59ea5c8f19de47dc15cbce2e2e97d9de01d50fb9 Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Sun, 28 Feb 2021 12:18:52 +0100 Subject: [PATCH 50/80] [C++] Refactor util::Status This change refactors util::Status to have a similar shape as the recently open-sourced absl::Status. This will allow Protobuf to eventually use absl::Status and reduce the codesize. Note that there is more work required before absl::Status can be used. --- BUILD | 2 +- cmake/libprotobuf-lite.cmake | 2 +- src/Makefile.am | 2 +- .../protobuf/stubs/{ => internal}/status.cc | 60 ++++----- src/google/protobuf/stubs/internal/status.h | 119 ++++++++++++++++++ src/google/protobuf/stubs/logging.h | 4 +- src/google/protobuf/stubs/status.h | 93 ++------------ src/google/protobuf/stubs/status_test.cc | 10 +- src/google/protobuf/stubs/statusor.h | 13 +- .../protobuf/util/internal/datapiece.cc | 1 - .../util/internal/json_stream_parser_test.cc | 2 +- .../util/internal/protostream_objectsource.cc | 5 +- 12 files changed, 180 insertions(+), 133 deletions(-) rename src/google/protobuf/stubs/{ => internal}/status.cc (73%) create mode 100644 src/google/protobuf/stubs/internal/status.h diff --git a/BUILD b/BUILD index 1124321602..9b4b2fbd02 100644 --- a/BUILD +++ b/BUILD @@ -183,7 +183,7 @@ cc_library( "src/google/protobuf/stubs/bytestream.cc", "src/google/protobuf/stubs/common.cc", "src/google/protobuf/stubs/int128.cc", - "src/google/protobuf/stubs/status.cc", + "src/google/protobuf/stubs/internal/status.cc", "src/google/protobuf/stubs/statusor.cc", "src/google/protobuf/stubs/stringpiece.cc", "src/google/protobuf/stubs/stringprintf.cc", diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index 6d325d5dca..bbd3c11cb7 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -20,7 +20,7 @@ set(libprotobuf_lite_files ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream.cc ${protobuf_source_dir}/src/google/protobuf/stubs/common.cc ${protobuf_source_dir}/src/google/protobuf/stubs/int128.cc - ${protobuf_source_dir}/src/google/protobuf/stubs/status.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/internal/status.cc ${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc diff --git a/src/Makefile.am b/src/Makefile.am index a59971a94b..207e6c92b1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -185,7 +185,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/io/io_win32.cc \ google/protobuf/stubs/map_util.h \ google/protobuf/stubs/mathutil.h \ - google/protobuf/stubs/status.cc \ + google/protobuf/stubs/internal/status.cc \ google/protobuf/stubs/status.h \ google/protobuf/stubs/status_macros.h \ google/protobuf/stubs/statusor.cc \ diff --git a/src/google/protobuf/stubs/status.cc b/src/google/protobuf/stubs/internal/status.cc similarity index 73% rename from src/google/protobuf/stubs/status.cc rename to src/google/protobuf/stubs/internal/status.cc index 03b37c365b..731e1084e1 100644 --- a/src/google/protobuf/stubs/status.cc +++ b/src/google/protobuf/stubs/internal/status.cc @@ -37,42 +37,44 @@ namespace google { namespace protobuf { namespace util { -namespace error { -inline std::string CodeEnumToString(error::Code code) { +namespace status_internal { +namespace { + +inline std::string StatusCodeToString(StatusCode code) { switch (code) { - case OK: + case StatusCode::kOk: return "OK"; - case CANCELLED: + case StatusCode::kCancelled: return "CANCELLED"; - case UNKNOWN: + case StatusCode::kUnknown: return "UNKNOWN"; - case INVALID_ARGUMENT: + case StatusCode::kInvalidArgument: return "INVALID_ARGUMENT"; - case DEADLINE_EXCEEDED: + case StatusCode::kDeadlineExceeded: return "DEADLINE_EXCEEDED"; - case NOT_FOUND: + case StatusCode::kNotFound: return "NOT_FOUND"; - case ALREADY_EXISTS: + case StatusCode::kAlreadyExists: return "ALREADY_EXISTS"; - case PERMISSION_DENIED: + case StatusCode::kPermissionDenied: return "PERMISSION_DENIED"; - case UNAUTHENTICATED: + case StatusCode::kUnauthenticated: return "UNAUTHENTICATED"; - case RESOURCE_EXHAUSTED: + case StatusCode::kResourceExhausted: return "RESOURCE_EXHAUSTED"; - case FAILED_PRECONDITION: + case StatusCode::kFailedPrecondition: return "FAILED_PRECONDITION"; - case ABORTED: + case StatusCode::kAborted: return "ABORTED"; - case OUT_OF_RANGE: + case StatusCode::kOutOfRange: return "OUT_OF_RANGE"; - case UNIMPLEMENTED: + case StatusCode::kUnimplemented: return "UNIMPLEMENTED"; - case INTERNAL: + case StatusCode::kInternal: return "INTERNAL"; - case UNAVAILABLE: + case StatusCode::kUnavailable: return "UNAVAILABLE"; - case DATA_LOSS: + case StatusCode::kDataLoss: return "DATA_LOSS"; } @@ -80,18 +82,19 @@ inline std::string CodeEnumToString(error::Code code) { // above switch. return "UNKNOWN"; } -} // namespace error. + +} // namespace const Status Status::OK = Status(); -const Status Status::CANCELLED = Status(error::CANCELLED, ""); -const Status Status::UNKNOWN = Status(error::UNKNOWN, ""); +const Status Status::CANCELLED = Status(StatusCode::kCancelled, ""); +const Status Status::UNKNOWN = Status(StatusCode::kUnknown, ""); -Status::Status() : error_code_(error::OK) { +Status::Status() : error_code_(StatusCode::kOk) { } -Status::Status(error::Code error_code, StringPiece error_message) +Status::Status(StatusCode error_code, StringPiece error_message) : error_code_(error_code) { - if (error_code != error::OK) { + if (error_code != StatusCode::kOk) { error_message_ = error_message.ToString(); } } @@ -112,13 +115,13 @@ bool Status::operator==(const Status& x) const { } std::string Status::ToString() const { - if (error_code_ == error::OK) { + if (error_code_ == StatusCode::kOk) { return "OK"; } else { if (error_message_.empty()) { - return error::CodeEnumToString(error_code_); + return StatusCodeToString(error_code_); } else { - return error::CodeEnumToString(error_code_) + ":" + + return StatusCodeToString(error_code_) + ":" + error_message_; } } @@ -129,6 +132,7 @@ std::ostream& operator<<(std::ostream& os, const Status& x) { return os; } +} // namespace status_internal } // namespace util } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/internal/status.h b/src/google/protobuf/stubs/internal/status.h new file mode 100644 index 0000000000..79c1f80795 --- /dev/null +++ b/src/google/protobuf/stubs/internal/status.h @@ -0,0 +1,119 @@ +// 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_STUBS_INTERNAL_STATUS_H_ +#define GOOGLE_PROTOBUF_STUBS_INTERNAL_STATUS_H_ + +#include + +#include + +#include + +namespace google { +namespace protobuf { +namespace util { +namespace status_internal { + +// These values must match error codes defined in google/rpc/code.proto. +enum class StatusCode : int { + kOk = 0, + kCancelled = 1, + kUnknown = 2, + kInvalidArgument = 3, + kDeadlineExceeded = 4, + kNotFound = 5, + kAlreadyExists = 6, + kPermissionDenied = 7, + kUnauthenticated = 16, + kResourceExhausted = 8, + kFailedPrecondition = 9, + kAborted = 10, + kOutOfRange = 11, + kUnimplemented = 12, + kInternal = 13, + kUnavailable = 14, + kDataLoss = 15, +}; + +class PROTOBUF_EXPORT Status { + public: + // Creates a "successful" status. + Status(); + + // Create a status in the canonical error space with the specified + // code, and error message. If "code == 0", error_message is + // ignored and a Status object identical to Status::kOk is + // constructed. + Status(StatusCode error_code, StringPiece error_message); + Status(const Status&); + Status& operator=(const Status& x); + ~Status() {} + + // Some pre-defined Status objects + static const Status OK; // Identical to 0-arg constructor + static const Status CANCELLED; + static const Status UNKNOWN; + + // Accessor + bool ok() const { + return error_code_ == StatusCode::kOk; + } + StatusCode code() const { + return error_code_; + } + StringPiece message() const { + return error_message_; + } + + bool operator==(const Status& x) const; + bool operator!=(const Status& x) const { + return !operator==(x); + } + + // Return a combination of the error code name and message. + std::string ToString() const; + + private: + StatusCode error_code_; + std::string error_message_; +}; + +// Prints a human-readable representation of 'x' to 'os'. +PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); + +} // namespace status_internal +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_INTERNAL_STATUS_H_ diff --git a/src/google/protobuf/stubs/logging.h b/src/google/protobuf/stubs/logging.h index f37048d677..110ccdc950 100644 --- a/src/google/protobuf/stubs/logging.h +++ b/src/google/protobuf/stubs/logging.h @@ -33,6 +33,7 @@ #include #include +#include #include @@ -64,9 +65,6 @@ enum LogLevel { }; class StringPiece; -namespace util { -class Status; -} class uint128; namespace internal { diff --git a/src/google/protobuf/stubs/status.h b/src/google/protobuf/stubs/status.h index bededad541..67951abfd6 100644 --- a/src/google/protobuf/stubs/status.h +++ b/src/google/protobuf/stubs/status.h @@ -27,99 +27,32 @@ // 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_STUBS_STATUS_H_ #define GOOGLE_PROTOBUF_STUBS_STATUS_H_ -#include -#include - -#include -#include - -#include +#include namespace google { namespace protobuf { namespace util { -namespace error { -// These values must match error codes defined in google/rpc/code.proto. -enum Code { - OK = 0, - CANCELLED = 1, - UNKNOWN = 2, - INVALID_ARGUMENT = 3, - DEADLINE_EXCEEDED = 4, - NOT_FOUND = 5, - ALREADY_EXISTS = 6, - PERMISSION_DENIED = 7, - UNAUTHENTICATED = 16, - RESOURCE_EXHAUSTED = 8, - FAILED_PRECONDITION = 9, - ABORTED = 10, - OUT_OF_RANGE = 11, - UNIMPLEMENTED = 12, - INTERNAL = 13, - UNAVAILABLE = 14, - DATA_LOSS = 15, -}; -} // namespace error - -class PROTOBUF_EXPORT Status { - public: - // Creates a "successful" status. - Status(); - - // Create a status in the canonical error space with the specified - // code, and error message. If "code == 0", error_message is - // ignored and a Status object identical to Status::OK is - // constructed. - Status(error::Code error_code, StringPiece error_message); - Status(const Status&); - Status& operator=(const Status& x); - ~Status() {} - // Some pre-defined Status objects - static const Status OK; // Identical to 0-arg constructor - static const Status CANCELLED; - static const Status UNKNOWN; +using ::google::protobuf::util::status_internal::Status; +using ::google::protobuf::util::status_internal::StatusCode; - // Accessor - bool ok() const { - return error_code_ == error::OK; - } - int error_code() const { - return error_code_; - } - error::Code code() const { - return error_code_; - } - StringPiece error_message() const { - return error_message_; - } - StringPiece message() const { - return error_message_; - } - - bool operator==(const Status& x) const; - bool operator!=(const Status& x) const { - return !operator==(x); - } - - // Return a combination of the error code name and message. - std::string ToString() const; - - private: - error::Code error_code_; - std::string error_message_; -}; +namespace error { -// Prints a human-readable representation of 'x' to 'os'. -PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); +// TODO(yannic): Remove these. +constexpr StatusCode OK = StatusCode::kOk; +constexpr StatusCode CANCELLED = StatusCode::kCancelled; +constexpr StatusCode UNKNOWN = StatusCode::kUnknown; +constexpr StatusCode INVALID_ARGUMENT = StatusCode::kInvalidArgument; +constexpr StatusCode NOT_FOUND = StatusCode::kNotFound; +constexpr StatusCode INTERNAL = StatusCode::kInternal; +} // namespace error } // namespace util } // namespace protobuf } // namespace google -#include - #endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_ diff --git a/src/google/protobuf/stubs/status_test.cc b/src/google/protobuf/stubs/status_test.cc index 8f4398c9c9..ce486809db 100644 --- a/src/google/protobuf/stubs/status_test.cc +++ b/src/google/protobuf/stubs/status_test.cc @@ -39,17 +39,13 @@ namespace protobuf { namespace { TEST(Status, Empty) { util::Status status; - EXPECT_EQ(util::error::OK, util::Status::OK.error_code()); EXPECT_EQ(util::error::OK, util::Status::OK.code()); EXPECT_EQ("OK", util::Status::OK.ToString()); } TEST(Status, GenericCodes) { - EXPECT_EQ(util::error::OK, util::Status::OK.error_code()); EXPECT_EQ(util::error::OK, util::Status::OK.code()); - EXPECT_EQ(util::error::CANCELLED, util::Status::CANCELLED.error_code()); EXPECT_EQ(util::error::CANCELLED, util::Status::CANCELLED.code()); - EXPECT_EQ(util::error::UNKNOWN, util::Status::UNKNOWN.error_code()); EXPECT_EQ(util::error::UNKNOWN, util::Status::UNKNOWN.code()); } @@ -69,17 +65,17 @@ TEST(Status, CheckOK) { TEST(Status, ErrorMessage) { util::Status status(util::error::INVALID_ARGUMENT, ""); EXPECT_FALSE(status.ok()); - EXPECT_EQ("", status.error_message().ToString()); + EXPECT_EQ("", status.message().ToString()); EXPECT_EQ("", status.message().ToString()); EXPECT_EQ("INVALID_ARGUMENT", status.ToString()); status = util::Status(util::error::INVALID_ARGUMENT, "msg"); EXPECT_FALSE(status.ok()); - EXPECT_EQ("msg", status.error_message().ToString()); + EXPECT_EQ("msg", status.message().ToString()); EXPECT_EQ("msg", status.message().ToString()); EXPECT_EQ("INVALID_ARGUMENT:msg", status.ToString()); status = util::Status(util::error::OK, "msg"); EXPECT_TRUE(status.ok()); - EXPECT_EQ("", status.error_message().ToString()); + EXPECT_EQ("", status.message().ToString()); EXPECT_EQ("", status.message().ToString()); EXPECT_EQ("OK", status.ToString()); } diff --git a/src/google/protobuf/stubs/statusor.h b/src/google/protobuf/stubs/statusor.h index c02e89a9f0..c3748eacc1 100644 --- a/src/google/protobuf/stubs/statusor.h +++ b/src/google/protobuf/stubs/statusor.h @@ -32,7 +32,7 @@ // object. StatusOr models the concept of an object that is either a // usable value, or an error Status explaining why such a value is // not present. To this end, StatusOr does not allow its Status -// value to be Status::OK. Further, StatusOr does not allow the +// value to be Status::kOk. Further, StatusOr does not allow the // contained pointer to be nullptr. // // The primary use-case for StatusOr is as the return value of a @@ -110,8 +110,8 @@ class StatusOr { // value, so it is convenient and sensible to be able to do 'return // Status()' when the return type is StatusOr. // - // REQUIRES: status != Status::OK. This requirement is DCHECKed. - // In optimized builds, passing Status::OK here will have the effect + // REQUIRES: status != Status::kOk. This requirement is DCHECKed. + // In optimized builds, passing Status::kOk here will have the effect // of passing PosixErrorSpace::EINVAL as a fallback. StatusOr(const Status& status); // NOLINT @@ -143,7 +143,7 @@ class StatusOr { StatusOr& operator=(const StatusOr& other); // Returns a reference to our status. If this contains a T, then - // returns Status::OK. + // returns Status::kOk. const Status& status() const; // Returns this->status().ok() @@ -196,7 +196,8 @@ inline StatusOr::StatusOr() template inline StatusOr::StatusOr(const Status& status) { if (status.ok()) { - status_ = Status(error::INTERNAL, "Status::OK is not a valid argument."); + status_ = + Status(StatusCode::kInternal, "Status::kOk is not a valid argument."); } else { status_ = status; } @@ -205,7 +206,7 @@ inline StatusOr::StatusOr(const Status& status) { template inline StatusOr::StatusOr(const T& value) { if (internal::StatusOrHelper::Specialize::IsValueNull(value)) { - status_ = Status(error::INTERNAL, "nullptr is not a valid argument."); + status_ = Status(StatusCode::kInternal, "nullptr is not a valid argument."); } else { status_ = Status::OK; value_ = value; diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index d3a98e5589..feb4ab441f 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -48,7 +48,6 @@ namespace util { namespace converter { using util::Status; -using util::error::Code; namespace { diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index 21620c2b87..5e25a98d58 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -139,7 +139,7 @@ class JsonStreamParserTest : public ::testing::Test { }) { util::Status result = RunTest(json, split, setup); EXPECT_EQ(util::error::INVALID_ARGUMENT, result.code()); - StringPiece error_message(result.error_message()); + StringPiece error_message(result.message()); EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); } diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 472aa411ee..8ad51df28b 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -60,11 +60,8 @@ namespace google { namespace protobuf { namespace util { -namespace error { -using util::error::Code; -using util::error::INTERNAL; -} // namespace error namespace converter { + using ::PROTOBUF_NAMESPACE_ID::internal::WireFormat; using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; From de53e1afff299ea67eab77ba33bff304b6007ca7 Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Thu, 4 Mar 2021 19:25:16 +0100 Subject: [PATCH 51/80] Revert moving status.cc --- BUILD | 2 +- cmake/libprotobuf-lite.cmake | 2 +- src/Makefile.am | 2 +- src/google/protobuf/stubs/internal/status.h | 119 ------------------ .../protobuf/stubs/{internal => }/status.cc | 0 src/google/protobuf/stubs/status.h | 78 +++++++++++- 6 files changed, 80 insertions(+), 123 deletions(-) delete mode 100644 src/google/protobuf/stubs/internal/status.h rename src/google/protobuf/stubs/{internal => }/status.cc (100%) diff --git a/BUILD b/BUILD index 9b4b2fbd02..1124321602 100644 --- a/BUILD +++ b/BUILD @@ -183,7 +183,7 @@ cc_library( "src/google/protobuf/stubs/bytestream.cc", "src/google/protobuf/stubs/common.cc", "src/google/protobuf/stubs/int128.cc", - "src/google/protobuf/stubs/internal/status.cc", + "src/google/protobuf/stubs/status.cc", "src/google/protobuf/stubs/statusor.cc", "src/google/protobuf/stubs/stringpiece.cc", "src/google/protobuf/stubs/stringprintf.cc", diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index bbd3c11cb7..6d325d5dca 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -20,7 +20,7 @@ set(libprotobuf_lite_files ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream.cc ${protobuf_source_dir}/src/google/protobuf/stubs/common.cc ${protobuf_source_dir}/src/google/protobuf/stubs/int128.cc - ${protobuf_source_dir}/src/google/protobuf/stubs/internal/status.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/status.cc ${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc diff --git a/src/Makefile.am b/src/Makefile.am index 207e6c92b1..a59971a94b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -185,7 +185,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/io/io_win32.cc \ google/protobuf/stubs/map_util.h \ google/protobuf/stubs/mathutil.h \ - google/protobuf/stubs/internal/status.cc \ + google/protobuf/stubs/status.cc \ google/protobuf/stubs/status.h \ google/protobuf/stubs/status_macros.h \ google/protobuf/stubs/statusor.cc \ diff --git a/src/google/protobuf/stubs/internal/status.h b/src/google/protobuf/stubs/internal/status.h deleted file mode 100644 index 79c1f80795..0000000000 --- a/src/google/protobuf/stubs/internal/status.h +++ /dev/null @@ -1,119 +0,0 @@ -// 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_STUBS_INTERNAL_STATUS_H_ -#define GOOGLE_PROTOBUF_STUBS_INTERNAL_STATUS_H_ - -#include - -#include - -#include - -namespace google { -namespace protobuf { -namespace util { -namespace status_internal { - -// These values must match error codes defined in google/rpc/code.proto. -enum class StatusCode : int { - kOk = 0, - kCancelled = 1, - kUnknown = 2, - kInvalidArgument = 3, - kDeadlineExceeded = 4, - kNotFound = 5, - kAlreadyExists = 6, - kPermissionDenied = 7, - kUnauthenticated = 16, - kResourceExhausted = 8, - kFailedPrecondition = 9, - kAborted = 10, - kOutOfRange = 11, - kUnimplemented = 12, - kInternal = 13, - kUnavailable = 14, - kDataLoss = 15, -}; - -class PROTOBUF_EXPORT Status { - public: - // Creates a "successful" status. - Status(); - - // Create a status in the canonical error space with the specified - // code, and error message. If "code == 0", error_message is - // ignored and a Status object identical to Status::kOk is - // constructed. - Status(StatusCode error_code, StringPiece error_message); - Status(const Status&); - Status& operator=(const Status& x); - ~Status() {} - - // Some pre-defined Status objects - static const Status OK; // Identical to 0-arg constructor - static const Status CANCELLED; - static const Status UNKNOWN; - - // Accessor - bool ok() const { - return error_code_ == StatusCode::kOk; - } - StatusCode code() const { - return error_code_; - } - StringPiece message() const { - return error_message_; - } - - bool operator==(const Status& x) const; - bool operator!=(const Status& x) const { - return !operator==(x); - } - - // Return a combination of the error code name and message. - std::string ToString() const; - - private: - StatusCode error_code_; - std::string error_message_; -}; - -// Prints a human-readable representation of 'x' to 'os'. -PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); - -} // namespace status_internal -} // namespace util -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_STUBS_INTERNAL_STATUS_H_ diff --git a/src/google/protobuf/stubs/internal/status.cc b/src/google/protobuf/stubs/status.cc similarity index 100% rename from src/google/protobuf/stubs/internal/status.cc rename to src/google/protobuf/stubs/status.cc diff --git a/src/google/protobuf/stubs/status.h b/src/google/protobuf/stubs/status.h index 67951abfd6..0eb0b53f93 100644 --- a/src/google/protobuf/stubs/status.h +++ b/src/google/protobuf/stubs/status.h @@ -31,11 +31,85 @@ #ifndef GOOGLE_PROTOBUF_STUBS_STATUS_H_ #define GOOGLE_PROTOBUF_STUBS_STATUS_H_ -#include +#include + +#include + +#include namespace google { namespace protobuf { namespace util { +namespace status_internal { + +// These values must match error codes defined in google/rpc/code.proto. +enum class StatusCode : int { + kOk = 0, + kCancelled = 1, + kUnknown = 2, + kInvalidArgument = 3, + kDeadlineExceeded = 4, + kNotFound = 5, + kAlreadyExists = 6, + kPermissionDenied = 7, + kUnauthenticated = 16, + kResourceExhausted = 8, + kFailedPrecondition = 9, + kAborted = 10, + kOutOfRange = 11, + kUnimplemented = 12, + kInternal = 13, + kUnavailable = 14, + kDataLoss = 15, +}; + +class PROTOBUF_EXPORT Status { + public: + // Creates a "successful" status. + Status(); + + // Create a status in the canonical error space with the specified + // code, and error message. If "code == 0", error_message is + // ignored and a Status object identical to Status::kOk is + // constructed. + Status(StatusCode error_code, StringPiece error_message); + Status(const Status&); + Status& operator=(const Status& x); + ~Status() {} + + // Some pre-defined Status objects + static const Status OK; // Identical to 0-arg constructor + static const Status CANCELLED; + static const Status UNKNOWN; + + // Accessor + bool ok() const { + return error_code_ == StatusCode::kOk; + } + StatusCode code() const { + return error_code_; + } + StringPiece message() const { + return error_message_; + } + + bool operator==(const Status& x) const; + bool operator!=(const Status& x) const { + return !operator==(x); + } + + // Return a combination of the error code name and message. + std::string ToString() const; + + private: + StatusCode error_code_; + std::string error_message_; +}; + +// Prints a human-readable representation of 'x' to 'os'. +PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); + +} // namespace status_internal using ::google::protobuf::util::status_internal::Status; using ::google::protobuf::util::status_internal::StatusCode; @@ -55,4 +129,6 @@ constexpr StatusCode INTERNAL = StatusCode::kInternal; } // namespace protobuf } // namespace google +#include + #endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_ From baef01b7566075cf91e437b6322fbf582ec713dc Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Tue, 9 Mar 2021 22:18:43 +0100 Subject: [PATCH 52/80] Fix build error --- src/google/protobuf/util/internal/json_stream_parser_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index 5e25a98d58..9d38a4f618 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -150,7 +150,7 @@ class JsonStreamParserTest : public ::testing::Test { }) { util::Status result = RunTest(json, split, setup); EXPECT_EQ(util::error::INVALID_ARGUMENT, result.code()); - StringPiece error_message(result.error_message()); + StringPiece error_message(result.message()); EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); } From dedbd63306e4c464b5a58ee9452b388347bd2e06 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Sun, 25 Feb 2018 17:22:40 -0500 Subject: [PATCH 53/80] Add --fatal_warnings flag to treat warnings as errors Add a --fatal_warnings flag that requests that protoc exit with a failing status code if any warnings are generated during compilation. Partially address #3980. --- .../compiler/command_line_interface.cc | 18 +++++++++-- .../compiler/command_line_interface.h | 3 ++ .../command_line_interface_unittest.cc | 31 +++++++++++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 28b0bfa933..7b66f01103 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -288,7 +288,7 @@ class CommandLineInterface::ErrorPrinter public DescriptorPool::ErrorCollector { public: ErrorPrinter(ErrorFormat format, DiskSourceTree* tree = NULL) - : format_(format), tree_(tree), found_errors_(false) {} + : format_(format), tree_(tree), found_errors_(false), found_warnings_(false) {} ~ErrorPrinter() {} // implements MultiFileErrorCollector ------------------------------ @@ -300,6 +300,7 @@ class CommandLineInterface::ErrorPrinter void AddWarning(const std::string& filename, int line, int column, const std::string& message) { + found_warnings_ = true; AddErrorOrWarning(filename, line, column, message, "warning", std::clog); } @@ -327,6 +328,8 @@ class CommandLineInterface::ErrorPrinter bool FoundErrors() const { return found_errors_; } + bool FoundWarnings() const { return found_warnings_; } + private: void AddErrorOrWarning(const std::string& filename, int line, int column, const std::string& message, const std::string& type, @@ -365,6 +368,7 @@ class CommandLineInterface::ErrorPrinter const ErrorFormat format_; DiskSourceTree* tree_; bool found_errors_; + bool found_warnings_; }; // ------------------------------------------------------------------- @@ -1117,7 +1121,8 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { } } - if (error_collector->FoundErrors()) { + if (error_collector->FoundErrors() || + (fatal_warnings_ && error_collector->FoundWarnings())) { return 1; } @@ -1630,7 +1635,8 @@ bool CommandLineInterface::ParseArgument(const char* arg, std::string* name, *name == "--version" || *name == "--decode_raw" || *name == "--print_free_field_numbers" || *name == "--experimental_allow_proto3_optional" || - *name == "--deterministic_output") { + *name == "--deterministic_output" || + *name == "--fatal_warnings") { // HACK: These are the only flags that don't take a value. // They probably should not be hard-coded like this but for now it's // not worth doing better. @@ -1883,6 +1889,12 @@ CommandLineInterface::InterpretArgument(const std::string& name, return PARSE_ARGUMENT_FAIL; } + } else if (name == "--fatal_warnings") { + if (fatal_warnings_) { + std::cerr << name << " may only be passed once." << std::endl; + return PARSE_ARGUMENT_FAIL; + } + fatal_warnings_ = true; } else if (name == "--plugin") { if (plugin_prefix_.empty()) { std::cerr << "This compiler does not support plugins." << std::endl; diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 4ff2471c76..e2361fffab 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -392,6 +392,9 @@ class PROTOC_EXPORT CommandLineInterface { ErrorFormat error_format_ = ERROR_FORMAT_GCC; + // True if we should treat warnings as errors that fail the compilation. + bool fatal_warnings_; + std::vector > proto_path_; // Search path for proto files. std::vector input_files_; // Names of the input proto files. diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 74dc9bffdb..a0e79874ad 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -132,6 +132,9 @@ class CommandLineInterfaceTest : public testing::Test { // ----------------------------------------------------------------- // Methods to check the test results (called after Run()). + // Checks that Run() returned code r. + void ExpectReturnCode(int r); + // Checks that no text was written to stderr during Run(), and Run() // returned 0. void ExpectNoErrors(); @@ -406,6 +409,10 @@ void CommandLineInterfaceTest::CreateTempDir(const std::string& name) { // ------------------------------------------------------------------- +void CommandLineInterfaceTest::ExpectReturnCode(int r) { + EXPECT_EQ(r, return_code_); +} + void CommandLineInterfaceTest::ExpectNoErrors() { EXPECT_EQ(0, return_code_); EXPECT_EQ("", error_text_); @@ -2309,12 +2316,32 @@ TEST_F(CommandLineInterfaceTest, InvalidErrorFormat) { "syntax = \"proto2\";\n" "badsyntax\n"); - Run("protocol_compiler --test_out=$tmpdir " - "--proto_path=$tmpdir --error_format=invalid foo.proto"); + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir foo.proto"); ExpectErrorText("Unknown error format: invalid\n"); } +TEST_F(CommandLineInterfaceTest, Warnings) { + // Test --fatal_warnings. + + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "import \"bar.proto\";\n"); + CreateTempFile("bar.proto", + "syntax = \"proto2\";\n"); + + Run("protocol_compiler --test_out=$tmpdir " + "--proto_path=$tmpdir foo.proto"); + ExpectReturnCode(0); + ExpectErrorSubstringWithZeroReturnCode( + "foo.proto: warning: Import bar.proto but not used."); + + Run("protocol_compiler --test_out=$tmpdir --fatal_warnings " + "--proto_path=$tmpdir foo.proto"); + ExpectErrorSubstring( + "foo.proto: warning: Import bar.proto but not used."); +} + // ------------------------------------------------------------------- // Flag parsing tests From c7a6160a87eea71ac002aefad54c116a108ba010 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 9 Dec 2020 22:58:37 +0200 Subject: [PATCH 54/80] Fixes to make the --fatal_warnings flag work with current master --- .../compiler/command_line_interface.cc | 4 +++ .../compiler/command_line_interface.h | 2 +- .../command_line_interface_unittest.cc | 33 +++++++++++-------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 7b66f01103..b0b2963d2d 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -2054,6 +2054,10 @@ Parse PROTO_FILES and generate output based on the options given: --error_format=FORMAT Set the format in which to print errors. FORMAT may be 'gcc' (the default) or 'msvs' (Microsoft Visual Studio format). + --fatal_warnings Make warnings be fatal (similar to -Werr in + gcc). This flag will make protoc return + with a non-zero exit code if any warnings + are generated. --print_free_field_numbers Print the free field numbers of the messages defined in the given proto files. Groups share the same field number space with the parent diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index e2361fffab..5fdc04b4ed 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -393,7 +393,7 @@ class PROTOC_EXPORT CommandLineInterface { ErrorFormat error_format_ = ERROR_FORMAT_GCC; // True if we should treat warnings as errors that fail the compilation. - bool fatal_warnings_; + bool fatal_warnings_ = false; std::vector > proto_path_; // Search path for proto files. diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index a0e79874ad..2ca86086af 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -132,9 +132,6 @@ class CommandLineInterfaceTest : public testing::Test { // ----------------------------------------------------------------- // Methods to check the test results (called after Run()). - // Checks that Run() returned code r. - void ExpectReturnCode(int r); - // Checks that no text was written to stderr during Run(), and Run() // returned 0. void ExpectNoErrors(); @@ -160,6 +157,11 @@ class CommandLineInterfaceTest : public testing::Test { void ExpectCapturedStdoutSubstringWithZeroReturnCode( const std::string& expected_substring); + // Checks that Run() returned zero and the stderr contains the given + // substring. + void ExpectCapturedStderrSubstringWithZeroReturnCode( + const std::string& expected_substring); + #if defined(_WIN32) && !defined(__CYGWIN__) // Returns true if ExpectErrorSubstring(expected_substring) would pass, but // does not fail otherwise. @@ -409,10 +411,6 @@ void CommandLineInterfaceTest::CreateTempDir(const std::string& name) { // ------------------------------------------------------------------- -void CommandLineInterfaceTest::ExpectReturnCode(int r) { - EXPECT_EQ(r, return_code_); -} - void CommandLineInterfaceTest::ExpectNoErrors() { EXPECT_EQ(0, return_code_); EXPECT_EQ("", error_text_); @@ -433,8 +431,8 @@ void CommandLineInterfaceTest::ExpectErrorSubstring( void CommandLineInterfaceTest::ExpectWarningSubstring( const std::string& expected_substring) { - EXPECT_EQ(0, return_code_); EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, error_text_); + EXPECT_EQ(0, return_code_); } #if defined(_WIN32) && !defined(__CYGWIN__) @@ -522,6 +520,13 @@ void CommandLineInterfaceTest::ExpectCapturedStdoutSubstringWithZeroReturnCode( captured_stdout_); } +void CommandLineInterfaceTest::ExpectCapturedStderrSubstringWithZeroReturnCode( + const std::string& expected_substring) { + EXPECT_EQ(0, return_code_); + EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, + error_text_); +} + void CommandLineInterfaceTest::ExpectFileContent(const std::string& filename, const std::string& content) { std::string path = temp_directory_ + "/" + filename; @@ -2310,13 +2315,14 @@ TEST_F(CommandLineInterfaceTest, MsvsFormatErrors) { } TEST_F(CommandLineInterfaceTest, InvalidErrorFormat) { - // Test --error_format=msvs + // Test invalid --error_format CreateTempFile("foo.proto", "syntax = \"proto2\";\n" "badsyntax\n"); - Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir foo.proto"); + Run("protocol_compiler --test_out=$tmpdir " + "--proto_path=$tmpdir --error_format=invalid foo.proto"); ExpectErrorText("Unknown error format: invalid\n"); } @@ -2332,14 +2338,13 @@ TEST_F(CommandLineInterfaceTest, Warnings) { Run("protocol_compiler --test_out=$tmpdir " "--proto_path=$tmpdir foo.proto"); - ExpectReturnCode(0); - ExpectErrorSubstringWithZeroReturnCode( - "foo.proto: warning: Import bar.proto but not used."); + ExpectCapturedStderrSubstringWithZeroReturnCode( + "foo.proto:2:1: warning: Import bar.proto is unused."); Run("protocol_compiler --test_out=$tmpdir --fatal_warnings " "--proto_path=$tmpdir foo.proto"); ExpectErrorSubstring( - "foo.proto: warning: Import bar.proto but not used."); + "foo.proto:2:1: warning: Import bar.proto is unused."); } // ------------------------------------------------------------------- From c6bce8c10f31ddc30e089ac5fb483dffbfa9bd7f Mon Sep 17 00:00:00 2001 From: Cody Casterline Date: Tue, 9 Mar 2021 14:07:09 -0800 Subject: [PATCH 55/80] Remove link to unmaintained TypeScript library y3llowcake/protoc-gen-ts is no longer maintained: https://github.com/y3llowcake/protoc-gen-ts/issues/2#issuecomment-758215154 FWIW, neither is this one w/ a similar name: thesayyn/protoc-gen-ts: https://github.com/thesayyn/protoc-gen-ts/issues/31#issuecomment-781681955 --- docs/third_party.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/third_party.md b/docs/third_party.md index 7799e308a7..6b0e2710f0 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -101,7 +101,6 @@ These are projects we know about implementing Protocol Buffers for other program * Solidity: https://github.com/celer-network/pb3-gen-sol * Swift: https://github.com/alexeyxo/protobuf-swift * Swift: https://github.com/apple/swift-protobuf/ -* Typescript: https://github.com/y3llowcake/protoc-gen-ts * Vala: https://launchpad.net/protobuf-vala * Visual Basic: http://code.google.com/p/protobuf-net/ From aa5cb98712222e05594dc40a8009de024991c01d Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Wed, 10 Mar 2021 10:05:31 +0100 Subject: [PATCH 56/80] Fix conformance_cpp --- conformance/conformance_cpp.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc index d27612b151..5782789dfd 100644 --- a/conformance/conformance_cpp.cc +++ b/conformance/conformance_cpp.cc @@ -134,7 +134,7 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { &proto_binary, options); if (!status.ok()) { response->set_parse_error(string("Parse error: ") + - std::string(status.error_message())); + std::string(status.message())); return; } @@ -189,7 +189,7 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { if (!status.ok()) { response->set_serialize_error( string("Failed to serialize JSON output: ") + - std::string(status.error_message())); + std::string(status.message())); return; } break; From a3aecacc24f0ce0b05106fb7f7ae3ce9a5e5cd91 Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Wed, 10 Mar 2021 10:20:39 +0100 Subject: [PATCH 57/80] [bazel] Remove deprecated way to depend on googletest --- BUILD | 44 +++++++++----------------------------------- WORKSPACE | 12 ------------ 2 files changed, 9 insertions(+), 47 deletions(-) diff --git a/BUILD b/BUILD index 1124321602..07ee629a18 100644 --- a/BUILD +++ b/BUILD @@ -14,38 +14,6 @@ exports_files(["LICENSE"]) # build configuration ################################################################################ -# TODO(yannic): Remove in 3.14.0. -string_flag( - name = "incompatible_use_com_google_googletest", - build_setting_default = "true", - values = ["true", "false"] -) - -config_setting( - name = "use_com_google_googletest", - flag_values = { - "//:incompatible_use_com_google_googletest": "true" - }, -) - -GTEST = select({ - "//:use_com_google_googletest": [ - "@com_google_googletest//:gtest", - ], - "//conditions:default": [ - "//external:gtest", - ], -}) - -GTEST_MAIN = select({ - "//:use_com_google_googletest": [ - "@com_google_googletest//:gtest_main", - ], - "//conditions:default": [ - "//external:gtest_main", - ], -}) - ################################################################################ # ZLIB configuration ################################################################################ @@ -571,6 +539,7 @@ COMMON_TEST_SRCS = [ cc_binary( name = "test_plugin", + testonly = True, srcs = [ # AUTOGEN(test_plugin_srcs) "src/google/protobuf/compiler/mock_code_generator.cc", @@ -580,7 +549,8 @@ cc_binary( deps = [ ":protobuf", ":protoc_lib", - ] + GTEST, + "@com_google_googletest//:gtest", + ], ) cc_test( @@ -592,7 +562,9 @@ cc_test( ], deps = [ ":protobuf_lite", - ] + GTEST_MAIN, + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], ) cc_test( @@ -695,7 +667,9 @@ cc_test( ":cc_test_protos", ":protobuf", ":protoc_lib", - ] + PROTOBUF_DEPS + GTEST_MAIN, + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ] + PROTOBUF_DEPS, ) ################################################################################ diff --git a/WORKSPACE b/WORKSPACE index 5a767a97c0..d9ed7c883f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -29,18 +29,6 @@ bind( actual = "//util/python:python_headers", ) -# TODO(yannic): Remove in 3.14.0. -bind( - name = "gtest", - actual = "@com_google_googletest//:gtest", -) - -# TODO(yannic): Remove in 3.14.0. -bind( - name = "gtest_main", - actual = "@com_google_googletest//:gtest_main", -) - jvm_maven_import_external( name = "guava_maven", artifact = "com.google.guava:guava:18.0", From a4694f9b66698a3cd197cbab7932bffeb0ea2ab1 Mon Sep 17 00:00:00 2001 From: salamani Date: Fri, 5 Mar 2021 00:20:07 -0500 Subject: [PATCH 58/80] correcting arch name for s390x --- kokoro/release/protoc/linux/build.sh | 2 +- protoc-artifacts/README.md | 2 +- protoc-artifacts/build-protoc.sh | 6 +++--- protoc-artifacts/build-zip.sh | 4 ++-- protoc-artifacts/pom.xml | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kokoro/release/protoc/linux/build.sh b/kokoro/release/protoc/linux/build.sh index efc3ee62ca..44a95aab35 100755 --- a/kokoro/release/protoc/linux/build.sh +++ b/kokoro/release/protoc/linux/build.sh @@ -23,7 +23,7 @@ sudo apt install -y g++-powerpc64le-linux-gnu protoc-artifacts/build-protoc.sh linux ppcle_64 protoc sudo apt install -y g++-s390x-linux-gnu -protoc-artifacts/build-protoc.sh linux s390x protoc +protoc-artifacts/build-protoc.sh linux s390_64 protoc # Use docker image to build linux artifacts. DOCKER_IMAGE_NAME=protobuf/protoc_$(sha1sum protoc-artifacts/Dockerfile | cut -f1 -d " ") diff --git a/protoc-artifacts/README.md b/protoc-artifacts/README.md index 2c45fefe78..1706ddc0d8 100644 --- a/protoc-artifacts/README.md +++ b/protoc-artifacts/README.md @@ -123,7 +123,7 @@ target directory layout: protoc.exe + ppcle_64 protoc.exe - + s390x + + s390_64 protoc.exe + osx + x86_64 diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh index 7f65d37643..4602842622 100755 --- a/protoc-artifacts/build-protoc.sh +++ b/protoc-artifacts/build-protoc.sh @@ -93,7 +93,7 @@ checkArch () assertEq $format "elf64-x86-64" $LINENO elif [[ "$ARCH" == aarch_64 ]]; then assertEq $format "elf64-little" $LINENO - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine == s390x ]];then assertEq $format "elf64-s390" $LINENO else @@ -149,7 +149,7 @@ checkDependencies () white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2" elif [[ "$ARCH" == x86_64 ]]; then white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2" - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine != s390x ]];then dump_cmd='objdump -p '"$1"' | grep NEEDED' fi @@ -226,7 +226,7 @@ elif [[ "$(uname)" == Linux* ]]; then elif [[ "$ARCH" == ppcle_64 ]]; then CXXFLAGS="$CXXFLAGS -m64" CONFIGURE_ARGS="$CONFIGURE_ARGS --host=powerpc64le-linux-gnu" - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then CXXFLAGS="$CXXFLAGS -m64" CONFIGURE_ARGS="$CONFIGURE_ARGS --host=s390x-linux-gnu" else diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index 2a25d3cd7e..7d1923e6e6 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -21,7 +21,7 @@ included. Each invocation will create 8 zip packages: dist/--linux-x86_64.zip dist/--linux-aarch_64.zip dist/--linux-ppcle_64.zip - dist/--linux-s390x.zip + dist/--linux-s390_64.zip EOF exit 1 fi @@ -38,7 +38,7 @@ declare -a FILE_NAMES=( \ linux-x86_64.zip linux-x86_64.exe \ linux-aarch_64.zip linux-aarch_64.exe \ linux-ppcle_64.zip linux-ppcle_64.exe \ - linux-s390x.zip linux-s390x.exe \ + linux-s390_64.zip linux-s390_64.exe \ ) # List of all well-known types to be included. diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index ba9eaf8ac5..e46c902ad5 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -81,8 +81,8 @@ exe - ${basedir}/target/linux/s390x/protoc.exe - linux-s390x + ${basedir}/target/linux/s390_64/protoc.exe + linux-s390_64 exe From 43aca5761385db72e1e8d04997195a262314378a Mon Sep 17 00:00:00 2001 From: chenzhihui Date: Wed, 10 Mar 2021 22:17:30 +0800 Subject: [PATCH 59/80] Allocate extension 1108 to Kratos API Errors --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index d186a52234..79a085e0be 100644 --- a/docs/options.md +++ b/docs/options.md @@ -272,3 +272,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Coach Client Connect (planned release in March 2021) * Website: https://www.coachclientconnect.com * Extension: 1107 + +1. Kratos API Errors + * Website: https://go-kratos.dev + * Extension: 1108 From addd0615bfbc956ca0b9b7328955d0198218e2e7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 10 Mar 2021 13:54:04 -0800 Subject: [PATCH 60/80] Register mark objects so Protobuf is compaction friendly This commit removes an unused reference and registers globals with the GC so that they will never die. Ruby is getting a compacting GC, and it means that these references can move. Registering them with `rb_gc_register_mark_object` will ensure the constants don't move and will not be collected. --- ruby/ext/google/protobuf_c/protobuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index c27f30aa2d..c9eecee11e 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -37,7 +37,7 @@ #include "message.h" #include "repeated_field.h" -VALUE cError; +VALUE cParseError; VALUE cTypeError; const upb_fielddef* map_field_key(const upb_fielddef* field) { @@ -368,8 +368,10 @@ void Init_protobuf_c() { Map_register(protobuf); Message_register(protobuf); - cError = rb_const_get(protobuf, rb_intern("Error")); + cParseError = rb_const_get(protobuf, rb_intern("ParseError")); + rb_gc_register_mark_object(cParseError); cTypeError = rb_const_get(protobuf, rb_intern("TypeError")); + rb_gc_register_mark_object(cTypeError); rb_define_singleton_method(protobuf, "discard_unknown", Google_Protobuf_discard_unknown, 1); From c5abd97e365d6a99216dbd0ca7c120ad85a6053e Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Tue, 21 Jul 2020 19:38:33 +0200 Subject: [PATCH 61/80] [bazel] Add BUILD files for benchmark protos This change adds BUILD files to //benchmarks that allow users to consume the .proto files in that directory to run benchmarks (e.g. for custom generators). --- benchmarks/BUILD | 53 +++++++++++++++++++ benchmarks/datasets/BUILD | 51 ++++++++++++++++++ .../datasets/google_message1/proto2/BUILD | 44 +++++++++++++++ .../datasets/google_message1/proto3/BUILD | 44 +++++++++++++++ benchmarks/datasets/google_message2/BUILD | 44 +++++++++++++++ benchmarks/datasets/google_message3/BUILD | 50 +++++++++++++++++ benchmarks/datasets/google_message4/BUILD | 45 ++++++++++++++++ 7 files changed, 331 insertions(+) create mode 100644 benchmarks/BUILD create mode 100644 benchmarks/datasets/BUILD create mode 100644 benchmarks/datasets/google_message1/proto2/BUILD create mode 100644 benchmarks/datasets/google_message1/proto3/BUILD create mode 100644 benchmarks/datasets/google_message2/BUILD create mode 100644 benchmarks/datasets/google_message3/BUILD create mode 100644 benchmarks/datasets/google_message4/BUILD diff --git a/benchmarks/BUILD b/benchmarks/BUILD new file mode 100644 index 0000000000..0ac35c3b78 --- /dev/null +++ b/benchmarks/BUILD @@ -0,0 +1,53 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "benchmarks_proto", + srcs = [ + "benchmarks.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = ["//visibility:public"], +) + +cc_proto_library( + name = "benchmarks_cc_proto", + visibility = ["//visibility:public"], + deps = [ + "benchmarks_proto", + ], +) + +java_proto_library( + name = "benchmarks_java_proto", + visibility = ["//visibility:public"], + deps = [ + "benchmarks_proto", + ], +) + +proto_library( + name = "google_size_proto", + srcs = [ + "google_size.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = ["//visibility:public"], +) + +cc_proto_library( + name = "google_size_cc_proto", + visibility = ["//visibility:public"], + deps = [ + "google_size_proto", + ], +) + +java_proto_library( + name = "google_size_java_proto", + visibility = ["//visibility:public"], + deps = [ + "google_size_proto", + ], +) diff --git a/benchmarks/datasets/BUILD b/benchmarks/datasets/BUILD new file mode 100644 index 0000000000..c34e303b62 --- /dev/null +++ b/benchmarks/datasets/BUILD @@ -0,0 +1,51 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_java//java:defs.bzl", "java_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "//benchmarks/datasets/google_message1/proto2:datasets", + "//benchmarks/datasets/google_message1/proto3:datasets", + "//benchmarks/datasets/google_message2:datasets", + "//benchmarks/datasets/google_message3:datasets", + "//benchmarks/datasets/google_message4:datasets", + ], + visibility = ["//visibility:public"], +) + +proto_library( + name = "protos", + visibility = ["//visibility:public"], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_proto", + ], +) + +cc_library( + name = "cc_protos", + visibility = ["//visibility:public"], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_cc_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_cc_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_cc_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_cc_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_cc_proto", + ], +) + +java_library( + name = "java_protos", + visibility = ["//visibility:public"], + exports = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_java_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_java_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_java_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_java_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_java_proto", + ], +) diff --git a/benchmarks/datasets/google_message1/proto2/BUILD b/benchmarks/datasets/google_message1/proto2/BUILD new file mode 100644 index 0000000000..d4d38cec22 --- /dev/null +++ b/benchmarks/datasets/google_message1/proto2/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto2_proto", + srcs = [ + "benchmark_message1_proto2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) diff --git a/benchmarks/datasets/google_message1/proto3/BUILD b/benchmarks/datasets/google_message1/proto3/BUILD new file mode 100644 index 0000000000..c2d627acd8 --- /dev/null +++ b/benchmarks/datasets/google_message1/proto3/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto3.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto3_proto", + srcs = [ + "benchmark_message1_proto3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) diff --git a/benchmarks/datasets/google_message2/BUILD b/benchmarks/datasets/google_message2/BUILD new file mode 100644 index 0000000000..1ca87fb64f --- /dev/null +++ b/benchmarks/datasets/google_message2/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message2_proto", + srcs = [ + "benchmark_message2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) + +java_proto_library( + name = "benchmark_message2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) diff --git a/benchmarks/datasets/google_message3/BUILD b/benchmarks/datasets/google_message3/BUILD new file mode 100644 index 0000000000..9a00294464 --- /dev/null +++ b/benchmarks/datasets/google_message3/BUILD @@ -0,0 +1,50 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message3_proto", + srcs = [ + "benchmark_message3.proto", + "benchmark_message3_1.proto", + "benchmark_message3_2.proto", + "benchmark_message3_3.proto", + "benchmark_message3_4.proto", + "benchmark_message3_5.proto", + "benchmark_message3_6.proto", + "benchmark_message3_7.proto", + "benchmark_message3_8.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) + +java_proto_library( + name = "benchmark_message3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) diff --git a/benchmarks/datasets/google_message4/BUILD b/benchmarks/datasets/google_message4/BUILD new file mode 100644 index 0000000000..b23a4c955c --- /dev/null +++ b/benchmarks/datasets/google_message4/BUILD @@ -0,0 +1,45 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message4_proto", + srcs = [ + "benchmark_message4.proto", + "benchmark_message4_1.proto", + "benchmark_message4_2.proto", + "benchmark_message4_3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message4_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) + +java_proto_library( + name = "benchmark_message4_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) From ef70abad8acfc70983585c0d0bb4049bf38dc62e Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Sun, 14 Mar 2021 10:58:03 +0100 Subject: [PATCH 62/80] Restrict visibility and add target for C++ benchmark --- WORKSPACE | 9 +++++++++ benchmarks/BUILD | 24 ++++++++++++++++++------ benchmarks/cpp/BUILD | 15 +++++++++++++++ benchmarks/datasets/BUILD | 16 ++++++++++++---- 4 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 benchmarks/cpp/BUILD diff --git a/WORKSPACE b/WORKSPACE index d9ed7c883f..4346dbd906 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,6 +17,15 @@ http_archive( ], ) +http_archive( + name = "com_github_google_benchmark", + sha256 = "2a778d821997df7d8646c9c59b8edb9a573a6e04c534c01892a40aa524a7b68c", + strip_prefix = "benchmark-bf585a2789e30585b4e3ce6baf11ef2750b54677", + urls = [ + "https://github.com/google/benchmark/archive/bf585a2789e30585b4e3ce6baf11ef2750b54677.zip", + ], +) + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("//:protobuf_deps.bzl", "protobuf_deps") diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 0ac35c3b78..8e6063ba83 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -8,12 +8,16 @@ proto_library( "benchmarks.proto", ], strip_import_prefix = "/benchmarks", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], ) cc_proto_library( name = "benchmarks_cc_proto", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], deps = [ "benchmarks_proto", ], @@ -21,7 +25,9 @@ cc_proto_library( java_proto_library( name = "benchmarks_java_proto", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], deps = [ "benchmarks_proto", ], @@ -33,12 +39,16 @@ proto_library( "google_size.proto", ], strip_import_prefix = "/benchmarks", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], ) cc_proto_library( name = "google_size_cc_proto", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], deps = [ "google_size_proto", ], @@ -46,7 +56,9 @@ cc_proto_library( java_proto_library( name = "google_size_java_proto", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], deps = [ "google_size_proto", ], diff --git a/benchmarks/cpp/BUILD b/benchmarks/cpp/BUILD new file mode 100644 index 0000000000..b744f896ad --- /dev/null +++ b/benchmarks/cpp/BUILD @@ -0,0 +1,15 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") + +cc_binary( + name = "cpp", + srcs = [ + "cpp_benchmark.cc", + ], + tags = ["benchmark"], + deps = [ + "//:protobuf", + "//benchmarks:benchmarks_cc_proto", + "//benchmarks/datasets:cc_protos", + "@com_github_google_benchmark//:benchmark_main", + ], +) diff --git a/benchmarks/datasets/BUILD b/benchmarks/datasets/BUILD index c34e303b62..f29a27650b 100644 --- a/benchmarks/datasets/BUILD +++ b/benchmarks/datasets/BUILD @@ -11,12 +11,16 @@ filegroup( "//benchmarks/datasets/google_message3:datasets", "//benchmarks/datasets/google_message4:datasets", ], - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], ) proto_library( name = "protos", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], deps = [ "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_proto", "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_proto", @@ -28,7 +32,9 @@ proto_library( cc_library( name = "cc_protos", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], deps = [ "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_cc_proto", "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_cc_proto", @@ -40,7 +46,9 @@ cc_library( java_library( name = "java_protos", - visibility = ["//visibility:public"], + visibility = [ + "//benchmarks:__subpackages__", + ], exports = [ "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_java_proto", "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_java_proto", From 3a7bd9c236fda465c16b90567f6b8706915da6cb Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Sun, 14 Mar 2021 13:47:33 +0100 Subject: [PATCH 63/80] Make util::Status more similar to absl::Status Progress on #3688 --- src/google/protobuf/stubs/status.cc | 136 +++++++++++- src/google/protobuf/stubs/status.h | 96 +++++++-- src/google/protobuf/stubs/status_test.cc | 200 +++++++++++++++--- src/google/protobuf/stubs/statusor.h | 22 +- src/google/protobuf/stubs/statusor_test.cc | 36 ++-- .../protobuf/util/internal/datapiece.cc | 26 +-- .../util/internal/field_mask_utility.cc | 18 +- .../util/internal/json_stream_parser.cc | 34 ++- .../util/internal/json_stream_parser.h | 2 +- .../util/internal/json_stream_parser_test.cc | 4 +- .../protobuf/util/internal/proto_writer.cc | 5 +- .../util/internal/protostream_objectsource.cc | 43 ++-- .../util/internal/protostream_objectsource.h | 2 +- .../internal/protostream_objectsource_test.cc | 16 +- .../util/internal/protostream_objectwriter.cc | 50 ++--- src/google/protobuf/util/json_util.cc | 18 +- src/google/protobuf/util/json_util_test.cc | 3 +- .../protobuf/util/type_resolver_util.cc | 14 +- 18 files changed, 512 insertions(+), 213 deletions(-) diff --git a/src/google/protobuf/stubs/status.cc b/src/google/protobuf/stubs/status.cc index 731e1084e1..e0718521a4 100644 --- a/src/google/protobuf/stubs/status.cc +++ b/src/google/protobuf/stubs/status.cc @@ -85,10 +85,6 @@ inline std::string StatusCodeToString(StatusCode code) { } // namespace -const Status Status::OK = Status(); -const Status Status::CANCELLED = Status(StatusCode::kCancelled, ""); -const Status Status::UNKNOWN = Status(StatusCode::kUnknown, ""); - Status::Status() : error_code_(StatusCode::kOk) { } @@ -127,11 +123,143 @@ std::string Status::ToString() const { } } +Status OkStatus() { + return Status(); +} + std::ostream& operator<<(std::ostream& os, const Status& x) { os << x.ToString(); return os; } +bool IsAborted(const Status& status) { + return status.code() == StatusCode::kAborted; +} + +bool IsAlreadyExists(const Status& status) { + return status.code() == StatusCode::kAlreadyExists; +} + +bool IsCancelled(const Status& status) { + return status.code() == StatusCode::kCancelled; +} + +bool IsDataLoss(const Status& status) { + return status.code() == StatusCode::kDataLoss; +} + +bool IsDeadlineExceeded(const Status& status) { + return status.code() == StatusCode::kDeadlineExceeded; +} + +bool IsFailedPrecondition(const Status& status) { + return status.code() == StatusCode::kFailedPrecondition; +} + +bool IsInternal(const Status& status) { + return status.code() == StatusCode::kInternal; +} + +bool IsInvalidArgument(const Status& status) { + return status.code() == StatusCode::kInvalidArgument; +} + +bool IsNotFound(const Status& status) { + return status.code() == StatusCode::kNotFound; +} + +bool IsOutOfRange(const Status& status) { + return status.code() == StatusCode::kOutOfRange; +} + +bool IsPermissionDenied(const Status& status) { + return status.code() == StatusCode::kPermissionDenied; +} + +bool IsResourceExhausted(const Status& status) { + return status.code() == StatusCode::kResourceExhausted; +} + +bool IsUnauthenticated(const Status& status) { + return status.code() == StatusCode::kUnauthenticated; +} + +bool IsUnavailable(const Status& status) { + return status.code() == StatusCode::kUnavailable; +} + +bool IsUnimplemented(const Status& status) { + return status.code() == StatusCode::kUnimplemented; +} + +bool IsUnknown(const Status& status) { + return status.code() == StatusCode::kUnknown; +} + +Status AbortedError(StringPiece message) { + return Status(StatusCode::kAborted, message); +} + +Status AlreadyExistsError(StringPiece message) { + return Status(StatusCode::kAlreadyExists, message); +} + +Status CancelledError(StringPiece message) { + return Status(StatusCode::kCancelled, message); +} + +Status DataLossError(StringPiece message) { + return Status(StatusCode::kDataLoss, message); +} + +Status DeadlineExceededError(StringPiece message) { + return Status(StatusCode::kDeadlineExceeded, message); +} + +Status FailedPreconditionError(StringPiece message) { + return Status(StatusCode::kFailedPrecondition, message); +} + +Status InternalError(StringPiece message) { + return Status(StatusCode::kInternal, message); +} + +Status InvalidArgumentError(StringPiece message) { + return Status(StatusCode::kInvalidArgument, message); +} + +Status NotFoundError(StringPiece message) { + return Status(StatusCode::kNotFound, message); +} + +Status OutOfRangeError(StringPiece message) { + return Status(StatusCode::kOutOfRange, message); +} + +Status PermissionDeniedError(StringPiece message) { + return Status(StatusCode::kPermissionDenied, message); +} + +Status ResourceExhaustedError(StringPiece message) { + return Status(StatusCode::kResourceExhausted, message); +} + +Status UnauthenticatedError(StringPiece message) { + return Status(StatusCode::kUnauthenticated, message); +} + +Status UnavailableError(StringPiece message) { + return Status(StatusCode::kUnavailable, message); +} + +Status UnimplementedError(StringPiece message) { + return Status(StatusCode::kUnimplemented, message); +} + +Status UnknownError(StringPiece message) { + return Status(StatusCode::kUnknown, message); +} + } // namespace status_internal } // namespace util } // namespace protobuf diff --git a/src/google/protobuf/stubs/status.h b/src/google/protobuf/stubs/status.h index 0eb0b53f93..187bc27078 100644 --- a/src/google/protobuf/stubs/status.h +++ b/src/google/protobuf/stubs/status.h @@ -77,11 +77,6 @@ class PROTOBUF_EXPORT Status { Status& operator=(const Status& x); ~Status() {} - // Some pre-defined Status objects - static const Status OK; // Identical to 0-arg constructor - static const Status CANCELLED; - static const Status UNKNOWN; - // Accessor bool ok() const { return error_code_ == StatusCode::kOk; @@ -106,25 +101,96 @@ class PROTOBUF_EXPORT Status { std::string error_message_; }; +// Returns an OK status, equivalent to a default constructed instance. Prefer +// usage of `OkStatus()` when constructing such an OK status. +PROTOBUF_EXPORT Status OkStatus(); + // Prints a human-readable representation of 'x' to 'os'. PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); +// These convenience functions return `true` if a given status matches the +// `StatusCode` error code of its associated function. +PROTOBUF_EXPORT bool IsAborted(const Status& status); +PROTOBUF_EXPORT bool IsAlreadyExists(const Status& status); +PROTOBUF_EXPORT bool IsCancelled(const Status& status); +PROTOBUF_EXPORT bool IsDataLoss(const Status& status); +PROTOBUF_EXPORT bool IsDeadlineExceeded(const Status& status); +PROTOBUF_EXPORT bool IsFailedPrecondition(const Status& status); +PROTOBUF_EXPORT bool IsInternal(const Status& status); +PROTOBUF_EXPORT bool IsInvalidArgument(const Status& status); +PROTOBUF_EXPORT bool IsNotFound(const Status& status); +PROTOBUF_EXPORT bool IsOutOfRange(const Status& status); +PROTOBUF_EXPORT bool IsPermissionDenied(const Status& status); +PROTOBUF_EXPORT bool IsResourceExhausted(const Status& status); +PROTOBUF_EXPORT bool IsUnauthenticated(const Status& status); +PROTOBUF_EXPORT bool IsUnavailable(const Status& status); +PROTOBUF_EXPORT bool IsUnimplemented(const Status& status); +PROTOBUF_EXPORT bool IsUnknown(const Status& status); + +// These convenience functions create an `Status` object with an error code as +// indicated by the associated function name, using the error message passed in +// `message`. +// +// These functions are intentionally named `*Error` rather than `*Status` to +// match the names from Abseil: +// https://github.com/abseil/abseil-cpp/blob/2e9532cc6c701a8323d0cffb468999ab804095ab/absl/status/status.h#L716 +PROTOBUF_EXPORT Status AbortedError(StringPiece message); +PROTOBUF_EXPORT Status AlreadyExistsError(StringPiece message); +PROTOBUF_EXPORT Status CancelledError(StringPiece message); +PROTOBUF_EXPORT Status DataLossError(StringPiece message); +PROTOBUF_EXPORT Status DeadlineExceededError(StringPiece message); +PROTOBUF_EXPORT Status FailedPreconditionError(StringPiece message); +PROTOBUF_EXPORT Status InternalError(StringPiece message); +PROTOBUF_EXPORT Status InvalidArgumentError(StringPiece message); +PROTOBUF_EXPORT Status NotFoundError(StringPiece message); +PROTOBUF_EXPORT Status OutOfRangeError(StringPiece message); +PROTOBUF_EXPORT Status PermissionDeniedError(StringPiece message); +PROTOBUF_EXPORT Status ResourceExhaustedError(StringPiece message); +PROTOBUF_EXPORT Status UnauthenticatedError(StringPiece message); +PROTOBUF_EXPORT Status UnavailableError(StringPiece message); +PROTOBUF_EXPORT Status UnimplementedError(StringPiece message); +PROTOBUF_EXPORT Status UnknownError(StringPiece message); + } // namespace status_internal using ::google::protobuf::util::status_internal::Status; using ::google::protobuf::util::status_internal::StatusCode; -namespace error { - -// TODO(yannic): Remove these. -constexpr StatusCode OK = StatusCode::kOk; -constexpr StatusCode CANCELLED = StatusCode::kCancelled; -constexpr StatusCode UNKNOWN = StatusCode::kUnknown; -constexpr StatusCode INVALID_ARGUMENT = StatusCode::kInvalidArgument; -constexpr StatusCode NOT_FOUND = StatusCode::kNotFound; -constexpr StatusCode INTERNAL = StatusCode::kInternal; +using ::google::protobuf::util::status_internal::IsAborted; +using ::google::protobuf::util::status_internal::IsAlreadyExists; +using ::google::protobuf::util::status_internal::IsCancelled; +using ::google::protobuf::util::status_internal::IsDataLoss; +using ::google::protobuf::util::status_internal::IsDeadlineExceeded; +using ::google::protobuf::util::status_internal::IsFailedPrecondition; +using ::google::protobuf::util::status_internal::IsInternal; +using ::google::protobuf::util::status_internal::IsInvalidArgument; +using ::google::protobuf::util::status_internal::IsNotFound; +using ::google::protobuf::util::status_internal::IsOutOfRange; +using ::google::protobuf::util::status_internal::IsPermissionDenied; +using ::google::protobuf::util::status_internal::IsResourceExhausted; +using ::google::protobuf::util::status_internal::IsUnauthenticated; +using ::google::protobuf::util::status_internal::IsUnavailable; +using ::google::protobuf::util::status_internal::IsUnimplemented; +using ::google::protobuf::util::status_internal::IsUnknown; + +using ::google::protobuf::util::status_internal::OkStatus; +using ::google::protobuf::util::status_internal::AbortedError; +using ::google::protobuf::util::status_internal::AlreadyExistsError; +using ::google::protobuf::util::status_internal::CancelledError; +using ::google::protobuf::util::status_internal::DataLossError; +using ::google::protobuf::util::status_internal::DeadlineExceededError; +using ::google::protobuf::util::status_internal::FailedPreconditionError; +using ::google::protobuf::util::status_internal::InternalError; +using ::google::protobuf::util::status_internal::InvalidArgumentError; +using ::google::protobuf::util::status_internal::NotFoundError; +using ::google::protobuf::util::status_internal::OutOfRangeError; +using ::google::protobuf::util::status_internal::PermissionDeniedError; +using ::google::protobuf::util::status_internal::ResourceExhaustedError; +using ::google::protobuf::util::status_internal::UnauthenticatedError; +using ::google::protobuf::util::status_internal::UnavailableError; +using ::google::protobuf::util::status_internal::UnimplementedError; +using ::google::protobuf::util::status_internal::UnknownError; -} // namespace error } // namespace util } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/status_test.cc b/src/google/protobuf/stubs/status_test.cc index ce486809db..cca6c2bc3d 100644 --- a/src/google/protobuf/stubs/status_test.cc +++ b/src/google/protobuf/stubs/status_test.cc @@ -37,22 +37,170 @@ namespace google { namespace protobuf { namespace { -TEST(Status, Empty) { - util::Status status; - EXPECT_EQ(util::error::OK, util::Status::OK.code()); - EXPECT_EQ("OK", util::Status::OK.ToString()); -} -TEST(Status, GenericCodes) { - EXPECT_EQ(util::error::OK, util::Status::OK.code()); - EXPECT_EQ(util::error::CANCELLED, util::Status::CANCELLED.code()); - EXPECT_EQ(util::error::UNKNOWN, util::Status::UNKNOWN.code()); +TEST(Status, Constructor) { + EXPECT_EQ(util::StatusCode::kOk, + util::Status(util::StatusCode::kOk, "").code()); + EXPECT_EQ(util::StatusCode::kCancelled, + util::Status(util::StatusCode::kCancelled, "").code()); + EXPECT_EQ(util::StatusCode::kUnknown, + util::Status(util::StatusCode::kUnknown, "").code()); + EXPECT_EQ(util::StatusCode::kInvalidArgument, + util::Status(util::StatusCode::kInvalidArgument, "").code()); + EXPECT_EQ(util::StatusCode::kDeadlineExceeded, + util::Status(util::StatusCode::kDeadlineExceeded, "").code()); + EXPECT_EQ(util::StatusCode::kNotFound, + util::Status(util::StatusCode::kNotFound, "").code()); + EXPECT_EQ(util::StatusCode::kAlreadyExists, + util::Status(util::StatusCode::kAlreadyExists, "").code()); + EXPECT_EQ(util::StatusCode::kPermissionDenied, + util::Status(util::StatusCode::kPermissionDenied, "").code()); + EXPECT_EQ(util::StatusCode::kUnauthenticated, + util::Status(util::StatusCode::kUnauthenticated, "").code()); + EXPECT_EQ(util::StatusCode::kResourceExhausted, + util::Status(util::StatusCode::kResourceExhausted, "").code()); + EXPECT_EQ(util::StatusCode::kFailedPrecondition, + util::Status(util::StatusCode::kFailedPrecondition, "").code()); + EXPECT_EQ(util::StatusCode::kAborted, + util::Status(util::StatusCode::kAborted, "").code()); + EXPECT_EQ(util::StatusCode::kOutOfRange, + util::Status(util::StatusCode::kOutOfRange, "").code()); + EXPECT_EQ(util::StatusCode::kUnimplemented, + util::Status(util::StatusCode::kUnimplemented, "").code()); + EXPECT_EQ(util::StatusCode::kInternal, + util::Status(util::StatusCode::kInternal, "").code()); + EXPECT_EQ(util::StatusCode::kUnavailable, + util::Status(util::StatusCode::kUnavailable, "").code()); + EXPECT_EQ(util::StatusCode::kDataLoss, + util::Status(util::StatusCode::kDataLoss, "").code()); } TEST(Status, ConstructorZero) { - util::Status status(util::error::OK, "msg"); + util::Status status(util::StatusCode::kOk, "msg"); EXPECT_TRUE(status.ok()); EXPECT_EQ("OK", status.ToString()); + EXPECT_EQ(util::OkStatus(), status); +} + +TEST(Status, ConvenienceConstructors) { + EXPECT_EQ(util::StatusCode::kOk, util::OkStatus().code()); + EXPECT_EQ("", util::OkStatus().message()); + + EXPECT_EQ(util::StatusCode::kCancelled, util::CancelledError("").code()); + EXPECT_EQ("", util::CancelledError("").message()); + EXPECT_EQ("foo", util::CancelledError("foo").message()); + EXPECT_EQ("bar", util::CancelledError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnknown, util::UnknownError("").code()); + EXPECT_EQ("", util::UnknownError("").message()); + EXPECT_EQ("foo", util::UnknownError("foo").message()); + EXPECT_EQ("bar", util::UnknownError("bar").message()); + + EXPECT_EQ(util::StatusCode::kInvalidArgument, + util::InvalidArgumentError("").code()); + EXPECT_EQ("", util::InvalidArgumentError("").message()); + EXPECT_EQ("foo", util::InvalidArgumentError("foo").message()); + EXPECT_EQ("bar", util::InvalidArgumentError("bar").message()); + + EXPECT_EQ(util::StatusCode::kDeadlineExceeded, + util::DeadlineExceededError("").code()); + EXPECT_EQ("", util::DeadlineExceededError("").message()); + EXPECT_EQ("foo", util::DeadlineExceededError("foo").message()); + EXPECT_EQ("bar", util::DeadlineExceededError("bar").message()); + + EXPECT_EQ(util::StatusCode::kNotFound, util::NotFoundError("").code()); + EXPECT_EQ("", util::NotFoundError("").message()); + EXPECT_EQ("foo", util::NotFoundError("foo").message()); + EXPECT_EQ("bar", util::NotFoundError("bar").message()); + + EXPECT_EQ(util::StatusCode::kAlreadyExists, + util::AlreadyExistsError("").code()); + EXPECT_EQ("", util::AlreadyExistsError("").message()); + EXPECT_EQ("foo", util::AlreadyExistsError("foo").message()); + EXPECT_EQ("bar", util::AlreadyExistsError("bar").message()); + + EXPECT_EQ(util::StatusCode::kPermissionDenied, + util::PermissionDeniedError("").code()); + EXPECT_EQ("", util::PermissionDeniedError("").message()); + EXPECT_EQ("foo", util::PermissionDeniedError("foo").message()); + EXPECT_EQ("bar", util::PermissionDeniedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnauthenticated, + util::UnauthenticatedError("").code()); + EXPECT_EQ("", util::UnauthenticatedError("").message()); + EXPECT_EQ("foo", util::UnauthenticatedError("foo").message()); + EXPECT_EQ("bar", util::UnauthenticatedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kResourceExhausted, + util::ResourceExhaustedError("").code()); + EXPECT_EQ("", util::ResourceExhaustedError("").message()); + EXPECT_EQ("foo", util::ResourceExhaustedError("foo").message()); + EXPECT_EQ("bar", util::ResourceExhaustedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kFailedPrecondition, + util::FailedPreconditionError("").code()); + EXPECT_EQ("", util::FailedPreconditionError("").message()); + EXPECT_EQ("foo", util::FailedPreconditionError("foo").message()); + EXPECT_EQ("bar", util::FailedPreconditionError("bar").message()); + + EXPECT_EQ(util::StatusCode::kAborted, util::AbortedError("").code()); + EXPECT_EQ("", util::AbortedError("").message()); + EXPECT_EQ("foo", util::AbortedError("foo").message()); + EXPECT_EQ("bar", util::AbortedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kOutOfRange, util::OutOfRangeError("").code()); + EXPECT_EQ("", util::OutOfRangeError("").message()); + EXPECT_EQ("foo", util::OutOfRangeError("foo").message()); + EXPECT_EQ("bar", util::OutOfRangeError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnimplemented, + util::UnimplementedError("").code()); + EXPECT_EQ("", util::UnimplementedError("").message()); + EXPECT_EQ("foo", util::UnimplementedError("foo").message()); + EXPECT_EQ("bar", util::UnimplementedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kInternal, util::InternalError("").code()); + EXPECT_EQ("", util::InternalError("").message()); + EXPECT_EQ("foo", util::InternalError("foo").message()); + EXPECT_EQ("bar", util::InternalError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnavailable, util::UnavailableError("").code()); + EXPECT_EQ("", util::UnavailableError("").message()); + EXPECT_EQ("foo", util::UnavailableError("foo").message()); + EXPECT_EQ("bar", util::UnavailableError("bar").message()); + + EXPECT_EQ(util::StatusCode::kDataLoss, util::DataLossError("").code()); + EXPECT_EQ("", util::DataLossError("").message()); + EXPECT_EQ("foo", util::DataLossError("foo").message()); + EXPECT_EQ("bar", util::DataLossError("bar").message()); +} + +TEST(Status, ConvenienceTests) { + EXPECT_TRUE(util::OkStatus().ok()); + EXPECT_TRUE(util::IsCancelled(util::CancelledError(""))); + EXPECT_TRUE(util::IsUnknown(util::UnknownError(""))); + EXPECT_TRUE(util::IsInvalidArgument(util::InvalidArgumentError(""))); + EXPECT_TRUE(util::IsDeadlineExceeded(util::DeadlineExceededError(""))); + EXPECT_TRUE(util::IsNotFound(util::NotFoundError(""))); + EXPECT_TRUE(util::IsAlreadyExists(util::AlreadyExistsError(""))); + EXPECT_TRUE(util::IsPermissionDenied(util::PermissionDeniedError(""))); + EXPECT_TRUE(util::IsUnauthenticated(util::UnauthenticatedError(""))); + EXPECT_TRUE(util::IsResourceExhausted(util::ResourceExhaustedError(""))); + EXPECT_TRUE(util::IsFailedPrecondition(util::FailedPreconditionError(""))); + EXPECT_TRUE(util::IsAborted(util::AbortedError(""))); + EXPECT_TRUE(util::IsOutOfRange(util::OutOfRangeError(""))); + EXPECT_TRUE(util::IsUnimplemented(util::UnimplementedError(""))); + EXPECT_TRUE(util::IsInternal(util::InternalError(""))); + EXPECT_TRUE(util::IsUnavailable(util::UnavailableError(""))); + EXPECT_TRUE(util::IsDataLoss(util::DataLossError(""))); +} + +TEST(Status, Empty) { + util::Status status; + EXPECT_TRUE(status.ok()); + EXPECT_EQ(util::OkStatus(), status); + EXPECT_EQ(util::StatusCode::kOk, status.code()); + EXPECT_EQ("OK", status.ToString()); } TEST(Status, CheckOK) { @@ -63,38 +211,35 @@ TEST(Status, CheckOK) { } TEST(Status, ErrorMessage) { - util::Status status(util::error::INVALID_ARGUMENT, ""); + util::Status status = util::InvalidArgumentError(""); EXPECT_FALSE(status.ok()); EXPECT_EQ("", status.message().ToString()); - EXPECT_EQ("", status.message().ToString()); EXPECT_EQ("INVALID_ARGUMENT", status.ToString()); - status = util::Status(util::error::INVALID_ARGUMENT, "msg"); + status = util::InvalidArgumentError("msg"); EXPECT_FALSE(status.ok()); EXPECT_EQ("msg", status.message().ToString()); - EXPECT_EQ("msg", status.message().ToString()); EXPECT_EQ("INVALID_ARGUMENT:msg", status.ToString()); - status = util::Status(util::error::OK, "msg"); + status = util::Status(util::StatusCode::kOk, "msg"); EXPECT_TRUE(status.ok()); EXPECT_EQ("", status.message().ToString()); - EXPECT_EQ("", status.message().ToString()); EXPECT_EQ("OK", status.ToString()); } TEST(Status, Copy) { - util::Status a(util::error::UNKNOWN, "message"); + util::Status a = util::UnknownError("message"); util::Status b(a); ASSERT_EQ(a.ToString(), b.ToString()); } TEST(Status, Assign) { - util::Status a(util::error::UNKNOWN, "message"); + util::Status a = util::UnknownError("message"); util::Status b; b = a; ASSERT_EQ(a.ToString(), b.ToString()); } TEST(Status, AssignEmpty) { - util::Status a(util::error::UNKNOWN, "message"); + util::Status a = util::UnknownError("message"); util::Status b; a = b; ASSERT_EQ(std::string("OK"), a.ToString()); @@ -103,32 +248,33 @@ TEST(Status, AssignEmpty) { } TEST(Status, EqualsOK) { - ASSERT_EQ(util::Status::OK, util::Status()); + ASSERT_EQ(util::OkStatus(), util::Status()); } TEST(Status, EqualsSame) { - const util::Status a = util::Status(util::error::CANCELLED, "message"); - const util::Status b = util::Status(util::error::CANCELLED, "message"); + const util::Status a = util::CancelledError("message"); + const util::Status b = util::CancelledError("message"); ASSERT_EQ(a, b); } TEST(Status, EqualsCopy) { - const util::Status a = util::Status(util::error::CANCELLED, "message"); + const util::Status a = util::CancelledError("message"); const util::Status b = a; ASSERT_EQ(a, b); } TEST(Status, EqualsDifferentCode) { - const util::Status a = util::Status(util::error::CANCELLED, "message"); - const util::Status b = util::Status(util::error::UNKNOWN, "message"); + const util::Status a = util::CancelledError("message"); + const util::Status b = util::UnknownError("message"); ASSERT_NE(a, b); } TEST(Status, EqualsDifferentMessage) { - const util::Status a = util::Status(util::error::CANCELLED, "message"); - const util::Status b = util::Status(util::error::CANCELLED, "another"); + const util::Status a = util::CancelledError("message"); + const util::Status b = util::CancelledError("another"); ASSERT_NE(a, b); } + } // namespace } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/statusor.h b/src/google/protobuf/stubs/statusor.h index c3748eacc1..6d8aea5909 100644 --- a/src/google/protobuf/stubs/statusor.h +++ b/src/google/protobuf/stubs/statusor.h @@ -32,7 +32,7 @@ // object. StatusOr models the concept of an object that is either a // usable value, or an error Status explaining why such a value is // not present. To this end, StatusOr does not allow its Status -// value to be Status::kOk. Further, StatusOr does not allow the +// value to be OkStatus(). Further, StatusOr does not allow the // contained pointer to be nullptr. // // The primary use-case for StatusOr is as the return value of a @@ -72,8 +72,7 @@ // // StatusOr FooFactory::MakeNewFoo(int arg) { // if (arg <= 0) { -// return ::util::Status(::util::error::INVALID_ARGUMENT, -// "Arg must be positive"); +// return InvalidArgumentError("Arg must be positive"); // } else { // return new Foo(arg); // } @@ -100,7 +99,7 @@ class StatusOr { template friend class StatusOr; public: - // Construct a new StatusOr with Status::UNKNOWN status + // Construct a new StatusOr with UnknownError() status. StatusOr(); // Construct a new StatusOr with the given non-ok status. After calling @@ -110,8 +109,8 @@ class StatusOr { // value, so it is convenient and sensible to be able to do 'return // Status()' when the return type is StatusOr. // - // REQUIRES: status != Status::kOk. This requirement is DCHECKed. - // In optimized builds, passing Status::kOk here will have the effect + // REQUIRES: status != OkStatus(). This requirement is DCHECKed. + // In optimized builds, passing OkStatus() here will have the effect // of passing PosixErrorSpace::EINVAL as a fallback. StatusOr(const Status& status); // NOLINT @@ -143,7 +142,7 @@ class StatusOr { StatusOr& operator=(const StatusOr& other); // Returns a reference to our status. If this contains a T, then - // returns Status::kOk. + // returns OkStatus(). const Status& status() const; // Returns this->status().ok() @@ -190,14 +189,13 @@ struct StatusOrHelper::Specialize { template inline StatusOr::StatusOr() - : status_(util::Status::UNKNOWN) { + : status_(util::UnknownError("")) { } template inline StatusOr::StatusOr(const Status& status) { if (status.ok()) { - status_ = - Status(StatusCode::kInternal, "Status::kOk is not a valid argument."); + status_ = util::InternalError("OkStatus() is not a valid argument."); } else { status_ = status; } @@ -206,9 +204,9 @@ inline StatusOr::StatusOr(const Status& status) { template inline StatusOr::StatusOr(const T& value) { if (internal::StatusOrHelper::Specialize::IsValueNull(value)) { - status_ = Status(StatusCode::kInternal, "nullptr is not a valid argument."); + status_ = util::InternalError("nullptr is not a valid argument."); } else { - status_ = Status::OK; + status_ = util::OkStatus(); value_ = value; } } diff --git a/src/google/protobuf/stubs/statusor_test.cc b/src/google/protobuf/stubs/statusor_test.cc index 6e2a9e5545..683900c6c3 100644 --- a/src/google/protobuf/stubs/statusor_test.cc +++ b/src/google/protobuf/stubs/statusor_test.cc @@ -71,13 +71,13 @@ class CopyNoAssign { TEST(StatusOr, TestDefaultCtor) { StatusOr thing; EXPECT_FALSE(thing.ok()); - EXPECT_EQ(Status::UNKNOWN, thing.status()); + EXPECT_EQ(util::UnknownError(""), thing.status()); } TEST(StatusOr, TestStatusCtor) { - StatusOr thing(Status::CANCELLED); + StatusOr thing(util::CancelledError("")); EXPECT_FALSE(thing.ok()); - EXPECT_EQ(Status::CANCELLED, thing.status()); + EXPECT_EQ(util::CancelledError(""), thing.status()); } TEST(StatusOr, TestValueCtor) { @@ -96,7 +96,7 @@ TEST(StatusOr, TestCopyCtorStatusOk) { } TEST(StatusOr, TestCopyCtorStatusNotOk) { - StatusOr original(Status::CANCELLED); + StatusOr original(util::CancelledError("")); StatusOr copy(original); EXPECT_EQ(original.status(), copy.status()); } @@ -110,7 +110,7 @@ TEST(StatusOr, TestCopyCtorStatusOKConverting) { } TEST(StatusOr, TestCopyCtorStatusNotOkConverting) { - StatusOr original(Status::CANCELLED); + StatusOr original(util::CancelledError("")); StatusOr copy(original); EXPECT_EQ(original.status(), copy.status()); } @@ -125,7 +125,7 @@ TEST(StatusOr, TestAssignmentStatusOk) { } TEST(StatusOr, TestAssignmentStatusNotOk) { - StatusOr source(Status::CANCELLED); + StatusOr source(util::CancelledError("")); StatusOr target; target = source; EXPECT_EQ(source.status(), target.status()); @@ -141,7 +141,7 @@ TEST(StatusOr, TestAssignmentStatusOKConverting) { } TEST(StatusOr, TestAssignmentStatusNotOkConverting) { - StatusOr source(Status::CANCELLED); + StatusOr source(util::CancelledError("")); StatusOr target; target = source; EXPECT_EQ(source.status(), target.status()); @@ -150,9 +150,9 @@ TEST(StatusOr, TestAssignmentStatusNotOkConverting) { TEST(StatusOr, TestStatus) { StatusOr good(4); EXPECT_TRUE(good.ok()); - StatusOr bad(Status::CANCELLED); + StatusOr bad(util::CancelledError("")); EXPECT_FALSE(bad.ok()); - EXPECT_EQ(Status::CANCELLED, bad.status()); + EXPECT_EQ(util::CancelledError(""), bad.status()); } TEST(StatusOr, TestValue) { @@ -170,13 +170,13 @@ TEST(StatusOr, TestValueConst) { TEST(StatusOr, TestPointerDefaultCtor) { StatusOr thing; EXPECT_FALSE(thing.ok()); - EXPECT_EQ(Status::UNKNOWN, thing.status()); + EXPECT_EQ(util::UnknownError(""), thing.status()); } TEST(StatusOr, TestPointerStatusCtor) { - StatusOr thing(Status::CANCELLED); + StatusOr thing(util::CancelledError("")); EXPECT_FALSE(thing.ok()); - EXPECT_EQ(Status::CANCELLED, thing.status()); + EXPECT_EQ(util::CancelledError(""), thing.status()); } TEST(StatusOr, TestPointerValueCtor) { @@ -195,7 +195,7 @@ TEST(StatusOr, TestPointerCopyCtorStatusOk) { } TEST(StatusOr, TestPointerCopyCtorStatusNotOk) { - StatusOr original(Status::CANCELLED); + StatusOr original(util::CancelledError("")); StatusOr copy(original); EXPECT_EQ(original.status(), copy.status()); } @@ -210,7 +210,7 @@ TEST(StatusOr, TestPointerCopyCtorStatusOKConverting) { } TEST(StatusOr, TestPointerCopyCtorStatusNotOkConverting) { - StatusOr original(Status::CANCELLED); + StatusOr original(util::CancelledError("")); StatusOr copy(original); EXPECT_EQ(original.status(), copy.status()); } @@ -225,7 +225,7 @@ TEST(StatusOr, TestPointerAssignmentStatusOk) { } TEST(StatusOr, TestPointerAssignmentStatusNotOk) { - StatusOr source(Status::CANCELLED); + StatusOr source(util::CancelledError("")); StatusOr target; target = source; EXPECT_EQ(source.status(), target.status()); @@ -242,7 +242,7 @@ TEST(StatusOr, TestPointerAssignmentStatusOKConverting) { } TEST(StatusOr, TestPointerAssignmentStatusNotOkConverting) { - StatusOr source(Status::CANCELLED); + StatusOr source(util::CancelledError("")); StatusOr target; target = source; EXPECT_EQ(source.status(), target.status()); @@ -252,8 +252,8 @@ TEST(StatusOr, TestPointerStatus) { const int kI = 0; StatusOr good(&kI); EXPECT_TRUE(good.ok()); - StatusOr bad(Status::CANCELLED); - EXPECT_EQ(Status::CANCELLED, bad.status()); + StatusOr bad(util::CancelledError("")); + EXPECT_EQ(util::CancelledError(""), bad.status()); } TEST(StatusOr, TestPointerValue) { diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index feb4ab441f..4384b79c24 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -51,17 +51,13 @@ using util::Status; namespace { -inline Status InvalidArgument(StringPiece value_str) { - return Status(util::error::INVALID_ARGUMENT, value_str); -} - template util::StatusOr ValidateNumberConversion(To after, From before) { if (after == before && MathUtil::Sign(before) == MathUtil::Sign(after)) { return after; } else { - return InvalidArgument(std::is_integral::value + return util::InvalidArgumentError(std::is_integral::value ? ValueAsString(before) : std::is_same::value ? DoubleAsString(before) @@ -106,7 +102,7 @@ util::StatusOr DoubleToFloat(double before) { } else if (before > std::numeric_limits::max() || before < -std::numeric_limits::max()) { // Double value outside of the range of float. - return InvalidArgument(DoubleAsString(before)); + return util::InvalidArgumentError(DoubleAsString(before)); } else { return static_cast(before); } @@ -178,7 +174,7 @@ util::StatusOr DataPiece::ToDouble() const { if (value.ok() && !std::isfinite(value.value())) { // safe_strtod converts out-of-range values to +inf/-inf, but we want // to report them as errors. - return InvalidArgument(StrCat("\"", str_, "\"")); + return util::InvalidArgumentError(StrCat("\"", str_, "\"")); } else { return value; } @@ -208,7 +204,7 @@ util::StatusOr DataPiece::ToBool() const { case TYPE_STRING: return StringToNumber(safe_strtob); default: - return InvalidArgument( + return util::InvalidArgumentError( ValueAsStringOrDefault("Wrong type. Cannot convert to Bool.")); } } @@ -223,7 +219,7 @@ util::StatusOr DataPiece::ToString() const { return base64; } default: - return InvalidArgument( + return util::InvalidArgumentError( ValueAsStringOrDefault("Cannot convert to string.")); } } @@ -264,11 +260,11 @@ util::StatusOr DataPiece::ToBytes() const { if (type_ == TYPE_STRING) { std::string decoded; if (!DecodeBase64(str_, &decoded)) { - return InvalidArgument(ValueAsStringOrDefault("Invalid data in input.")); + return util::InvalidArgumentError(ValueAsStringOrDefault("Invalid data in input.")); } return decoded; } else { - return InvalidArgument(ValueAsStringOrDefault( + return util::InvalidArgumentError(ValueAsStringOrDefault( "Wrong type. Only String or Bytes can be converted to Bytes.")); } } @@ -328,7 +324,7 @@ util::StatusOr DataPiece::ToEnum(const google::protobuf::Enum* enum_type, // enum because we preserve unknown enum values as well. return ToInt32(); } - return InvalidArgument( + return util::InvalidArgumentError( ValueAsStringOrDefault("Cannot find enum with given value.")); } @@ -348,7 +344,7 @@ util::StatusOr DataPiece::GenericConvert() const { case TYPE_FLOAT: return NumberConvertAndCheck(float_); default: // TYPE_ENUM, TYPE_STRING, TYPE_CORD, TYPE_BOOL - return InvalidArgument(ValueAsStringOrDefault( + return util::InvalidArgumentError(ValueAsStringOrDefault( "Wrong type. Bool, Enum, String and Cord not supported in " "GenericConvert.")); } @@ -358,11 +354,11 @@ template util::StatusOr DataPiece::StringToNumber(bool (*func)(StringPiece, To*)) const { if (str_.size() > 0 && (str_[0] == ' ' || str_[str_.size() - 1] == ' ')) { - return InvalidArgument(StrCat("\"", str_, "\"")); + return util::InvalidArgumentError(StrCat("\"", str_, "\"")); } To result; if (func(str_, &result)) return result; - return InvalidArgument(StrCat("\"", std::string(str_), "\"")); + return util::InvalidArgumentError(StrCat("\"", std::string(str_), "\"")); } bool DataPiece::DecodeBase64(StringPiece src, std::string* dest) const { diff --git a/src/google/protobuf/util/internal/field_mask_utility.cc b/src/google/protobuf/util/internal/field_mask_utility.cc index 0beff996a6..cd194e87d4 100644 --- a/src/google/protobuf/util/internal/field_mask_utility.cc +++ b/src/google/protobuf/util/internal/field_mask_utility.cc @@ -134,8 +134,7 @@ util::Status DecodeCompactFieldMaskPaths(StringPiece paths, } // Un-escaped '"' must be followed with a ']'. if (i >= length - 1 || paths[i + 1] != ']') { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat( "Invalid FieldMask '", paths, "'. Map keys should be represented as [\"some_key\"].")); @@ -147,8 +146,7 @@ util::Status DecodeCompactFieldMaskPaths(StringPiece paths, // Checks whether the key ends at the end of a path segment. if (i < length - 1 && paths[i + 1] != '.' && paths[i + 1] != ',' && paths[i + 1] != ')' && paths[i + 1] != '(') { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat( "Invalid FieldMask '", paths, "'. Map keys should be at the end of a path segment.")); @@ -160,8 +158,7 @@ util::Status DecodeCompactFieldMaskPaths(StringPiece paths, // We are not in a map key, look for the start of one. if (paths[i] == '[') { if (i >= length - 1 || paths[i + 1] != '\"') { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat( "Invalid FieldMask '", paths, "'. Map keys should be represented as [\"some_key\"].")); @@ -197,8 +194,7 @@ util::Status DecodeCompactFieldMaskPaths(StringPiece paths, // Removes the last prefix after seeing a ')'. if (i < length && paths[i] == ')') { if (prefix.empty()) { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat("Invalid FieldMask '", paths, "'. Cannot find matching '(' for all ')'.")); } @@ -207,14 +203,12 @@ util::Status DecodeCompactFieldMaskPaths(StringPiece paths, previous_position = i + 1; } if (in_map_key) { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat("Invalid FieldMask '", paths, "'. Cannot find matching ']' for all '['.")); } if (!prefix.empty()) { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat("Invalid FieldMask '", paths, "'. Cannot find matching ')' for all '('.")); } diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc index dc0bacad03..f38b68a1d2 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.cc +++ b/src/google/protobuf/util/internal/json_stream_parser.cc @@ -302,14 +302,12 @@ util::Status JsonStreamParser::RunParser() { break; default: - result = util::Status(util::error::INTERNAL, - StrCat("Unknown parse type: ", type)); + result = util::InternalError(StrCat("Unknown parse type: ", type)); break; } if (!result.ok()) { // If we were cancelled, save our state and try again later. - if (!finishing_ && - result == util::Status(util::error::CANCELLED, "")) { + if (!finishing_ && util::IsCancelled(result)) { stack_.push(type); // If we have a key we still need to render, make sure to save off the // contents in our own storage. @@ -353,7 +351,7 @@ util::Status JsonStreamParser::ParseValue(TokenType type) { // don't know if the next char would be e, completing it, or something // else, making it invalid. if (!finishing_ && p_.length() < kKeywordFalse.length()) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } return ReportFailure("Unexpected token.", ParseErrorType::UNEXPECTED_TOKEN); @@ -392,7 +390,7 @@ util::Status JsonStreamParser::ParseStringHelper() { // depending on if we expect more data later. if (p_.length() == 1) { if (!finishing_) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } return ReportFailure("Closing quote expected in string.", ParseErrorType::EXPECTED_CLOSING_QUOTE); @@ -461,7 +459,7 @@ util::Status JsonStreamParser::ParseStringHelper() { } // If we didn't find the closing quote but we expect more data, cancel for now if (!finishing_) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } // End of string reached without a closing quote, report an error. string_open_ = 0; @@ -479,7 +477,7 @@ util::Status JsonStreamParser::ParseStringHelper() { util::Status JsonStreamParser::ParseUnicodeEscape() { if (p_.length() < kUnicodeEscapedLength) { if (!finishing_) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } return ReportFailure("Illegal hex string.", ParseErrorType::ILLEGAL_HEX_STRING); @@ -498,7 +496,7 @@ util::Status JsonStreamParser::ParseUnicodeEscape() { code <= JsonEscaping::kMaxHighSurrogate) { if (p_.length() < 2 * kUnicodeEscapedLength) { if (!finishing_) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } if (!coerce_to_utf8_) { return ReportFailure("Missing low surrogate.", @@ -612,7 +610,7 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { // If the entire input is a valid number, and we may have more content in the // future, we abort for now and resume when we know more. if (index == length && !finishing_) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } // Create a string containing just the number, so we can use safe_strtoX @@ -799,7 +797,7 @@ util::Status JsonStreamParser::ParseArrayValue(TokenType type) { // empty-null array value is relying on this ARRAY_MID token. stack_.push(ARRAY_MID); util::Status result = ParseValue(type); - if (result == util::Status(util::error::CANCELLED, "")) { + if (util::IsCancelled(result)) { // If we were cancelled, pop back off the ARRAY_MID so we don't try to // push it on again when we try over. stack_.pop(); @@ -874,18 +872,15 @@ util::Status JsonStreamParser::ReportFailure(StringPiece message, StringPiece segment(begin, end - begin); std::string location(p_start - begin, ' '); location.push_back('^'); - auto status = - util::Status(util::error::INVALID_ARGUMENT, - StrCat(message, "\n", segment, "\n", location)); - - return status; + return util::InvalidArgumentError( + StrCat(message, "\n", segment, "\n", location)); } util::Status JsonStreamParser::ReportUnknown(StringPiece message, ParseErrorType parse_code) { // If we aren't finishing the parse, cancel parsing and try later. if (!finishing_) { - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } if (p_.empty()) { return ReportFailure(StrCat("Unexpected end of string. ", message), @@ -897,8 +892,7 @@ util::Status JsonStreamParser::ReportUnknown(StringPiece message, util::Status JsonStreamParser::IncrementRecursionDepth( StringPiece key) const { if (++recursion_depth_ > max_recursion_depth_) { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat("Message too deep. Max recursion depth reached for key '", key, "'")); } @@ -940,7 +934,7 @@ util::Status JsonStreamParser::ParseKey() { // we can't know if the key was complete or not. if (!finishing_ && p_.empty()) { p_ = original; - return util::Status(util::error::CANCELLED, ""); + return util::CancelledError(""); } // Since we aren't using the key storage, clear it out. key_storage_.clear(); diff --git a/src/google/protobuf/util/internal/json_stream_parser.h b/src/google/protobuf/util/internal/json_stream_parser.h index 4c93d77fc5..47dfe82f4a 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.h +++ b/src/google/protobuf/util/internal/json_stream_parser.h @@ -244,7 +244,7 @@ class PROTOBUF_EXPORT JsonStreamParser { ParseErrorType parse_code); // Helper function to check recursion depth and increment it. It will return - // Status::OK if the current depth is allowed. Otherwise an error is returned. + // OkStatus() if the current depth is allowed. Otherwise an error is returned. // key is used for error reporting. util::Status IncrementRecursionDepth(StringPiece key) const; diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index 9d38a4f618..4bb10251ec 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -138,7 +138,7 @@ class JsonStreamParserTest : public ::testing::Test { std::function setup = [](JsonStreamParser* p) { }) { util::Status result = RunTest(json, split, setup); - EXPECT_EQ(util::error::INVALID_ARGUMENT, result.code()); + EXPECT_TRUE(util::IsInvalidArgument(result)); StringPiece error_message(result.message()); EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); } @@ -149,7 +149,7 @@ class JsonStreamParserTest : public ::testing::Test { std::function setup = [](JsonStreamParser* p) { }) { util::Status result = RunTest(json, split, setup); - EXPECT_EQ(util::error::INVALID_ARGUMENT, result.code()); + EXPECT_TRUE(util::IsInvalidArgument(result)); StringPiece error_message(result.message()); EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); } diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 8821dbef6b..ff4fe54aaa 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -55,8 +55,6 @@ namespace converter { using io::CodedOutputStream; using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; -using util::error::INVALID_ARGUMENT; - ProtoWriter::ProtoWriter(TypeResolver* type_resolver, const google::protobuf::Type& type, @@ -695,8 +693,7 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField( break; } default: // TYPE_GROUP, TYPE_MESSAGE, TYPE_UNKNOWN. - status = util::Status(util::error::INVALID_ARGUMENT, - data.ValueAsStringOrDefault("")); + status = util::InvalidArgumentError(data.ValueAsStringOrDefault("")); } if (!status.ok()) { diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 8ad51df28b..b98a14cdb0 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -102,7 +102,7 @@ util::StatusOr MapKeyDefaultValueAsString( case google::protobuf::Field::TYPE_STRING: return std::string(); default: - return util::Status(util::error::INTERNAL, "Invalid map key type."); + return util::InternalError("Invalid map key type."); } } } // namespace @@ -282,8 +282,7 @@ util::StatusOr ProtoStreamObjectSource::RenderMap( if (key_field == nullptr) { // The Type info for this map entry is incorrect. It should always // have a field named "key" and with field number 1. - return util::Status(util::error::INTERNAL, - "Invalid map entry."); + return util::InternalError("Invalid map entry."); } ASSIGN_OR_RETURN(map_key, MapKeyDefaultValueAsString(*key_field)); } @@ -291,7 +290,7 @@ util::StatusOr ProtoStreamObjectSource::RenderMap( } else { // The Type info for this map entry is incorrect. It should contain // exactly two fields with field number 1 and 2. - return util::Status(util::error::INTERNAL, "Invalid map entry."); + return util::InternalError("Invalid map entry."); } } stream_->PopLimit(old_limit); @@ -318,15 +317,12 @@ util::Status ProtoStreamObjectSource::RenderTimestamp( int64_t seconds = p.first; int32_t nanos = p.second; if (seconds > kTimestampMaxSeconds || seconds < kTimestampMinSeconds) { - return util::Status( - util::error::INTERNAL, - StrCat("Timestamp seconds exceeds limit for field: ", - field_name)); + return util::InternalError( + StrCat("Timestamp seconds exceeds limit for field: ", field_name)); } if (nanos < 0 || nanos >= kNanosPerSecond) { - return util::Status( - util::error::INTERNAL, + return util::InternalError( StrCat("Timestamp nanos exceeds limit for field: ", field_name)); } @@ -343,22 +339,19 @@ util::Status ProtoStreamObjectSource::RenderDuration( int64_t seconds = p.first; int32_t nanos = p.second; if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds) { - return util::Status( - util::error::INTERNAL, + return util::InternalError( StrCat("Duration seconds exceeds limit for field: ", field_name)); } if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { - return util::Status( - util::error::INTERNAL, + return util::InternalError( StrCat("Duration nanos exceeds limit for field: ", field_name)); } std::string sign = ""; if (seconds < 0) { if (nanos > 0) { - return util::Status( - util::error::INTERNAL, + return util::InternalError( StrCat("Duration nanos is non-negative, but seconds is " "negative for field: ", field_name)); @@ -611,8 +604,7 @@ util::Status ProtoStreamObjectSource::RenderAny( // If there is a value but no type, we cannot render it, so report an error. if (type_url.empty()) { // TODO(sven): Add an external message once those are ready. - return util::Status(util::error::INTERNAL, - "Invalid Any, the type_url is missing."); + return util::InternalError("Invalid Any, the type_url is missing."); } util::StatusOr resolved_type = @@ -621,8 +613,7 @@ util::Status ProtoStreamObjectSource::RenderAny( if (!resolved_type.ok()) { // Convert into an internal error, since this means the backend gave us // an invalid response (missing or invalid type information). - return util::Status(util::error::INTERNAL, - resolved_type.status().message()); + return util::InternalError(resolved_type.status().message()); } // nested_type cannot be null at this time. const google::protobuf::Type* nested_type = resolved_type.value(); @@ -659,8 +650,7 @@ util::Status ProtoStreamObjectSource::RenderFieldMask( } } if (paths_field_tag != tag) { - return util::Status(util::error::INTERNAL, - "Invalid FieldMask, unexpected field."); + return util::InternalError("Invalid FieldMask, unexpected field."); } std::string str; os->stream_->ReadVarint32(&buffer32); // string size. @@ -744,8 +734,7 @@ util::Status ProtoStreamObjectSource::RenderField( const google::protobuf::Type* type = typeinfo_->GetTypeByTypeUrl(field->type_url()); if (type == nullptr) { - return util::Status( - util::error::INTERNAL, + return util::InternalError( StrCat("Invalid configuration. Could not find the type: ", field->type_url())); } @@ -762,8 +751,7 @@ util::Status ProtoStreamObjectSource::RenderField( --recursion_depth_; if (!stream_->ConsumedEntireMessage()) { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( "Nested protocol message not parsed in its entirety."); } stream_->PopLimit(old_limit); @@ -1062,8 +1050,7 @@ std::pair ProtoStreamObjectSource::ReadSecondsAndNanos( util::Status ProtoStreamObjectSource::IncrementRecursionDepth( StringPiece type_name, StringPiece field_name) const { if (++recursion_depth_ > max_recursion_depth_) { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat("Message too deep. Max recursion depth reached for type '", type_name, "', field '", field_name, "'")); } diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index 441e4fd162..60eaf4e1d8 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h @@ -287,7 +287,7 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { const google::protobuf::Type& type) const; // Helper function to check recursion depth and increment it. It will return - // Status::OK if the current depth is allowed. Otherwise an error is returned. + // OkStatus() if the current depth is allowed. Otherwise an error is returned. // type_name and field_name are used for error reporting. util::Status IncrementRecursionDepth(StringPiece type_name, StringPiece field_name) const; diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc index 5bd5a91020..6ea8b29fd7 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -597,7 +597,7 @@ TEST_P(ProtostreamObjectSourceTest, CyclicMessageDepthTest) { } util::Status status = ExecuteTest(cyclic, Cyclic::descriptor()); - EXPECT_EQ(util::error::INVALID_ARGUMENT, status.code()); + EXPECT_TRUE(util::IsInvalidArgument(status)); } class ProtostreamObjectSourceMapsTest : public ProtostreamObjectSourceTest { @@ -943,7 +943,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, MissingTypeUrlError) { ow_.StartObject(""); util::Status status = ExecuteTest(out, AnyOut::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeServiceError) { @@ -959,7 +959,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeServiceError) { ow_.StartObject(""); util::Status status = ExecuteTest(out, AnyOut::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeError) { @@ -975,7 +975,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeError) { ow_.StartObject(""); util::Status status = ExecuteTest(out, AnyOut::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } class ProtostreamObjectSourceStructTest : public ProtostreamObjectSourceTest { @@ -1108,7 +1108,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampBelowMinTest) { ow_.StartObject(""); util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampAboveMaxTest) { @@ -1119,7 +1119,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampAboveMaxTest) { ow_.StartObject(""); util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationBelowMinTest) { @@ -1130,7 +1130,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationBelowMinTest) { ow_.StartObject(""); util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationAboveMaxTest) { @@ -1141,7 +1141,7 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationAboveMaxTest) { ow_.StartObject(""); util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); - EXPECT_EQ(util::error::INTERNAL, status.code()); + EXPECT_TRUE(util::IsInternal(status)); } TEST_P(ProtostreamObjectSourceTimestampTest, TimestampDurationDefaultValue) { diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index 56ca3caed7..772e6985d9 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -59,7 +59,6 @@ namespace converter { using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; using std::placeholders::_1; using util::Status; -using util::error::INVALID_ARGUMENT; ProtoStreamObjectWriter::ProtoStreamObjectWriter( @@ -144,14 +143,14 @@ Status GetNanosFromStringPiece(StringPiece s_nanos, // conversion to 'nanos', rather than a double, so that there is no // loss of precision. if (!s_nanos.empty() && !safe_strto32(s_nanos, &i_nanos)) { - return Status(util::error::INVALID_ARGUMENT, parse_failure_message); + return util::InvalidArgumentError(parse_failure_message); } if (i_nanos > kNanosPerSecond || i_nanos < 0) { - return Status(util::error::INVALID_ARGUMENT, exceeded_limit_message); + return util::InvalidArgumentError(exceeded_limit_message); } // s_nanos should only have digits. No whitespace. if (s_nanos.find_first_not_of("0123456789") != StringPiece::npos) { - return Status(util::error::INVALID_ARGUMENT, parse_failure_message); + return util::InvalidArgumentError(parse_failure_message); } if (i_nanos > 0) { @@ -191,8 +190,7 @@ Status GetNanosFromStringPiece(StringPiece s_nanos, conversion = 1; break; default: - return Status(util::error::INVALID_ARGUMENT, - exceeded_limit_message); + return util::InvalidArgumentError(exceeded_limit_message); } *nanos = i_nanos * conversion; } @@ -1013,9 +1011,9 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, break; } default: { - return Status(util::error::INVALID_ARGUMENT, - "Invalid struct data type. Only number, string, boolean or " - "null values are supported."); + return util::InvalidArgumentError( + "Invalid struct data type. Only number, string, boolean or null " + "values are supported."); } } ow->ProtoWriter::RenderDataPiece(struct_field_name, data); @@ -1026,9 +1024,10 @@ Status ProtoStreamObjectWriter::RenderTimestamp(ProtoStreamObjectWriter* ow, const DataPiece& data) { if (data.type() == DataPiece::TYPE_NULL) return Status(); if (data.type() != DataPiece::TYPE_STRING) { - return Status(util::error::INVALID_ARGUMENT, - StrCat("Invalid data type for timestamp, value is ", - data.ValueAsStringOrDefault(""))); + return util::InvalidArgumentError( + StrCat( + "Invalid data type for timestamp, value is ", + data.ValueAsStringOrDefault(""))); } StringPiece value(data.str()); @@ -1037,7 +1036,7 @@ Status ProtoStreamObjectWriter::RenderTimestamp(ProtoStreamObjectWriter* ow, int32 nanos; if (!::google::protobuf::internal::ParseTime(value.ToString(), &seconds, &nanos)) { - return Status(INVALID_ARGUMENT, StrCat("Invalid time format: ", value)); + return util::InvalidArgumentError(StrCat("Invalid time format: ", value)); } @@ -1057,9 +1056,10 @@ Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow, const DataPiece& data) { if (data.type() == DataPiece::TYPE_NULL) return Status(); if (data.type() != DataPiece::TYPE_STRING) { - return Status(util::error::INVALID_ARGUMENT, - StrCat("Invalid data type for field mask, value is ", - data.ValueAsStringOrDefault(""))); + return util::InvalidArgumentError( + StrCat( + "Invalid data type for field mask, value is ", + data.ValueAsStringOrDefault(""))); } // TODO(tsun): figure out how to do proto descriptor based snake case @@ -1073,16 +1073,17 @@ Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow, const DataPiece& data) { if (data.type() == DataPiece::TYPE_NULL) return Status(); if (data.type() != DataPiece::TYPE_STRING) { - return Status(util::error::INVALID_ARGUMENT, - StrCat("Invalid data type for duration, value is ", - data.ValueAsStringOrDefault(""))); + return util::InvalidArgumentError( + StrCat( + "Invalid data type for duration, value is ", + data.ValueAsStringOrDefault(""))); } StringPiece value(data.str()); if (!HasSuffixString(value, "s")) { - return Status(util::error::INVALID_ARGUMENT, - "Illegal duration format; duration must end with 's'"); + return util::InvalidArgumentError( + "Illegal duration format; duration must end with 's'"); } value = value.substr(0, value.size() - 1); int sign = 1; @@ -1095,8 +1096,8 @@ Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow, SplitSecondsAndNanos(value, &s_secs, &s_nanos); uint64_t unsigned_seconds; if (!safe_strtou64(s_secs, &unsigned_seconds)) { - return Status(util::error::INVALID_ARGUMENT, - "Invalid duration format, failed to parse seconds"); + return util::InvalidArgumentError( + "Invalid duration format, failed to parse seconds"); } int32_t nanos = 0; @@ -1111,8 +1112,7 @@ Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow, int64_t seconds = sign * unsigned_seconds; if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds || nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { - return Status(util::error::INVALID_ARGUMENT, - "Duration value exceeds limits"); + return util::InvalidArgumentError("Duration value exceeds limits"); } ow->ProtoWriter::RenderDataPiece("seconds", DataPiece(seconds)); diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc index eb81b65e1a..2e7b78d039 100644 --- a/src/google/protobuf/util/json_util.cc +++ b/src/google/protobuf/util/json_util.cc @@ -140,25 +140,23 @@ class StatusErrorListener : public converter::ErrorListener { if (!loc_string.empty()) { loc_string.append(" "); } - status_ = - util::Status(util::error::INVALID_ARGUMENT, - StrCat(loc_string, unknown_name, ": ", message)); + status_ = util::InvalidArgumentError( + StrCat(loc_string, unknown_name, ": ", message)); } void InvalidValue(const converter::LocationTrackerInterface& loc, StringPiece type_name, StringPiece value) override { - status_ = util::Status( - util::error::INVALID_ARGUMENT, + status_ = util::InvalidArgumentError( StrCat(GetLocString(loc), ": invalid value ", std::string(value), " for type ", std::string(type_name))); } void MissingField(const converter::LocationTrackerInterface& loc, StringPiece missing_name) override { - status_ = util::Status(util::error::INVALID_ARGUMENT, - StrCat(GetLocString(loc), ": missing field ", - std::string(missing_name))); + status_ = util::InvalidArgumentError( + StrCat( + GetLocString(loc), ": missing field ", std::string(missing_name))); } private: @@ -271,8 +269,8 @@ util::Status JsonStringToMessage(StringPiece input, Message* message, util::Status result = JsonToBinaryString(resolver, GetTypeUrl(*message), input, &binary, options); if (result.ok() && !message->ParseFromString(binary)) { - result = util::Status(util::error::INVALID_ARGUMENT, - "JSON transcoder produced invalid protobuf output."); + result = util::InvalidArgumentError( + "JSON transcoder produced invalid protobuf output."); } if (pool != DescriptorPool::generated_pool()) { delete resolver; diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 9851cc5d7f..3ffe73ef6b 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -632,8 +632,7 @@ TEST_F(JsonUtilTest, TestWrongJsonInput) { delete resolver; EXPECT_FALSE(result_status.ok()); - EXPECT_EQ(result_status.code(), - util::error::INVALID_ARGUMENT); + EXPECT_TRUE(util::IsInvalidArgument(result_status)); } TEST_F(JsonUtilTest, HtmlEscape) { diff --git a/src/google/protobuf/util/type_resolver_util.cc b/src/google/protobuf/util/type_resolver_util.cc index addb33499a..80fe3411d2 100644 --- a/src/google/protobuf/util/type_resolver_util.cc +++ b/src/google/protobuf/util/type_resolver_util.cc @@ -64,9 +64,6 @@ using google::protobuf::Type; using google::protobuf::UInt32Value; using google::protobuf::UInt64Value; -using util::error::INVALID_ARGUMENT; -using util::error::NOT_FOUND; - class DescriptorPoolTypeResolver : public TypeResolver { public: DescriptorPoolTypeResolver(const std::string& url_prefix, @@ -83,8 +80,8 @@ class DescriptorPoolTypeResolver : public TypeResolver { const Descriptor* descriptor = pool_->FindMessageTypeByName(type_name); if (descriptor == NULL) { - return util::Status(util::error::NOT_FOUND, - "Invalid type URL, unknown type: " + type_name); + return util::NotFoundError( + "Invalid type URL, unknown type: " + type_name); } ConvertDescriptor(descriptor, type); return util::Status(); @@ -100,8 +97,8 @@ class DescriptorPoolTypeResolver : public TypeResolver { const EnumDescriptor* descriptor = pool_->FindEnumTypeByName(type_name); if (descriptor == NULL) { - return util::Status(util::error::NOT_FOUND, - "Invalid type URL, unknown type: " + type_name); + return util::InvalidArgumentError( + "Invalid type URL, unknown type: " + type_name); } ConvertEnumDescriptor(descriptor, enum_type); return util::Status(); @@ -309,8 +306,7 @@ class DescriptorPoolTypeResolver : public TypeResolver { util::Status ParseTypeUrl(const std::string& type_url, std::string* type_name) { if (type_url.substr(0, url_prefix_.size() + 1) != url_prefix_ + "/") { - return util::Status( - util::error::INVALID_ARGUMENT, + return util::InvalidArgumentError( StrCat("Invalid type URL, type URLs must be of the form '", url_prefix_, "/', got: ", type_url)); } From b4cddb71d604e52bddd6bf7d2d8311ef11a78dd4 Mon Sep 17 00:00:00 2001 From: Maxim Reznik Date: Tue, 16 Mar 2021 18:44:23 +0200 Subject: [PATCH 64/80] Add protobuf for Ada --- docs/third_party.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/third_party.md b/docs/third_party.md index 6b0e2710f0..9d490c0a6e 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -11,6 +11,7 @@ These are projects we know about implementing Protocol Buffers for other program * Action Script: https://code.google.com/p/protoc-gen-as3/ * Action Script: https://github.com/matrix3d/JProtoc * Action Script: https://github.com/zhongfq/protobuf-as3/ +* Ada: https://github.com/reznikmm/protobuf * C: https://github.com/protobuf-c/protobuf-c * C: http://koti.kapsi.fi/jpa/nanopb/ * C: https://github.com/cloudwu/pbc/ From 57e09ad84867f88792489b459caddb6482476b0d Mon Sep 17 00:00:00 2001 From: Steve Rago Date: Wed, 17 Mar 2021 10:31:03 -0400 Subject: [PATCH 65/80] add error returns missing from protoc to prevent it from exiting with a successful return value when writing the zip file fails --- src/google/protobuf/compiler/command_line_interface.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index b0b2963d2d..3705e369c6 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -586,10 +586,12 @@ bool CommandLineInterface::GeneratorContextImpl::WriteAllToZip( if (stream.GetErrno() != 0) { std::cerr << filename << ": " << strerror(stream.GetErrno()) << std::endl; + return false; } if (!stream.Close()) { std::cerr << filename << ": " << strerror(stream.GetErrno()) << std::endl; + return false; } return true; From 53b0cce27b0d0b3b894bf7a599cf0c9133c7ddd8 Mon Sep 17 00:00:00 2001 From: Levon Ter-Grigoryan Date: Tue, 16 Mar 2021 21:15:31 +0100 Subject: [PATCH 66/80] Fix -Wsuggest-destructor-override for generated C++ proto classes. --- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 6 +-- .../protobuf/compiler/cpp/cpp_message.cc | 2 +- src/google/protobuf/compiler/plugin.pb.h | 8 +-- src/google/protobuf/descriptor.pb.h | 54 +++++++++---------- 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/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 6 +-- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 10 ++-- src/google/protobuf/wrappers.pb.h | 18 +++---- 13 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index a08f962f78..3113a79b2b 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -69,7 +69,7 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { public: inline Any() : Any(nullptr) {} - virtual ~Any(); + ~Any() override; explicit constexpr Any(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Any(const Any& from); diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 8e5ebf8500..5abbe170ee 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -79,7 +79,7 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { public: inline Api() : Api(nullptr) {} - virtual ~Api(); + ~Api() override; explicit constexpr Api(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Api(const Api& from); @@ -322,7 +322,7 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { public: inline Method() : Method(nullptr) {} - virtual ~Method(); + ~Method() override; explicit constexpr Method(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Method(const Method& from); @@ -543,7 +543,7 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { public: inline Mixin() : Mixin(nullptr) {} - virtual ~Mixin(); + ~Mixin() override; explicit constexpr Mixin(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Mixin(const Mixin& from); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 73e66ae90f..8a43bbcb1a 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -1092,7 +1092,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { format( "inline $classname$() : $classname$(nullptr) {}\n" - "virtual ~$classname$();\n" + "~$classname$() override;\n" "explicit constexpr " "$classname$(::$proto_ns$::internal::ConstantInitialized);\n" "\n" diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 6f59291f88..d620297210 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -115,7 +115,7 @@ class PROTOC_EXPORT Version PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { public: inline Version() : Version(nullptr) {} - virtual ~Version(); + ~Version() override; explicit constexpr Version(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Version(const Version& from); @@ -308,7 +308,7 @@ class PROTOC_EXPORT CodeGeneratorRequest PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { public: inline CodeGeneratorRequest() : CodeGeneratorRequest(nullptr) {} - virtual ~CodeGeneratorRequest(); + ~CodeGeneratorRequest() override; explicit constexpr CodeGeneratorRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); CodeGeneratorRequest(const CodeGeneratorRequest& from); @@ -522,7 +522,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { public: inline CodeGeneratorResponse_File() : CodeGeneratorResponse_File(nullptr) {} - virtual ~CodeGeneratorResponse_File(); + ~CodeGeneratorResponse_File() override; explicit constexpr CodeGeneratorResponse_File(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); CodeGeneratorResponse_File(const CodeGeneratorResponse_File& from); @@ -730,7 +730,7 @@ class PROTOC_EXPORT CodeGeneratorResponse PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { public: inline CodeGeneratorResponse() : CodeGeneratorResponse(nullptr) {} - virtual ~CodeGeneratorResponse(); + ~CodeGeneratorResponse() override; explicit constexpr CodeGeneratorResponse(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); CodeGeneratorResponse(const CodeGeneratorResponse& from); diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index e00562b314..466226bff7 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -333,7 +333,7 @@ class PROTOBUF_EXPORT FileDescriptorSet PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorSet) */ { public: inline FileDescriptorSet() : FileDescriptorSet(nullptr) {} - virtual ~FileDescriptorSet(); + ~FileDescriptorSet() override; explicit constexpr FileDescriptorSet(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FileDescriptorSet(const FileDescriptorSet& from); @@ -480,7 +480,7 @@ class PROTOBUF_EXPORT FileDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorProto) */ { public: inline FileDescriptorProto() : FileDescriptorProto(nullptr) {} - virtual ~FileDescriptorProto(); + ~FileDescriptorProto() override; explicit constexpr FileDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FileDescriptorProto(const FileDescriptorProto& from); @@ -862,7 +862,7 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ExtensionRange) */ { public: inline DescriptorProto_ExtensionRange() : DescriptorProto_ExtensionRange(nullptr) {} - virtual ~DescriptorProto_ExtensionRange(); + ~DescriptorProto_ExtensionRange() override; explicit constexpr DescriptorProto_ExtensionRange(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); DescriptorProto_ExtensionRange(const DescriptorProto_ExtensionRange& from); @@ -1040,7 +1040,7 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ReservedRange) */ { public: inline DescriptorProto_ReservedRange() : DescriptorProto_ReservedRange(nullptr) {} - virtual ~DescriptorProto_ReservedRange(); + ~DescriptorProto_ReservedRange() override; explicit constexpr DescriptorProto_ReservedRange(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); DescriptorProto_ReservedRange(const DescriptorProto_ReservedRange& from); @@ -1198,7 +1198,7 @@ class PROTOBUF_EXPORT DescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto) */ { public: inline DescriptorProto() : DescriptorProto(nullptr) {} - virtual ~DescriptorProto(); + ~DescriptorProto() override; explicit constexpr DescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); DescriptorProto(const DescriptorProto& from); @@ -1535,7 +1535,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ExtensionRangeOptions) */ { public: inline ExtensionRangeOptions() : ExtensionRangeOptions(nullptr) {} - virtual ~ExtensionRangeOptions(); + ~ExtensionRangeOptions() override; explicit constexpr ExtensionRangeOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); ExtensionRangeOptions(const ExtensionRangeOptions& from); @@ -1685,7 +1685,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldDescriptorProto) */ { public: inline FieldDescriptorProto() : FieldDescriptorProto(nullptr) {} - virtual ~FieldDescriptorProto(); + ~FieldDescriptorProto() override; explicit constexpr FieldDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FieldDescriptorProto(const FieldDescriptorProto& from); @@ -2102,7 +2102,7 @@ class PROTOBUF_EXPORT OneofDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofDescriptorProto) */ { public: inline OneofDescriptorProto() : OneofDescriptorProto(nullptr) {} - virtual ~OneofDescriptorProto(); + ~OneofDescriptorProto() override; explicit constexpr OneofDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); OneofDescriptorProto(const OneofDescriptorProto& from); @@ -2270,7 +2270,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto.EnumReservedRange) */ { public: inline EnumDescriptorProto_EnumReservedRange() : EnumDescriptorProto_EnumReservedRange(nullptr) {} - virtual ~EnumDescriptorProto_EnumReservedRange(); + ~EnumDescriptorProto_EnumReservedRange() override; explicit constexpr EnumDescriptorProto_EnumReservedRange(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); EnumDescriptorProto_EnumReservedRange(const EnumDescriptorProto_EnumReservedRange& from); @@ -2428,7 +2428,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto) */ { public: inline EnumDescriptorProto() : EnumDescriptorProto(nullptr) {} - virtual ~EnumDescriptorProto(); + ~EnumDescriptorProto() override; explicit constexpr EnumDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); EnumDescriptorProto(const EnumDescriptorProto& from); @@ -2664,7 +2664,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueDescriptorProto) */ { public: inline EnumValueDescriptorProto() : EnumValueDescriptorProto(nullptr) {} - virtual ~EnumValueDescriptorProto(); + ~EnumValueDescriptorProto() override; explicit constexpr EnumValueDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); EnumValueDescriptorProto(const EnumValueDescriptorProto& from); @@ -2847,7 +2847,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceDescriptorProto) */ { public: inline ServiceDescriptorProto() : ServiceDescriptorProto(nullptr) {} - virtual ~ServiceDescriptorProto(); + ~ServiceDescriptorProto() override; explicit constexpr ServiceDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); ServiceDescriptorProto(const ServiceDescriptorProto& from); @@ -3035,7 +3035,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodDescriptorProto) */ { public: inline MethodDescriptorProto() : MethodDescriptorProto(nullptr) {} - virtual ~MethodDescriptorProto(); + ~MethodDescriptorProto() override; explicit constexpr MethodDescriptorProto(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); MethodDescriptorProto(const MethodDescriptorProto& from); @@ -3273,7 +3273,7 @@ class PROTOBUF_EXPORT FileOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileOptions) */ { public: inline FileOptions() : FileOptions(nullptr) {} - virtual ~FileOptions(); + ~FileOptions() override; explicit constexpr FileOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FileOptions(const FileOptions& from); @@ -3806,7 +3806,7 @@ class PROTOBUF_EXPORT MessageOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MessageOptions) */ { public: inline MessageOptions() : MessageOptions(nullptr) {} - virtual ~MessageOptions(); + ~MessageOptions() override; explicit constexpr MessageOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); MessageOptions(const MessageOptions& from); @@ -4017,7 +4017,7 @@ class PROTOBUF_EXPORT FieldOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldOptions) */ { public: inline FieldOptions() : FieldOptions(nullptr) {} - virtual ~FieldOptions(); + ~FieldOptions() override; explicit constexpr FieldOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FieldOptions(const FieldOptions& from); @@ -4322,7 +4322,7 @@ class PROTOBUF_EXPORT OneofOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofOptions) */ { public: inline OneofOptions() : OneofOptions(nullptr) {} - virtual ~OneofOptions(); + ~OneofOptions() override; explicit constexpr OneofOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); OneofOptions(const OneofOptions& from); @@ -4472,7 +4472,7 @@ class PROTOBUF_EXPORT EnumOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumOptions) */ { public: inline EnumOptions() : EnumOptions(nullptr) {} - virtual ~EnumOptions(); + ~EnumOptions() override; explicit constexpr EnumOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); EnumOptions(const EnumOptions& from); @@ -4653,7 +4653,7 @@ class PROTOBUF_EXPORT EnumValueOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueOptions) */ { public: inline EnumValueOptions() : EnumValueOptions(nullptr) {} - virtual ~EnumValueOptions(); + ~EnumValueOptions() override; explicit constexpr EnumValueOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); EnumValueOptions(const EnumValueOptions& from); @@ -4819,7 +4819,7 @@ class PROTOBUF_EXPORT ServiceOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceOptions) */ { public: inline ServiceOptions() : ServiceOptions(nullptr) {} - virtual ~ServiceOptions(); + ~ServiceOptions() override; explicit constexpr ServiceOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); ServiceOptions(const ServiceOptions& from); @@ -4985,7 +4985,7 @@ class PROTOBUF_EXPORT MethodOptions PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodOptions) */ { public: inline MethodOptions() : MethodOptions(nullptr) {} - virtual ~MethodOptions(); + ~MethodOptions() override; explicit constexpr MethodOptions(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); MethodOptions(const MethodOptions& from); @@ -5198,7 +5198,7 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption.NamePart) */ { public: inline UninterpretedOption_NamePart() : UninterpretedOption_NamePart(nullptr) {} - virtual ~UninterpretedOption_NamePart(); + ~UninterpretedOption_NamePart() override; explicit constexpr UninterpretedOption_NamePart(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); UninterpretedOption_NamePart(const UninterpretedOption_NamePart& from); @@ -5364,7 +5364,7 @@ class PROTOBUF_EXPORT UninterpretedOption PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption) */ { public: inline UninterpretedOption() : UninterpretedOption(nullptr) {} - virtual ~UninterpretedOption(); + ~UninterpretedOption() override; explicit constexpr UninterpretedOption(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); UninterpretedOption(const UninterpretedOption& from); @@ -5619,7 +5619,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo.Location) */ { public: inline SourceCodeInfo_Location() : SourceCodeInfo_Location(nullptr) {} - virtual ~SourceCodeInfo_Location(); + ~SourceCodeInfo_Location() override; explicit constexpr SourceCodeInfo_Location(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); SourceCodeInfo_Location(const SourceCodeInfo_Location& from); @@ -5863,7 +5863,7 @@ class PROTOBUF_EXPORT SourceCodeInfo PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo) */ { public: inline SourceCodeInfo() : SourceCodeInfo(nullptr) {} - virtual ~SourceCodeInfo(); + ~SourceCodeInfo() override; explicit constexpr SourceCodeInfo(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); SourceCodeInfo(const SourceCodeInfo& from); @@ -6012,7 +6012,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo.Annotation) */ { public: inline GeneratedCodeInfo_Annotation() : GeneratedCodeInfo_Annotation(nullptr) {} - virtual ~GeneratedCodeInfo_Annotation(); + ~GeneratedCodeInfo_Annotation() override; explicit constexpr GeneratedCodeInfo_Annotation(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); GeneratedCodeInfo_Annotation(const GeneratedCodeInfo_Annotation& from); @@ -6215,7 +6215,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo) */ { public: inline GeneratedCodeInfo() : GeneratedCodeInfo(nullptr) {} - virtual ~GeneratedCodeInfo(); + ~GeneratedCodeInfo() override; explicit constexpr GeneratedCodeInfo(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); GeneratedCodeInfo(const GeneratedCodeInfo& from); diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 598a608f2f..e584d67c41 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -69,7 +69,7 @@ class PROTOBUF_EXPORT Duration PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Duration) */ { public: inline Duration() : Duration(nullptr) {} - virtual ~Duration(); + ~Duration() override; explicit constexpr Duration(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Duration(const Duration& from); diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 392550d786..123d58afc8 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -69,7 +69,7 @@ class PROTOBUF_EXPORT Empty PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Empty) */ { public: inline Empty() : Empty(nullptr) {} - virtual ~Empty(); + ~Empty() override; explicit constexpr Empty(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Empty(const Empty& from); diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 03789f3bec..02553ca376 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -69,7 +69,7 @@ class PROTOBUF_EXPORT FieldMask PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldMask) */ { public: inline FieldMask() : FieldMask(nullptr) {} - virtual ~FieldMask(); + ~FieldMask() override; explicit constexpr FieldMask(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FieldMask(const FieldMask& from); diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 9edacf4e2f..d11218150e 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -69,7 +69,7 @@ class PROTOBUF_EXPORT SourceContext PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceContext) */ { public: inline SourceContext() : SourceContext(nullptr) {} - virtual ~SourceContext(); + ~SourceContext() override; explicit constexpr SourceContext(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); SourceContext(const SourceContext& from); diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index fea5719ae8..dd56d9bd98 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -134,7 +134,7 @@ class PROTOBUF_EXPORT Struct PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Struct) */ { public: inline Struct() : Struct(nullptr) {} - virtual ~Struct(); + ~Struct() override; explicit constexpr Struct(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Struct(const Struct& from); @@ -278,7 +278,7 @@ class PROTOBUF_EXPORT Value PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Value) */ { public: inline Value() : Value(nullptr) {} - virtual ~Value(); + ~Value() override; explicit constexpr Value(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Value(const Value& from); @@ -530,7 +530,7 @@ class PROTOBUF_EXPORT ListValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ListValue) */ { public: inline ListValue() : ListValue(nullptr) {} - virtual ~ListValue(); + ~ListValue() override; explicit constexpr ListValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); ListValue(const ListValue& from); diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 1ab2211bb6..ed4d23a70a 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -69,7 +69,7 @@ class PROTOBUF_EXPORT Timestamp PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Timestamp) */ { public: inline Timestamp() : Timestamp(nullptr) {} - virtual ~Timestamp(); + ~Timestamp() override; explicit constexpr Timestamp(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Timestamp(const Timestamp& from); diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index ea8a1359f2..fabd21185c 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -182,7 +182,7 @@ class PROTOBUF_EXPORT Type PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Type) */ { public: inline Type() : Type(nullptr) {} - virtual ~Type(); + ~Type() override; explicit constexpr Type(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Type(const Type& from); @@ -415,7 +415,7 @@ class PROTOBUF_EXPORT Field PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Field) */ { public: inline Field() : Field(nullptr) {} - virtual ~Field(); + ~Field() override; explicit constexpr Field(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Field(const Field& from); @@ -772,7 +772,7 @@ class PROTOBUF_EXPORT Enum PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Enum) */ { public: inline Enum() : Enum(nullptr) {} - virtual ~Enum(); + ~Enum() override; explicit constexpr Enum(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Enum(const Enum& from); @@ -979,7 +979,7 @@ class PROTOBUF_EXPORT EnumValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValue) */ { public: inline EnumValue() : EnumValue(nullptr) {} - virtual ~EnumValue(); + ~EnumValue() override; explicit constexpr EnumValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); EnumValue(const EnumValue& from); @@ -1146,7 +1146,7 @@ class PROTOBUF_EXPORT Option PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Option) */ { public: inline Option() : Option(nullptr) {} - virtual ~Option(); + ~Option() override; explicit constexpr Option(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Option(const Option& from); diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index a3bbd8550d..2d7963bf3f 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -101,7 +101,7 @@ class PROTOBUF_EXPORT DoubleValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DoubleValue) */ { public: inline DoubleValue() : DoubleValue(nullptr) {} - virtual ~DoubleValue(); + ~DoubleValue() override; explicit constexpr DoubleValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); DoubleValue(const DoubleValue& from); @@ -232,7 +232,7 @@ class PROTOBUF_EXPORT FloatValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FloatValue) */ { public: inline FloatValue() : FloatValue(nullptr) {} - virtual ~FloatValue(); + ~FloatValue() override; explicit constexpr FloatValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); FloatValue(const FloatValue& from); @@ -363,7 +363,7 @@ class PROTOBUF_EXPORT Int64Value PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int64Value) */ { public: inline Int64Value() : Int64Value(nullptr) {} - virtual ~Int64Value(); + ~Int64Value() override; explicit constexpr Int64Value(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Int64Value(const Int64Value& from); @@ -494,7 +494,7 @@ class PROTOBUF_EXPORT UInt64Value PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt64Value) */ { public: inline UInt64Value() : UInt64Value(nullptr) {} - virtual ~UInt64Value(); + ~UInt64Value() override; explicit constexpr UInt64Value(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); UInt64Value(const UInt64Value& from); @@ -625,7 +625,7 @@ class PROTOBUF_EXPORT Int32Value PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int32Value) */ { public: inline Int32Value() : Int32Value(nullptr) {} - virtual ~Int32Value(); + ~Int32Value() override; explicit constexpr Int32Value(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); Int32Value(const Int32Value& from); @@ -756,7 +756,7 @@ class PROTOBUF_EXPORT UInt32Value PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt32Value) */ { public: inline UInt32Value() : UInt32Value(nullptr) {} - virtual ~UInt32Value(); + ~UInt32Value() override; explicit constexpr UInt32Value(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); UInt32Value(const UInt32Value& from); @@ -887,7 +887,7 @@ class PROTOBUF_EXPORT BoolValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BoolValue) */ { public: inline BoolValue() : BoolValue(nullptr) {} - virtual ~BoolValue(); + ~BoolValue() override; explicit constexpr BoolValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); BoolValue(const BoolValue& from); @@ -1018,7 +1018,7 @@ class PROTOBUF_EXPORT StringValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.StringValue) */ { public: inline StringValue() : StringValue(nullptr) {} - virtual ~StringValue(); + ~StringValue() override; explicit constexpr StringValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); StringValue(const StringValue& from); @@ -1154,7 +1154,7 @@ class PROTOBUF_EXPORT BytesValue PROTOBUF_FINAL : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BytesValue) */ { public: inline BytesValue() : BytesValue(nullptr) {} - virtual ~BytesValue(); + ~BytesValue() override; explicit constexpr BytesValue(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); BytesValue(const BytesValue& from); From 96307d28f69662eb04edcaeb9d1d1ed25e692d88 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 22 Mar 2021 13:05:55 -0700 Subject: [PATCH 67/80] Sync from Piper @364389596 PROTOBUF_SYNC_PIPER --- .github/mergeable.yml | 4 +- BUILD | 44 +--- CHANGES.txt | 43 ++++ Makefile.am | 1 - Protobuf.podspec | 2 +- WORKSPACE | 21 +- benchmarks/BUILD | 65 ++++++ benchmarks/cpp/BUILD | 15 ++ benchmarks/datasets/BUILD | 59 +++++ .../datasets/google_message1/proto2/BUILD | 44 ++++ .../datasets/google_message1/proto3/BUILD | 44 ++++ benchmarks/datasets/google_message2/BUILD | 44 ++++ benchmarks/datasets/google_message3/BUILD | 50 ++++ benchmarks/datasets/google_message4/BUILD | 45 ++++ conformance/text_format_conformance_suite.cc | 21 ++ csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 340024 -> 340187 bytes .../Google.Protobuf/Google.Protobuf.csproj | 2 +- .../Google.Protobuf/Reflection/Descriptor.cs | 95 ++++---- docs/implementing_proto3_presence.md | 4 +- docs/options.md | 8 + docs/third_party.md | 2 +- java/README.md | 4 +- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- .../java/com/google/protobuf/ByteString.java | 6 +- .../com/google/protobuf/RopeByteString.java | 7 +- .../google/protobuf/AbstractMessageTest.java | 4 +- .../google/protobuf/DynamicMessageTest.java | 2 +- .../google/protobuf/GeneratedMessageTest.java | 1 + .../com/google/protobuf/MapForProto2Test.java | 4 +- .../java/com/google/protobuf/MapTest.java | 4 +- .../google/protobuf/TestBadIdentifiers.java | 6 +- .../protobuf/TestBadIdentifiersLite.java | 6 +- .../protobuf/test_extra_interfaces.proto | 56 ----- java/lite/generate-test-sources-build.xml | 1 + java/lite/pom.xml | 2 +- .../java/com/google/protobuf/LiteTest.java | 38 ++-- java/pom.xml | 6 +- java/util/pom.xml | 2 +- kokoro/release/protoc/linux/build.sh | 2 +- php/ext/google/protobuf/message.c | 2 +- php/ext/google/protobuf/package.xml | 63 ++++-- php/ext/google/protobuf/php-upb.c | 3 +- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/README.md | 2 +- protoc-artifacts/build-protoc.sh | 6 +- protoc-artifacts/build-zip.sh | 4 +- protoc-artifacts/pom.xml | 6 +- .../protobuf/internal/text_format_test.py | 55 +++++ python/google/protobuf/pyext/descriptor.cc | 15 +- .../protobuf/pyext/descriptor_database.cc | 4 +- .../google/protobuf/pyext/extension_dict.cc | 6 +- python/google/protobuf/pyext/map_container.cc | 7 +- python/google/protobuf/pyext/map_container.h | 3 +- python/google/protobuf/pyext/message.cc | 9 +- python/google/protobuf/pyext/message.h | 9 +- .../pyext/repeated_scalar_container.cc | 9 +- python/google/protobuf/text_format.py | 4 +- python/tox.ini | 7 +- .../v3.0.0/tests/repeated_field_test.rb | 12 - ruby/ext/google/protobuf_c/convert.c | 2 +- ruby/ext/google/protobuf_c/message.c | 4 +- ruby/ext/google/protobuf_c/protobuf.c | 6 +- ruby/ext/google/protobuf_c/ruby-upb.c | 3 +- ruby/google-protobuf.gemspec | 2 +- ruby/tests/basic.rb | 11 +- ruby/tests/common_tests.rb | 12 + ruby/tests/repeated_field_test.rb | 12 - src/google/protobuf/any.pb.cc | 4 +- src/google/protobuf/api.pb.cc | 12 +- src/google/protobuf/arenastring.cc | 8 + src/google/protobuf/arenastring.h | 12 +- .../protobuf/compiler/annotation_test_util.cc | 5 +- .../compiler/command_line_interface.cc | 4 +- .../compiler/command_line_interface.h | 3 +- .../command_line_interface_unittest.cc | 4 +- src/google/protobuf/compiler/cpp/cpp_enum.cc | 10 +- src/google/protobuf/compiler/cpp/cpp_field.cc | 4 +- src/google/protobuf/compiler/cpp/cpp_field.h | 3 +- .../protobuf/compiler/cpp/cpp_helpers.cc | 40 ++-- .../protobuf/compiler/cpp/cpp_helpers.h | 7 +- .../protobuf/compiler/cpp/cpp_message.cc | 129 ++++++++--- .../protobuf/compiler/cpp/cpp_message.h | 4 +- src/google/protobuf/compiler/cpp/cpp_names.h | 5 + .../compiler/cpp/cpp_primitive_field.cc | 32 +-- .../protobuf/compiler/cpp/cpp_unittest.inc | 52 +++-- .../protobuf/compiler/java/java_enum_field.cc | 6 +- .../compiler/java/java_enum_field_lite.cc | 12 +- .../compiler/java/java_enum_field_lite.h | 8 +- .../protobuf/compiler/java/java_field.h | 3 +- .../protobuf/compiler/java/java_helpers.cc | 17 +- .../protobuf/compiler/java/java_helpers.h | 11 +- .../compiler/java/java_map_field_lite.cc | 4 +- .../compiler/java/java_map_field_lite.h | 4 +- .../protobuf/compiler/java/java_message.cc | 9 +- .../compiler/java/java_message_field_lite.cc | 10 +- .../compiler/java/java_message_field_lite.h | 8 +- .../compiler/java/java_message_lite.cc | 5 +- .../compiler/java/java_primitive_field.cc | 6 +- .../java/java_primitive_field_lite.cc | 9 +- .../compiler/java/java_primitive_field_lite.h | 8 +- .../compiler/java/java_string_field.cc | 6 +- .../compiler/java/java_string_field_lite.cc | 12 +- .../compiler/java/java_string_field_lite.h | 8 +- .../protobuf/compiler/mock_code_generator.cc | 5 +- .../protobuf/compiler/mock_code_generator.h | 5 +- src/google/protobuf/compiler/parser.cc | 53 +++-- src/google/protobuf/compiler/parser.h | 10 +- src/google/protobuf/compiler/plugin.pb.cc | 16 +- src/google/protobuf/compiler/zip_writer.cc | 35 +-- src/google/protobuf/compiler/zip_writer.h | 8 +- src/google/protobuf/descriptor.pb.cc | 213 +++++++++--------- src/google/protobuf/descriptor.proto | 2 + src/google/protobuf/duration.pb.cc | 4 +- src/google/protobuf/empty.pb.cc | 4 +- src/google/protobuf/field_mask.pb.cc | 4 +- src/google/protobuf/io/coded_stream.cc | 20 ++ src/google/protobuf/io/coded_stream.h | 31 ++- src/google/protobuf/message_unittest.inc | 32 +++ src/google/protobuf/parse_context.cc | 12 + src/google/protobuf/parse_context.h | 20 +- src/google/protobuf/repeated_field.h | 51 ++++- .../protobuf/repeated_field_unittest.cc | 87 +++++++ src/google/protobuf/source_context.pb.cc | 4 +- src/google/protobuf/struct.pb.cc | 12 +- src/google/protobuf/timestamp.pb.cc | 4 +- src/google/protobuf/type.pb.cc | 20 +- src/google/protobuf/unittest.proto | 30 +++ src/google/protobuf/util/field_comparator.cc | 43 ++-- src/google/protobuf/util/field_comparator.h | 69 ++++-- src/google/protobuf/util/field_mask_util.cc | 7 +- src/google/protobuf/util/field_mask_util.h | 3 +- .../protobuf/util/field_mask_util_test.cc | 3 +- src/google/protobuf/util/json_util_test.cc | 3 +- .../protobuf/util/message_differencer.cc | 43 ++-- .../protobuf/util/message_differencer.h | 2 +- .../util/message_differencer_unittest.cc | 6 +- src/google/protobuf/util/time_util.cc | 127 ++++++----- src/google/protobuf/util/time_util.h | 59 ++--- src/google/protobuf/util/time_util_test.cc | 24 +- .../protobuf/util/type_resolver_util_test.cc | 5 +- src/google/protobuf/wire_format_lite.h | 2 +- src/google/protobuf/wrappers.pb.cc | 36 +-- 144 files changed, 1781 insertions(+), 867 deletions(-) create mode 100644 benchmarks/BUILD create mode 100644 benchmarks/cpp/BUILD create mode 100644 benchmarks/datasets/BUILD create mode 100644 benchmarks/datasets/google_message1/proto2/BUILD create mode 100644 benchmarks/datasets/google_message1/proto3/BUILD create mode 100644 benchmarks/datasets/google_message2/BUILD create mode 100644 benchmarks/datasets/google_message3/BUILD create mode 100644 benchmarks/datasets/google_message4/BUILD delete mode 100644 java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto diff --git a/.github/mergeable.yml b/.github/mergeable.yml index 8577f086ee..4027cf5a9f 100644 --- a/.github/mergeable.yml +++ b/.github/mergeable.yml @@ -11,8 +11,8 @@ mergeable: regex: 'release notes: yes' message: 'Please include release notes: yes' - must_include: - regex: '^(c#|c\+\+|cleanup|conformance tests|integration|java|javascript|go|objective-c|php|python|ruby|bazel|cmake|protoc)' - message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: bazel, cmake, cleanup, conformance tests, integration, protoc.' + regex: '^(autotools|bazel|c#|c\+\+|cleanup|cmake|conformance tests|integration|go|java|javascript|objective-c|php|protoc|python|ruby)' + message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: autotools, bazel, cmake, cleanup, conformance tests, integration, protoc.' - must_include: regex: 'release notes: no' message: 'Please include release notes: no' diff --git a/BUILD b/BUILD index 1124321602..07ee629a18 100644 --- a/BUILD +++ b/BUILD @@ -14,38 +14,6 @@ exports_files(["LICENSE"]) # build configuration ################################################################################ -# TODO(yannic): Remove in 3.14.0. -string_flag( - name = "incompatible_use_com_google_googletest", - build_setting_default = "true", - values = ["true", "false"] -) - -config_setting( - name = "use_com_google_googletest", - flag_values = { - "//:incompatible_use_com_google_googletest": "true" - }, -) - -GTEST = select({ - "//:use_com_google_googletest": [ - "@com_google_googletest//:gtest", - ], - "//conditions:default": [ - "//external:gtest", - ], -}) - -GTEST_MAIN = select({ - "//:use_com_google_googletest": [ - "@com_google_googletest//:gtest_main", - ], - "//conditions:default": [ - "//external:gtest_main", - ], -}) - ################################################################################ # ZLIB configuration ################################################################################ @@ -571,6 +539,7 @@ COMMON_TEST_SRCS = [ cc_binary( name = "test_plugin", + testonly = True, srcs = [ # AUTOGEN(test_plugin_srcs) "src/google/protobuf/compiler/mock_code_generator.cc", @@ -580,7 +549,8 @@ cc_binary( deps = [ ":protobuf", ":protoc_lib", - ] + GTEST, + "@com_google_googletest//:gtest", + ], ) cc_test( @@ -592,7 +562,9 @@ cc_test( ], deps = [ ":protobuf_lite", - ] + GTEST_MAIN, + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], ) cc_test( @@ -695,7 +667,9 @@ cc_test( ":cc_test_protos", ":protobuf", ":protoc_lib", - ] + PROTOBUF_DEPS + GTEST_MAIN, + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ] + PROTOBUF_DEPS, ) ################################################################################ diff --git a/CHANGES.txt b/CHANGES.txt index d73ef274c5..ef79313b59 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,46 @@ +Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + C++ + * Allow MessageDifferencer::TreatAsSet() (and friends) to override previous + calls instead of crashing. + * Reduce the size of generated proto headers for protos with `string` or + `bytes` fields. + * Move arena() operation on uncommon path to out-of-line routine + * For iterator-pair function parameter types, take both iterators by value. + * Code-space savings and perhaps some modest performance improvements in + RepeatedPtrField. + + Java: + * Exceptions thrown while reading from an InputStream in parseFrom are now included as causes. + +2021-03-10 version 3.15.6 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Fixed bug in string comparison logic (#8386) + +2021-03-04 version 3.15.5 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Fixed quadratic memory use in array append (#8379) + + PHP + * Fixed quadratic memory use in array append (#8379) + + C++ + * Do not disable RTTI by default in the CMake build (#8377) + +2021-03-02 version 3.15.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * Fixed SEGV when users pass nil messages (#8363) + * Fixed quadratic memory usage when appending to arrays (#8364) + + C++ + * Create a CMake option to control whether or not RTTI is enabled (#8361) + + PHP + * read_property() handler is not supposed to return NULL (#8362) + 2021-02-25 version 3.15.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Ruby diff --git a/Makefile.am b/Makefile.am index 53b259480a..915184213c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -529,7 +529,6 @@ java_EXTRA_DIST= java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto \ java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto \ java/core/src/test/proto/com/google/protobuf/test_custom_options.proto \ - java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto \ java/core/src/test/proto/com/google/protobuf/wrappers_test.proto \ java/lite.md \ java/lite/BUILD \ diff --git a/Protobuf.podspec b/Protobuf.podspec index b2958e0283..b61cafc518 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.15.3' + s.version = '3.15.6' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/WORKSPACE b/WORKSPACE index 5a767a97c0..4346dbd906 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,6 +17,15 @@ http_archive( ], ) +http_archive( + name = "com_github_google_benchmark", + sha256 = "2a778d821997df7d8646c9c59b8edb9a573a6e04c534c01892a40aa524a7b68c", + strip_prefix = "benchmark-bf585a2789e30585b4e3ce6baf11ef2750b54677", + urls = [ + "https://github.com/google/benchmark/archive/bf585a2789e30585b4e3ce6baf11ef2750b54677.zip", + ], +) + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("//:protobuf_deps.bzl", "protobuf_deps") @@ -29,18 +38,6 @@ bind( actual = "//util/python:python_headers", ) -# TODO(yannic): Remove in 3.14.0. -bind( - name = "gtest", - actual = "@com_google_googletest//:gtest", -) - -# TODO(yannic): Remove in 3.14.0. -bind( - name = "gtest_main", - actual = "@com_google_googletest//:gtest_main", -) - jvm_maven_import_external( name = "guava_maven", artifact = "com.google.guava:guava:18.0", diff --git a/benchmarks/BUILD b/benchmarks/BUILD new file mode 100644 index 0000000000..8e6063ba83 --- /dev/null +++ b/benchmarks/BUILD @@ -0,0 +1,65 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "benchmarks_proto", + srcs = [ + "benchmarks.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +cc_proto_library( + name = "benchmarks_cc_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "benchmarks_proto", + ], +) + +java_proto_library( + name = "benchmarks_java_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "benchmarks_proto", + ], +) + +proto_library( + name = "google_size_proto", + srcs = [ + "google_size.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +cc_proto_library( + name = "google_size_cc_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "google_size_proto", + ], +) + +java_proto_library( + name = "google_size_java_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "google_size_proto", + ], +) diff --git a/benchmarks/cpp/BUILD b/benchmarks/cpp/BUILD new file mode 100644 index 0000000000..b744f896ad --- /dev/null +++ b/benchmarks/cpp/BUILD @@ -0,0 +1,15 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") + +cc_binary( + name = "cpp", + srcs = [ + "cpp_benchmark.cc", + ], + tags = ["benchmark"], + deps = [ + "//:protobuf", + "//benchmarks:benchmarks_cc_proto", + "//benchmarks/datasets:cc_protos", + "@com_github_google_benchmark//:benchmark_main", + ], +) diff --git a/benchmarks/datasets/BUILD b/benchmarks/datasets/BUILD new file mode 100644 index 0000000000..f29a27650b --- /dev/null +++ b/benchmarks/datasets/BUILD @@ -0,0 +1,59 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_java//java:defs.bzl", "java_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "//benchmarks/datasets/google_message1/proto2:datasets", + "//benchmarks/datasets/google_message1/proto3:datasets", + "//benchmarks/datasets/google_message2:datasets", + "//benchmarks/datasets/google_message3:datasets", + "//benchmarks/datasets/google_message4:datasets", + ], + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +proto_library( + name = "protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_proto", + ], +) + +cc_library( + name = "cc_protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_cc_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_cc_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_cc_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_cc_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_cc_proto", + ], +) + +java_library( + name = "java_protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + exports = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_java_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_java_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_java_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_java_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_java_proto", + ], +) diff --git a/benchmarks/datasets/google_message1/proto2/BUILD b/benchmarks/datasets/google_message1/proto2/BUILD new file mode 100644 index 0000000000..d4d38cec22 --- /dev/null +++ b/benchmarks/datasets/google_message1/proto2/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto2_proto", + srcs = [ + "benchmark_message1_proto2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) diff --git a/benchmarks/datasets/google_message1/proto3/BUILD b/benchmarks/datasets/google_message1/proto3/BUILD new file mode 100644 index 0000000000..c2d627acd8 --- /dev/null +++ b/benchmarks/datasets/google_message1/proto3/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto3.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto3_proto", + srcs = [ + "benchmark_message1_proto3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) diff --git a/benchmarks/datasets/google_message2/BUILD b/benchmarks/datasets/google_message2/BUILD new file mode 100644 index 0000000000..1ca87fb64f --- /dev/null +++ b/benchmarks/datasets/google_message2/BUILD @@ -0,0 +1,44 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message2_proto", + srcs = [ + "benchmark_message2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) + +java_proto_library( + name = "benchmark_message2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) diff --git a/benchmarks/datasets/google_message3/BUILD b/benchmarks/datasets/google_message3/BUILD new file mode 100644 index 0000000000..9a00294464 --- /dev/null +++ b/benchmarks/datasets/google_message3/BUILD @@ -0,0 +1,50 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message3_proto", + srcs = [ + "benchmark_message3.proto", + "benchmark_message3_1.proto", + "benchmark_message3_2.proto", + "benchmark_message3_3.proto", + "benchmark_message3_4.proto", + "benchmark_message3_5.proto", + "benchmark_message3_6.proto", + "benchmark_message3_7.proto", + "benchmark_message3_8.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) + +java_proto_library( + name = "benchmark_message3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) diff --git a/benchmarks/datasets/google_message4/BUILD b/benchmarks/datasets/google_message4/BUILD new file mode 100644 index 0000000000..b23a4c955c --- /dev/null +++ b/benchmarks/datasets/google_message4/BUILD @@ -0,0 +1,45 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message4_proto", + srcs = [ + "benchmark_message4.proto", + "benchmark_message4_1.proto", + "benchmark_message4_2.proto", + "benchmark_message4_3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message4_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) + +java_proto_library( + name = "benchmark_message4_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) diff --git a/conformance/text_format_conformance_suite.cc b/conformance/text_format_conformance_suite.cc index 4c9dc7dbe0..460bc24900 100644 --- a/conformance/text_format_conformance_suite.cc +++ b/conformance/text_format_conformance_suite.cc @@ -451,6 +451,27 @@ void TextFormatConformanceTestSuite::RunSuiteImpl() { } )", prototype); + + prototype.Clear(); + ConformanceRequestSetting setting_map( + REQUIRED, conformance::TEXT_FORMAT, conformance::PROTOBUF, + conformance::TEXT_FORMAT_TEST, prototype, "DuplicateMapKey", R"( + map_string_nested_message { + key: "duplicate" + value: { a: 123 } + } + map_string_nested_message { + key: "duplicate" + value: { corecursive: {} } + } + )"); + // The last-specified value will be retained in a parsed map + RunValidInputTest(setting_map, R"( + map_string_nested_message { + key: "duplicate" + value: { corecursive: {} } + } + )"); } } // namespace protobuf diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 60c7fecda9..c6f019a13c 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.15.3 + 3.15.6 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 3cf55f9d4d7a6ff7869236b76c3fe6858e2bb371..06a17c1038c06c8a5879a2950630314fab7d1126 100644 GIT binary patch delta 4980 zcmZ8lYiv}<72df!Gk0_MeRp{o8$YlykD%ZrYK16@C^QKq%A=`Dd4!e_TGFOJ5~Ajz zN^8|P4#uRGh`Fdn7?o7jR!E?LypDwBHasi0M13gYq1uExUSmhZyi`y?^gDBB_HO&b zXumUO&N<(i@18rCzDwDQpJxvrKgB<24Ljbz@^I~uu~Qpe_U|LB&aY%io)W8gM5HAC zl_~p3=Y_Ecru_BKmSel3G4#I8oIfNT7IVXmg};5uo{&fWIX?Uh`=D@iF*_%6Q76o! z54ik#*vdFDhXaHNMPp9f5ro+PLQ6y6S1l%z+L!$wRK8gCeHBW(+SgLPRRK23`z2Lj zgV#GpLALYM46{m`cx9DSuUYNzZho81ehB6ryu^q$ zl|v*}uv%~G@E%{zW;Jn_cLbX_HkCtcQt(+-EPOk;cX%^fa3ny2w2A1nK1;L7fx_LCE;sIh)H&0JB5CwJf85IUb2+mw+ zpiOYjgHD1H@Q^F_a_ayO`^%hS?d5jNsdgkSQw94tPgZ!ZJkF|e_~|%F$M%=NV;_$v z5X$$(-u;}%OAaI^7$SiIJNDCwm>s~s<$OxXfg}Y(DljOIOxC$T4UsW&$QPndu=Q+d zKIjNT-}6RPa3U|BG96*)NS-?K8=<<2n7xG$pJaQjTyGG=LRWiv)IX(|MVWfJ>z^SY zV)XKvmAZ`1p^C%>=g8IBQ;p+e8o z>@~S=C?HQy^yi_=r^W4tzS20s`@ie40OHVwOPsBClAW;|s(u@`m{ije;2IV8R~-%K*S;B1j|EqMij< zMVbjS3jmR3!pwpgD!NLuV0BYW;J~k%fdGVUfLdyTj{GVOgi0C#80C}RhVQdkD<{qH zim4f14zWW)8X<94-r%7-dW6Ig`v#2=A`>U2-O_U{xf*lrmf?aWaJgmX8Xz{_GF$+` z<(A2Zoi9ja33@tPy-0YU_=LW>L#B4`y58NEajID|IuA8T0c!Zx8_I|+3N| zXh5XeDf9~@>B>$K+N&F#glDISOn3f6ZAwz7yS(qNV|UhenWA7srY_SaK7c%#*06o0zX( z*=nkECmIxiM1Qmj+N`k-RH48JiT4hC6>_CZ4%tK@2E10u^o zLpz0n4*3V3q60rNng0!M)#b2L$(i;yy`|O4F6$6Jee5Uf;yNTKVC& z?3DYs;Fap-tuWHSFfA~E$8k|H6Sq4_k*JX;yboVybLvhAo+x`JAP7N4G1A~9_1jNyt7Eynq03!KmQR!cd z0MUfgVv+ww2SgLj2-#plp$TV1x<0BDkfy|gz5?(YX$FHd^vDky1z;6v28{v$k!H{+ zAdO==s}%5PniO!>C;$lC0DT1jBH>w5z>Y8`zU#_!BJ^e9)Q?#^%bXLDna&{HkK8a0 zXGmC|7dCBSt5|MGIMf@w!@}xxh6S%v%~KdlJiEO1BLOGIF7lo}?gk=`Nl%R=37p*HnQPhJgB8Ps{#~^xwP*;L( z!+Bg-hCCbynoxA78V`!1JJq;Io1>vS)i{ZP?v<{(H3`dq^neg)B8c>eM5u|NDs^uX zZmlj#-J3*xgL8pF-5K0xMChh>?^Sj_b%W;muhK}7A!+m!Mt{z>MK<(ET_vp0M32;( z07R8NGV5Q|0a0a-tgcZbB16x|eres1{`U?ryz#l}IxRLH6JScxS2*(v)*81` zRN29xPsZKAfUSKp<4-r`fmD4G(~YFA445H(vT}iwaw6IQJ@v_|`Oe=hoen_;B!95t zPgc#cSKr+D_STv$8@JYMerw~VHwu4whb?7WupCrD;vFcjf*z-V@+wHc1LalFBpWEN zf<;ip09En3n63hb$--;DWQ{U6S)Ps*J}LD`AWEe1NtvxLaU@w!N~oO140!-wlYD;3 zfrJi2K!K!wtvn`){hG`+s4Y1aLj{>TuM`w9u1o%KDJW?kh9D@Z{(5;((*1RrT^MXZ z%r`8yVRCndR6q#57Vs%B*et7cnkP8qPZ+18p<2Bd1XwdRxor`>F8&G`l#ZnKTkepY8g zj27>?ciHnRTFR4=v|4O^*0htP)naF>OXZNXTI{;n&YLtA#1$fBMq0 zLynjo_$0*a;|ZHZo#5>J`Y+iEdHT-1o2%Gw@`Fp*S0Zvu+MGwMpu_j%zxgdz7hJlB zTecmu1z82mJd!Yw5ll`ukT&t^8oR*`^2ij2?{(eftp51`e(^}u^O_RCrc!8WSgSX6 zx}(e4j79M3^f$5pgV>~2-%`bLhwta^AJ(&#uSP7cP_bk#X)!WG*T@lQKd*hkK$N_n zzqG_&L)pRZ0C(SB%idWP5vckAk4^I&1yv20G7tqE;N{cosBQ76BMim-ZH0Hhj}P!*V>Ynse&HP6P0ds1*^&8r)?+fkhcULJvI#AS-?I7$a&b^ssayu9dOVFwIJ-=I9o()Lwqh>Vg$E`M?bdzUTC`5j^C ze$HqMPUOXtrXvg;$x%lR3)NM`?9H!eVm(&2*NRp!Xgx%KB_SE-)Qc_?PjR-Izh)jYIT>27#~HP+#$X&RPL zU7jaX_FV0Yy=UCtzrp6$ohkKW@HCCO*~lA_($BeEK}I3i3m|VXi&GR0iCkVK@E*cJIAmKLJOA zVLt&~rD2{lBIQUh%xk=h7PUAM4D;HBIsr$5VLtD9`(+g$kqX>eP`RjU%f#Xq8ZJ>w zASsOAtN~O$de#6UTfwIzkgdR{dZP!c$X4K$^K~|XYz5vp&!+hhB~^^-`2c`4qkbBx z7WI6xtQPF*GKDd8>hlvIE&3uTe`2eVuCrAPJX+BibM8GHeupoxL~$KLe`4a`vCsYPTJ~uib!1wNL1eOTv-+Mc}Y*cLK5Zi|{o2F*Pee{qA!Avz9$s(`D*`5lOmCvjDND z%QOoR^>mqL0is!5rdfb!Ru?skNGFKOAw~KX{D#yH`B@lPA2O`5O0I@AAhH}XtP?1x zn^>=2l^~^c8|pyV2Ix@-1odu1J?Y3E5jd%-C*j#6!WH(FAWBOT^;~}EI(Ch%$(gEP zMXH?P4v0-T!yOP+Dg$PYm zUwYUn_gTTK)rVbSq=8|oZvc<8qOuAPKuM9Ph3DKAEo@fZIl;?{e)QctCn~1e-_U-* z=iN_R*plpd!Q(|gx^w46%2A)>6r#xs!WtB_)Oi6zkT7^33_u*s1rhP)3LuhS5Y^tJ z2@p-VAQpOGdq6Z{P{>9T3QZUksfLI;`xGU<=;;YGhHm>sqX4WT%|)XCK%}{7 z6p+HPTv7^nF+~cvWE22|ZGfHv0Fm$#DPUg^h1A^WVGwbkF1_Kh&En(HDz5^j3 zpm&6T=6XCzt%sEASo8q7?S5|yJDR=i$DoRC3;hOkR6Vza zQ>R0c3~r0YS-Kjuy&$Z)dXY{V&{Sg~Qo)ZzCtVOugKW)a&8)vn5)@)rAw%!$%Sp-vpCK5fu?)pVh5AKRA`c020^aP>q z`rU@}h_DQKdSL;YQ1rqY@r$At)`&=%qoEhp2#LWvH=N9VfKok8}DV%2+N#jUFNm~fl1elWa<+to$?ZIpx z{^U_IRdz7wlQG9PU~8W&^QN2fK&n28=|)ml2F#E?Sv}uQ+F@;gp890XJo}%PPKO`^ zk}s${Yh_;fU`O-LZJEu@+cGU5H*egY-}(!-jAgOxS3%+(D6N97(?DqzB;bM4Drk}o zlvcsQsA7Ps_$;ccfMHDXxs?Z_nWjyd?VDS-Wxl`lXCG~BS-v$t|CcN&vsm`4AmNWm zJt>GONq{(=Ven(p4Hz$tNq1merW@6ktcsz6%$ZvZ ziWn1;FD?e9s{n%^lrFaIZR1C+ z8(OxZA?}jh>{{Zn3{ST|h8EK#lc#QdJNx;2PmL5|gcP63NV$?VAd)?m6&VAO>Zz=6 zP*O~j6u*|%zK|zHV0eEm?X>+VL(hOI$E0-s+s=NSoiwbJ9jqpe2$TU^CyfY{0jVa9 z2$TULm^32r3^?;i62V(K8)EDV@rKHmGfnTee7L=JQ>$X$lG)Vyfg9Pwmb`{#ueB6_ zl(;LTHJ}VCK)P17RvA#lu25aQy+da}#&)-358L^Adub$6Q+r6?EZRtFY7do7D@G#q zw1+U*ubI}s(CL1=gI#~IvosWmsIxQ_iKsJFR#6N^f97`XS-qFxpM`(H{OY}YckX|w C-(NKV diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 23517d4ca3..9969a45f52 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.15.3 + 3.15.6 7.2 Google Inc. diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 0a1f4a7440..5c5b2ffaf4 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -107,57 +107,58 @@ namespace Google.Protobuf.Reflection { "eV9wYWNrYWdlGC0gASgJEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMo", "CzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIjoKDE9w", "dGltaXplTW9kZRIJCgVTUEVFRBABEg0KCUNPREVfU0laRRACEhAKDExJVEVf", - "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECci8gEKDk1lc3NhZ2VPcHRpb25z", + "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECcihAIKDk1lc3NhZ2VPcHRpb25z", "EiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9ybWF0GAEgASgIOgVmYWxzZRIuCh9u", "b19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZRIZ", "CgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRIRCgltYXBfZW50cnkYByABKAgS", "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", - "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAgQCUoECAkQ", - "CiKeAwoMRmllbGRPcHRpb25zEjoKBWN0eXBlGAEgASgOMiMuZ29vZ2xlLnBy", - "b3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToGU1RSSU5HEg4KBnBhY2tlZBgC", - "IAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29nbGUucHJvdG9idWYuRmllbGRP", - "cHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMKBGxhenkYBSABKAg6BWZhbHNl", - "EhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEhMKBHdlYWsYCiABKAg6BWZh", - "bHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5w", - "cm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIi8KBUNUeXBlEgoKBlNUUklO", - "RxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElFQ0UQAiI1CgZKU1R5cGUSDQoJ", - "SlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAESDQoJSlNfTlVNQkVSEAIqCQjo", - "BxCAgICAAkoECAQQBSJeCgxPbmVvZk9wdGlvbnMSQwoUdW5pbnRlcnByZXRl", - "ZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0", - "ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoLRW51bU9wdGlvbnMSEwoLYWxsb3df", - "YWxpYXMYAiABKAgSGQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USQwoUdW5p", - "bnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVu", - "aW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAUQBiJ9ChBFbnVtVmFs", - "dWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQYASABKAg6BWZhbHNlEkMKFHVuaW50", - "ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu", - "dGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIiewoOU2VydmljZU9wdGlvbnMS", - "GQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9v", - "cHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRP", - "cHRpb24qCQjoBxCAgICAAiKtAgoNTWV0aG9kT3B0aW9ucxIZCgpkZXByZWNh", - "dGVkGCEgASgIOgVmYWxzZRJfChFpZGVtcG90ZW5jeV9sZXZlbBgiIAEoDjIv", - "Lmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRpb25zLklkZW1wb3RlbmN5TGV2", - "ZWw6E0lERU1QT1RFTkNZX1VOS05PV04SQwoUdW5pbnRlcnByZXRlZF9vcHRp", - "b24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRp", - "b24iUAoQSWRlbXBvdGVuY3lMZXZlbBIXChNJREVNUE9URU5DWV9VTktOT1dO", - "EAASEwoPTk9fU0lERV9FRkZFQ1RTEAESDgoKSURFTVBPVEVOVBACKgkI6AcQ", - "gICAgAIingIKE1VuaW50ZXJwcmV0ZWRPcHRpb24SOwoEbmFtZRgCIAMoCzIt", - "Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uLk5hbWVQYXJ0", - "EhgKEGlkZW50aWZpZXJfdmFsdWUYAyABKAkSGgoScG9zaXRpdmVfaW50X3Zh", - "bHVlGAQgASgEEhoKEm5lZ2F0aXZlX2ludF92YWx1ZRgFIAEoAxIUCgxkb3Vi", - "bGVfdmFsdWUYBiABKAESFAoMc3RyaW5nX3ZhbHVlGAcgASgMEhcKD2FnZ3Jl", - "Z2F0ZV92YWx1ZRgIIAEoCRozCghOYW1lUGFydBIRCgluYW1lX3BhcnQYASAC", - "KAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigIItUBCg5Tb3VyY2VDb2RlSW5mbxI6", - "Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2Rl", - "SW5mby5Mb2NhdGlvbhqGAQoITG9jYXRpb24SEAoEcGF0aBgBIAMoBUICEAES", - "EAoEc3BhbhgCIAMoBUICEAESGAoQbGVhZGluZ19jb21tZW50cxgDIAEoCRIZ", - "ChF0cmFpbGluZ19jb21tZW50cxgEIAEoCRIhChlsZWFkaW5nX2RldGFjaGVk", - "X2NvbW1lbnRzGAYgAygJIqcBChFHZW5lcmF0ZWRDb2RlSW5mbxJBCgphbm5v", - "dGF0aW9uGAEgAygLMi0uZ29vZ2xlLnByb3RvYnVmLkdlbmVyYXRlZENvZGVJ", - "bmZvLkFubm90YXRpb24aTwoKQW5ub3RhdGlvbhIQCgRwYXRoGAEgAygFQgIQ", - "ARITCgtzb3VyY2VfZmlsZRgCIAEoCRINCgViZWdpbhgDIAEoBRILCgNlbmQY", - "BCABKAVCfgoTY29tLmdvb2dsZS5wcm90b2J1ZkIQRGVzY3JpcHRvclByb3Rv", - "c0gBWi1nb29nbGUuZ29sYW5nLm9yZy9wcm90b2J1Zi90eXBlcy9kZXNjcmlw", - "dG9ycGL4AQGiAgNHUEKqAhpHb29nbGUuUHJvdG9idWYuUmVmbGVjdGlvbg==")); + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAQQBUoECAUQ", + "BkoECAYQB0oECAgQCUoECAkQCiKeAwoMRmllbGRPcHRpb25zEjoKBWN0eXBl", + "GAEgASgOMiMuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToG", + "U1RSSU5HEg4KBnBhY2tlZBgCIAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29n", + "bGUucHJvdG9idWYuRmllbGRPcHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMK", + "BGxhenkYBSABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNl", + "EhMKBHdlYWsYCiABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9u", + "GOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9u", + "Ii8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElF", + "Q0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAES", + "DQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJeCgxPbmVvZk9wdGlv", + "bnMSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnBy", + "b3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoLRW51", + "bU9wdGlvbnMSEwoLYWxsb3dfYWxpYXMYAiABKAgSGQoKZGVwcmVjYXRlZBgD", + "IAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQu", + "Z29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICA", + "AkoECAUQBiJ9ChBFbnVtVmFsdWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQYASAB", + "KAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdv", + "b2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIi", + "ewoOU2VydmljZU9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2US", + "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKtAgoNTWV0aG9k", + "T3B0aW9ucxIZCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZRJfChFpZGVtcG90", + "ZW5jeV9sZXZlbBgiIAEoDjIvLmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRp", + "b25zLklkZW1wb3RlbmN5TGV2ZWw6E0lERU1QT1RFTkNZX1VOS05PV04SQwoU", + "dW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVm", + "LlVuaW50ZXJwcmV0ZWRPcHRpb24iUAoQSWRlbXBvdGVuY3lMZXZlbBIXChNJ", + "REVNUE9URU5DWV9VTktOT1dOEAASEwoPTk9fU0lERV9FRkZFQ1RTEAESDgoK", + "SURFTVBPVEVOVBACKgkI6AcQgICAgAIingIKE1VuaW50ZXJwcmV0ZWRPcHRp", + "b24SOwoEbmFtZRgCIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJl", + "dGVkT3B0aW9uLk5hbWVQYXJ0EhgKEGlkZW50aWZpZXJfdmFsdWUYAyABKAkS", + "GgoScG9zaXRpdmVfaW50X3ZhbHVlGAQgASgEEhoKEm5lZ2F0aXZlX2ludF92", + "YWx1ZRgFIAEoAxIUCgxkb3VibGVfdmFsdWUYBiABKAESFAoMc3RyaW5nX3Zh", + "bHVlGAcgASgMEhcKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCRozCghOYW1lUGFy", + "dBIRCgluYW1lX3BhcnQYASACKAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigIItUB", + "Cg5Tb3VyY2VDb2RlSW5mbxI6Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5w", + "cm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvbhqGAQoITG9jYXRpb24S", + "EAoEcGF0aBgBIAMoBUICEAESEAoEc3BhbhgCIAMoBUICEAESGAoQbGVhZGlu", + "Z19jb21tZW50cxgDIAEoCRIZChF0cmFpbGluZ19jb21tZW50cxgEIAEoCRIh", + "ChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJIqcBChFHZW5lcmF0", + "ZWRDb2RlSW5mbxJBCgphbm5vdGF0aW9uGAEgAygLMi0uZ29vZ2xlLnByb3Rv", + "YnVmLkdlbmVyYXRlZENvZGVJbmZvLkFubm90YXRpb24aTwoKQW5ub3RhdGlv", + "bhIQCgRwYXRoGAEgAygFQgIQARITCgtzb3VyY2VfZmlsZRgCIAEoCRINCgVi", + "ZWdpbhgDIAEoBRILCgNlbmQYBCABKAVCfgoTY29tLmdvb2dsZS5wcm90b2J1", + "ZkIQRGVzY3JpcHRvclByb3Rvc0gBWi1nb29nbGUuZ29sYW5nLm9yZy9wcm90", + "b2J1Zi90eXBlcy9kZXNjcmlwdG9ycGL4AQGiAgNHUEKqAhpHb29nbGUuUHJv", + "dG9idWYuUmVmbGVjdGlvbg==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { diff --git a/docs/implementing_proto3_presence.md b/docs/implementing_proto3_presence.md index 73f21a3829..ae8b369579 100644 --- a/docs/implementing_proto3_presence.md +++ b/docs/implementing_proto3_presence.md @@ -261,7 +261,7 @@ bool FieldHasPresence(const google::protobuf::FieldDescriptor* field) { Old: ```c++ -bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { +bool FieldIsInOneof(const google::protobuf::FieldDescriptor* field) { return field->containing_oneof() != nullptr; } ``` @@ -269,7 +269,7 @@ bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { New: ```c++ -bool FieldIsInOneof(const google::protobuf::FielDescriptor* field) { +bool FieldIsInOneof(const google::protobuf::FieldDescriptor* field) { // real_containing_oneof() returns nullptr for synthetic oneofs. return field->real_containing_oneof() != nullptr; } diff --git a/docs/options.md b/docs/options.md index 907fe5aa02..79a085e0be 100644 --- a/docs/options.md +++ b/docs/options.md @@ -268,3 +268,11 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-sanitize * Website: https://github.com/Intrinsec/protoc-gen-sanitize * Extension: 1102-1106 + +1. Coach Client Connect (planned release in March 2021) + * Website: https://www.coachclientconnect.com + * Extension: 1107 + +1. Kratos API Errors + * Website: https://go-kratos.dev + * Extension: 1108 diff --git a/docs/third_party.md b/docs/third_party.md index 7799e308a7..9d490c0a6e 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -11,6 +11,7 @@ These are projects we know about implementing Protocol Buffers for other program * Action Script: https://code.google.com/p/protoc-gen-as3/ * Action Script: https://github.com/matrix3d/JProtoc * Action Script: https://github.com/zhongfq/protobuf-as3/ +* Ada: https://github.com/reznikmm/protobuf * C: https://github.com/protobuf-c/protobuf-c * C: http://koti.kapsi.fi/jpa/nanopb/ * C: https://github.com/cloudwu/pbc/ @@ -101,7 +102,6 @@ These are projects we know about implementing Protocol Buffers for other program * Solidity: https://github.com/celer-network/pb3-gen-sol * Swift: https://github.com/alexeyxo/protobuf-swift * Swift: https://github.com/apple/swift-protobuf/ -* Typescript: https://github.com/y3llowcake/protoc-gen-ts * Vala: https://launchpad.net/protobuf-vala * Visual Basic: http://code.google.com/p/protobuf-net/ diff --git a/java/README.md b/java/README.md index c8050893e0..c3434144b1 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.11.0 + 3.15.3 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.11.0 + 3.15.3 ``` diff --git a/java/bom/pom.xml b/java/bom/pom.xml index cec091173e..af2d7025ab 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.15.3 + 3.15.6 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 4fc530b9db..4df7d434df 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 protobuf-java diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 17b7c98c99..74c9a71b6c 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -1043,8 +1043,10 @@ public abstract class ByteString implements Iterable, Serializable { } /** - * Creates a byte string. Its size is the current size of this output stream and its output has - * been copied to it. + * Creates a byte string with the size and contents of this output stream. This does not create + * a new copy of the underlying bytes. If the stream size grows dynamically, the runtime is + * O(log n) in respect to the number of bytes written to the {@link Output}. If the stream size + * stays within the initial capacity, the runtime is O(1). * * @return the current contents of this output stream, as a byte string. */ diff --git a/java/core/src/main/java/com/google/protobuf/RopeByteString.java b/java/core/src/main/java/com/google/protobuf/RopeByteString.java index cc6e0445b0..f584164410 100644 --- a/java/core/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/core/src/main/java/com/google/protobuf/RopeByteString.java @@ -603,7 +603,12 @@ final class RopeByteString extends ByteString { @Override public CodedInputStream newCodedInput() { - return CodedInputStream.newInstance(new RopeInputStream()); + // Passing along direct references to internal ByteBuffers can support more efficient parsing + // via aliasing in CodedInputStream for users who wish to use it. + // + // Otherwise we force data copies, both in copying as an input stream and in buffering in the + // CodedInputSteam. + return CodedInputStream.newInstance(asReadOnlyByteBufferList(), /* bufferIsImmutable= */ true); } @Override diff --git a/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java index cc979ac513..4bc8d10130 100644 --- a/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java @@ -283,7 +283,7 @@ public class AbstractMessageTest extends TestCase { Message.Builder abstractMessageBuilder = new AbstractMessageWrapper.Builder(TestRequiredForeign.newBuilder()); // mergeFrom() should not throw initialization error. - abstractMessageBuilder.mergeFrom(bytes).buildPartial(); + Message unused1 = abstractMessageBuilder.mergeFrom(bytes).buildPartial(); try { abstractMessageBuilder.mergeFrom(bytes).build(); fail(); @@ -295,7 +295,7 @@ public class AbstractMessageTest extends TestCase { Message.Builder dynamicMessageBuilder = DynamicMessage.newBuilder(TestRequiredForeign.getDescriptor()); // mergeFrom() should not throw initialization error. - dynamicMessageBuilder.mergeFrom(bytes).buildPartial(); + Message unused2 = dynamicMessageBuilder.mergeFrom(bytes).buildPartial(); try { dynamicMessageBuilder.mergeFrom(bytes).build(); fail(); diff --git a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java index fe37ea8087..cd40ffaeeb 100644 --- a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java @@ -69,7 +69,7 @@ public class DynamicMessageTest extends TestCase { Message.Builder builder = DynamicMessage.newBuilder(TestAllTypes.getDescriptor()); Message firstMessage = builder.build(); // double build() - builder.build(); + Message unused = builder.build(); // clear() after build() builder.clear(); // setters after build() diff --git a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 9261a36122..840e13e877 100644 --- a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java @@ -76,6 +76,7 @@ import junit.framework.TestCase; * * @author kenton@google.com Kenton Varda */ +@SuppressWarnings({"ProtoBuilderReturnValueIgnored", "ReturnValueIgnored"}) public class GeneratedMessageTest extends TestCase { TestUtil.ReflectionTester reflectionTester = new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null); diff --git a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index d2565ca157..25c5625f40 100644 --- a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java @@ -1163,8 +1163,8 @@ public class MapForProto2Test extends TestCase { } public void testReservedWordsFieldNames() { - ReservedAsMapField.newBuilder().build(); - ReservedAsMapFieldWithEnumValue.newBuilder().build(); + ReservedAsMapField unused1 = ReservedAsMapField.newBuilder().build(); + ReservedAsMapFieldWithEnumValue unused2 = ReservedAsMapFieldWithEnumValue.newBuilder().build(); } public void testGetMap() { diff --git a/java/core/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java index 2f55328b51..c3b1fa3804 100644 --- a/java/core/src/test/java/com/google/protobuf/MapTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapTest.java @@ -1294,8 +1294,8 @@ public class MapTest extends TestCase { } public void testReservedWordsFieldNames() { - ReservedAsMapField.newBuilder().build(); - ReservedAsMapFieldWithEnumValue.newBuilder().build(); + ReservedAsMapField unused1 = ReservedAsMapField.newBuilder().build(); + ReservedAsMapFieldWithEnumValue unused2 = ReservedAsMapFieldWithEnumValue.newBuilder().build(); } public void testDeterministicSerialziation() throws Exception { diff --git a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java index 3d82c5f9af..08a23bab94 100644 --- a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java @@ -43,8 +43,10 @@ public class TestBadIdentifiers extends TestCase { public void testCompilation() { // If this compiles, it means the generation was correct. - TestBadIdentifiersProto.Deprecated.newBuilder(); - TestBadIdentifiersProto.Override.newBuilder(); + TestBadIdentifiersProto.Deprecated unused1 = + TestBadIdentifiersProto.Deprecated.newBuilder().build(); + TestBadIdentifiersProto.Override unused2 = + TestBadIdentifiersProto.Override.getDefaultInstance(); } public void testGetDescriptor() { diff --git a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java index 798d7ca612..523e23aa76 100644 --- a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java @@ -45,8 +45,10 @@ public final class TestBadIdentifiersLite extends TestCase { public void testCompilation() { // If this compiles, it means the generation was correct. - TestBadIdentifiersProto.Deprecated.newBuilder(); - TestBadIdentifiersProto.Override.newBuilder(); + TestBadIdentifiersProto.Deprecated.Builder builder1 = + TestBadIdentifiersProto.Deprecated.newBuilder(); + TestBadIdentifiersProto.Override.Builder builder2 = + TestBadIdentifiersProto.Override.newBuilder(); } public void testConflictingFieldNames() throws Exception { diff --git a/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto b/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto deleted file mode 100644 index d41b7a11cc..0000000000 --- a/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -// Author: Darick Tong (darick@google.com) -syntax = "proto2"; - -package protobuf_unittest; - -message Proto1 { - option experimental_java_message_interface = - "com.google.protobuf.ExtraInterfaces.HasBoolValue"; - option experimental_java_message_interface = - "com.google.protobuf.ExtraInterfaces.HasStringValue"; - option experimental_java_builder_interface = - "com.google.protobuf.ExtraInterfaces.HasStringValueBuilder" - ""; - - optional string string_value = 1; - optional bool bool_value = 2; - optional bytes byte_value = 3; - optional int32 int_value = 4; -} - -message Proto2 { - option experimental_java_message_interface = - "com.google.protobuf.ExtraInterfaces.HasBoolValue"; - - optional bool bool_value = 1; -} diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 62bca93c86..65e62ce4fb 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -4,6 +4,7 @@ + diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 478ba0e15c..021eac0ac4 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 protobuf-javalite diff --git a/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/java/lite/src/test/java/com/google/protobuf/LiteTest.java index 06d244a643..f2ce4614c7 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -2406,24 +2406,26 @@ public class LiteTest extends TestCase { } public void testAddAllIteratesOnce() { - TestAllTypesLite.newBuilder() - .addAllRepeatedBool(new OneTimeIterableList<>(false)) - .addAllRepeatedInt32(new OneTimeIterableList<>(0)) - .addAllRepeatedInt64(new OneTimeIterableList<>(0L)) - .addAllRepeatedFloat(new OneTimeIterableList<>(0f)) - .addAllRepeatedDouble(new OneTimeIterableList<>(0d)) - .addAllRepeatedBytes(new OneTimeIterableList<>(ByteString.EMPTY)) - .addAllRepeatedString(new OneTimeIterableList<>("")) - .addAllRepeatedNestedMessage(new OneTimeIterableList<>(NestedMessage.getDefaultInstance())) - .addAllRepeatedBool(new OneTimeIterable<>(false)) - .addAllRepeatedInt32(new OneTimeIterable<>(0)) - .addAllRepeatedInt64(new OneTimeIterable<>(0L)) - .addAllRepeatedFloat(new OneTimeIterable<>(0f)) - .addAllRepeatedDouble(new OneTimeIterable<>(0d)) - .addAllRepeatedBytes(new OneTimeIterable<>(ByteString.EMPTY)) - .addAllRepeatedString(new OneTimeIterable<>("")) - .addAllRepeatedNestedMessage(new OneTimeIterable<>(NestedMessage.getDefaultInstance())) - .build(); + TestAllTypesLite unused = + TestAllTypesLite.newBuilder() + .addAllRepeatedBool(new OneTimeIterableList<>(false)) + .addAllRepeatedInt32(new OneTimeIterableList<>(0)) + .addAllRepeatedInt64(new OneTimeIterableList<>(0L)) + .addAllRepeatedFloat(new OneTimeIterableList<>(0f)) + .addAllRepeatedDouble(new OneTimeIterableList<>(0d)) + .addAllRepeatedBytes(new OneTimeIterableList<>(ByteString.EMPTY)) + .addAllRepeatedString(new OneTimeIterableList<>("")) + .addAllRepeatedNestedMessage( + new OneTimeIterableList<>(NestedMessage.getDefaultInstance())) + .addAllRepeatedBool(new OneTimeIterable<>(false)) + .addAllRepeatedInt32(new OneTimeIterable<>(0)) + .addAllRepeatedInt64(new OneTimeIterable<>(0L)) + .addAllRepeatedFloat(new OneTimeIterable<>(0f)) + .addAllRepeatedDouble(new OneTimeIterable<>(0d)) + .addAllRepeatedBytes(new OneTimeIterable<>(ByteString.EMPTY)) + .addAllRepeatedString(new OneTimeIterable<>("")) + .addAllRepeatedNestedMessage(new OneTimeIterable<>(NestedMessage.getDefaultInstance())) + .build(); } public void testAddAllIteratesOnce_throwsOnNull() { diff --git a/java/pom.xml b/java/pom.xml index dc3e89f884..649ec0ce11 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 pom Protocol Buffers [Parent] @@ -75,7 +75,7 @@ junit junit - 4.13.1 + 4.13.2 test @@ -104,7 +104,7 @@ com.google.truth truth - 1.0.1 + 1.1.2 test diff --git a/java/util/pom.xml b/java/util/pom.xml index 9028b1b2f0..37d7c0fb85 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.15.3 + 3.15.6 protobuf-java-util diff --git a/kokoro/release/protoc/linux/build.sh b/kokoro/release/protoc/linux/build.sh index efc3ee62ca..44a95aab35 100755 --- a/kokoro/release/protoc/linux/build.sh +++ b/kokoro/release/protoc/linux/build.sh @@ -23,7 +23,7 @@ sudo apt install -y g++-powerpc64le-linux-gnu protoc-artifacts/build-protoc.sh linux ppcle_64 protoc sudo apt install -y g++-s390x-linux-gnu -protoc-artifacts/build-protoc.sh linux s390x protoc +protoc-artifacts/build-protoc.sh linux s390_64 protoc # Use docker image to build linux artifacts. DOCKER_IMAGE_NAME=protobuf/protoc_$(sha1sum protoc-artifacts/Dockerfile | cut -f1 -d " ") diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 7f27670320..0f1f4c964e 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -334,7 +334,7 @@ static zval *Message_read_property(PROTO_VAL *obj, PROTO_STR *member, Message* intern = PROTO_VAL_P(obj); const upb_fielddef *f = get_field(intern, member); - if (!f) return NULL; + if (!f) return &EG(uninitialized_zval); Message_get(intern, f, rv); return rv; } diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 75a440cd55..48e403bf72 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2021-02-24 - + 2021-03-10 + - 3.15.3 - 3.15.3 + 3.15.6 + 3.15.6 stable @@ -22,15 +22,7 @@ 3-Clause BSD License - New changes in 3.15.0: - * unregister INI entries and fix invalid read on shutdown (#8042) - * Fix PhpDoc comments for message accessors to include "|null". (#8136) - * fix: convert native PHP floats to single precision (#8187) - * Fixed PHP to support field numbers >=2**28. (#8235) - * feat: add support for deprecated fields to PHP compiler (#8223) - * Protect against stack overflow if the user derives from Message. (#8248) - * Fixed clone for Message, RepeatedField, and MapField. (#8245) - * Updated upb to allow nonzero offset minutes in JSON timestamps. (#8258) + No new changes in 3.15.6 @@ -850,5 +842,50 @@ G A release. + + + 3.15.4 + 3.15.4 + + + stable + stable + + 2021-03-02 + + 3-Clause BSD License + + + + + + 3.15.5 + 3.15.5 + + + stable + stable + + 2021-03-04 + + 3-Clause BSD License + + + + + + 3.15.6 + 3.15.6 + + + stable + stable + + 2021-03-10 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index c56a567ca3..913dfad7e9 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7047,10 +7047,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { } bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { - if (!_upb_array_realloc(arr, arr->len + 1, arena)) { + if (!upb_array_resize(arr, arr->len + 1, arena)) { return false; } - arr->len++; upb_array_set(arr, arr->len - 1, val); return true; } diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index a03261c295..1a2069bfbb 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -76,7 +76,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.15.3" +#define PHP_PROTOBUF_VERSION "3.15.6" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protoc-artifacts/README.md b/protoc-artifacts/README.md index 2c45fefe78..1706ddc0d8 100644 --- a/protoc-artifacts/README.md +++ b/protoc-artifacts/README.md @@ -123,7 +123,7 @@ target directory layout: protoc.exe + ppcle_64 protoc.exe - + s390x + + s390_64 protoc.exe + osx + x86_64 diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh index 7f65d37643..4602842622 100755 --- a/protoc-artifacts/build-protoc.sh +++ b/protoc-artifacts/build-protoc.sh @@ -93,7 +93,7 @@ checkArch () assertEq $format "elf64-x86-64" $LINENO elif [[ "$ARCH" == aarch_64 ]]; then assertEq $format "elf64-little" $LINENO - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine == s390x ]];then assertEq $format "elf64-s390" $LINENO else @@ -149,7 +149,7 @@ checkDependencies () white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2" elif [[ "$ARCH" == x86_64 ]]; then white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2" - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine != s390x ]];then dump_cmd='objdump -p '"$1"' | grep NEEDED' fi @@ -226,7 +226,7 @@ elif [[ "$(uname)" == Linux* ]]; then elif [[ "$ARCH" == ppcle_64 ]]; then CXXFLAGS="$CXXFLAGS -m64" CONFIGURE_ARGS="$CONFIGURE_ARGS --host=powerpc64le-linux-gnu" - elif [[ "$ARCH" == s390x ]]; then + elif [[ "$ARCH" == s390_64 ]]; then CXXFLAGS="$CXXFLAGS -m64" CONFIGURE_ARGS="$CONFIGURE_ARGS --host=s390x-linux-gnu" else diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index 2a25d3cd7e..7d1923e6e6 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -21,7 +21,7 @@ included. Each invocation will create 8 zip packages: dist/--linux-x86_64.zip dist/--linux-aarch_64.zip dist/--linux-ppcle_64.zip - dist/--linux-s390x.zip + dist/--linux-s390_64.zip EOF exit 1 fi @@ -38,7 +38,7 @@ declare -a FILE_NAMES=( \ linux-x86_64.zip linux-x86_64.exe \ linux-aarch_64.zip linux-aarch_64.exe \ linux-ppcle_64.zip linux-ppcle_64.exe \ - linux-s390x.zip linux-s390x.exe \ + linux-s390_64.zip linux-s390_64.exe \ ) # List of all well-known types to be included. diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 591ab09284..9cb0b63e5a 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.15.3 + 3.15.6 pom Protobuf Compiler @@ -81,8 +81,8 @@ exe - ${basedir}/target/linux/s390x/protoc.exe - linux-s390x + ${basedir}/target/linux/s390_64/protoc.exe + linux-s390_64 exe diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 987116a106..6f75251dbe 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -1176,6 +1176,54 @@ class OnlyWorksWithProto2RightNowTests(TextFormatBase): ' }\n' '}\n') + def testDuplicateMapKey(self): + message = map_unittest_pb2.TestMap() + text = ( + 'map_uint64_uint64 {\n' + ' key: 123\n' + ' value: 17179869184\n' + '}\n' + 'map_string_string {\n' + ' key: "abc"\n' + ' value: "first"\n' + '}\n' + 'map_int32_foreign_message {\n' + ' key: 111\n' + ' value {\n' + ' c: 5\n' + ' }\n' + '}\n' + 'map_uint64_uint64 {\n' + ' key: 123\n' + ' value: 321\n' + '}\n' + 'map_string_string {\n' + ' key: "abc"\n' + ' value: "second"\n' + '}\n' + 'map_int32_foreign_message {\n' + ' key: 111\n' + ' value {\n' + ' d: 5\n' + ' }\n' + '}\n') + text_format.Parse(text, message) + self.CompareToGoldenText( + text_format.MessageToString(message), 'map_uint64_uint64 {\n' + ' key: 123\n' + ' value: 321\n' + '}\n' + 'map_string_string {\n' + ' key: "abc"\n' + ' value: "second"\n' + '}\n' + 'map_int32_foreign_message {\n' + ' key: 111\n' + ' value {\n' + ' d: 5\n' + ' }\n' + '}\n') + # In cpp implementation, __str__ calls the cpp implementation of text format. def testPrintMapUsingCppImplementation(self): message = map_unittest_pb2.TestMap() @@ -2348,6 +2396,13 @@ class OptionalColonMessageToStringTest(unittest.TestCase): '}\n') self.assertEqual(expected, output) + def testPrintShortFormatRepeatedFields(self): + message = unittest_pb2.TestAllTypes() + message.repeated_int32.append(1) + output = text_format.MessageToString( + message, use_short_repeated_primitives=True, force_colon=True) + self.assertEqual('repeated_int32: [1]\n', output) + if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 75f1760ccf..42d99e8fc8 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -30,15 +30,18 @@ // Author: petar@google.com (Petar Petrov) +#include + #include #include + +#include #include #include #include #include #include -#include #include #include #include @@ -195,7 +198,7 @@ bool Reparse( std::string serialized; from.SerializeToString(&serialized); io::CodedInputStream input( - reinterpret_cast(serialized.c_str()), serialized.size()); + reinterpret_cast(serialized.c_str()), serialized.size()); input.SetExtensionRegistry(message_factory->pool->pool, message_factory->message_factory); bool success = to->ParseFromCodedStream(&input); @@ -804,22 +807,22 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) { switch (_GetDescriptor(self)->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { - int32 value = _GetDescriptor(self)->default_value_int32(); + int32_t value = _GetDescriptor(self)->default_value_int32(); result = PyInt_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { - int64 value = _GetDescriptor(self)->default_value_int64(); + int64_t value = _GetDescriptor(self)->default_value_int64(); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT32: { - uint32 value = _GetDescriptor(self)->default_value_uint32(); + uint32_t value = _GetDescriptor(self)->default_value_uint32(); result = PyInt_FromSize_t(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { - uint64 value = _GetDescriptor(self)->default_value_uint64(); + uint64_t value = _GetDescriptor(self)->default_value_uint64(); result = PyLong_FromUnsignedLongLong(value); break; } diff --git a/python/google/protobuf/pyext/descriptor_database.cc b/python/google/protobuf/pyext/descriptor_database.cc index 26f1b5fb42..da1c84a465 100644 --- a/python/google/protobuf/pyext/descriptor_database.cc +++ b/python/google/protobuf/pyext/descriptor_database.cc @@ -33,6 +33,8 @@ #include +#include + #include #include #include @@ -164,7 +166,7 @@ bool PyDescriptorDatabase::FindAllExtensionNumbers( return false; } Py_ssize_t size = PyList_Size(py_list.get()); - int64 item_value; + int64_t item_value; for (Py_ssize_t i = 0 ; i < size; ++i) { ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i)); item_value = PyLong_AsLong(item.get()); diff --git a/python/google/protobuf/pyext/extension_dict.cc b/python/google/protobuf/pyext/extension_dict.cc index e9ac71409e..37b414c375 100644 --- a/python/google/protobuf/pyext/extension_dict.cc +++ b/python/google/protobuf/pyext/extension_dict.cc @@ -32,14 +32,16 @@ // Author: tibell@google.com (Johan Tibell) #include + +#include #include #include #include +#include #include #include #include -#include #include #include #include @@ -263,7 +265,7 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) { } PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) { - int64 number = PyLong_AsLong(arg); + int64_t number = PyLong_AsLong(arg); if (number == -1 && PyErr_Occurred()) { return NULL; } diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index a0ee16fe86..2573327e3b 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -32,15 +32,16 @@ #include +#include #include #include #include -#include #include +#include #include -#include #include +#include #include #include #include @@ -99,7 +100,7 @@ struct MapIterator { // // We store this so that if the map is modified during iteration we can throw // an error. - uint64 version; + uint64_t version; }; Message* MapContainer::GetMutableMessage() { diff --git a/python/google/protobuf/pyext/map_container.h b/python/google/protobuf/pyext/map_container.h index a28945da07..842602e79f 100644 --- a/python/google/protobuf/pyext/map_container.h +++ b/python/google/protobuf/pyext/map_container.h @@ -33,6 +33,7 @@ #include +#include #include #include @@ -56,7 +57,7 @@ struct MapContainer : public ContainerBase { // We bump this whenever we perform a mutation, to invalidate existing // iterators. - uint64 version; + uint64_t version; }; struct MessageMapContainer : public MapContainer { diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 4e74386e2d..33034bf3f4 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -35,6 +35,7 @@ #include // A Python header file. +#include #include #include #include @@ -2191,22 +2192,22 @@ PyObject* InternalGetScalar(const Message* message, PyObject* result = NULL; switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { - int32 value = reflection->GetInt32(*message, field_descriptor); + int32_t value = reflection->GetInt32(*message, field_descriptor); result = PyInt_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { - int64 value = reflection->GetInt64(*message, field_descriptor); + int64_t value = reflection->GetInt64(*message, field_descriptor); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT32: { - uint32 value = reflection->GetUInt32(*message, field_descriptor); + uint32_t value = reflection->GetUInt32(*message, field_descriptor); result = PyInt_FromSize_t(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { - uint64 value = reflection->GetUInt64(*message, field_descriptor); + uint64_t value = reflection->GetUInt64(*message, field_descriptor); result = PyLong_FromUnsignedLongLong(value); break; } diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index a1e8326512..6a175dd667 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -36,6 +36,7 @@ #include +#include #include #include #include @@ -286,25 +287,25 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg); ((field_descriptor)->label() == FieldDescriptor::LABEL_REPEATED) #define GOOGLE_CHECK_GET_INT32(arg, value, err) \ - int32 value; \ + int32_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } #define GOOGLE_CHECK_GET_INT64(arg, value, err) \ - int64 value; \ + int64_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } #define GOOGLE_CHECK_GET_UINT32(arg, value, err) \ - uint32 value; \ + uint32_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } #define GOOGLE_CHECK_GET_UINT64(arg, value, err) \ - uint64 value; \ + uint64_t value; \ if (!CheckAndGetInteger(arg, &value)) { \ return err; \ } diff --git a/python/google/protobuf/pyext/repeated_scalar_container.cc b/python/google/protobuf/pyext/repeated_scalar_container.cc index 5a5c4db16e..d76114bbae 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.cc +++ b/python/google/protobuf/pyext/repeated_scalar_container.cc @@ -33,6 +33,7 @@ #include +#include #include #include @@ -207,25 +208,25 @@ static PyObject* Item(PyObject* pself, Py_ssize_t index) { PyObject* result = nullptr; switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { - int32 value = + int32_t value = reflection->GetRepeatedInt32(*message, field_descriptor, index); result = PyInt_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { - int64 value = + int64_t value = reflection->GetRepeatedInt64(*message, field_descriptor, index); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT32: { - uint32 value = + uint32_t value = reflection->GetRepeatedUInt32(*message, field_descriptor, index); result = PyLong_FromLongLong(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { - uint64 value = + uint64_t value = reflection->GetRepeatedUInt64(*message, field_descriptor, index); result = PyLong_FromUnsignedLongLong(value); break; diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index c376c7bac7..9c4ca90ee6 100644 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -567,8 +567,6 @@ class _Printer(object): self.out.write(', ') self.PrintFieldValue(field, value[-1]) self.out.write(']') - if self.force_colon: - self.out.write(':') self.out.write(' ' if self.as_one_line else '\n') def _PrintMessageFieldValue(self, value): @@ -1060,7 +1058,7 @@ class _Parser(object): value_cpptype = field.message_type.fields_by_name['value'].cpp_type if value_cpptype == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: value = getattr(message, field.name)[sub_message.key] - value.MergeFrom(sub_message.value) + value.CopyFrom(sub_message.value) else: getattr(message, field.name)[sub_message.key] = sub_message.value diff --git a/python/tox.ini b/python/tox.ini index 9fabb6ddbb..f9eee920fd 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -14,10 +14,9 @@ setenv = commands = python setup.py -q build_py python: python setup.py -q build - # --warnings_as_errors disabled until we update the Python C extension. See: - # https://github.com/protocolbuffers/protobuf/issues/7930 - # cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension - cpp: python setup.py -q build --cpp_implementation --compile_static_extension + # --warnings_as_errors disabled for Python 2.7 because _POSIX_C_SOURCE and _XOPEN_SOURCE are redefined + py27-cpp: python setup.py -q build --cpp_implementation --compile_static_extension + py{33,34,35,36,37,38,39}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension python: python setup.py -q test -q cpp: python setup.py -q test -q --cpp_implementation python: python setup.py -q test_conformance diff --git a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb index b4a158f37c..4f70f52dc4 100755 --- a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb @@ -326,18 +326,6 @@ class RepeatedFieldTest < Test::Unit::TestCase end end - def test_compact! - m = TestMessage.new - m.repeated_msg << TestMessage2.new(:foo => 1) - m.repeated_msg << nil - m.repeated_msg << TestMessage2.new(:foo => 2) - reference_arr = m.repeated_string.to_a - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.compact! - end - end - def test_delete m = TestMessage.new reference_arr = %w(foo bar baz) diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index bc3e35a5ed..2fddc09629 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -315,7 +315,7 @@ bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) { return memcmp(&val1, &val2, 8) == 0; case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - return val1.str_val.size != val2.str_val.size || + return val1.str_val.size == val2.str_val.size && memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) == 0; case UPB_TYPE_MESSAGE: diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 67f22212c6..b01741b61c 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1250,7 +1250,9 @@ upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m, const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m, const char* name, upb_arena* arena) { - if (value == Qnil) return NULL; + if (value == Qnil) { + rb_raise(cTypeError, "nil message not allowed here."); + } VALUE klass = CLASS_OF(value); VALUE desc_rb = rb_ivar_get(klass, descriptor_instancevar_interned); diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index c27f30aa2d..c9eecee11e 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -37,7 +37,7 @@ #include "message.h" #include "repeated_field.h" -VALUE cError; +VALUE cParseError; VALUE cTypeError; const upb_fielddef* map_field_key(const upb_fielddef* field) { @@ -368,8 +368,10 @@ void Init_protobuf_c() { Map_register(protobuf); Message_register(protobuf); - cError = rb_const_get(protobuf, rb_intern("Error")); + cParseError = rb_const_get(protobuf, rb_intern("ParseError")); + rb_gc_register_mark_object(cParseError); cTypeError = rb_const_get(protobuf, rb_intern("TypeError")); + rb_gc_register_mark_object(cTypeError); rb_define_singleton_method(protobuf, "discard_unknown", Google_Protobuf_discard_unknown, 1); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index a7aeda2df2..61762fcd99 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6663,10 +6663,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { } bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { - if (!_upb_array_realloc(arr, arr->len + 1, arena)) { + if (!upb_array_resize(arr, arr->len + 1, arena)) { return false; } - arr->len++; upb_array_set(arr, arr->len - 1, val); return true; } diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index dde0c30183..0602bab4e7 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.15.3" + s.version = "3.15.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/tests/basic.rb b/ruby/tests/basic.rb index 107084e664..8ddf72b81e 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -52,10 +52,15 @@ module BasicTest outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass - outer_proto = outer.new( + outer.new( inners: [] - ) - outer_proto['inners'].to_s + )['inners'].to_s + + assert_raise Google::Protobuf::TypeError do + outer.new( + inners: [nil] + ).to_s + end end def test_has_field diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 1957422fa9..40c7726d83 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -436,6 +436,18 @@ module CommonTests end end + def test_b_8385 + m1 = Google::Protobuf::Map.new(:string, :string) + m2 = Google::Protobuf::Map.new(:string, :string) + + assert_equal m1, m2 + + m1["counter"] = "a" + m2["counter"] = "aa" + + assert_not_equal m1, m2 + end + def test_map_ctor m = Google::Protobuf::Map.new(:string, :int32, {"a" => 1, "b" => 2, "c" => 3}) diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 6307447bc3..1df6e1d4f1 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -339,18 +339,6 @@ class RepeatedFieldTest < Test::Unit::TestCase end end - def test_compact! - m = TestMessage.new - m.repeated_msg << TestMessage2.new(:foo => 1) - m.repeated_msg << nil - m.repeated_msg << TestMessage2.new(:foo => 2) - reference_arr = m.repeated_string.to_a - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.compact! - end - end - def test_delete m = TestMessage.new reference_arr = %w(foo bar baz) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index c16e188071..5ecf63f8c4 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -163,7 +163,6 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string type_url = 1; case 1: @@ -184,7 +183,8 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 1ee6112b8a..0f4facd1f4 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -268,7 +268,6 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -341,7 +340,8 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -673,7 +673,6 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -738,7 +737,8 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1043,7 +1043,6 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1065,7 +1064,8 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index 452d2bfec8..da49325ec1 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -62,6 +62,14 @@ const std::string& LazyString::Init() const { } +std::string* ArenaStringPtr::SetAndReturnNewString() { + std::string* new_string = new std::string(); + tagged_ptr_.Set(new_string); + return new_string; +} + +void ArenaStringPtr::DestroyNoArenaSlowPath() { delete UnsafeMutablePointer(); } + void ArenaStringPtr::Set(const std::string* default_value, ConstStringParam value, ::google::protobuf::Arena* arena) { if (IsDefault(default_value)) { diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 4238579bb4..a9eb5de33e 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -328,6 +328,12 @@ struct PROTOBUF_EXPORT ArenaStringPtr { template std::string* MutableSlow(::google::protobuf::Arena* arena, const Lazy&... lazy_default); + // Sets value to a newly allocated string and returns it + std::string* SetAndReturnNewString(); + + // Destroys the non-default string value out-of-line + void DestroyNoArenaSlowPath(); + }; inline void ArenaStringPtr::UnsafeSetDefault(const std::string* value) { @@ -379,9 +385,7 @@ inline std::string* ArenaStringPtr::MutableNoArenaNoDefault( // static global) and a branch to the slowpath (which calls operator new and // the ctor). DO NOT add any tagged-pointer operations here. if (IsDefault(default_value)) { - std::string* new_string = new std::string(); - tagged_ptr_.Set(new_string); - return new_string; + return SetAndReturnNewString(); } else { return UnsafeMutablePointer(); } @@ -389,7 +393,7 @@ inline std::string* ArenaStringPtr::MutableNoArenaNoDefault( inline void ArenaStringPtr::DestroyNoArena(const std::string* default_value) { if (!IsDefault(default_value)) { - delete UnsafeMutablePointer(); + DestroyNoArenaSlowPath(); } } diff --git a/src/google/protobuf/compiler/annotation_test_util.cc b/src/google/protobuf/compiler/annotation_test_util.cc index fb659f627f..3c47aa42db 100644 --- a/src/google/protobuf/compiler/annotation_test_util.cc +++ b/src/google/protobuf/compiler/annotation_test_util.cc @@ -30,6 +30,7 @@ #include +#include #include #include @@ -141,8 +142,8 @@ bool AtLeastOneAnnotationMatchesSubstring( e = annotations.end(); i != e; ++i) { const GeneratedCodeInfo::Annotation* annotation = *i; - uint32 begin = annotation->begin(); - uint32 end = annotation->end(); + uint32_t begin = annotation->begin(); + uint32_t end = annotation->end(); if (end < begin || end > file_content.size()) { return false; } diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 28b0bfa933..ff1fdd0511 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -34,6 +34,8 @@ #include +#include + #include #include @@ -2087,7 +2089,7 @@ Parse PROTO_FILES and generate output based on the options given: } bool CommandLineInterface::EnforceProto3OptionalSupport( - const std::string& codegen_name, uint64 supported_features, + const std::string& codegen_name, uint64_t supported_features, const std::vector& parsed_files) const { bool supports_proto3_optional = supported_features & CodeGenerator::FEATURE_PROTO3_OPTIONAL; diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 4ff2471c76..73551f0b8d 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -38,6 +38,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ #define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ +#include #include #include #include @@ -229,7 +230,7 @@ class PROTOC_EXPORT CommandLineInterface { // Fails if these files use proto3 optional and the code generator doesn't // support it. This is a permanent check. bool EnforceProto3OptionalSupport( - const std::string& codegen_name, uint64 supported_features, + const std::string& codegen_name, uint64_t supported_features, const std::vector& parsed_files) const; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 74dc9bffdb..92f3d08eb7 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -36,6 +36,8 @@ #include #include +#include + #ifndef _MSC_VER #include #endif @@ -211,7 +213,7 @@ class CommandLineInterfaceTest : public testing::Test { // code generator that omits the given feature(s). void CreateGeneratorWithMissingFeatures(const std::string& name, const std::string& description, - uint64 features) { + uint64_t features) { MockCodeGenerator* generator = new MockCodeGenerator(name); generator->SuppressFeatures(features); mock_generators_to_delete_.push_back(generator); diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 7f9754f67f..c9b9c20b9c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -32,10 +32,14 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include +#include #include -#include #include +#include #include #include @@ -49,13 +53,13 @@ namespace { // is kint32max, GOOGLE_ARRAYSIZE will overflow. In such cases we should omit the // generation of the GOOGLE_ARRAYSIZE constant. bool ShouldGenerateArraySize(const EnumDescriptor* descriptor) { - int32 max_value = descriptor->value(0)->number(); + int32_t max_value = descriptor->value(0)->number(); for (int i = 0; i < descriptor->value_count(); i++) { if (descriptor->value(i)->number() > max_value) { max_value = descriptor->value(i)->number(); } } - return max_value != kint32max; + return max_value != std::numeric_limits::max(); } // Returns the number of unique numeric enum values. This is less than diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc index f95e14e58b..b28f6f2d27 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_field.cc @@ -33,6 +33,8 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include + +#include #include #include @@ -89,7 +91,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["}"] = ""; } -void FieldGenerator::SetHasBitIndex(int32 has_bit_index) { +void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { if (!HasHasbit(descriptor_)) { GOOGLE_CHECK_EQ(has_bit_index, -1); return; diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h index 5a77639407..b210ef92b9 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_field.h @@ -35,6 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ +#include #include #include #include @@ -180,7 +181,7 @@ class FieldGenerator { // are placed in the message's ByteSize() method. virtual void GenerateByteSize(io::Printer* printer) const = 0; - void SetHasBitIndex(int32 has_bit_index); + void SetHasBitIndex(int32_t has_bit_index); protected: const FieldDescriptor* descriptor_; diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 5825af2181..ceecb95078 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -642,7 +643,7 @@ const char* DeclaredTypeMethodName(FieldDescriptor::Type type) { } std::string Int32ToString(int number) { - if (number == kint32min) { + if (number == std::numeric_limits::min()) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 return StrCat(number + 1, " - 1"); @@ -651,8 +652,8 @@ std::string Int32ToString(int number) { } } -std::string Int64ToString(const std::string& macro_prefix, int64 number) { - if (number == kint64min) { +std::string Int64ToString(const std::string& macro_prefix, int64_t number) { + if (number == std::numeric_limits::min()) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 return StrCat(macro_prefix, "_LONGLONG(", number + 1, ") - 1"); @@ -660,7 +661,7 @@ std::string Int64ToString(const std::string& macro_prefix, int64 number) { return StrCat(macro_prefix, "_LONGLONG(", number, ")"); } -std::string UInt64ToString(const std::string& macro_prefix, uint64 number) { +std::string UInt64ToString(const std::string& macro_prefix, uint64_t number) { return StrCat(macro_prefix, "_ULONGLONG(", number, ")"); } @@ -748,7 +749,8 @@ std::string FilenameIdentifier(const std::string& filename) { } else { // Not alphanumeric. To avoid any possibility of name conflicts we // use the hex code for the character. - StrAppend(&result, "_", strings::Hex(static_cast(filename[i]))); + StrAppend(&result, "_", + strings::Hex(static_cast(filename[i]))); } } return result; @@ -1612,7 +1614,7 @@ class ParseLoopGenerator { } // Convert a 1 or 2 byte varint into the equivalent value upon a direct load. - static uint32 SmallVarintValue(uint32 x) { + static uint32_t SmallVarintValue(uint32_t x) { GOOGLE_DCHECK(x < 128 * 128); if (x >= 128) x += (x & 0xFF80) + 128; return x; @@ -1629,7 +1631,7 @@ class ParseLoopGenerator { void GenerateFieldBody(internal::WireFormatLite::WireType wiretype, const FieldDescriptor* field) { - uint32 tag = WireFormatLite::MakeTag(field->number(), wiretype); + uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype); switch (wiretype) { case WireFormatLite::WIRETYPE_VARINT: { std::string type = PrimitiveTypeName(options_, field->cpp_type()); @@ -1724,16 +1726,16 @@ class ParseLoopGenerator { // Returns the tag for this field and in case of repeated packable fields, // sets a fallback tag in fallback_tag_ptr. - static uint32 ExpectedTag(const FieldDescriptor* field, - uint32* fallback_tag_ptr) { - uint32 expected_tag; + static uint32_t ExpectedTag(const FieldDescriptor* field, + uint32_t* fallback_tag_ptr) { + uint32_t expected_tag; if (field->is_packable()) { auto expected_wiretype = WireFormat::WireTypeForFieldType(field->type()); expected_tag = WireFormatLite::MakeTag(field->number(), expected_wiretype); GOOGLE_CHECK(expected_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED); auto fallback_wiretype = WireFormatLite::WIRETYPE_LENGTH_DELIMITED; - uint32 fallback_tag = + uint32_t fallback_tag = WireFormatLite::MakeTag(field->number(), fallback_wiretype); if (field->is_packed()) std::swap(expected_tag, fallback_tag); @@ -1752,8 +1754,7 @@ class ParseLoopGenerator { format_( "while (!ctx->Done(&ptr)) {\n" " $uint32$ tag;\n" - " ptr = $pi_ns$::ReadTag(ptr, &tag);\n" - " CHK_(ptr);\n"); + " ptr = $pi_ns$::ReadTag(ptr, &tag);\n"); if (!ordered_fields.empty()) format_(" switch (tag >> 3) {\n"); format_.Indent(); @@ -1763,14 +1764,14 @@ class ParseLoopGenerator { PrintFieldComment(format_, field); format_("case $1$:\n", field->number()); format_.Indent(); - uint32 fallback_tag = 0; - uint32 expected_tag = ExpectedTag(field, &fallback_tag); + uint32_t fallback_tag = 0; + uint32_t expected_tag = ExpectedTag(field, &fallback_tag); format_( "if (PROTOBUF_PREDICT_TRUE(static_cast<$uint8$>(tag) == $1$)) {\n", expected_tag & 0xFF); format_.Indent(); auto wiretype = WireFormatLite::GetTagWireType(expected_tag); - uint32 tag = WireFormatLite::MakeTag(field->number(), wiretype); + uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype); int tag_size = io::CodedOutputStream::VarintSize32(tag); bool is_repeat = ShouldRepeat(field, wiretype); if (is_repeat) { @@ -1807,7 +1808,8 @@ class ParseLoopGenerator { if (!ordered_fields.empty()) format_("default: {\n"); if (!ordered_fields.empty()) format_("handle_unusual:\n"); format_( - " if ((tag & 7) == 4 || tag == 0) {\n" + " if ((tag == 0) || ((tag & 7) == 4)) {\n" + " CHK_(ptr);\n" " ctx->SetLastTag(tag);\n" " goto success;\n" " }\n"); @@ -1821,9 +1823,9 @@ class ParseLoopGenerator { descriptor->extension_range(i); if (i > 0) format_(" ||\n "); - uint32 start_tag = WireFormatLite::MakeTag( + uint32_t start_tag = WireFormatLite::MakeTag( range->start, static_cast(0)); - uint32 end_tag = WireFormatLite::MakeTag( + uint32_t end_tag = WireFormatLite::MakeTag( range->end, static_cast(0)); if (range->end > FieldDescriptor::kMaxNumber) { diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index 46d9477f5e..43faf1cdaf 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -36,11 +36,13 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ #include +#include #include #include #include #include +#include #include #include #include @@ -184,9 +186,6 @@ std::string ResolveKeyword(const std::string& name); // anyway, so normally this just returns field->name(). std::string FieldName(const FieldDescriptor* field); -// Get the sanitized name that should be used for the given enum in C++ code. -std::string EnumValueName(const EnumValueDescriptor* enum_value); - // Returns an estimate of the compiler's alignment for the field. This // can't guarantee to be correct because the generated code could be compiled on // different systems with different alignment rules. The estimates below assume @@ -222,7 +221,7 @@ const char* DeclaredTypeMethodName(FieldDescriptor::Type type); std::string Int32ToString(int number); // Return the code that evaluates to the number when compiled. -std::string Int64ToString(const Options& options, int64 number); +std::string Int64ToString(const Options& options, int64_t number); // Get code that evaluates to the field's default value. std::string DefaultValue(const Options& options, const FieldDescriptor* field); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 73e66ae90f..2e2c2d4e3d 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,7 @@ static constexpr int kNoHasbit = -1; // masks is allowed to be shorter than _has_bits_, but at least one element of // masks must be non-zero. std::string ConditionalToCheckBitmasks( - const std::vector& masks, bool return_success = true, + const std::vector& masks, bool return_success = true, StringPiece has_bits_var = "_has_bits_") { std::vector parts; for (int i = 0; i < masks.size(); i++) { @@ -405,23 +406,23 @@ std::vector> CollectFields( // Returns a bit mask based on has_bit index of "fields" that are typically on // the same chunk. It is used in a group presence check where _has_bits_ is // masked to tell if any thing in "fields" is present. -uint32 GenChunkMask(const std::vector& fields, - const std::vector& has_bit_indices) { +uint32_t GenChunkMask(const std::vector& fields, + const std::vector& has_bit_indices) { GOOGLE_CHECK(!fields.empty()); int first_index_offset = has_bit_indices[fields.front()->index()] / 32; - uint32 chunk_mask = 0; + uint32_t chunk_mask = 0; for (auto field : fields) { // "index" defines where in the _has_bits_ the field appears. int index = has_bit_indices[field->index()]; GOOGLE_CHECK_EQ(first_index_offset, index / 32); - chunk_mask |= static_cast(1) << (index % 32); + chunk_mask |= static_cast(1) << (index % 32); } GOOGLE_CHECK_NE(0, chunk_mask); return chunk_mask; } // Return the number of bits set in n, a non-negative integer. -static int popcnt(uint32 n) { +static int popcnt(uint32_t n) { int result = 0; while (n != 0) { result += (n & 1); @@ -507,7 +508,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, format("if (PROTOBUF_PREDICT_FALSE("); int first_word = HasbitWord(chunk, 0); while (chunk < limit_chunk_) { - uint32 mask = 0; + uint32_t mask = 0; int this_word = HasbitWord(chunk, 0); // Generate mask for chunks on the same word. for (; chunk < limit_chunk_ && HasbitWord(chunk, 0) == this_word; chunk++) { @@ -1654,8 +1655,8 @@ namespace { // We need to calculate for each field what function the table driven code // should use to serialize it. This returns the index in a lookup table. -uint32 CalcFieldNum(const FieldGenerator& generator, - const FieldDescriptor* field, const Options& options) { +uint32_t CalcFieldNum(const FieldGenerator& generator, + const FieldDescriptor* field, const Options& options) { bool is_a_map = IsMapEntryMessage(field->containing_type()); int type = field->type(); if (type == FieldDescriptor::TYPE_STRING || @@ -1707,7 +1708,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { const FieldDescriptor* field = sorted[i]; const FieldGenerator& generator = field_generators_.get(field); - uint32 tag = internal::WireFormatLite::MakeTag( + uint32_t tag = internal::WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); std::map vars; @@ -1764,7 +1765,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { if (i == sorted.size()) break; const FieldDescriptor* field = sorted[i]; - uint32 tag = internal::WireFormatLite::MakeTag( + uint32_t tag = internal::WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); if (field->is_packed()) { tag = internal::WireFormatLite::MakeTag( @@ -1827,7 +1828,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { tag); } else if (field->real_containing_oneof()) { format.Set("oneofoffset", - sizeof(uint32) * field->containing_oneof()->index()); + sizeof(uint32_t) * field->containing_oneof()->index()); format( "{PROTOBUF_FIELD_OFFSET($classtype$, $field_name$_), $1$," " PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_) + " @@ -1933,7 +1934,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { } } if (num_required_fields_ > 0) { - const std::vector masks_for_has_bits = RequiredFieldsBitMask(); + const std::vector masks_for_has_bits = RequiredFieldsBitMask(); format( "static bool MissingRequiredFields(const HasBits& has_bits) " "{\n" @@ -2751,7 +2752,7 @@ void MessageGenerator::GenerateClear(io::Printer* printer) { if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. - uint32 chunk_mask = GenChunkMask(chunk, has_bit_indices_); + uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); @@ -3055,7 +3056,7 @@ void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) { if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. - uint32 chunk_mask = GenChunkMask(chunk, has_bit_indices_); + uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); @@ -3445,6 +3446,12 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( } } + void EmitIfNotNull(const FieldDescriptor* field) { + if (field != nullptr) { + Emit(field); + } + } + void Flush() { if (!v_.empty()) { mg_->GenerateSerializeOneofFields(format_.printer(), v_); @@ -3471,6 +3478,61 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( int cached_has_bit_index_; }; + class LazyExtensionRangeEmitter { + public: + LazyExtensionRangeEmitter(MessageGenerator* mg, io::Printer* printer) + : mg_(mg), format_(printer) {} + + void AddToRange(const Descriptor::ExtensionRange* range) { + if (!has_current_range_) { + current_combined_range_ = *range; + has_current_range_ = true; + } else { + current_combined_range_.start = + std::min(current_combined_range_.start, range->start); + current_combined_range_.end = + std::max(current_combined_range_.end, range->end); + } + } + + void Flush() { + if (has_current_range_) { + mg_->GenerateSerializeOneExtensionRange(format_.printer(), + ¤t_combined_range_); + } + has_current_range_ = false; + } + + private: + MessageGenerator* mg_; + Formatter format_; + bool has_current_range_ = false; + Descriptor::ExtensionRange current_combined_range_; + }; + + // We need to track the largest weak field, because weak fields are serialized + // differently than normal fields. The WeakFieldMap::FieldWriter will + // serialize all weak fields that are ordinally between the last serialized + // weak field and the current field. In order to guarantee that all weak + // fields are serialized, we need to make sure to emit the code to serialize + // the largest weak field present at some point. + class LargestWeakFieldHolder { + public: + const FieldDescriptor* Release() { + const FieldDescriptor* result = field_; + field_ = nullptr; + return result; + } + void ReplaceIfLarger(const FieldDescriptor* field) { + if (field_ == nullptr || field_->number() < field->number()) { + field_ = field; + } + } + + private: + const FieldDescriptor* field_ = nullptr; + }; + std::vector ordered_fields = SortFieldsByNumber(descriptor_); @@ -3494,7 +3556,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( // Merge the fields and the extension ranges, both sorted by field number. { LazySerializerEmitter e(this, printer); - const FieldDescriptor* last_weak_field = nullptr; + LazyExtensionRangeEmitter re(this, printer); + LargestWeakFieldHolder largest_weak_field; int i, j; for (i = 0, j = 0; i < ordered_fields.size() || j < sorted_extensions.size();) { @@ -3505,31 +3568,22 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( if (IsFieldStripped(field, options_)) { continue; } + re.Flush(); if (field->options().weak()) { - if (last_weak_field == nullptr || - last_weak_field->number() < field->number()) { - last_weak_field = field; - } + largest_weak_field.ReplaceIfLarger(field); PrintFieldComment(format, field); } else { - if (last_weak_field != nullptr) { - e.Emit(last_weak_field); - last_weak_field = nullptr; - } + e.EmitIfNotNull(largest_weak_field.Release()); e.Emit(field); } } else { - if (last_weak_field != nullptr) { - e.Emit(last_weak_field); - last_weak_field = nullptr; - } + e.EmitIfNotNull(largest_weak_field.Release()); e.Flush(); - GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); + re.AddToRange(sorted_extensions[j++]); } } - if (last_weak_field != nullptr) { - e.Emit(last_weak_field); - } + re.Flush(); + e.EmitIfNotNull(largest_weak_field.Release()); } std::map vars; @@ -3644,9 +3698,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( format("}\n"); } -std::vector MessageGenerator::RequiredFieldsBitMask() const { +std::vector MessageGenerator::RequiredFieldsBitMask() const { const int array_size = HasBitsSize(); - std::vector masks(array_size, 0); + std::vector masks(array_size, 0); for (auto field : FieldRange(descriptor_)) { if (!field->is_required()) { @@ -3654,7 +3708,8 @@ std::vector MessageGenerator::RequiredFieldsBitMask() const { } const int has_bit_index = has_bit_indices_[field->index()]; - masks[has_bit_index / 32] |= static_cast(1) << (has_bit_index % 32); + masks[has_bit_index / 32] |= static_cast(1) + << (has_bit_index % 32); } return masks; } @@ -3735,7 +3790,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) { // present then the fast path executes; otherwise the slow path executes. if (num_required_fields_ > 1) { // The fast path works if all required fields are present. - const std::vector masks_for_has_bits = RequiredFieldsBitMask(); + const std::vector masks_for_has_bits = RequiredFieldsBitMask(); format("if ($1$) { // All required fields are present.\n", ConditionalToCheckBitmasks(masks_for_has_bits)); format.Indent(); @@ -3791,7 +3846,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) { if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. - uint32 chunk_mask = GenChunkMask(chunk, has_bit_indices_); + uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index 4e3f4b9822..cb1d77c9be 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -35,9 +35,11 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ +#include #include #include #include + #include #include #include @@ -179,7 +181,7 @@ class MessageGenerator { int HasByteIndex(const FieldDescriptor* a) const; int HasWordIndex(const FieldDescriptor* a) const; bool SameHasByte(const FieldDescriptor* a, const FieldDescriptor* b) const; - std::vector RequiredFieldsBitMask() const; + std::vector RequiredFieldsBitMask() const; const Descriptor* descriptor_; int index_in_file_messages_; diff --git a/src/google/protobuf/compiler/cpp/cpp_names.h b/src/google/protobuf/compiler/cpp/cpp_names.h index 9bede74fc8..cbc69a7cb7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_names.h +++ b/src/google/protobuf/compiler/cpp/cpp_names.h @@ -40,6 +40,7 @@ namespace protobuf { class Descriptor; class EnumDescriptor; +class EnumValueDescriptor; class FieldDescriptor; namespace compiler { @@ -72,6 +73,10 @@ std::string QualifiedExtensionName(const FieldDescriptor* d); // anyway, so normally this just returns field->name(). std::string FieldName(const FieldDescriptor* field); +// Get the (unqualified) name that should be used for this enum value in C++ +// code. +std::string EnumValueName(const EnumValueDescriptor* enum_value); + // Strips ".proto" or ".protodevel" from the end of a filename. PROTOC_EXPORT std::string StripProto(const std::string& filename); diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index d840492b68..9f7f61e169 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -33,6 +33,7 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include + #include #include #include @@ -301,7 +302,7 @@ void RepeatedPrimitiveFieldGenerator::GeneratePrivateMembers( io::Printer* printer) const { Formatter format(printer, variables_); format("::$proto_ns$::RepeatedField< $type$ > $name$_;\n"); - if (descriptor_->is_packed() && + if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 && HasGeneratedMethods(descriptor_->file(), options_)) { format("mutable std::atomic _$name$_cached_byte_size_;\n"); } @@ -409,13 +410,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( io::Printer* printer) const { Formatter format(printer, variables_); if (descriptor_->is_packed()) { - if (FixedSize(descriptor_->type()) > 0) { - format( - "if (this->_internal_$name$_size() > 0) {\n" - " target = stream->WriteFixedPacked($number$, _internal_$name$(), " - "target);\n" - "}\n"); - } else { + if (FixedSize(descriptor_->type()) == -1) { format( "{\n" " int byte_size = " @@ -425,6 +420,12 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( " $number$, _internal_$name$(), byte_size, target);\n" " }\n" "}\n"); + } else { + format( + "if (this->_internal_$name$_size() > 0) {\n" + " target = stream->WriteFixedPacked($number$, _internal_$name$(), " + "target);\n" + "}\n"); } } else { format( @@ -460,11 +461,14 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize( " total_size += $tag_size$ +\n" " ::$proto_ns$::internal::WireFormatLite::Int32Size(\n" " static_cast<$int32$>(data_size));\n" - "}\n" - "int cached_size = ::$proto_ns$::internal::ToCachedSize(data_size);\n" - "_$name$_cached_byte_size_.store(cached_size,\n" - " std::memory_order_relaxed);\n" - "total_size += data_size;\n"); + "}\n"); + if (FixedSize(descriptor_->type()) == -1) { + format( + "int cached_size = ::$proto_ns$::internal::ToCachedSize(data_size);\n" + "_$name$_cached_byte_size_.store(cached_size,\n" + " std::memory_order_relaxed);\n"); + } + format("total_size += data_size;\n"); } else { format( "total_size += $tag_size$ *\n" @@ -480,7 +484,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateConstinitInitializer( io::Printer* printer) const { Formatter format(printer, variables_); format("$name$_()"); - if (descriptor_->is_packed() && + if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 && HasGeneratedMethods(descriptor_->file(), options_)) { format("\n, _$name$_cached_byte_size_()"); } diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.inc b/src/google/protobuf/compiler/cpp/cpp_unittest.inc index c8238abdef..a717f99e4d 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.inc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.inc @@ -44,6 +44,8 @@ // correctly and produces the interfaces we expect, which is why this test // is written this way. +#include +#include #include #include @@ -203,10 +205,13 @@ TEST(GENERATED_MESSAGE_TEST_NAME, Trigraph) { TEST(GENERATED_MESSAGE_TEST_NAME, ExtremeSmallIntegerDefault) { const UNITTEST::TestExtremeDefaultValues& extreme_default = UNITTEST::TestExtremeDefaultValues::default_instance(); - EXPECT_EQ(~0x7fffffff, kint32min); - EXPECT_EQ(PROTOBUF_LONGLONG(~0x7fffffffffffffff), kint64min); - EXPECT_EQ(kint32min, extreme_default.really_small_int32()); - EXPECT_EQ(kint64min, extreme_default.really_small_int64()); + EXPECT_EQ(~0x7fffffff, std::numeric_limits::min()); + EXPECT_EQ(PROTOBUF_LONGLONG(~0x7fffffffffffffff), + std::numeric_limits::min()); + EXPECT_EQ(std::numeric_limits::min(), + extreme_default.really_small_int32()); + EXPECT_EQ(std::numeric_limits::min(), + extreme_default.really_small_int64()); } TEST(GENERATED_MESSAGE_TEST_NAME, Accessors) { @@ -369,7 +374,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ClearOneField) { UNITTEST::TestAllTypes message; TestUtil::SetAllFields(&message); - int64 original_value = message.optional_int64(); + int64_t original_value = message.optional_int64(); // Clear the field and make sure it shows up as cleared. message.clear_optional_int64(); @@ -498,7 +503,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ADLSwap) { // Note the address of one of the repeated fields, to verify it was swapped // rather than copied. - const int32* addr = &message1.repeated_int32().Get(0); + const int32_t* addr = &message1.repeated_int32().Get(0); using std::swap; swap(message1, message2); @@ -648,7 +653,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, NonEmptyMergeFrom) { // This tests concatenating. message2.add_repeated_int32(message1.repeated_int32(1)); - int32 i = message1.repeated_int32(0); + int32_t i = message1.repeated_int32(0); message1.clear_repeated_int32(); message1.add_repeated_int32(i); @@ -665,8 +670,8 @@ TEST(GENERATED_MESSAGE_TEST_NAME, SerializationToArray) { TestUtil::SetAllFields(&message1); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); TestUtil::ExpectAllFieldsSet(message2); @@ -679,8 +684,9 @@ TEST(GENERATED_MESSAGE_TEST_NAME, PackedFieldsSerializationToArray) { TestUtil::SetPackedFields(&packed_message1); int packed_size = packed_message1.ByteSizeLong(); packed_data.resize(packed_size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&packed_data)); - uint8* end = packed_message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = + reinterpret_cast(::google::protobuf::string_as_array(&packed_data)); + uint8_t* end = packed_message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(packed_size, end - start); EXPECT_TRUE(packed_message2.ParseFromString(packed_data)); TestUtil::ExpectPackedFieldsSet(packed_message2); @@ -1846,8 +1852,8 @@ std::string data; message1.set_foo_int(123); int size = message1.ByteSizeLong(); data.resize(size); -uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); -uint8* end = message1.SerializeWithCachedSizesToArray(start); +uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); +uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_int(), 123); @@ -1860,8 +1866,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_string("foo"); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_string(), "foo"); @@ -1875,8 +1881,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_bytes("qux"); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_bytes(), "qux"); @@ -1889,8 +1895,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_enum(UNITTEST::TestOneof2::FOO); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_enum(), UNITTEST::TestOneof2::FOO); @@ -1903,8 +1909,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.mutable_foo_message()->set_qux_int(234); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foo_message().qux_int(), 234); @@ -1917,8 +1923,8 @@ EXPECT_EQ(message2.foo_int(), 123); message1.mutable_foogroup()->set_a(345); int size = message1.ByteSizeLong(); data.resize(size); - uint8* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); - uint8* end = message1.SerializeWithCachedSizesToArray(start); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); + uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); EXPECT_EQ(message2.foogroup().a(), 345); diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc index 9706c6d027..9a0799ee46 100644 --- a/src/google/protobuf/compiler/java/java_enum_field.cc +++ b/src/google/protobuf/compiler/java/java_enum_field.cc @@ -32,6 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -39,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -67,7 +69,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["default_number"] = StrCat(descriptor->default_value_enum()->number()); (*variables)["tag"] = StrCat( - static_cast(internal::WireFormat::MakeTag(descriptor))); + static_cast(internal::WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/src/google/protobuf/compiler/java/java_enum_field_lite.cc index dfa051c16d..8403f95fbd 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.cc @@ -32,6 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -39,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -74,7 +76,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["default_number"] = StrCat(descriptor->default_value_enum()->number()); (*variables)["tag"] = StrCat( - static_cast(internal::WireFormat::MakeTag(descriptor))); + static_cast(internal::WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported @@ -281,7 +283,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateInitializationCode( } void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -377,7 +379,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( } void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -632,7 +634,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( } void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.h b/src/google/protobuf/compiler/java/java_enum_field_lite.h index b5e9807728..fbc11279b5 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.h +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.h @@ -35,8 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -70,7 +72,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -95,7 +97,7 @@ class ImmutableEnumOneofFieldLiteGenerator void GenerateMembers(io::Printer* printer) const; void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldLiteGenerator); @@ -115,7 +117,7 @@ class RepeatedImmutableEnumFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_field.h b/src/google/protobuf/compiler/java/java_field.h index 9d04dc8455..df6c38d752 100644 --- a/src/google/protobuf/compiler/java/java_field.h +++ b/src/google/protobuf/compiler/java/java_field.h @@ -35,6 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ +#include #include #include #include @@ -104,7 +105,7 @@ class ImmutableFieldLiteGenerator { virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; virtual void GenerateInitializationCode(io::Printer* printer) const = 0; virtual void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const = 0; + std::vector* output) const = 0; virtual std::string GetBoxedType() const = 0; diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc index 3aebf72c7e..e32b6e32b5 100644 --- a/src/google/protobuf/compiler/java/java_helpers.cc +++ b/src/google/protobuf/compiler/java/java_helpers.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -500,11 +501,11 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable, return StrCat(field->default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: // Need to print as a signed int since Java has no unsigned. - return StrCat(static_cast(field->default_value_uint32())); + return StrCat(static_cast(field->default_value_uint32())); case FieldDescriptor::CPPTYPE_INT64: return StrCat(field->default_value_int64()) + "L"; case FieldDescriptor::CPPTYPE_UINT64: - return StrCat(static_cast(field->default_value_uint64())) + + return StrCat(static_cast(field->default_value_uint64())) + "L"; case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field->default_value_double(); @@ -896,11 +897,11 @@ bool HasRepeatedFields(const Descriptor* descriptor) { // // Note that we only use code points in [0x0000, 0xD7FF] and [0xE000, 0xFFFF]. // There will be no surrogate pairs in the encoded character sequence. -void WriteUInt32ToUtf16CharSequence(uint32 number, - std::vector* output) { +void WriteUInt32ToUtf16CharSequence(uint32_t number, + std::vector* output) { // For values in [0x0000, 0xD7FF], only use one char to encode it. if (number < 0xD800) { - output->push_back(static_cast(number)); + output->push_back(static_cast(number)); return; } // Encode into multiple chars. All except the last char will be in the range @@ -910,10 +911,10 @@ void WriteUInt32ToUtf16CharSequence(uint32 number, // them. while (number >= 0xD800) { // [0xE000, 0xFFFF] can represent 13 bits of info. - output->push_back(static_cast(0xE000 | (number & 0x1FFF))); + output->push_back(static_cast(0xE000 | (number & 0x1FFF))); number >>= 13; } - output->push_back(static_cast(number)); + output->push_back(static_cast(number)); } int GetExperimentalJavaFieldTypeForSingular(const FieldDescriptor* field) { @@ -994,7 +995,7 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) { } // Escape a UTF-16 character to be embedded in a Java string. -void EscapeUtf16ToString(uint16 code, std::string* output) { +void EscapeUtf16ToString(uint16_t code, std::string* output) { if (code == '\t') { output->append("\\t"); } else if (code == '\b') { diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h index 8cc2f5af80..5ede13cc77 100644 --- a/src/google/protobuf/compiler/java/java_helpers.h +++ b/src/google/protobuf/compiler/java/java_helpers.h @@ -35,7 +35,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ +#include #include + #include #include #include @@ -412,15 +414,16 @@ inline std::string GeneratedCodeVersionSuffix() { return "V3"; } -void WriteUInt32ToUtf16CharSequence(uint32 number, std::vector* output); +void WriteUInt32ToUtf16CharSequence(uint32_t number, + std::vector* output); inline void WriteIntToUtf16CharSequence(int value, - std::vector* output) { - WriteUInt32ToUtf16CharSequence(static_cast(value), output); + std::vector* output) { + WriteUInt32ToUtf16CharSequence(static_cast(value), output); } // Escape a UTF-16 character so it can be embedded in a Java string literal. -void EscapeUtf16ToString(uint16 code, std::string* output); +void EscapeUtf16ToString(uint16_t code, std::string* output); // Only the lowest two bytes of the return value are used. The lowest byte // is the integer value of a j/c/g/protobuf/FieldType enum. For the other diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc index 63c1ad3ebd..8db281d93e 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -505,7 +507,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( } void ImmutableMapFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.h b/src/google/protobuf/compiler/java/java_map_field_lite.h index 49cbf6cca7..37aec06398 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.h +++ b/src/google/protobuf/compiler/java/java_map_field_lite.h @@ -31,6 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_LITE_H__ +#include + #include namespace google { @@ -52,7 +54,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index ba31775334..f2df25f0fe 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -1213,11 +1214,11 @@ void ImmutableMessageGenerator::GenerateParsingConstructor( for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = sorted_fields[i]; - uint32 tag = WireFormatLite::MakeTag( + uint32_t tag = WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); printer->Print("case $tag$: {\n", "tag", - StrCat(static_cast(tag))); + StrCat(static_cast(tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCode(printer); @@ -1230,10 +1231,10 @@ void ImmutableMessageGenerator::GenerateParsingConstructor( if (field->is_packable()) { // To make packed = true wire compatible, we generate parsing code from a // packed version of this field regardless of field->options().packed(). - uint32 packed_tag = WireFormatLite::MakeTag( + uint32_t packed_tag = WireFormatLite::MakeTag( field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); printer->Print("case $tag$: {\n", "tag", - StrCat(static_cast(packed_tag))); + StrCat(static_cast(packed_tag))); printer->Indent(); field_generators_.get(field).GenerateParsingCodeFromPacked(printer); diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc index b17859d6b3..73f1bcf543 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -32,13 +32,15 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include #include #include #include -#include #include #include #include @@ -276,7 +278,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( } void ImmutableMessageFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -366,7 +368,7 @@ void ImmutableMessageOneofFieldLiteGenerator::GenerateMembers( } void ImmutableMessageOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -731,7 +733,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( } void RepeatedImmutableMessageFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.h b/src/google/protobuf/compiler/java/java_message_field_lite.h index c0a9b37f4f..8b935e68f9 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.h +++ b/src/google/protobuf/compiler/java/java_message_field_lite.h @@ -35,8 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -70,7 +72,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -95,7 +97,7 @@ class ImmutableMessageOneofFieldLiteGenerator void GenerateMembers(io::Printer* printer) const; void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator); @@ -115,7 +117,7 @@ class RepeatedImmutableMessageFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 4afffdc7a9..cae9963759 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -471,7 +472,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( // Collect field info into a sequence of UTF-16 chars. It will be embedded // as a Java string in the generated code. - std::vector chars; + std::vector chars; int flags = 0; if (IsProto2(descriptor_->file())) { @@ -553,7 +554,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( printer->Print("java.lang.String info =\n"); std::string line; for (size_t i = 0; i < chars.size(); i++) { - uint16 code = chars[i]; + uint16_t code = chars[i]; EscapeUtf16ToString(code, &line); if (line.size() >= 80) { printer->Print(" \"$string$\" +\n", "string", line); diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc index 8bc68b7b22..65cc05adcf 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field.cc @@ -32,6 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -41,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -112,7 +114,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_type"] = GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); if (IsReferenceType(GetJavaType(descriptor))) { diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc index 11facdd0a7..1932e99a27 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc @@ -34,6 +34,7 @@ #include +#include #include #include @@ -78,7 +79,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_type"] = GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; @@ -304,7 +305,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( void ImmutablePrimitiveFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -385,7 +386,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers( } void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -615,7 +616,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers( } void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/src/google/protobuf/compiler/java/java_primitive_field_lite.h index 5867cee746..22a25579a7 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.h @@ -35,8 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -70,7 +72,7 @@ class ImmutablePrimitiveFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -96,7 +98,7 @@ class ImmutablePrimitiveOneofFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator); @@ -116,7 +118,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index 485fcf812e..2e9a9e789a 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -33,6 +33,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -42,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -71,7 +73,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "String"; (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["null_check"] = diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc index a0c27735c1..63702c1992 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -33,6 +33,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + +#include #include #include @@ -42,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -72,7 +74,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "java.lang.String"; (*variables)["tag"] = - StrCat(static_cast(WireFormat::MakeTag(descriptor))); + StrCat(static_cast(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // We use `x.getClass()` as a null check because it generates less bytecode @@ -303,7 +305,7 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( } void ImmutableStringFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -407,7 +409,7 @@ void ImmutableStringOneofFieldLiteGenerator::GenerateMembers( } void ImmutableStringOneofFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); @@ -703,7 +705,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers( } void RepeatedImmutableStringFieldLiteGenerator::GenerateFieldInfo( - io::Printer* printer, std::vector* output) const { + io::Printer* printer, std::vector* output) const { WriteIntToUtf16CharSequence(descriptor_->number(), output); WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.h b/src/google/protobuf/compiler/java/java_string_field_lite.h index b67135cd81..194a19ddc2 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.h +++ b/src/google/protobuf/compiler/java/java_string_field_lite.h @@ -36,8 +36,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ +#include #include #include + #include namespace google { @@ -71,7 +73,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; @@ -96,7 +98,7 @@ class ImmutableStringOneofFieldLiteGenerator void GenerateMembers(io::Printer* printer) const; void GenerateBuilderMembers(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator); }; @@ -115,7 +117,7 @@ class RepeatedImmutableStringFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const; void GenerateInitializationCode(io::Printer* printer) const; void GenerateFieldInfo(io::Printer* printer, - std::vector* output) const; + std::vector* output) const; std::string GetBoxedType() const; diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 3abb5c0b13..1fce106096 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -88,11 +89,11 @@ MockCodeGenerator::MockCodeGenerator(const std::string& name) : name_(name) {} MockCodeGenerator::~MockCodeGenerator() {} uint64_t MockCodeGenerator::GetSupportedFeatures() const { - uint64 all_features = CodeGenerator::FEATURE_PROTO3_OPTIONAL; + uint64_t all_features = CodeGenerator::FEATURE_PROTO3_OPTIONAL; return all_features & ~suppressed_features_; } -void MockCodeGenerator::SuppressFeatures(uint64 features) { +void MockCodeGenerator::SuppressFeatures(uint64_t features) { suppressed_features_ = features; } diff --git a/src/google/protobuf/compiler/mock_code_generator.h b/src/google/protobuf/compiler/mock_code_generator.h index 9677d1904d..6e101055de 100644 --- a/src/google/protobuf/compiler/mock_code_generator.h +++ b/src/google/protobuf/compiler/mock_code_generator.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_MOCK_CODE_GENERATOR_H__ +#include #include #include @@ -112,11 +113,11 @@ class MockCodeGenerator : public CodeGenerator { GeneratorContext* context, std::string* error) const override; uint64_t GetSupportedFeatures() const override; - void SuppressFeatures(uint64 features); + void SuppressFeatures(uint64_t features); private: std::string name_; - uint64 suppressed_features_ = 0; + uint64_t suppressed_features_ = 0; static std::string GetOutputFileContent(const std::string& generator_name, const std::string& parameter, diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index d92cd55873..b1bf2882e3 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -38,6 +38,7 @@ #include +#include #include #include #include @@ -243,8 +244,9 @@ bool Parser::ConsumeIdentifier(std::string* output, const char* error) { bool Parser::ConsumeInteger(int* output, const char* error) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { - uint64 value = 0; - if (!io::Tokenizer::ParseInteger(input_->current().text, kint32max, + uint64_t value = 0; + 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 an integer. @@ -260,19 +262,19 @@ bool Parser::ConsumeInteger(int* output, const char* error) { bool Parser::ConsumeSignedInteger(int* output, const char* error) { bool is_negative = false; - uint64 max_value = kint32max; + uint64_t max_value = std::numeric_limits::max(); if (TryConsume("-")) { is_negative = true; max_value += 1; } - uint64 value = 0; + uint64_t value = 0; DO(ConsumeInteger64(max_value, &value, error)); if (is_negative) value *= -1; *output = value; return true; } -bool Parser::ConsumeInteger64(uint64 max_value, uint64* output, +bool Parser::ConsumeInteger64(uint64_t max_value, uint64_t* output, const char* error) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (!io::Tokenizer::ParseInteger(input_->current().text, max_value, @@ -296,8 +298,9 @@ bool Parser::ConsumeNumber(double* output, const char* error) { return true; } else if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { // Also accept integers. - uint64 value = 0; - if (!io::Tokenizer::ParseInteger(input_->current().text, kuint64max, + uint64_t value = 0; + 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. @@ -829,8 +832,9 @@ bool IsMessageSetWireFormatMessage(const DescriptorProto& message) { // tag number can only be determined after all options have been parsed. void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) { const bool is_message_set = IsMessageSetWireFormatMessage(*message); - const int max_extension_number = - is_message_set ? kint32max : FieldDescriptor::kMaxNumber + 1; + const int max_extension_number = is_message_set + ? std::numeric_limits::max() + : FieldDescriptor::kMaxNumber + 1; for (int i = 0; i < message->extension_range_size(); ++i) { if (message->extension_range(i).end() == kMaxRangeSentinel) { message->mutable_extension_range(i)->set_end(max_extension_number); @@ -843,8 +847,9 @@ void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) { // tag number can only be determined after all options have been parsed. void AdjustReservedRangesWithMaxEndNumber(DescriptorProto* message) { const bool is_message_set = IsMessageSetWireFormatMessage(*message); - const int max_field_number = - is_message_set ? kint32max : FieldDescriptor::kMaxNumber + 1; + const int max_field_number = is_message_set + ? std::numeric_limits::max() + : FieldDescriptor::kMaxNumber + 1; for (int i = 0; i < message->reserved_range_size(); ++i) { if (message->reserved_range(i).end() == kMaxRangeSentinel) { message->mutable_reserved_range(i)->set_end(max_field_number); @@ -1260,11 +1265,11 @@ bool Parser::ParseDefaultAssignment( case FieldDescriptorProto::TYPE_SINT64: case FieldDescriptorProto::TYPE_SFIXED32: case FieldDescriptorProto::TYPE_SFIXED64: { - uint64 max_value = kint64max; + uint64_t max_value = std::numeric_limits::max(); if (field->type() == FieldDescriptorProto::TYPE_INT32 || field->type() == FieldDescriptorProto::TYPE_SINT32 || field->type() == FieldDescriptorProto::TYPE_SFIXED32) { - max_value = kint32max; + max_value = std::numeric_limits::max(); } // These types can be negative. @@ -1274,7 +1279,7 @@ bool Parser::ParseDefaultAssignment( ++max_value; } // Parse the integer to verify that it is not out-of-range. - uint64 value; + uint64_t value; DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. @@ -1286,10 +1291,10 @@ bool Parser::ParseDefaultAssignment( case FieldDescriptorProto::TYPE_UINT64: case FieldDescriptorProto::TYPE_FIXED32: case FieldDescriptorProto::TYPE_FIXED64: { - uint64 max_value = kuint64max; + uint64_t max_value = std::numeric_limits::max(); if (field->type() == FieldDescriptorProto::TYPE_UINT32 || field->type() == FieldDescriptorProto::TYPE_FIXED32) { - max_value = kuint32max; + max_value = std::numeric_limits::max(); } // Numeric, not negative. @@ -1297,7 +1302,7 @@ bool Parser::ParseDefaultAssignment( AddError("Unsigned field can't have negative default value."); } // Parse the integer to verify that it is not out-of-range. - uint64 value; + uint64_t value; DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. @@ -1529,15 +1534,17 @@ bool Parser::ParseOption(Message* options, } case io::Tokenizer::TYPE_INTEGER: { - uint64 value; - uint64 max_value = - is_negative ? static_cast(kint64max) + 1 : kuint64max; + uint64_t value; + uint64_t max_value = + 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(-value)); + static_cast(-value)); } else { value_location.AddPath( UninterpretedOption::kPositiveIntValueFieldNumber); @@ -2338,8 +2345,8 @@ bool Parser::ParsePackage(FileDescriptorProto* file, } bool Parser::ParseImport(RepeatedPtrField* dependency, - RepeatedField* public_dependency, - RepeatedField* weak_dependency, + RepeatedField* public_dependency, + RepeatedField* weak_dependency, const LocationRecorder& root_location, const FileDescriptorProto* containing_file) { LocationRecorder location(root_location, diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index e8afdbc4d8..e0ba90f921 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -37,14 +37,17 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PARSER_H__ #define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ +#include #include #include #include + #include #include #include #include +// Must be included last. #include namespace google { @@ -172,7 +175,8 @@ class PROTOBUF_EXPORT Parser { bool ConsumeSignedInteger(int* output, const char* error); // Consume a 64-bit integer and store its value in "output". If the value // is greater than max_value, an error will be reported. - bool ConsumeInteger64(uint64 max_value, uint64* output, const char* error); + bool ConsumeInteger64(uint64_t max_value, uint64_t* output, + const char* error); // 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); @@ -323,8 +327,8 @@ class PROTOBUF_EXPORT Parser { const LocationRecorder& root_location, const FileDescriptorProto* containing_file); bool ParseImport(RepeatedPtrField* dependency, - RepeatedField* public_dependency, - RepeatedField* weak_dependency, + RepeatedField* public_dependency, + RepeatedField* weak_dependency, const LocationRecorder& root_location, const FileDescriptorProto* containing_file); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 564e237e5e..374a444a9e 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -305,7 +305,6 @@ const char* Version::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 major = 1; case 1: @@ -344,7 +343,8 @@ const char* Version::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -636,7 +636,6 @@ const char* CodeGeneratorRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAM while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated string file_to_generate = 1; case 1: @@ -686,7 +685,8 @@ const char* CodeGeneratorRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAM continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1001,7 +1001,6 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* ptr, ::PROTOB while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -1045,7 +1044,8 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* ptr, ::PROTOB continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1322,7 +1322,6 @@ const char* CodeGeneratorResponse::_InternalParse(const char* ptr, ::PROTOBUF_NA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string error = 1; case 1: @@ -1357,7 +1356,8 @@ const char* CodeGeneratorResponse::_InternalParse(const char* ptr, ::PROTOBUF_NA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/compiler/zip_writer.cc b/src/google/protobuf/compiler/zip_writer.cc index 5ae026154b..72e1d7114d 100644 --- a/src/google/protobuf/compiler/zip_writer.cc +++ b/src/google/protobuf/compiler/zip_writer.cc @@ -34,6 +34,9 @@ // Based on http://www.pkware.com/documents/casestudies/APPNOTE.TXT #include + +#include + #include namespace google { @@ -42,9 +45,9 @@ namespace compiler { // January 1, 1980 as a DOS date. // see https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx -static const uint16 kDosEpoch = 1 << 5 | 1; +static const uint16_t kDosEpoch = 1 << 5 | 1; -static const uint32 kCRC32Table[256] = { +static const uint32_t kCRC32Table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, @@ -89,8 +92,8 @@ static const uint32 kCRC32Table[256] = { 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; -static uint32 ComputeCRC32(const std::string& buf) { - uint32 x = ~0U; +static uint32_t ComputeCRC32(const std::string& buf) { + uint32_t x = ~0U; for (int i = 0; i < buf.size(); ++i) { unsigned char c = buf[i]; x = kCRC32Table[(x ^ c) & 0xff] ^ (x >> 8); @@ -98,10 +101,10 @@ static uint32 ComputeCRC32(const std::string& buf) { return ~x; } -static void WriteShort(io::CodedOutputStream* out, uint16 val) { - uint8 p[2]; - p[0] = static_cast(val); - p[1] = static_cast(val >> 8); +static void WriteShort(io::CodedOutputStream* out, uint16_t val) { + uint8_t p[2]; + p[0] = static_cast(val); + p[1] = static_cast(val >> 8); out->WriteRaw(p, 2); } @@ -114,7 +117,7 @@ bool ZipWriter::Write(const std::string& filename, FileInfo info; info.name = filename; - uint16 filename_size = filename.size(); + uint16_t filename_size = filename.size(); info.offset = raw_output_->ByteCount(); info.size = contents.size(); info.crc32 = ComputeCRC32(contents); @@ -141,17 +144,17 @@ bool ZipWriter::Write(const std::string& filename, } bool ZipWriter::WriteDirectory() { - uint16 num_entries = files_.size(); - uint32 dir_ofs = raw_output_->ByteCount(); + uint16_t num_entries = files_.size(); + uint32_t dir_ofs = raw_output_->ByteCount(); // write central directory io::CodedOutputStream output(raw_output_); for (int i = 0; i < num_entries; ++i) { const std::string& filename = files_[i].name; - uint16 filename_size = filename.size(); - uint32 crc32 = files_[i].crc32; - uint32 size = files_[i].size; - uint32 offset = files_[i].offset; + uint16_t filename_size = filename.size(); + uint32_t crc32 = files_[i].crc32; + uint32_t size = files_[i].size; + uint32_t offset = files_[i].offset; output.WriteLittleEndian32(0x02014b50); // magic WriteShort(&output, 10); // version made by @@ -172,7 +175,7 @@ bool ZipWriter::WriteDirectory() { output.WriteLittleEndian32(offset); // local header offset output.WriteString(filename); // file name } - uint32 dir_len = output.ByteCount(); + uint32_t dir_len = output.ByteCount(); // write end of central directory marker output.WriteLittleEndian32(0x06054b50); // magic diff --git a/src/google/protobuf/compiler/zip_writer.h b/src/google/protobuf/compiler/zip_writer.h index 3a8903a3f3..0a8a773552 100644 --- a/src/google/protobuf/compiler/zip_writer.h +++ b/src/google/protobuf/compiler/zip_writer.h @@ -30,7 +30,9 @@ // Author: kenton@google.com (Kenton Varda) +#include #include + #include #include @@ -49,9 +51,9 @@ class ZipWriter { private: struct FileInfo { std::string name; - uint32 offset; - uint32 size; - uint32 crc32; + uint32_t offset; + uint32_t size; + uint32_t crc32; }; io::ZeroCopyOutputStream* raw_output_; diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index d51236cf3a..c22ae431c0 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -990,67 +990,68 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] PR "\347\007 \003(\0132$.google.protobuf.UninterpretedOp" "tion\":\n\014OptimizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_" "SIZE\020\002\022\020\n\014LITE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020" - "\'\"\362\001\n\016MessageOptions\022&\n\027message_set_wire" + "\'\"\204\002\n\016MessageOptions\022&\n\027message_set_wire" "_format\030\001 \001(\010:\005false\022.\n\037no_standard_desc" "riptor_accessor\030\002 \001(\010:\005false\022\031\n\ndeprecat" "ed\030\003 \001(\010:\005false\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024un" "interpreted_option\030\347\007 \003(\0132$.google.proto" - "buf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\t" - "J\004\010\t\020\n\"\236\003\n\014FieldOptions\022:\n\005ctype\030\001 \001(\0162#" - ".google.protobuf.FieldOptions.CType:\006STR" - "ING\022\016\n\006packed\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.go" - "ogle.protobuf.FieldOptions.JSType:\tJS_NO" - "RMAL\022\023\n\004lazy\030\005 \001(\010:\005false\022\031\n\ndeprecated\030" - "\003 \001(\010:\005false\022\023\n\004weak\030\n \001(\010:\005false\022C\n\024uni" - "nterpreted_option\030\347\007 \003(\0132$.google.protob" - "uf.UninterpretedOption\"/\n\005CType\022\n\n\006STRIN" - "G\020\000\022\010\n\004CORD\020\001\022\020\n\014STRING_PIECE\020\002\"5\n\006JSTyp" - "e\022\r\n\tJS_NORMAL\020\000\022\r\n\tJS_STRING\020\001\022\r\n\tJS_NU" - "MBER\020\002*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005\"^\n\014OneofOptions\022" - "C\n\024uninterpreted_option\030\347\007 \003(\0132$.google." - "protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"" - "\223\001\n\013EnumOptions\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\n" - "deprecated\030\003 \001(\010:\005false\022C\n\024uninterpreted" - "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" - "pretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\005\020\006\"}\n\020EnumVal" - "ueOptions\022\031\n\ndeprecated\030\001 \001(\010:\005false\022C\n\024" - "uninterpreted_option\030\347\007 \003(\0132$.google.pro" - "tobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016" - "ServiceOptions\022\031\n\ndeprecated\030! \001(\010:\005fals" + "buf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005" + "J\004\010\005\020\006J\004\010\006\020\007J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n\014FieldOption" + "s\022:\n\005ctype\030\001 \001(\0162#.google.protobuf.Field" + "Options.CType:\006STRING\022\016\n\006packed\030\002 \001(\010\022\?\n" + "\006jstype\030\006 \001(\0162$.google.protobuf.FieldOpt" + "ions.JSType:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010:\005fa" + "lse\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\023\n\004weak\030\n" + " \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003" + "(\0132$.google.protobuf.UninterpretedOption" + "\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014STRIN" + "G_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NORMAL\020\000\022\r\n\tJS" + "_STRING\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020" + "\005\"^\n\014OneofOptions\022C\n\024uninterpreted_optio" + "n\030\347\007 \003(\0132$.google.protobuf.Uninterpreted" + "Option*\t\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOptions\022\023\n\013all" + "ow_alias\030\002 \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005fals" "e\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" "e.protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200" - "\002\"\255\002\n\rMethodOptions\022\031\n\ndeprecated\030! \001(\010:" - "\005false\022_\n\021idempotency_level\030\" \001(\0162/.goog" - "le.protobuf.MethodOptions.IdempotencyLev" - "el:\023IDEMPOTENCY_UNKNOWN\022C\n\024uninterpreted" - "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" - "pretedOption\"P\n\020IdempotencyLevel\022\027\n\023IDEM" - "POTENCY_UNKNOWN\020\000\022\023\n\017NO_SIDE_EFFECTS\020\001\022\016" - "\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023Uninterpre" - "tedOption\022;\n\004name\030\002 \003(\0132-.google.protobu" - "f.UninterpretedOption.NamePart\022\030\n\020identi" - "fier_value\030\003 \001(\t\022\032\n\022positive_int_value\030\004" - " \001(\004\022\032\n\022negative_int_value\030\005 \001(\003\022\024\n\014doub" - "le_value\030\006 \001(\001\022\024\n\014string_value\030\007 \001(\014\022\027\n\017" - "aggregate_value\030\010 \001(\t\0323\n\010NamePart\022\021\n\tnam" - "e_part\030\001 \002(\t\022\024\n\014is_extension\030\002 \002(\010\"\325\001\n\016S" - "ourceCodeInfo\022:\n\010location\030\001 \003(\0132(.google" - ".protobuf.SourceCodeInfo.Location\032\206\001\n\010Lo" - "cation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002" - "\020\001\022\030\n\020leading_comments\030\003 \001(\t\022\031\n\021trailing" - "_comments\030\004 \001(\t\022!\n\031leading_detached_comm" - "ents\030\006 \003(\t\"\247\001\n\021GeneratedCodeInfo\022A\n\nanno" - "tation\030\001 \003(\0132-.google.protobuf.Generated" - "CodeInfo.Annotation\032O\n\nAnnotation\022\020\n\004pat" - "h\030\001 \003(\005B\002\020\001\022\023\n\013source_file\030\002 \001(\t\022\r\n\005begi" - "n\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B~\n\023com.google.proto" - "bufB\020DescriptorProtosH\001Z-google.golang.o" - "rg/protobuf/types/descriptorpb\370\001\001\242\002\003GPB\252" - "\002\032Google.Protobuf.Reflection" + "\002J\004\010\005\020\006\"}\n\020EnumValueOptions\022\031\n\ndeprecate" + "d\030\001 \001(\010:\005false\022C\n\024uninterpreted_option\030\347" + "\007 \003(\0132$.google.protobuf.UninterpretedOpt" + "ion*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOptions\022\031\n\ndepr" + "ecated\030! \001(\010:\005false\022C\n\024uninterpreted_opt" + "ion\030\347\007 \003(\0132$.google.protobuf.Uninterpret" + "edOption*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n" + "\ndeprecated\030! \001(\010:\005false\022_\n\021idempotency_" + "level\030\" \001(\0162/.google.protobuf.MethodOpti" + "ons.IdempotencyLevel:\023IDEMPOTENCY_UNKNOW" + "N\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" + "e.protobuf.UninterpretedOption\"P\n\020Idempo" + "tencyLevel\022\027\n\023IDEMPOTENCY_UNKNOWN\020\000\022\023\n\017N" + "O_SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200" + "\200\200\002\"\236\002\n\023UninterpretedOption\022;\n\004name\030\002 \003(" + "\0132-.google.protobuf.UninterpretedOption." + "NamePart\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022po" + "sitive_int_value\030\004 \001(\004\022\032\n\022negative_int_v" + "alue\030\005 \001(\003\022\024\n\014double_value\030\006 \001(\001\022\024\n\014stri" + "ng_value\030\007 \001(\014\022\027\n\017aggregate_value\030\010 \001(\t\032" + "3\n\010NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_ext" + "ension\030\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010locat" + "ion\030\001 \003(\0132(.google.protobuf.SourceCodeIn" + "fo.Location\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002" + "\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments" + "\030\003 \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031lea" + "ding_detached_comments\030\006 \003(\t\"\247\001\n\021Generat" + "edCodeInfo\022A\n\nannotation\030\001 \003(\0132-.google." + "protobuf.GeneratedCodeInfo.Annotation\032O\n" + "\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_" + "file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B~" + "\n\023com.google.protobufB\020DescriptorProtosH" + "\001Z-google.golang.org/protobuf/types/desc" + "riptorpb\370\001\001\242\002\003GPB\252\002\032Google.Protobuf.Refl" + "ection" ; static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once; const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = { - false, false, 6028, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, "google/protobuf/descriptor.proto", + false, false, 6046, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, "google/protobuf/descriptor.proto", &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, nullptr, 0, 27, schemas, file_default_instances, TableStruct_google_2fprotobuf_2fdescriptor_2eproto::offsets, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto, file_level_service_descriptors_google_2fprotobuf_2fdescriptor_2eproto, @@ -1289,7 +1290,6 @@ const char* FileDescriptorSet::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.FileDescriptorProto file = 1; case 1: @@ -1305,7 +1305,8 @@ const char* FileDescriptorSet::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1589,7 +1590,6 @@ const char* FileDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -1734,7 +1734,8 @@ const char* FileDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -2177,7 +2178,6 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* ptr, ::PR while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: @@ -2204,7 +2204,8 @@ const char* DescriptorProto_ExtensionRange::_InternalParse(const char* ptr, ::PR continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -2455,7 +2456,6 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* ptr, ::PRO while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: @@ -2475,7 +2475,8 @@ const char* DescriptorProto_ReservedRange::_InternalParse(const char* ptr, ::PRO continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -2745,7 +2746,6 @@ const char* DescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -2867,7 +2867,8 @@ const char* DescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -3229,7 +3230,6 @@ const char* ExtensionRangeOptions::_InternalParse(const char* ptr, ::PROTOBUF_NA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: @@ -3245,7 +3245,8 @@ const char* ExtensionRangeOptions::_InternalParse(const char* ptr, ::PROTOBUF_NA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -3564,7 +3565,6 @@ const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -3678,7 +3678,8 @@ const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -4103,7 +4104,6 @@ const char* OneofDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -4125,7 +4125,8 @@ const char* OneofDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAM continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -4359,7 +4360,6 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* pt while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional int32 start = 1; case 1: @@ -4379,7 +4379,8 @@ const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* pt continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -4634,7 +4635,6 @@ const char* EnumDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -4696,7 +4696,8 @@ const char* EnumDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NAME continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -5009,7 +5010,6 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -5039,7 +5039,8 @@ const char* EnumValueDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -5314,7 +5315,6 @@ const char* ServiceDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_N while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -5348,7 +5348,8 @@ const char* ServiceDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_N continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -5657,7 +5658,6 @@ const char* MethodDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string name = 1; case 1: @@ -5717,7 +5717,8 @@ const char* MethodDescriptorProto::_InternalParse(const char* ptr, ::PROTOBUF_NA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -6200,7 +6201,6 @@ const char* FileOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional string java_package = 1; case 1: @@ -6410,7 +6410,8 @@ const char* FileOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7016,7 +7017,6 @@ const char* MessageOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool message_set_wire_format = 1 [default = false]; case 1: @@ -7064,7 +7064,8 @@ const char* MessageOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7372,7 +7373,6 @@ const char* FieldOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; case 1: @@ -7444,7 +7444,8 @@ const char* FieldOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7749,7 +7750,6 @@ const char* OneofOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: @@ -7765,7 +7765,8 @@ const char* OneofOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_I continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -7986,7 +7987,6 @@ const char* EnumOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool allow_alias = 2; case 2: @@ -8018,7 +8018,8 @@ const char* EnumOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -8273,7 +8274,6 @@ const char* EnumValueOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPA while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool deprecated = 1 [default = false]; case 1: @@ -8297,7 +8297,8 @@ const char* EnumValueOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPA continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -8527,7 +8528,6 @@ const char* ServiceOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool deprecated = 33 [default = false]; case 33: @@ -8551,7 +8551,8 @@ const char* ServiceOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -8794,7 +8795,6 @@ const char* MethodOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // optional bool deprecated = 33 [default = false]; case 33: @@ -8830,7 +8830,8 @@ const char* MethodOptions::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -9098,7 +9099,6 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* ptr, ::PROT while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // required string name_part = 1; case 1: @@ -9121,7 +9121,8 @@ const char* UninterpretedOption_NamePart::_InternalParse(const char* ptr, ::PROT continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -9412,7 +9413,6 @@ const char* UninterpretedOption::_InternalParse(const char* ptr, ::PROTOBUF_NAME while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; case 2: @@ -9482,7 +9482,8 @@ const char* UninterpretedOption::_InternalParse(const char* ptr, ::PROTOBUF_NAME continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -9822,7 +9823,6 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* ptr, ::PROTOBUF_ while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated int32 path = 1 [packed = true]; case 1: @@ -9884,7 +9884,8 @@ const char* SourceCodeInfo_Location::_InternalParse(const char* ptr, ::PROTOBUF_ continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -10169,7 +10170,6 @@ const char* SourceCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.SourceCodeInfo.Location location = 1; case 1: @@ -10185,7 +10185,8 @@ const char* SourceCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -10400,7 +10401,6 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* ptr, ::PROT while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated int32 path = 1 [packed = true]; case 1: @@ -10441,7 +10441,8 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* ptr, ::PROT continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -10698,7 +10699,6 @@ const char* GeneratedCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; case 1: @@ -10714,7 +10714,8 @@ const char* GeneratedCodeInfo::_InternalParse(const char* ptr, ::PROTOBUF_NAMESP continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 9f0ce6cde0..69c75208ee 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -496,6 +496,8 @@ message MessageOptions { // this is a formalization for deprecating messages. optional bool deprecated = 3 [default = false]; + reserved 4, 5, 6; + // Whether the message is an automatically generated map entry type for the // maps field. // diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index d00883ddb8..01cd8d75b3 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -140,7 +140,6 @@ const char* Duration::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // int64 seconds = 1; case 1: @@ -158,7 +157,8 @@ const char* Duration::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index c86d5f2be5..b2149abb7b 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -125,8 +125,8 @@ const char* Empty::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index d368693b9e..5890bb2c70 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -131,7 +131,6 @@ const char* FieldMask::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated string paths = 1; case 1: @@ -149,7 +148,8 @@ const char* FieldMask::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index 2b20e0a5ce..a318da404a 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -951,6 +951,26 @@ uint8* CodedOutputStream::WriteStringWithSizeToArray(const std::string& str, return WriteStringToArray(str, target); } +uint8* CodedOutputStream::WriteVarint32ToArrayOutOfLineHelper(uint32 value, + uint8* target) { + GOOGLE_DCHECK_GE(value, 0x80); + target[0] |= static_cast(0x80); + value >>= 7; + target[1] = static_cast(value); + if (value < 0x80) { + return target + 2; + } + target += 2; + do { + // Turn on continuation bit in the byte we just wrote. + target[-1] |= static_cast(0x80); + value >>= 7; + *target = static_cast(value); + ++target; + } while (value >= 0x80); + return target; +} + } // namespace io } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 97626f74a3..5ce3ce06f4 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -904,23 +904,25 @@ class PROTOBUF_EXPORT EpsCopyOutputStream { PROTOBUF_ALWAYS_INLINE static uint8* UnsafeVarint(T value, uint8* ptr) { static_assert(std::is_unsigned::value, "Varint serialization must be unsigned"); + ptr[0] = static_cast(value); if (value < 0x80) { - ptr[0] = static_cast(value); return ptr + 1; } - ptr[0] = static_cast(value | 0x80); + // Turn on continuation bit in the byte we just wrote. + ptr[0] |= static_cast(0x80); value >>= 7; + ptr[1] = static_cast(value); if (value < 0x80) { - ptr[1] = static_cast(value); return ptr + 2; } - ptr++; + ptr += 2; do { - *ptr = static_cast(value | 0x80); + // Turn on continuation bit in the byte we just wrote. + ptr[-1] |= static_cast(0x80); value >>= 7; + *ptr = static_cast(value); ++ptr; - } while (PROTOBUF_PREDICT_FALSE(value >= 0x80)); - *ptr++ = static_cast(value); + } while (value >= 0x80); return ptr; } @@ -1149,6 +1151,9 @@ class PROTOBUF_EXPORT CodedOutputStream { void WriteVarint32(uint32 value); // Like WriteVarint32() but writing directly to the target array. static uint8* WriteVarint32ToArray(uint32 value, uint8* target); + // Like WriteVarint32() but writing directly to the target array, and with the + // less common-case paths being out of line rather than inlined. + static uint8* WriteVarint32ToArrayOutOfLine(uint32 value, uint8* target); // Write an unsigned integer with Varint encoding. void WriteVarint64(uint64 value); // Like WriteVarint64() but writing directly to the target array. @@ -1263,6 +1268,8 @@ class PROTOBUF_EXPORT CodedOutputStream { static void SetDefaultSerializationDeterministic() { default_serialization_deterministic_.store(true, std::memory_order_relaxed); } + // REQUIRES: value >= 0x80, and that (value & 7f) has been written to *target. + static uint8* WriteVarint32ToArrayOutOfLineHelper(uint32 value, uint8* target); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); }; @@ -1593,6 +1600,16 @@ inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value, return EpsCopyOutputStream::UnsafeVarint(value, target); } +inline uint8* CodedOutputStream::WriteVarint32ToArrayOutOfLine(uint32 value, + uint8* target) { + target[0] = static_cast(value); + if (value < 0x80) { + return target + 1; + } else { + return WriteVarint32ToArrayOutOfLineHelper(value, target); + } +} + inline uint8* CodedOutputStream::WriteVarint64ToArray(uint64 value, uint8* target) { return EpsCopyOutputStream::UnsafeVarint(value, target); diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index 003f1fe859..0d97d407f1 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -661,5 +661,37 @@ TEST(MESSAGE_TEST_NAME, MOMIParserEdgeCases) { } +TEST(MESSAGE_TEST_NAME, CheckSerializationWhenInterleavedExtensions) { + UNITTEST::TestExtensionRangeSerialize in_message; + + in_message.set_foo_one(1); + in_message.set_foo_two(2); + in_message.set_foo_three(3); + in_message.set_foo_four(4); + + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_one, 1); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_two, 2); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_three, 3); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_four, 4); + in_message.SetExtension(UNITTEST::TestExtensionRangeSerialize::bar_five, 5); + + std::string buffer; + in_message.SerializeToString(&buffer); + + UNITTEST::TestExtensionRangeSerialize out_message; + out_message.ParseFromString(buffer); + + EXPECT_EQ(1, out_message.foo_one()); + EXPECT_EQ(2, out_message.foo_two()); + EXPECT_EQ(3, out_message.foo_three()); + EXPECT_EQ(4, out_message.foo_four()); + + EXPECT_EQ(1, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_one)); + EXPECT_EQ(2, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_two)); + EXPECT_EQ(3, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_three)); + EXPECT_EQ(4, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_four)); + EXPECT_EQ(5, out_message.GetExtension(UNITTEST::TestExtensionRangeSerialize::bar_five)); +} + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 8143af8d8b..e141c43439 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -326,6 +326,18 @@ const char* EpsCopyInputStream::InitFrom(io::ZeroCopyInputStream* zcis) { return buffer_; } +const char* ParseContext::ReadSizeAndPushLimitAndDepth(const char* ptr, + int* old_limit) { + int size = ReadSize(&ptr); + if (PROTOBUF_PREDICT_FALSE(!ptr)) { + *old_limit = 0; // Make sure this isn't uninitialized even on error return + return nullptr; + } + *old_limit = PushLimit(ptr, size); + if (--depth_ < 0) return nullptr; + return ptr; +} + const char* ParseContext::ParseMessage(MessageLite* msg, const char* ptr) { return ParseMessage(msg, ptr); } diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 7966d99d57..b8e16446b5 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -413,6 +413,17 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { } private: + // Out-of-line routine to save space in ParseContext::ParseMessage + // int old; + // ptr = ReadSizeAndPushLimitAndDepth(ptr, &old) + // is equivalent to: + // int size = ReadSize(&ptr); + // if (!ptr) return nullptr; + // int old = PushLimit(ptr, size); + // if (--depth_ < 0) return nullptr; + PROTOBUF_MUST_USE_RESULT const char* ReadSizeAndPushLimitAndDepth( + const char* ptr, int* old_limit); + // The context keeps an internal stack to keep track of the recursive // part of the parse state. // Current depth of the active parser, depth counts down. @@ -640,12 +651,9 @@ inline int32 ReadVarintZigZag32(const char** p) { template PROTOBUF_MUST_USE_RESULT const char* ParseContext::ParseMessage( T* msg, const char* ptr) { - int size = ReadSize(&ptr); - if (!ptr) return nullptr; - auto old = PushLimit(ptr, size); - if (--depth_ < 0) return nullptr; - ptr = msg->_InternalParse(ptr, this); - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) return nullptr; + int old; + ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); + ptr = ptr ? msg->_InternalParse(ptr, this) : nullptr; depth_++; if (!PopLimit(old)) return nullptr; return ptr; diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 43ca45844b..58190e3d85 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -221,6 +221,10 @@ class RepeatedField final { void MergeFrom(const RepeatedField& other); void CopyFrom(const RepeatedField& other); + // Replaces the contents with RepeatedField(begin, end). + template + void Assign(Iter begin, Iter end); + // Reserve space to expand the field to at least the given size. If the // array is grown, it will always be at least doubled in size. void Reserve(int new_size); @@ -765,8 +769,9 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { int)); template - void MergeFromInnerLoop(void** our_elems, void** other_elems, int length, - int already_allocated); + PROTOBUF_NOINLINE void MergeFromInnerLoop(void** our_elems, + void** other_elems, int length, + int already_allocated); // Internal helper: extend array space if necessary to contain |extend_amount| // more elements, and return a pointer to the element immediately following @@ -953,6 +958,10 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { Element* Mutable(int index); Element* Add(); void Add(Element&& value); + // Append elements in the range [begin, end) after reserving + // the appropriate number of elements. + template + void Add(Iter begin, Iter end); const Element& operator[](int index) const { return Get(index); } Element& operator[](int index) { return *Mutable(index); } @@ -973,6 +982,10 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { void MergeFrom(const RepeatedPtrField& other); void CopyFrom(const RepeatedPtrField& other); + // Replaces the contents with RepeatedPtrField(begin, end). + template + void Assign(Iter begin, Iter end); + // Reserve space to expand the field to at least the given size. This only // resizes the pointer array; it doesn't allocate any objects. If the // array is grown, it will always be at least doubled in size. @@ -1447,6 +1460,13 @@ inline void RepeatedField::CopyFrom(const RepeatedField& other) { MergeFrom(other); } +template +template +inline void RepeatedField::Assign(Iter begin, Iter end) { + Clear(); + Add(begin, end); +} + template inline typename RepeatedField::iterator RepeatedField::erase( const_iterator position) { @@ -2122,13 +2142,7 @@ inline RepeatedPtrField::RepeatedPtrField( template template inline RepeatedPtrField::RepeatedPtrField(Iter begin, Iter end) { - int reserve = internal::CalculateReserve(begin, end); - if (reserve != -1) { - Reserve(reserve); - } - for (; begin != end; ++begin) { - *Add() = *begin; - } + Add(begin, end); } template @@ -2213,6 +2227,18 @@ inline void RepeatedPtrField::Add(Element&& value) { RepeatedPtrFieldBase::Add(std::move(value)); } +template +template +inline void RepeatedPtrField::Add(Iter begin, Iter end) { + int reserve = internal::CalculateReserve(begin, end); + if (reserve != -1) { + Reserve(size() + reserve); + } + for (; begin != end; ++begin) { + *Add() = *begin; + } +} + template inline void RepeatedPtrField::RemoveLast() { RepeatedPtrFieldBase::RemoveLast(); @@ -2319,6 +2345,13 @@ inline void RepeatedPtrField::CopyFrom(const RepeatedPtrField& other) { RepeatedPtrFieldBase::CopyFrom(other); } +template +template +inline void RepeatedPtrField::Assign(Iter begin, Iter end) { + Clear(); + Add(begin, end); +} + template inline typename RepeatedPtrField::iterator RepeatedPtrField::erase(const_iterator position) { diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index a396b619f2..f3e8c2d5fa 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -488,6 +488,30 @@ TEST(RepeatedField, AddRange5) { ASSERT_EQ(me.Get(1), 2); } +TEST(RepeatedField, AddAndAssignRanges) { + RepeatedField field; + + int vals[] = {2, 27, 2875, 609250}; + field.Assign(std::begin(vals), std::end(vals)); + + ASSERT_EQ(field.size(), 4); + EXPECT_EQ(field.Get(0), 2); + EXPECT_EQ(field.Get(1), 27); + EXPECT_EQ(field.Get(2), 2875); + EXPECT_EQ(field.Get(3), 609250); + + field.Add(std::begin(vals), std::end(vals)); + ASSERT_EQ(field.size(), 8); + EXPECT_EQ(field.Get(0), 2); + EXPECT_EQ(field.Get(1), 27); + EXPECT_EQ(field.Get(2), 2875); + EXPECT_EQ(field.Get(3), 609250); + EXPECT_EQ(field.Get(4), 2); + EXPECT_EQ(field.Get(5), 27); + EXPECT_EQ(field.Get(6), 2875); + EXPECT_EQ(field.Get(7), 609250); +} + TEST(RepeatedField, CopyConstruct) { RepeatedField source; source.Add(1); @@ -837,6 +861,45 @@ TEST(RepeatedPtrField, ConstInit) { EXPECT_TRUE(field.empty()); } +// This helper overload set tests whether X::f can be called with a braced pair, +// X::f({a, b}) of std::string iterators (specifically, pointers: That call is +// ambiguous if and only if the call to ValidResolutionPointerRange is not. +template +auto ValidResolutionPointerRange(const std::string* p) + -> decltype(X::f({p, p + 2}), std::true_type{}); +template +std::false_type ValidResolutionPointerRange(void*); + +TEST(RepeatedPtrField, UnambiguousConstructor) { + struct X { + static bool f(std::vector) { return false; } + static bool f(google::protobuf::RepeatedPtrField) { return true; } + + static bool g(std::vector) { return false; } + static bool g(google::protobuf::RepeatedPtrField) { return true; } + }; + + // RepeatedPtrField has no initializer-list constructor, and a constructor + // from to const char* values is excluded by its constraints. + EXPECT_FALSE(X::f({"abc", "xyz"})); + + // Construction from a pair of int* is also not ambiguous. + int a[5] = {}; + EXPECT_FALSE(X::g({a, a + 5})); + + // Construction from string iterators for the unique string overload "g" + // works. + std::string b[2] = {"abc", "xyz"}; + // Disabling this for now, this is actually ambiguous with libstdc++. + // EXPECT_TRUE(X::g({b, b + 2})); + + // Construction from string iterators for "f" is ambiguous, since both + // containers are equally good. + // + // X::f({b, b + 2}); // error => ValidResolutionPointerRange is unambiguous. + EXPECT_FALSE(decltype(ValidResolutionPointerRange(nullptr))::value); +} + TEST(RepeatedPtrField, Small) { RepeatedPtrField field; @@ -899,6 +962,30 @@ TEST(RepeatedPtrField, Large) { EXPECT_GE(field.SpaceUsedExcludingSelf(), min_expected_usage); } +TEST(RepeatedPtrField, AddAndAssignRanges) { + RepeatedPtrField field; + + const char* vals[] = {"abc", "x", "yz", "xyzzy"}; + field.Assign(std::begin(vals), std::end(vals)); + + ASSERT_EQ(field.size(), 4); + EXPECT_EQ(field.Get(0), "abc"); + EXPECT_EQ(field.Get(1), "x"); + EXPECT_EQ(field.Get(2), "yz"); + EXPECT_EQ(field.Get(3), "xyzzy"); + + field.Add(std::begin(vals), std::end(vals)); + ASSERT_EQ(field.size(), 8); + EXPECT_EQ(field.Get(0), "abc"); + EXPECT_EQ(field.Get(1), "x"); + EXPECT_EQ(field.Get(2), "yz"); + EXPECT_EQ(field.Get(3), "xyzzy"); + EXPECT_EQ(field.Get(4), "abc"); + EXPECT_EQ(field.Get(5), "x"); + EXPECT_EQ(field.Get(6), "yz"); + EXPECT_EQ(field.Get(7), "xyzzy"); +} + TEST(RepeatedPtrField, SwapSmallSmall) { RepeatedPtrField field1; RepeatedPtrField field2; diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index aed802b473..3994ceba89 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -136,7 +136,6 @@ const char* SourceContext::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string file_name = 1; case 1: @@ -149,7 +148,8 @@ const char* SourceContext::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 7f461f1904..fbe98e786d 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -241,7 +241,6 @@ const char* Struct::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // map fields = 1; case 1: @@ -257,7 +256,8 @@ const char* Struct::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -582,7 +582,6 @@ const char* Value::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // .google.protobuf.NullValue null_value = 1; case 1: @@ -631,7 +630,8 @@ const char* Value::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -911,7 +911,6 @@ const char* ListValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // repeated .google.protobuf.Value values = 1; case 1: @@ -927,7 +926,8 @@ const char* ListValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 1ca2e71d92..a3040a62b3 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -140,7 +140,6 @@ const char* Timestamp::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // int64 seconds = 1; case 1: @@ -158,7 +157,8 @@ const char* Timestamp::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index cff9744773..024b277519 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -430,7 +430,6 @@ const char* Type::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -496,7 +495,8 @@ const char* Type::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -815,7 +815,6 @@ const char* Field::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // .google.protobuf.Field.Kind kind = 1; case 1: @@ -904,7 +903,8 @@ const char* Field::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1289,7 +1289,6 @@ const char* Enum::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1341,7 +1340,8 @@ const char* Enum::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1609,7 +1609,6 @@ const char* EnumValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1641,7 +1640,8 @@ const char* EnumValue::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID:: continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } @@ -1885,7 +1885,6 @@ const char* Option::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int while (!ctx->Done(&ptr)) { ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); switch (tag >> 3) { // string name = 1; case 1: @@ -1905,7 +1904,8 @@ const char* Option::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int continue; default: { handle_unusual: - if ((tag & 7) == 4 || tag == 0) { + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); ctx->SetLastTag(tag); goto success; } diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index a4d5045710..75b65f0249 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -1115,3 +1115,33 @@ enum VeryLargeEnum { ENUM_LABEL_99 = 99; ENUM_LABEL_100 = 100; }; + +message TestExtensionRangeSerialize { + optional int32 foo_one = 1; + + extensions 2 to 2; + extensions 3 to 4; + + optional int32 foo_two = 6; + optional int32 foo_three = 7; + + extensions 9 to 10; + + optional int32 foo_four = 13; + + extensions 15 to 15; + extensions 17 to 17; + extensions 19 to 19; + + extend TestExtensionRangeSerialize { + optional int32 bar_one = 2; + optional int32 bar_two = 4; + + optional int32 bar_three = 10; + + optional int32 bar_four = 15; + optional int32 bar_five = 19; + } +} + + diff --git a/src/google/protobuf/util/field_comparator.cc b/src/google/protobuf/util/field_comparator.cc index 54abcd43a4..46d5dbaf3d 100644 --- a/src/google/protobuf/util/field_comparator.cc +++ b/src/google/protobuf/util/field_comparator.cc @@ -48,14 +48,14 @@ namespace util { FieldComparator::FieldComparator() {} FieldComparator::~FieldComparator() {} -DefaultFieldComparator::DefaultFieldComparator() +SimpleFieldComparator::SimpleFieldComparator() : float_comparison_(EXACT), treat_nan_as_equal_(false), has_default_tolerance_(false) {} -DefaultFieldComparator::~DefaultFieldComparator() {} +SimpleFieldComparator::~SimpleFieldComparator() {} -FieldComparator::ComparisonResult DefaultFieldComparator::Compare( +FieldComparator::ComparisonResult SimpleFieldComparator::SimpleCompare( const Message& message_1, const Message& message_2, const FieldDescriptor* field, int index_1, int index_2, const util::FieldContext* field_context) { @@ -127,23 +127,22 @@ FieldComparator::ComparisonResult DefaultFieldComparator::Compare( } } -bool DefaultFieldComparator::Compare(MessageDifferencer* differencer, - const Message& message1, - const Message& message2, - const util::FieldContext* field_context) { +bool SimpleFieldComparator::CompareWithDifferencer( + MessageDifferencer* differencer, const Message& message1, + const Message& message2, const util::FieldContext* field_context) { return differencer->Compare(message1, message2, field_context->parent_fields()); } -void DefaultFieldComparator::SetDefaultFractionAndMargin(double fraction, - double margin) { +void SimpleFieldComparator::SetDefaultFractionAndMargin(double fraction, + double margin) { default_tolerance_ = Tolerance(fraction, margin); has_default_tolerance_ = true; } -void DefaultFieldComparator::SetFractionAndMargin(const FieldDescriptor* field, - double fraction, - double margin) { +void SimpleFieldComparator::SetFractionAndMargin(const FieldDescriptor* field, + double fraction, + double margin) { GOOGLE_CHECK(FieldDescriptor::CPPTYPE_FLOAT == field->cpp_type() || FieldDescriptor::CPPTYPE_DOUBLE == field->cpp_type()) << "Field has to be float or double type. Field name is: " @@ -151,25 +150,25 @@ void DefaultFieldComparator::SetFractionAndMargin(const FieldDescriptor* field, map_tolerance_[field] = Tolerance(fraction, margin); } -bool DefaultFieldComparator::CompareDouble(const FieldDescriptor& field, - double value_1, double value_2) { +bool SimpleFieldComparator::CompareDouble(const FieldDescriptor& field, + double value_1, double value_2) { return CompareDoubleOrFloat(field, value_1, value_2); } -bool DefaultFieldComparator::CompareEnum(const FieldDescriptor& field, - const EnumValueDescriptor* value_1, - const EnumValueDescriptor* value_2) { +bool SimpleFieldComparator::CompareEnum(const FieldDescriptor& field, + const EnumValueDescriptor* value_1, + const EnumValueDescriptor* value_2) { return value_1->number() == value_2->number(); } -bool DefaultFieldComparator::CompareFloat(const FieldDescriptor& field, - float value_1, float value_2) { +bool SimpleFieldComparator::CompareFloat(const FieldDescriptor& field, + float value_1, float value_2) { return CompareDoubleOrFloat(field, value_1, value_2); } template -bool DefaultFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, - T value_1, T value_2) { +bool SimpleFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, + T value_1, T value_2) { if (value_1 == value_2) { // Covers +inf and -inf (which are not within margin or fraction of // themselves), and is a shortcut for finite values. @@ -201,7 +200,7 @@ bool DefaultFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, } } -FieldComparator::ComparisonResult DefaultFieldComparator::ResultFromBoolean( +FieldComparator::ComparisonResult SimpleFieldComparator::ResultFromBoolean( bool boolean_result) const { return boolean_result ? FieldComparator::SAME : FieldComparator::DIFFERENT; } diff --git a/src/google/protobuf/util/field_comparator.h b/src/google/protobuf/util/field_comparator.h index 9058bbef15..7ad715b201 100644 --- a/src/google/protobuf/util/field_comparator.h +++ b/src/google/protobuf/util/field_comparator.h @@ -33,12 +33,12 @@ #ifndef GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__ #define GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__ +#include #include #include #include #include - #include namespace google { @@ -97,7 +97,7 @@ class PROTOBUF_EXPORT FieldComparator { // Basic implementation of FieldComparator. Supports three modes of floating // point value comparison: exact, approximate using MathUtil::AlmostEqual // method, and arbitrarily precise using MathUtil::WithinFractionOrMargin. -class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { +class PROTOBUF_EXPORT SimpleFieldComparator : public FieldComparator { public: enum FloatComparison { EXACT, // Floats and doubles are compared exactly. @@ -109,14 +109,9 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { }; // Creates new comparator with float comparison set to EXACT. - DefaultFieldComparator(); - - ~DefaultFieldComparator() override; + SimpleFieldComparator(); - ComparisonResult Compare(const Message& message_1, const Message& message_2, - const FieldDescriptor* field, int index_1, - int index_2, - const util::FieldContext* field_context) override; + ~SimpleFieldComparator() override; void set_float_comparison(FloatComparison float_comparison) { float_comparison_ = float_comparison; @@ -151,12 +146,32 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { void SetDefaultFractionAndMargin(double fraction, double margin); protected: + // NOTE: this will go away. + ComparisonResult Compare(const Message& message_1, const Message& message_2, + const FieldDescriptor* field, int index_1, + int index_2, + const util::FieldContext* field_context) override { + return SimpleCompare(message_1, message_2, field, index_1, index_2, + field_context); + } + + // Returns the comparison result for the given field in two messages. + // + // This function is called directly by DefaultFieldComparator::Compare. + // Subclasses can call this function to compare fields they do not need to + // handle specially. + ComparisonResult SimpleCompare(const Message& message_1, + const Message& message_2, + const FieldDescriptor* field, int index_1, + int index_2, + const util::FieldContext* field_context); + // Compare using the provided message_differencer. For example, a subclass can // use this method to compare some field in a certain way using the same // message_differencer instance and the field context. - bool Compare(MessageDifferencer* differencer, const Message& message1, - const Message& message2, - const util::FieldContext* field_context); + bool CompareWithDifferencer(MessageDifferencer* differencer, + const Message& message1, const Message& message2, + const util::FieldContext* field_context); private: // Defines the tolerance for floating point comparison (fraction and margin). @@ -193,13 +208,13 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { // CompareFloat. bool CompareFloat(const FieldDescriptor& field, float value_1, float value_2); - bool CompareInt32(const FieldDescriptor& /* unused */, int32 value_1, - int32 value_2) { + bool CompareInt32(const FieldDescriptor& /* unused */, int32_t value_1, + int32_t value_2) { return value_1 == value_2; } - bool CompareInt64(const FieldDescriptor& /* unused */, int64 value_1, - int64 value_2) { + bool CompareInt64(const FieldDescriptor& /* unused */, int64_t value_1, + int64_t value_2) { return value_1 == value_2; } @@ -208,13 +223,13 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { return value_1 == value_2; } - bool CompareUInt32(const FieldDescriptor& /* unused */, uint32 value_1, - uint32 value_2) { + bool CompareUInt32(const FieldDescriptor& /* unused */, uint32_t value_1, + uint32_t value_2) { return value_1 == value_2; } - bool CompareUInt64(const FieldDescriptor& /* unused */, uint64 value_1, - uint64 value_2) { + bool CompareUInt64(const FieldDescriptor& /* unused */, uint64_t value_1, + uint64_t value_2) { return value_1 == value_2; } @@ -249,7 +264,19 @@ class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { // those particular fields. ToleranceMap map_tolerance_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DefaultFieldComparator); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleFieldComparator); +}; + +// Default field comparison: use the basic implementation of FieldComparator. +class PROTOBUF_EXPORT DefaultFieldComparator : public SimpleFieldComparator { + public: + ComparisonResult Compare(const Message& message_1, const Message& message_2, + const FieldDescriptor* field, int index_1, + int index_2, + const util::FieldContext* field_context) override { + return SimpleCompare(message_1, message_2, field, index_1, index_2, + field_context); + } }; } // namespace util diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc index 23800181b4..c5f713f4c3 100644 --- a/src/google/protobuf/util/field_mask_util.cc +++ b/src/google/protobuf/util/field_mask_util.cc @@ -30,10 +30,13 @@ #include +#include + #include #include #include +// Must be included last. #include namespace google { @@ -552,7 +555,7 @@ void FieldMaskTree::MergeMessage(const Node* node, const Message& source, void FieldMaskTree::AddRequiredFieldPath(Node* node, const Descriptor* descriptor) { - const int32 field_count = descriptor->field_count(); + const int32_t field_count = descriptor->field_count(); for (int index = 0; index < field_count; ++index) { const FieldDescriptor* field = descriptor->field(index); if (field->is_required()) { @@ -589,7 +592,7 @@ bool FieldMaskTree::TrimMessage(const Node* node, Message* message) { GOOGLE_DCHECK(!node->children.empty()); const Reflection* reflection = message->GetReflection(); const Descriptor* descriptor = message->GetDescriptor(); - const int32 field_count = descriptor->field_count(); + const int32_t field_count = descriptor->field_count(); bool modified = false; for (int index = 0; index < field_count; ++index) { const FieldDescriptor* field = descriptor->field(index); diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h index 3ca93597c9..84cd1202ef 100644 --- a/src/google/protobuf/util/field_mask_util.h +++ b/src/google/protobuf/util/field_mask_util.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ #define GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ +#include #include #include @@ -58,7 +59,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // Populates the FieldMask with the paths corresponding to the fields with the // given numbers, after checking that all field numbers are valid. template - static void FromFieldNumbers(const std::vector& field_numbers, + static void FromFieldNumbers(const std::vector& field_numbers, FieldMask* out) { for (const auto field_number : field_numbers) { const FieldDescriptor* field_desc = diff --git a/src/google/protobuf/util/field_mask_util_test.cc b/src/google/protobuf/util/field_mask_util_test.cc index f639b32678..df5d087379 100644 --- a/src/google/protobuf/util/field_mask_util_test.cc +++ b/src/google/protobuf/util/field_mask_util_test.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -164,7 +165,7 @@ TEST(FieldMaskUtilTest, JsonStringFormat) { TEST(FieldMaskUtilTest, FromFieldNumbers) { FieldMask mask; - std::vector field_numbers = { + std::vector field_numbers = { TestAllTypes::kOptionalInt64FieldNumber, TestAllTypes::kOptionalBoolFieldNumber, TestAllTypes::kRepeatedStringFieldNumber, diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 9851cc5d7f..a736ea80bf 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -30,6 +30,7 @@ #include +#include #include #include @@ -524,7 +525,7 @@ class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { private: std::list segments_; Segment last_segment_; - int64 byte_count_; + int64_t byte_count_; }; // This test splits the output buffer and also the input data into multiple diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index 47e3031185..10fdc021a2 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -36,7 +36,9 @@ #include #include +#include #include +#include #include #include @@ -71,7 +73,7 @@ class NumDiffsReporter : public google::protobuf::util::MessageDifferencer::Repo NumDiffsReporter() : num_diffs_(0) {} // Returns the total number of diffs. - int32 GetNumDiffs() const { return num_diffs_; } + int32_t GetNumDiffs() const { return num_diffs_; } void Reset() { num_diffs_ = 0; } // Report that a field has been added into Message2. @@ -99,7 +101,7 @@ class NumDiffsReporter : public google::protobuf::util::MessageDifferencer::Repo } private: - int32 num_diffs_; + int32_t num_diffs_; }; // When comparing a repeated field as map, MultipleFieldMapKeyComparator can @@ -145,7 +147,7 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator int path_index) const { const FieldDescriptor* field = key_field_path[path_index]; std::vector current_parent_fields(parent_fields); - if (path_index == static_cast(key_field_path.size() - 1)) { + if (path_index == static_cast(key_field_path.size() - 1)) { if (field->is_repeated()) { if (!message_differencer_->CompareRepeatedField( message1, message2, field, ¤t_parent_fields)) { @@ -913,6 +915,11 @@ bool MessageDifferencer::CompareMapFieldByMapReflection( const Message& message1, const Message& message2, const FieldDescriptor* map_field, std::vector* parent_fields, DefaultFieldComparator* comparator) { + GOOGLE_DCHECK_EQ(nullptr, reporter_); + GOOGLE_DCHECK(map_field->is_map()); + GOOGLE_DCHECK(map_field_key_comparator_.find(map_field) == + map_field_key_comparator_.end()); + GOOGLE_DCHECK_EQ(repeated_field_comparison_, AS_LIST); const Reflection* reflection1 = message1.GetReflection(); const Reflection* reflection2 = message2.GetReflection(); const int count1 = reflection1->MapSize(message1, map_field); @@ -924,18 +931,28 @@ bool MessageDifferencer::CompareMapFieldByMapReflection( if (count1 > count2) { return false; } + + // First pass: check whether the same keys are present. + for (MapIterator it = reflection1->MapBegin(const_cast(&message1), + map_field), + it_end = reflection1->MapEnd(const_cast(&message1), + map_field); + it != it_end; ++it) { + if (!reflection2->ContainsMapKey(message2, map_field, it.GetKey())) { + return false; + } + } + + // Second pass: compare values for matching keys. const FieldDescriptor* val_des = map_field->message_type()->map_value(); switch (val_des->cpp_type()) { #define HANDLE_TYPE(CPPTYPE, METHOD, COMPAREMETHOD) \ case FieldDescriptor::CPPTYPE_##CPPTYPE: { \ for (MapIterator it = reflection1->MapBegin( \ - const_cast(&message1), map_field); \ - it != \ - reflection1->MapEnd(const_cast(&message1), map_field); \ - ++it) { \ - if (!reflection2->ContainsMapKey(message2, map_field, it.GetKey())) { \ - return false; \ - } \ + const_cast(&message1), map_field), \ + it_end = reflection1->MapEnd( \ + const_cast(&message1), map_field); \ + it != it_end; ++it) { \ MapValueConstRef value2; \ reflection2->LookupMapValue(message2, map_field, it.GetKey(), &value2); \ if (!comparator->Compare##COMPAREMETHOD(*val_des, \ @@ -1716,9 +1733,9 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( Reporter* reporter = reporter_; reporter_ = NULL; NumDiffsReporter num_diffs_reporter; - std::vector num_diffs_list1; + std::vector num_diffs_list1; if (is_treated_as_smart_set) { - num_diffs_list1.assign(count1, kint32max); + num_diffs_list1.assign(count1, std::numeric_limits::max()); } bool success = true; @@ -1786,7 +1803,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( } else if (repeated_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { // Replace with the one with fewer diffs. - const int32 num_diffs = num_diffs_reporter.GetNumDiffs(); + const int32_t num_diffs = num_diffs_reporter.GetNumDiffs(); if (num_diffs < num_diffs_list1[i]) { // If j has been already matched to some element, ensure the // current num_diffs is smaller. diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index 4f2983e9d1..57588b9e3d 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -708,7 +708,7 @@ class PROTOBUF_EXPORT MessageDifferencer { }; private: - friend class DefaultFieldComparator; + friend class SimpleFieldComparator; // A MapKeyComparator to be used in TreatAsMapUsingKeyComparator. // Implementation of this class needs to do field value comparison which diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index ada26552f4..fbbcd3c8be 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -3375,7 +3375,11 @@ TEST_F(ComparisonTest, MapEntryPartialEmptyKeyTest) { util::MessageDifferencer differencer; differencer.set_scope(util::MessageDifferencer::PARTIAL); - EXPECT_TRUE(differencer.Compare(map1, map2)); + // TODO(jieluo): Remove the round trip + std::string serialized_value; + map1.SerializeToString(&serialized_value); + map1.ParseFromString(serialized_value); + EXPECT_FALSE(differencer.Compare(map1, map2)); } TEST_F(ComparisonTest, MapEntryMissingEmptyFieldIsOkTest) { diff --git a/src/google/protobuf/util/time_util.cc b/src/google/protobuf/util/time_util.cc index 08c6e9c1d8..6b9c6654b6 100644 --- a/src/google/protobuf/util/time_util.cc +++ b/src/google/protobuf/util/time_util.cc @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -57,10 +59,10 @@ static const int kSecondsPerMinute = 60; // Note that we ignore leap seconds. static const int kSecondsPerHour = 3600; template -T CreateNormalized(int64 seconds, int64 nanos); +T CreateNormalized(int64_t seconds, int64_t nanos); template <> -Timestamp CreateNormalized(int64 seconds, int64 nanos) { +Timestamp CreateNormalized(int64_t seconds, int64_t nanos) { // Make sure nanos is in the range. if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { seconds += nanos / kNanosPerSecond; @@ -75,12 +77,12 @@ Timestamp CreateNormalized(int64 seconds, int64 nanos) { seconds <= TimeUtil::kTimestampMaxSeconds); Timestamp result; result.set_seconds(seconds); - result.set_nanos(static_cast(nanos)); + result.set_nanos(static_cast(nanos)); return result; } template <> -Duration CreateNormalized(int64 seconds, int64 nanos) { +Duration CreateNormalized(int64_t seconds, int64_t nanos) { // Make sure nanos is in the range. if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { seconds += nanos / kNanosPerSecond; @@ -98,13 +100,13 @@ Duration CreateNormalized(int64 seconds, int64 nanos) { seconds <= TimeUtil::kDurationMaxSeconds); Duration result; result.set_seconds(seconds); - result.set_nanos(static_cast(nanos)); + result.set_nanos(static_cast(nanos)); return result; } // Format nanoseconds with either 3, 6, or 9 digits depending on the required // precision to represent the exact value. -std::string FormatNanos(int32 nanos) { +std::string FormatNanos(int32_t nanos) { if (nanos % kNanosPerMillisecond == 0) { return StringPrintf("%03d", nanos / kNanosPerMillisecond); } else if (nanos % kNanosPerMicrosecond == 0) { @@ -127,9 +129,9 @@ void CurrentTime(int64* seconds, int32* nanos) { } // Truncates the remainder part after division. -int64 RoundTowardZero(int64 value, int64 divider) { - int64 result = value / divider; - int64 remainder = value % divider; +int64_t RoundTowardZero(int64_t value, int64_t divider) { + int64_t result = value / divider; + int64_t remainder = value % divider; // Before C++11, the sign of the remainder is implementation dependent if // any of the operands is negative. Here we try to enforce C++11's "rounded // toward zero" semantics. For example, for (-5) / 2 an implementation may @@ -146,10 +148,10 @@ int64 RoundTowardZero(int64 value, int64 divider) { // Actually define these static const integers. Required by C++ standard (but // some compilers don't like it). #ifndef _MSC_VER -const int64 TimeUtil::kTimestampMinSeconds; -const int64 TimeUtil::kTimestampMaxSeconds; -const int64 TimeUtil::kDurationMaxSeconds; -const int64 TimeUtil::kDurationMinSeconds; +const int64_t TimeUtil::kTimestampMinSeconds; +const int64_t TimeUtil::kTimestampMaxSeconds; +const int64_t TimeUtil::kDurationMaxSeconds; +const int64_t TimeUtil::kDurationMinSeconds; #endif // !_MSC_VER std::string TimeUtil::ToString(const Timestamp& timestamp) { @@ -157,8 +159,8 @@ std::string TimeUtil::ToString(const Timestamp& timestamp) { } bool TimeUtil::FromString(const std::string& value, Timestamp* timestamp) { - int64 seconds; - int32 nanos; + int64_t seconds; + int32_t nanos; if (!ParseTime(value, &seconds, &nanos)) { return false; } @@ -167,8 +169,8 @@ bool TimeUtil::FromString(const std::string& value, Timestamp* timestamp) { } Timestamp TimeUtil::GetCurrentTime() { - int64 seconds; - int32 nanos; + int64_t seconds; + int32_t nanos; CurrentTime(&seconds, &nanos); return CreateNormalized(seconds, nanos); } @@ -177,8 +179,8 @@ Timestamp TimeUtil::GetEpoch() { return Timestamp(); } std::string TimeUtil::ToString(const Duration& duration) { std::string result; - int64 seconds = duration.seconds(); - int32 nanos = duration.nanos(); + int64_t seconds = duration.seconds(); + int32_t nanos = duration.nanos(); if (seconds < 0 || nanos < 0) { result += "-"; seconds = -seconds; @@ -192,8 +194,8 @@ std::string TimeUtil::ToString(const Duration& duration) { return result; } -static int64 Pow(int64 x, int y) { - int64 result = 1; +static int64_t Pow(int64_t x, int y) { + int64_t result = 1; for (int i = 0; i < y; ++i) { result *= x; } @@ -218,11 +220,11 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) { nanos_part = value.substr(pos + 1, value.length() - pos - 2); } char* end; - int64 seconds = strto64(seconds_part.c_str(), &end, 10); + int64_t seconds = strto64(seconds_part.c_str(), &end, 10); if (end != seconds_part.c_str() + seconds_part.length()) { return false; } - int64 nanos = strto64(nanos_part.c_str(), &end, 10); + int64_t nanos = strto64(nanos_part.c_str(), &end, 10); if (end != nanos_part.c_str() + nanos_part.length()) { return false; } @@ -233,106 +235,106 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) { nanos = -nanos; } duration->set_seconds(seconds); - duration->set_nanos(static_cast(nanos)); + duration->set_nanos(static_cast(nanos)); return true; } -Duration TimeUtil::NanosecondsToDuration(int64 nanos) { +Duration TimeUtil::NanosecondsToDuration(int64_t nanos) { return CreateNormalized(nanos / kNanosPerSecond, nanos % kNanosPerSecond); } -Duration TimeUtil::MicrosecondsToDuration(int64 micros) { +Duration TimeUtil::MicrosecondsToDuration(int64_t micros) { return CreateNormalized( micros / kMicrosPerSecond, (micros % kMicrosPerSecond) * kNanosPerMicrosecond); } -Duration TimeUtil::MillisecondsToDuration(int64 millis) { +Duration TimeUtil::MillisecondsToDuration(int64_t millis) { return CreateNormalized( millis / kMillisPerSecond, (millis % kMillisPerSecond) * kNanosPerMillisecond); } -Duration TimeUtil::SecondsToDuration(int64 seconds) { +Duration TimeUtil::SecondsToDuration(int64_t seconds) { return CreateNormalized(seconds, 0); } -Duration TimeUtil::MinutesToDuration(int64 minutes) { +Duration TimeUtil::MinutesToDuration(int64_t minutes) { return CreateNormalized(minutes * kSecondsPerMinute, 0); } -Duration TimeUtil::HoursToDuration(int64 hours) { +Duration TimeUtil::HoursToDuration(int64_t hours) { return CreateNormalized(hours * kSecondsPerHour, 0); } -int64 TimeUtil::DurationToNanoseconds(const Duration& duration) { +int64_t TimeUtil::DurationToNanoseconds(const Duration& duration) { return duration.seconds() * kNanosPerSecond + duration.nanos(); } -int64 TimeUtil::DurationToMicroseconds(const Duration& duration) { +int64_t TimeUtil::DurationToMicroseconds(const Duration& duration) { return duration.seconds() * kMicrosPerSecond + RoundTowardZero(duration.nanos(), kNanosPerMicrosecond); } -int64 TimeUtil::DurationToMilliseconds(const Duration& duration) { +int64_t TimeUtil::DurationToMilliseconds(const Duration& duration) { return duration.seconds() * kMillisPerSecond + RoundTowardZero(duration.nanos(), kNanosPerMillisecond); } -int64 TimeUtil::DurationToSeconds(const Duration& duration) { +int64_t TimeUtil::DurationToSeconds(const Duration& duration) { return duration.seconds(); } -int64 TimeUtil::DurationToMinutes(const Duration& duration) { +int64_t TimeUtil::DurationToMinutes(const Duration& duration) { return RoundTowardZero(duration.seconds(), kSecondsPerMinute); } -int64 TimeUtil::DurationToHours(const Duration& duration) { +int64_t TimeUtil::DurationToHours(const Duration& duration) { return RoundTowardZero(duration.seconds(), kSecondsPerHour); } -Timestamp TimeUtil::NanosecondsToTimestamp(int64 nanos) { +Timestamp TimeUtil::NanosecondsToTimestamp(int64_t nanos) { return CreateNormalized(nanos / kNanosPerSecond, nanos % kNanosPerSecond); } -Timestamp TimeUtil::MicrosecondsToTimestamp(int64 micros) { +Timestamp TimeUtil::MicrosecondsToTimestamp(int64_t micros) { return CreateNormalized( micros / kMicrosPerSecond, micros % kMicrosPerSecond * kNanosPerMicrosecond); } -Timestamp TimeUtil::MillisecondsToTimestamp(int64 millis) { +Timestamp TimeUtil::MillisecondsToTimestamp(int64_t millis) { return CreateNormalized( millis / kMillisPerSecond, millis % kMillisPerSecond * kNanosPerMillisecond); } -Timestamp TimeUtil::SecondsToTimestamp(int64 seconds) { +Timestamp TimeUtil::SecondsToTimestamp(int64_t seconds) { return CreateNormalized(seconds, 0); } -int64 TimeUtil::TimestampToNanoseconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToNanoseconds(const Timestamp& timestamp) { return timestamp.seconds() * kNanosPerSecond + timestamp.nanos(); } -int64 TimeUtil::TimestampToMicroseconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToMicroseconds(const Timestamp& timestamp) { return timestamp.seconds() * kMicrosPerSecond + RoundTowardZero(timestamp.nanos(), kNanosPerMicrosecond); } -int64 TimeUtil::TimestampToMilliseconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToMilliseconds(const Timestamp& timestamp) { return timestamp.seconds() * kMillisPerSecond + RoundTowardZero(timestamp.nanos(), kNanosPerMillisecond); } -int64 TimeUtil::TimestampToSeconds(const Timestamp& timestamp) { +int64_t TimeUtil::TimestampToSeconds(const Timestamp& timestamp) { return timestamp.seconds(); } Timestamp TimeUtil::TimeTToTimestamp(time_t value) { - return CreateNormalized(static_cast(value), 0); + return CreateNormalized(static_cast(value), 0); } time_t TimeUtil::TimestampToTimeT(const Timestamp& value) { @@ -382,19 +384,20 @@ using ::PROTOBUF_NAMESPACE_ID::util::kNanosPerSecond; void ToUint128(const Duration& value, uint128* result, bool* negative) { if (value.seconds() < 0 || value.nanos() < 0) { *negative = true; - *result = static_cast(-value.seconds()); - *result = *result * kNanosPerSecond + static_cast(-value.nanos()); + *result = static_cast(-value.seconds()); + *result = *result * kNanosPerSecond + static_cast(-value.nanos()); } else { *negative = false; - *result = static_cast(value.seconds()); - *result = *result * kNanosPerSecond + static_cast(value.nanos()); + *result = static_cast(value.seconds()); + *result = *result * kNanosPerSecond + static_cast(value.nanos()); } } void ToDuration(const uint128& value, bool negative, Duration* duration) { - int64 seconds = - static_cast(Uint128Low64(value / kNanosPerSecond)); - int32 nanos = static_cast(Uint128Low64(value % kNanosPerSecond)); + int64_t seconds = + static_cast(Uint128Low64(value / kNanosPerSecond)); + int32_t nanos = + static_cast(Uint128Low64(value % kNanosPerSecond)); if (negative) { seconds = -seconds; nanos = -nanos; @@ -416,15 +419,15 @@ Duration& operator-=(Duration& d1, const Duration& d2) { // NOLINT return d1; } -Duration& operator*=(Duration& d, int64 r) { // NOLINT +Duration& operator*=(Duration& d, int64_t r) { // NOLINT bool negative; uint128 value; ToUint128(d, &value, &negative); if (r > 0) { - value *= static_cast(r); + value *= static_cast(r); } else { negative = !negative; - value *= static_cast(-r); + value *= static_cast(-r); } ToDuration(value, negative, &d); return d; @@ -432,8 +435,8 @@ Duration& operator*=(Duration& d, int64 r) { // NOLINT Duration& operator*=(Duration& d, double r) { // NOLINT double result = (d.seconds() * 1.0 + 1.0 * d.nanos() / kNanosPerSecond) * r; - int64 seconds = static_cast(result); - int32 nanos = static_cast((result - seconds) * kNanosPerSecond); + int64_t seconds = static_cast(result); + int32_t nanos = static_cast((result - seconds) * kNanosPerSecond); // Note that we normalize here not just because nanos can have a different // sign from seconds but also that nanos can be any arbitrary value when // overflow happens (i.e., the result is a much larger value than what @@ -442,15 +445,15 @@ Duration& operator*=(Duration& d, double r) { // NOLINT return d; } -Duration& operator/=(Duration& d, int64 r) { // NOLINT +Duration& operator/=(Duration& d, int64_t r) { // NOLINT bool negative; uint128 value; ToUint128(d, &value, &negative); if (r > 0) { - value /= static_cast(r); + value /= static_cast(r); } else { negative = !negative; - value /= static_cast(-r); + value /= static_cast(-r); } ToDuration(value, negative, &d); return d; @@ -476,12 +479,12 @@ Duration& operator%=(Duration& d1, const Duration& d2) { // NOLINT return d1; } -int64 operator/(const Duration& d1, const Duration& d2) { +int64_t operator/(const Duration& d1, const Duration& d2) { bool negative1, negative2; uint128 value1, value2; ToUint128(d1, &value1, &negative1); ToUint128(d2, &value2, &negative2); - int64 result = Uint128Low64(value1 / value2); + int64_t result = Uint128Low64(value1 / value2); if (negative1 != negative2) { result = -result; } diff --git a/src/google/protobuf/util/time_util.h b/src/google/protobuf/util/time_util.h index 95063fc49c..96b1aac46b 100644 --- a/src/google/protobuf/util/time_util.h +++ b/src/google/protobuf/util/time_util.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__ #define GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__ +#include #include #include #include @@ -67,11 +68,11 @@ class PROTOBUF_EXPORT TimeUtil { // The min/max Timestamp/Duration values we support. // // For "0001-01-01T00:00:00Z". - static const int64 kTimestampMinSeconds = -62135596800LL; + static const int64_t kTimestampMinSeconds = -62135596800LL; // For "9999-12-31T23:59:59.999999999Z". - static const int64 kTimestampMaxSeconds = 253402300799LL; - static const int64 kDurationMinSeconds = -315576000000LL; - static const int64 kDurationMaxSeconds = 315576000000LL; + static const int64_t kTimestampMaxSeconds = 253402300799LL; + static const int64_t kDurationMinSeconds = -315576000000LL; + static const int64_t kDurationMaxSeconds = 315576000000LL; // Converts Timestamp to/from RFC 3339 date string format. // Generated output will always be Z-normalized and uses 3, 6 or 9 @@ -110,12 +111,12 @@ class PROTOBUF_EXPORT TimeUtil { // Converts between Duration and integer types. The behavior is undefined if // the input value is not in the valid range of Duration. - static Duration NanosecondsToDuration(int64 nanos); - static Duration MicrosecondsToDuration(int64 micros); - static Duration MillisecondsToDuration(int64 millis); - static Duration SecondsToDuration(int64 seconds); - static Duration MinutesToDuration(int64 minutes); - static Duration HoursToDuration(int64 hours); + static Duration NanosecondsToDuration(int64_t nanos); + static Duration MicrosecondsToDuration(int64_t micros); + static Duration MillisecondsToDuration(int64_t millis); + static Duration SecondsToDuration(int64_t seconds); + static Duration MinutesToDuration(int64_t minutes); + static Duration HoursToDuration(int64_t hours); // Result will be truncated towards zero. For example, "-1.5s" will be // truncated to "-1s", and "1.5s" to "1s" when converting to seconds. // It's undefined behavior if the input duration is not valid or the result @@ -123,28 +124,28 @@ class PROTOBUF_EXPORT TimeUtil { // valid range of Duration, or have an invalid nanos value (i.e., larger // than 999999999, less than -999999999, or have a different sign from the // seconds part). - static int64 DurationToNanoseconds(const Duration& duration); - static int64 DurationToMicroseconds(const Duration& duration); - static int64 DurationToMilliseconds(const Duration& duration); - static int64 DurationToSeconds(const Duration& duration); - static int64 DurationToMinutes(const Duration& duration); - static int64 DurationToHours(const Duration& duration); + static int64_t DurationToNanoseconds(const Duration& duration); + static int64_t DurationToMicroseconds(const Duration& duration); + static int64_t DurationToMilliseconds(const Duration& duration); + static int64_t DurationToSeconds(const Duration& duration); + static int64_t DurationToMinutes(const Duration& duration); + static int64_t DurationToHours(const Duration& duration); // Creates Timestamp from integer types. The integer value indicates the // time elapsed from Epoch time. The behavior is undefined if the input // value is not in the valid range of Timestamp. - static Timestamp NanosecondsToTimestamp(int64 nanos); - static Timestamp MicrosecondsToTimestamp(int64 micros); - static Timestamp MillisecondsToTimestamp(int64 millis); - static Timestamp SecondsToTimestamp(int64 seconds); + static Timestamp NanosecondsToTimestamp(int64_t nanos); + static Timestamp MicrosecondsToTimestamp(int64_t micros); + static Timestamp MillisecondsToTimestamp(int64_t millis); + static Timestamp SecondsToTimestamp(int64_t seconds); // Result will be truncated down to the nearest integer value. For example, // with "1969-12-31T23:59:59.9Z", TimestampToMilliseconds() returns -100 // and TimestampToSeconds() returns -1. It's undefined behavior if the input // Timestamp is not valid (i.e., its seconds part or nanos part does not fall // in the valid range) or the return value doesn't fit into int64. - static int64 TimestampToNanoseconds(const Timestamp& timestamp); - static int64 TimestampToMicroseconds(const Timestamp& timestamp); - static int64 TimestampToMilliseconds(const Timestamp& timestamp); - static int64 TimestampToSeconds(const Timestamp& timestamp); + static int64_t TimestampToNanoseconds(const Timestamp& timestamp); + static int64_t TimestampToMicroseconds(const Timestamp& timestamp); + static int64_t TimestampToMilliseconds(const Timestamp& timestamp); + static int64_t TimestampToSeconds(const Timestamp& timestamp); // Conversion to/from other time/date types. Note that these types may // have a different precision and time range from Timestamp/Duration. @@ -176,19 +177,19 @@ PROTOBUF_EXPORT Duration& operator+=(Duration& d1, const Duration& d2); // NOLINT PROTOBUF_EXPORT Duration& operator-=(Duration& d1, const Duration& d2); // NOLINT -PROTOBUF_EXPORT Duration& operator*=(Duration& d, int64 r); // NOLINT +PROTOBUF_EXPORT Duration& operator*=(Duration& d, int64_t r); // NOLINT PROTOBUF_EXPORT Duration& operator*=(Duration& d, double r); // NOLINT -PROTOBUF_EXPORT Duration& operator/=(Duration& d, int64 r); // NOLINT +PROTOBUF_EXPORT Duration& operator/=(Duration& d, int64_t r); // NOLINT PROTOBUF_EXPORT Duration& operator/=(Duration& d, double r); // NOLINT // Overload for other integer types. template Duration& operator*=(Duration& d, T r) { // NOLINT - int64 x = r; + int64_t x = r; return d *= x; } template Duration& operator/=(Duration& d, T r) { // NOLINT - int64 x = r; + int64_t x = r; return d /= x; } PROTOBUF_EXPORT Duration& operator%=(Duration& d1, @@ -243,7 +244,7 @@ template inline Duration operator/(Duration d, T r) { return d /= r; } -PROTOBUF_EXPORT int64 operator/(const Duration& d1, const Duration& d2); +PROTOBUF_EXPORT int64_t operator/(const Duration& d1, const Duration& d2); inline Duration operator%(const Duration& d1, const Duration& d2) { Duration result = d1; diff --git a/src/google/protobuf/util/time_util_test.cc b/src/google/protobuf/util/time_util_test.cc index b6d3813264..d38a27d955 100644 --- a/src/google/protobuf/util/time_util_test.cc +++ b/src/google/protobuf/util/time_util_test.cc @@ -30,6 +30,7 @@ #include +#include #include #include @@ -119,10 +120,10 @@ TEST(TimeUtilTest, DurationStringFormat) { // Duration must support range from -315,576,000,000s to +315576000000s // which includes negative values. EXPECT_TRUE(TimeUtil::FromString("315576000000.999999999s", &d)); - EXPECT_EQ(int64{315576000000}, d.seconds()); + EXPECT_EQ(int64_t{315576000000}, d.seconds()); EXPECT_EQ(999999999, d.nanos()); EXPECT_TRUE(TimeUtil::FromString("-315576000000.999999999s", &d)); - EXPECT_EQ(int64{-315576000000}, d.seconds()); + EXPECT_EQ(int64_t{-315576000000}, d.seconds()); EXPECT_EQ(-999999999, d.nanos()); } @@ -277,23 +278,24 @@ TEST(TimeUtilTest, DurationOperators) { EXPECT_EQ("-0.999999999s", TimeUtil::ToString(b * 0.5)); // Multiplication should not overflow if the result fits into the supported // range of Duration (intermediate result may be larger than int64). - EXPECT_EQ("315575999684.424s", - TimeUtil::ToString((one_second - one_nano) * int64{315576000000})); - EXPECT_EQ("-315575999684.424s", - TimeUtil::ToString((one_nano - one_second) * int64{315576000000})); + EXPECT_EQ("315575999684.424s", TimeUtil::ToString((one_second - one_nano) * + int64_t{315576000000})); + EXPECT_EQ("-315575999684.424s", TimeUtil::ToString((one_nano - one_second) * + int64_t{315576000000})); EXPECT_EQ("-315575999684.424s", TimeUtil::ToString((one_second - one_nano) * - (int64{-315576000000}))); + (int64_t{-315576000000}))); // Test / and % EXPECT_EQ("0.999999999s", TimeUtil::ToString(a / 2)); EXPECT_EQ("-0.999999999s", TimeUtil::ToString(b / 2)); - Duration large = TimeUtil::SecondsToDuration(int64{315576000000}) - one_nano; + Duration large = + TimeUtil::SecondsToDuration(int64_t{315576000000}) - one_nano; // We have to handle division with values beyond 64 bits. - EXPECT_EQ("0.999999999s", TimeUtil::ToString(large / int64{315576000000})); + EXPECT_EQ("0.999999999s", TimeUtil::ToString(large / int64_t{315576000000})); EXPECT_EQ("-0.999999999s", - TimeUtil::ToString((-large) / int64{315576000000})); + TimeUtil::ToString((-large) / int64_t{315576000000})); EXPECT_EQ("-0.999999999s", - TimeUtil::ToString(large / (int64{-315576000000}))); + TimeUtil::ToString(large / (int64_t{-315576000000}))); Duration large2 = large + one_nano; EXPECT_EQ(large, large % large2); EXPECT_EQ(-large, (-large) % large2); diff --git a/src/google/protobuf/util/type_resolver_util_test.cc b/src/google/protobuf/util/type_resolver_util_test.cc index d90fdffd9e..f0a0a74aaf 100644 --- a/src/google/protobuf/util/type_resolver_util_test.cc +++ b/src/google/protobuf/util/type_resolver_util_test.cc @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -135,12 +136,12 @@ class DescriptorPoolTypeResolverTest : public testing::Test { } bool HasInt32Option(const RepeatedPtrField