diff options
186 files changed, 2866 insertions, 1113 deletions
@@ -108,6 +108,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/io_win32.cc", "src/google/protobuf/stubs/once.cc", "src/google/protobuf/stubs/status.cc", "src/google/protobuf/stubs/statusor.cc", @@ -148,6 +149,7 @@ cc_library( "src/google/protobuf/extension_set_heavy.cc", "src/google/protobuf/field_mask.pb.cc", "src/google/protobuf/generated_message_reflection.cc", + "src/google/protobuf/generated_message_table_driven.cc", "src/google/protobuf/io/gzip_stream.cc", "src/google/protobuf/io/printer.cc", "src/google/protobuf/io/strtod.cc", @@ -159,6 +161,7 @@ cc_library( "src/google/protobuf/service.cc", "src/google/protobuf/source_context.pb.cc", "src/google/protobuf/struct.pb.cc", + "src/google/protobuf/stubs/io_win32.cc", "src/google/protobuf/stubs/mathlimits.cc", "src/google/protobuf/stubs/substitute.cc", "src/google/protobuf/text_format.cc", @@ -470,6 +473,7 @@ COMMON_TEST_SRCS = [ # AUTOGEN(common_test_srcs) "src/google/protobuf/arena_test_util.cc", "src/google/protobuf/map_test_util.cc", + "src/google/protobuf/stubs/io_win32.cc", "src/google/protobuf/test_util.cc", "src/google/protobuf/testing/file.cc", "src/google/protobuf/testing/googletest.cc", @@ -491,6 +495,16 @@ cc_binary( ) cc_test( + name = "win32_test", + srcs = ["src/google/protobuf/stubs/io_win32_unittest.cc"], + deps = [ + ":protobuf_lite", + "//external:gtest_main", + ], + tags = ["manual", "windows"], +) + +cc_test( name = "protobuf_test", srcs = COMMON_TEST_SRCS + [ # AUTOGEN(test_srcs) @@ -536,6 +550,7 @@ cc_test( "src/google/protobuf/stubs/bytestream_unittest.cc", "src/google/protobuf/stubs/common_unittest.cc", "src/google/protobuf/stubs/int128_unittest.cc", + "src/google/protobuf/stubs/io_win32_unittest.cc", "src/google/protobuf/stubs/once_unittest.cc", "src/google/protobuf/stubs/status_test.cc", "src/google/protobuf/stubs/statusor_test.cc", diff --git a/Makefile.am b/Makefile.am index f613c0f8..7ffb202e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -662,6 +662,7 @@ php_EXTRA_DIST= \ php/tests/gdb_test.sh \ php/tests/generated_class_test.php \ php/tests/generated_phpdoc_test.php \ + php/tests/generated_service_test.php \ php/tests/map_field_test.php \ php/tests/memory_leak_test.php \ php/tests/php_implementation_test.php \ @@ -672,6 +673,8 @@ php_EXTRA_DIST= \ php/tests/proto/test_no_namespace.proto \ php/tests/proto/test_php_namespace.proto \ php/tests/proto/test_prefix.proto \ + php/tests/proto/test_service.proto \ + php/tests/proto/test_service_namespace.proto \ php/tests/test.sh \ php/tests/test_base.php \ php/tests/test_util.php \ diff --git a/Protobuf.podspec b/Protobuf.podspec index af2e952f..249911c5 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.3.0' + s.version = '3.3.2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index 1278ee87..a16081a2 100644 --- a/cmake/extract_includes.bat.in +++ b/cmake/extract_includes.bat.in @@ -50,6 +50,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.pb.h" incl copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_reflection.h" include\google\protobuf\generated_enum_reflection.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h" include\google\protobuf\generated_enum_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_reflection.h" include\google\protobuf\generated_message_reflection.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_table_driven.h" include\google\protobuf\generated_message_table_driven.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_util.h" include\google\protobuf\generated_message_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_table_driven.h" include\google\protobuf\generated_message_table_driven.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\has_bits.h" include\google\protobuf\has_bits.h @@ -99,6 +100,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\casts.h" includ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h" include\google\protobuf\stubs\common.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\fastmem.h" include\google\protobuf\stubs\fastmem.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h" include\google\protobuf\stubs\hash.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\io_win32.h" include\google\protobuf\stubs\io_win32.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\logging.h" include\google\protobuf\stubs\logging.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\macros.h" include\google\protobuf\stubs\macros.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\mutex.h" include\google\protobuf\stubs\mutex.h diff --git a/cmake/install.cmake b/cmake/install.cmake index 28dc90dc..441bf553 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -1,5 +1,10 @@ include(GNUInstallDirs) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf.pc.cmake + ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-lite.pc.cmake + ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY) + foreach(_library libprotobuf-lite libprotobuf @@ -17,6 +22,8 @@ endforeach() install(TARGETS protoc EXPORT protobuf-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + file(STRINGS extract_includes.bat.in _extract_strings REGEX "^copy") foreach(_extract_string ${_extract_strings}) diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index 1ee9b9c5..cf72e2fe 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -13,6 +13,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/io_win32.cc ${protobuf_source_dir}/src/google/protobuf/stubs/once.cc ${protobuf_source_dir}/src/google/protobuf/stubs/status.cc ${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 030924d2..72db915b 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -13,6 +13,7 @@ set(libprotobuf_files ${protobuf_source_dir}/src/google/protobuf/extension_set_heavy.cc ${protobuf_source_dir}/src/google/protobuf/field_mask.pb.cc ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.cc + ${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven.cc ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/printer.cc ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 51226540..8ac8d479 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -93,6 +93,7 @@ set(libprotoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc ${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/io_win32.cc ) set(libprotoc_headers diff --git a/cmake/protobuf-lite.pc.cmake b/cmake/protobuf-lite.pc.cmake new file mode 100644 index 00000000..cbe5426a --- /dev/null +++ b/cmake/protobuf-lite.pc.cmake @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: Protocol Buffers +Description: Google's Data Interchange Format +Version: @protobuf_VERSION@ +Libs: -L${libdir} -lprotobuf-lite @CMAKE_THREAD_LIBS_INIT@ +Cflags: -I${includedir} @CMAKE_THREAD_LIBS_INIT@ +Conflicts: protobuf diff --git a/cmake/protobuf.pc.cmake b/cmake/protobuf.pc.cmake new file mode 100644 index 00000000..d33e98cc --- /dev/null +++ b/cmake/protobuf.pc.cmake @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: Protocol Buffers +Description: Google's Data Interchange Format +Version: @protobuf_VERSION@ +Libs: -L${libdir} -lprotobuf @CMAKE_THREAD_LIBS_INIT@ +Cflags: -I${includedir} @CMAKE_THREAD_LIBS_INIT@ +Conflicts: protobuf-lite diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 38dc0b52..31f22575 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -160,6 +160,8 @@ set(tests_files ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream_unittest.cc ${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc ${protobuf_source_dir}/src/google/protobuf/stubs/int128_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/io_win32.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/io_win32_unittest.cc ${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc ${protobuf_source_dir}/src/google/protobuf/stubs/status_test.cc ${protobuf_source_dir}/src/google/protobuf/stubs/statusor_test.cc @@ -198,6 +200,7 @@ target_link_libraries(tests libprotoc libprotobuf gmock_main) set(test_plugin_files ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/io_win32.cc ${protobuf_source_dir}/src/google/protobuf/testing/file.cc ${protobuf_source_dir}/src/google/protobuf/testing/file.h ${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc diff --git a/configure.ac b/configure.ac index 82b221e8..e75bdbaa 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.3.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.3.2],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index d7b81a5f..4630729a 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -726,7 +726,7 @@ void ConformanceTestSuite::SetFailureList(const string& filename, std::inserter(expected_to_fail_, expected_to_fail_.end())); } -bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, +bool ConformanceTestSuite::CheckSetEmpty(const std::set<string>& set_to_check, const std::string& write_to_file, const std::string& msg) { if (set_to_check.empty()) { @@ -734,7 +734,7 @@ bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, } else { StringAppendF(&output_, "\n"); StringAppendF(&output_, "%s\n\n", msg.c_str()); - for (set<string>::const_iterator iter = set_to_check.begin(); + for (std::set<string>::const_iterator iter = set_to_check.begin(); iter != set_to_check.end(); ++iter) { StringAppendF(&output_, " %s\n", iter->c_str()); } @@ -743,7 +743,7 @@ bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, if (!write_to_file.empty()) { std::ofstream os(write_to_file); if (os) { - for (set<string>::const_iterator iter = set_to_check.begin(); + for (std::set<string>::const_iterator iter = set_to_check.begin(); iter != set_to_check.end(); ++iter) { os << *iter << "\n"; } diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index 6eeea8b6..d1a822eb 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h @@ -215,7 +215,7 @@ class ConformanceTestSuite { void TestValidDataForType( google::protobuf::FieldDescriptor::Type, std::vector<std::pair<std::string, std::string>> values); - bool CheckSetEmpty(const set<string>& set_to_check, + bool CheckSetEmpty(const std::set<string>& set_to_check, const std::string& write_to_file, const std::string& msg); ConformanceTestRunner* runner_; int successes_; diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 182309bf..95e6b04a 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ <title>Google Protocol Buffers tools</title> <summary>Tools for Protocol Buffers - Google's data interchange format.</summary> <description>See project site for more info.</description> - <version>3.3.0</version> + <version>3.3.2</version> <authors>Google Inc.</authors> <owners>protobuf-packages</owners> <licenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</licenseUrl> diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs index c0a9ffd1..ff44895c 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -403,7 +403,7 @@ namespace Google.Protobuf output.Flush();
ms.Position = 0;
- CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0);
+ CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0, false);
uint tag = input.ReadTag();
Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 48bf6d60..01bd3218 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -334,7 +334,7 @@ namespace Google.Protobuf }
// Now test Input stream:
{
- CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0);
+ CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0, false);
Assert.AreEqual(0, cin.Position);
// Field 1:
uint tag = cin.ReadTag();
diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index c0a9ffd1..e719d2a0 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -403,7 +403,7 @@ namespace Google.Protobuf output.Flush();
ms.Position = 0;
- CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0);
+ CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0, false);
uint tag = input.ReadTag();
Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
@@ -594,5 +594,12 @@ namespace Google.Protobuf }
Assert.IsTrue(memoryStream.CanRead); // We left the stream open
}
+
+ [Test]
+ public void Dispose_FromByteArray()
+ {
+ var stream = new CodedInputStream(new byte[10]);
+ stream.Dispose();
+ }
}
}
\ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 48bf6d60..98cabd55 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -334,7 +334,7 @@ namespace Google.Protobuf }
// Now test Input stream:
{
- CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0);
+ CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0, false);
Assert.AreEqual(0, cin.Position);
// Field 1:
uint tag = cin.ReadTag();
@@ -415,5 +415,12 @@ namespace Google.Protobuf Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
Assert.IsTrue(memoryStream.CanWrite); // We left the stream open
}
+
+ [Test]
+ public void Dispose_FromByteArray()
+ {
+ var stream = new CodedOutputStream(new byte[10]);
+ stream.Dispose();
+ }
}
}
\ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs index 9d3d69af..68b4de45 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs @@ -540,6 +540,22 @@ namespace Google.Protobuf.Collections Assert.Throws<ArgumentException>(() => map.ToString()); } +#if !NET35 + [Test] + public void IDictionaryKeys_Equals_IReadOnlyDictionaryKeys() + { + var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } }; + CollectionAssert.AreEquivalent(((IDictionary<string, string>)map).Keys, ((IReadOnlyDictionary<string, string>)map).Keys); + } + + [Test] + public void IDictionaryValues_Equals_IReadOnlyDictionaryValues() + { + var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } }; + CollectionAssert.AreEquivalent(((IDictionary<string, string>)map).Values, ((IReadOnlyDictionary<string, string>)map).Values); + } +#endif + private static KeyValuePair<TKey, TValue> NewKeyValuePair<TKey, TValue>(TKey key, TValue value) { return new KeyValuePair<TKey, TValue>(key, value); diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs index 4aecc998..a3edd595 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs @@ -91,6 +91,24 @@ namespace Google.Protobuf.WellKnownTypes } [Test] + public void TryUnpack_WrongType() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var any = Any.Pack(message); + Assert.False(any.TryUnpack(out TestOneof unpacked)); + Assert.Null(unpacked); + } + + [Test] + public void TryUnpack_RightType() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var any = Any.Pack(message); + Assert.IsTrue(any.TryUnpack(out TestAllTypes unpacked)); + Assert.AreEqual(message, unpacked); + } + + [Test] public void ToString_WithValues() { var message = SampleMessages.CreateFullTestAllTypes(); @@ -100,6 +118,16 @@ namespace Google.Protobuf.WellKnownTypes } [Test] + [TestCase("proto://foo.bar", "foo.bar")] + [TestCase("/foo/bar/baz", "baz")] + [TestCase("foobar", "")] + public void GetTypeName(string typeUrl, string expectedTypeName) + { + var any = new Any { TypeUrl = typeUrl }; + Assert.AreEqual(expectedTypeName, Any.GetTypeName(typeUrl)); + } + + [Test] public void ToString_Empty() { var any = new Any(); diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs index 072e2e17..84f90a25 100644 --- a/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -121,7 +121,7 @@ namespace Google.Protobuf /// <summary>
/// Creates a new CodedInputStream reading data from the given byte array.
/// </summary>
- public CodedInputStream(byte[] buffer) : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), 0, buffer.Length)
+ public CodedInputStream(byte[] buffer) : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), 0, buffer.Length, true)
{
}
@@ -129,7 +129,7 @@ namespace Google.Protobuf /// Creates a new <see cref="CodedInputStream"/> that reads from the given byte array slice.
/// </summary>
public CodedInputStream(byte[] buffer, int offset, int length)
- : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), offset, offset + length)
+ : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), offset, offset + length, true)
{
if (offset < 0 || offset > buffer.Length)
{
@@ -158,16 +158,15 @@ namespace Google.Protobuf /// <c cref="CodedInputStream"/> is disposed; <c>false</c> to dispose of the given stream when the
/// returned object is disposed.</param>
public CodedInputStream(Stream input, bool leaveOpen)
- : this(ProtoPreconditions.CheckNotNull(input, "input"), new byte[BufferSize], 0, 0)
+ : this(ProtoPreconditions.CheckNotNull(input, "input"), new byte[BufferSize], 0, 0, leaveOpen)
{
- this.leaveOpen = leaveOpen;
}
/// <summary>
/// Creates a new CodedInputStream reading data from the given
/// stream and buffer, using the default limits.
/// </summary>
- internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize)
+ internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize, bool leaveOpen)
{
this.input = input;
this.buffer = buffer;
@@ -175,6 +174,7 @@ namespace Google.Protobuf this.bufferSize = bufferSize;
this.sizeLimit = DefaultSizeLimit;
this.recursionLimit = DefaultRecursionLimit;
+ this.leaveOpen = leaveOpen;
}
/// <summary>
@@ -185,8 +185,8 @@ namespace Google.Protobuf /// This chains to the version with the default limits instead of vice versa to avoid
/// having to check that the default values are valid every time.
/// </remarks>
- internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize, int sizeLimit, int recursionLimit)
- : this(input, buffer, bufferPos, bufferSize)
+ internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize, int sizeLimit, int recursionLimit, bool leaveOpen)
+ : this(input, buffer, bufferPos, bufferSize, leaveOpen)
{
if (sizeLimit <= 0)
{
@@ -217,7 +217,8 @@ namespace Google.Protobuf /// and recursion limits.</returns>
public static CodedInputStream CreateWithLimits(Stream input, int sizeLimit, int recursionLimit)
{
- return new CodedInputStream(input, new byte[BufferSize], 0, 0, sizeLimit, recursionLimit);
+ // Note: we may want an overload accepting leaveOpen
+ return new CodedInputStream(input, new byte[BufferSize], 0, 0, sizeLimit, recursionLimit, false);
}
/// <summary>
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index ef5651c9..8dac8e30 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -67,6 +67,9 @@ namespace Google.Protobuf.Collections /// </para> /// </remarks> public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary +#if !NET35 + , IReadOnlyDictionary<TKey, TValue> +#endif { // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.) private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> map = @@ -548,6 +551,14 @@ namespace Google.Protobuf.Collections } #endregion + #region IReadOnlyDictionary explicit interface implementation +#if !NET35 + IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys; + + IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values; +#endif + #endregion + private class DictionaryEnumerator : IDictionaryEnumerator { private readonly IEnumerator<KeyValuePair<TKey, TValue>> enumerator; diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4eebd99e..46418e39 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -16,7 +16,7 @@ <PackageProjectUrl>https://github.com/google/protobuf</PackageProjectUrl> <PackageLicenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</PackageLicenseUrl> <RepositoryType>git</RepositoryType> - <RepositoryUrl>https://github.com/nodatime/nodatime.git</RepositoryUrl> + <RepositoryUrl>https://github.com/google/protobuf.git</RepositoryUrl> <IncludeSymbols>true</IncludeSymbols> <IncludeSource>true</IncludeSource> </PropertyGroup> diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index c3517802..6c605f3c 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -80,7 +80,7 @@ namespace Google.Protobuf.Reflection { "ASgJEhMKC291dHB1dF90eXBlGAMgASgJEi8KB29wdGlvbnMYBCABKAsyHi5n", "b29nbGUucHJvdG9idWYuTWV0aG9kT3B0aW9ucxIfChBjbGllbnRfc3RyZWFt", "aW5nGAUgASgIOgVmYWxzZRIfChBzZXJ2ZXJfc3RyZWFtaW5nGAYgASgIOgVm", - "YWxzZSLLBQoLRmlsZU9wdGlvbnMSFAoMamF2YV9wYWNrYWdlGAEgASgJEhwK", + "YWxzZSLwBQoLRmlsZU9wdGlvbnMSFAoMamF2YV9wYWNrYWdlGAEgASgJEhwK", "FGphdmFfb3V0ZXJfY2xhc3NuYW1lGAggASgJEiIKE2phdmFfbXVsdGlwbGVf", "ZmlsZXMYCiABKAg6BWZhbHNlEikKHWphdmFfZ2VuZXJhdGVfZXF1YWxzX2Fu", "ZF9oYXNoGBQgASgIQgIYARIlChZqYXZhX3N0cmluZ19jaGVja191dGY4GBsg", @@ -88,65 +88,66 @@ namespace Google.Protobuf.Reflection { "dG9idWYuRmlsZU9wdGlvbnMuT3B0aW1pemVNb2RlOgVTUEVFRBISCgpnb19w", "YWNrYWdlGAsgASgJEiIKE2NjX2dlbmVyaWNfc2VydmljZXMYECABKAg6BWZh", "bHNlEiQKFWphdmFfZ2VuZXJpY19zZXJ2aWNlcxgRIAEoCDoFZmFsc2USIgoT", - "cHlfZ2VuZXJpY19zZXJ2aWNlcxgSIAEoCDoFZmFsc2USGQoKZGVwcmVjYXRl", - "ZBgXIAEoCDoFZmFsc2USHwoQY2NfZW5hYmxlX2FyZW5hcxgfIAEoCDoFZmFs", - "c2USGQoRb2JqY19jbGFzc19wcmVmaXgYJCABKAkSGAoQY3NoYXJwX25hbWVz", - "cGFjZRglIAEoCRIUCgxzd2lmdF9wcmVmaXgYJyABKAkSGAoQcGhwX2NsYXNz", - "X3ByZWZpeBgoIAEoCRIVCg1waHBfbmFtZXNwYWNlGCkgASgJEkMKFHVuaW50", - "ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu", - "dGVycHJldGVkT3B0aW9uIjoKDE9wdGltaXplTW9kZRIJCgVTUEVFRBABEg0K", - "CUNPREVfU0laRRACEhAKDExJVEVfUlVOVElNRRADKgkI6AcQgICAgAJKBAgm", - "ECci8gEKDk1lc3NhZ2VPcHRpb25zEiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9y", - "bWF0GAEgASgIOgVmYWxzZRIuCh9ub19zdGFuZGFyZF9kZXNjcmlwdG9yX2Fj", - "Y2Vzc29yGAIgASgIOgVmYWxzZRIZCgpkZXByZWNhdGVkGAMgASgIOgVmYWxz", - "ZRIRCgltYXBfZW50cnkYByABKAgSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y", - "5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24q", - "CQjoBxCAgICAAkoECAgQCUoECAkQCiKeAwoMRmllbGRPcHRpb25zEjoKBWN0", - "eXBlGAEgASgOMiMuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlw", - "ZToGU1RSSU5HEg4KBnBhY2tlZBgCIAEoCBI/CgZqc3R5cGUYBiABKA4yJC5n", - "b29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zLkpTVHlwZToJSlNfTk9STUFM", - "EhMKBGxhenkYBSABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZh", - "bHNlEhMKBHdlYWsYCiABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0", - "aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0", - "aW9uIi8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdf", - "UElFQ0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5H", - "EAESDQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJeCgxPbmVvZk9w", - "dGlvbnMSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xl", - "LnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoL", - "RW51bU9wdGlvbnMSEwoLYWxsb3dfYWxpYXMYAiABKAgSGQoKZGVwcmVjYXRl", - "ZBgDIAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygL", - "MiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCA", - "gICAAkoECAUQBiJ9ChBFbnVtVmFsdWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQY", - "ASABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIk", + "cHlfZ2VuZXJpY19zZXJ2aWNlcxgSIAEoCDoFZmFsc2USIwoUcGhwX2dlbmVy", + "aWNfc2VydmljZXMYEyABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYFyABKAg6", + "BWZhbHNlEh8KEGNjX2VuYWJsZV9hcmVuYXMYHyABKAg6BWZhbHNlEhkKEW9i", + "amNfY2xhc3NfcHJlZml4GCQgASgJEhgKEGNzaGFycF9uYW1lc3BhY2UYJSAB", + "KAkSFAoMc3dpZnRfcHJlZml4GCcgASgJEhgKEHBocF9jbGFzc19wcmVmaXgY", + "KCABKAkSFQoNcGhwX25hbWVzcGFjZRgpIAEoCRJDChR1bmludGVycHJldGVk", + "X29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRl", + "ZE9wdGlvbiI6CgxPcHRpbWl6ZU1vZGUSCQoFU1BFRUQQARINCglDT0RFX1NJ", + "WkUQAhIQCgxMSVRFX1JVTlRJTUUQAyoJCOgHEICAgIACSgQIJhAnIvIBCg5N", + "ZXNzYWdlT3B0aW9ucxImChdtZXNzYWdlX3NldF93aXJlX2Zvcm1hdBgBIAEo", + "CDoFZmFsc2USLgofbm9fc3RhbmRhcmRfZGVzY3JpcHRvcl9hY2Nlc3NvchgC", + "IAEoCDoFZmFsc2USGQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USEQoJbWFw", + "X2VudHJ5GAcgASgIEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIk", "Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICA", - "gAIiewoOU2VydmljZU9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFs", - "c2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnBy", - "b3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKtAgoNTWV0", - "aG9kT3B0aW9ucxIZCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZRJfChFpZGVt", - "cG90ZW5jeV9sZXZlbBgiIAEoDjIvLmdvb2dsZS5wcm90b2J1Zi5NZXRob2RP", - "cHRpb25zLklkZW1wb3RlbmN5TGV2ZWw6E0lERU1QT1RFTkNZX1VOS05PV04S", - "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", - "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24iUAoQSWRlbXBvdGVuY3lMZXZlbBIX", - "ChNJREVNUE9URU5DWV9VTktOT1dOEAASEwoPTk9fU0lERV9FRkZFQ1RTEAES", - "DgoKSURFTVBPVEVOVBACKgkI6AcQgICAgAIingIKE1VuaW50ZXJwcmV0ZWRP", - "cHRpb24SOwoEbmFtZRgCIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5VbmludGVy", - "cHJldGVkT3B0aW9uLk5hbWVQYXJ0EhgKEGlkZW50aWZpZXJfdmFsdWUYAyAB", - "KAkSGgoScG9zaXRpdmVfaW50X3ZhbHVlGAQgASgEEhoKEm5lZ2F0aXZlX2lu", - "dF92YWx1ZRgFIAEoAxIUCgxkb3VibGVfdmFsdWUYBiABKAESFAoMc3RyaW5n", - "X3ZhbHVlGAcgASgMEhcKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCRozCghOYW1l", - "UGFydBIRCgluYW1lX3BhcnQYASACKAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigI", - "ItUBCg5Tb3VyY2VDb2RlSW5mbxI6Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2ds", - "ZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvbhqGAQoITG9jYXRp", - "b24SEAoEcGF0aBgBIAMoBUICEAESEAoEc3BhbhgCIAMoBUICEAESGAoQbGVh", - "ZGluZ19jb21tZW50cxgDIAEoCRIZChF0cmFpbGluZ19jb21tZW50cxgEIAEo", - "CRIhChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJIqcBChFHZW5l", - "cmF0ZWRDb2RlSW5mbxJBCgphbm5vdGF0aW9uGAEgAygLMi0uZ29vZ2xlLnBy", - "b3RvYnVmLkdlbmVyYXRlZENvZGVJbmZvLkFubm90YXRpb24aTwoKQW5ub3Rh", - "dGlvbhIQCgRwYXRoGAEgAygFQgIQARITCgtzb3VyY2VfZmlsZRgCIAEoCRIN", - "CgViZWdpbhgDIAEoBRILCgNlbmQYBCABKAVCjAEKE2NvbS5nb29nbGUucHJv", - "dG9idWZCEERlc2NyaXB0b3JQcm90b3NIAVo+Z2l0aHViLmNvbS9nb2xhbmcv", - "cHJvdG9idWYvcHJvdG9jLWdlbi1nby9kZXNjcmlwdG9yO2Rlc2NyaXB0b3Ki", - "AgNHUEKqAhpHb29nbGUuUHJvdG9idWYuUmVmbGVjdGlvbg==")); + "gAJKBAgIEAlKBAgJEAoingMKDEZpZWxkT3B0aW9ucxI6CgVjdHlwZRgBIAEo", + "DjIjLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlvbnMuQ1R5cGU6BlNUUklO", + "RxIOCgZwYWNrZWQYAiABKAgSPwoGanN0eXBlGAYgASgOMiQuZ29vZ2xlLnBy", + "b3RvYnVmLkZpZWxkT3B0aW9ucy5KU1R5cGU6CUpTX05PUk1BTBITCgRsYXp5", + "GAUgASgIOgVmYWxzZRIZCgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRITCgR3", + "ZWFrGAogASgIOgVmYWxzZRJDChR1bmludGVycHJldGVkX29wdGlvbhjnByAD", + "KAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbiIvCgVD", + "VHlwZRIKCgZTVFJJTkcQABIICgRDT1JEEAESEAoMU1RSSU5HX1BJRUNFEAIi", + "NQoGSlNUeXBlEg0KCUpTX05PUk1BTBAAEg0KCUpTX1NUUklORxABEg0KCUpT", + "X05VTUJFUhACKgkI6AcQgICAgAJKBAgEEAUiXgoMT25lb2ZPcHRpb25zEkMK", + "FHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1", + "Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIikwEKC0VudW1PcHRp", + "b25zEhMKC2FsbG93X2FsaWFzGAIgASgIEhkKCmRlcHJlY2F0ZWQYAyABKAg6", + "BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2ds", + "ZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgF", + "EAYifQoQRW51bVZhbHVlT3B0aW9ucxIZCgpkZXByZWNhdGVkGAEgASgIOgVm", + "YWxzZRJDChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUu", + "cHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICAgIACInsKDlNl", + "cnZpY2VPcHRpb25zEhkKCmRlcHJlY2F0ZWQYISABKAg6BWZhbHNlEkMKFHVu", + "aW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5V", + "bmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIirQIKDU1ldGhvZE9wdGlv", + "bnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2USXwoRaWRlbXBvdGVuY3lf", + "bGV2ZWwYIiABKA4yLy5nb29nbGUucHJvdG9idWYuTWV0aG9kT3B0aW9ucy5J", + "ZGVtcG90ZW5jeUxldmVsOhNJREVNUE9URU5DWV9VTktOT1dOEkMKFHVuaW50", + "ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu", + "dGVycHJldGVkT3B0aW9uIlAKEElkZW1wb3RlbmN5TGV2ZWwSFwoTSURFTVBP", + "VEVOQ1lfVU5LTk9XThAAEhMKD05PX1NJREVfRUZGRUNUUxABEg4KCklERU1Q", + "T1RFTlQQAioJCOgHEICAgIACIp4CChNVbmludGVycHJldGVkT3B0aW9uEjsK", + "BG5hbWUYAiADKAsyLS5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9w", + "dGlvbi5OYW1lUGFydBIYChBpZGVudGlmaWVyX3ZhbHVlGAMgASgJEhoKEnBv", + "c2l0aXZlX2ludF92YWx1ZRgEIAEoBBIaChJuZWdhdGl2ZV9pbnRfdmFsdWUY", + "BSABKAMSFAoMZG91YmxlX3ZhbHVlGAYgASgBEhQKDHN0cmluZ192YWx1ZRgH", + "IAEoDBIXCg9hZ2dyZWdhdGVfdmFsdWUYCCABKAkaMwoITmFtZVBhcnQSEQoJ", + "bmFtZV9wYXJ0GAEgAigJEhQKDGlzX2V4dGVuc2lvbhgCIAIoCCLVAQoOU291", + "cmNlQ29kZUluZm8SOgoIbG9jYXRpb24YASADKAsyKC5nb29nbGUucHJvdG9i", + "dWYuU291cmNlQ29kZUluZm8uTG9jYXRpb24ahgEKCExvY2F0aW9uEhAKBHBh", + "dGgYASADKAVCAhABEhAKBHNwYW4YAiADKAVCAhABEhgKEGxlYWRpbmdfY29t", + "bWVudHMYAyABKAkSGQoRdHJhaWxpbmdfY29tbWVudHMYBCABKAkSIQoZbGVh", + "ZGluZ19kZXRhY2hlZF9jb21tZW50cxgGIAMoCSKnAQoRR2VuZXJhdGVkQ29k", + "ZUluZm8SQQoKYW5ub3RhdGlvbhgBIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5H", + "ZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9uGk8KCkFubm90YXRpb24SEAoE", + "cGF0aBgBIAMoBUICEAESEwoLc291cmNlX2ZpbGUYAiABKAkSDQoFYmVnaW4Y", + "AyABKAUSCwoDZW5kGAQgASgFQowBChNjb20uZ29vZ2xlLnByb3RvYnVmQhBE", + "ZXNjcmlwdG9yUHJvdG9zSAFaPmdpdGh1Yi5jb20vZ29sYW5nL3Byb3RvYnVm", + "L3Byb3RvYy1nZW4tZ28vZGVzY3JpcHRvcjtkZXNjcmlwdG9yogIDR1BCqgIa", + "R29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rpb24=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { @@ -160,7 +161,7 @@ namespace Google.Protobuf.Reflection { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumValueDescriptorProto), global::Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser, new[]{ "Name", "Number", "Options" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.ServiceDescriptorProto), global::Google.Protobuf.Reflection.ServiceDescriptorProto.Parser, new[]{ "Name", "Method", "Options" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.MethodDescriptorProto), global::Google.Protobuf.Reflection.MethodDescriptorProto.Parser, new[]{ "Name", "InputType", "OutputType", "Options", "ClientStreaming", "ServerStreaming" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileOptions), global::Google.Protobuf.Reflection.FileOptions.Parser, new[]{ "JavaPackage", "JavaOuterClassname", "JavaMultipleFiles", "JavaGenerateEqualsAndHash", "JavaStringCheckUtf8", "OptimizeFor", "GoPackage", "CcGenericServices", "JavaGenericServices", "PyGenericServices", "Deprecated", "CcEnableArenas", "ObjcClassPrefix", "CsharpNamespace", "SwiftPrefix", "PhpClassPrefix", "PhpNamespace", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) }, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileOptions), global::Google.Protobuf.Reflection.FileOptions.Parser, new[]{ "JavaPackage", "JavaOuterClassname", "JavaMultipleFiles", "JavaGenerateEqualsAndHash", "JavaStringCheckUtf8", "OptimizeFor", "GoPackage", "CcGenericServices", "JavaGenericServices", "PyGenericServices", "PhpGenericServices", "Deprecated", "CcEnableArenas", "ObjcClassPrefix", "CsharpNamespace", "SwiftPrefix", "PhpClassPrefix", "PhpNamespace", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) }, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.MessageOptions), global::Google.Protobuf.Reflection.MessageOptions.Parser, new[]{ "MessageSetWireFormat", "NoStandardDescriptorAccessor", "Deprecated", "MapEntry", "UninterpretedOption" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FieldOptions), global::Google.Protobuf.Reflection.FieldOptions.Parser, new[]{ "Ctype", "Packed", "Jstype", "Lazy", "Deprecated", "Weak", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FieldOptions.Types.CType), typeof(global::Google.Protobuf.Reflection.FieldOptions.Types.JSType) }, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.OneofOptions), global::Google.Protobuf.Reflection.OneofOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null), @@ -2804,6 +2805,7 @@ namespace Google.Protobuf.Reflection { ccGenericServices_ = other.ccGenericServices_; javaGenericServices_ = other.javaGenericServices_; pyGenericServices_ = other.pyGenericServices_; + phpGenericServices_ = other.phpGenericServices_; deprecated_ = other.deprecated_; ccEnableArenas_ = other.ccEnableArenas_; objcClassPrefix_ = other.objcClassPrefix_; @@ -2981,6 +2983,17 @@ namespace Google.Protobuf.Reflection { } } + /// <summary>Field number for the "php_generic_services" field.</summary> + public const int PhpGenericServicesFieldNumber = 19; + private bool phpGenericServices_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool PhpGenericServices { + get { return phpGenericServices_; } + set { + phpGenericServices_ = value; + } + } + /// <summary>Field number for the "deprecated" field.</summary> public const int DeprecatedFieldNumber = 23; private bool deprecated_; @@ -3126,6 +3139,7 @@ namespace Google.Protobuf.Reflection { if (CcGenericServices != other.CcGenericServices) return false; if (JavaGenericServices != other.JavaGenericServices) return false; if (PyGenericServices != other.PyGenericServices) return false; + if (PhpGenericServices != other.PhpGenericServices) return false; if (Deprecated != other.Deprecated) return false; if (CcEnableArenas != other.CcEnableArenas) return false; if (ObjcClassPrefix != other.ObjcClassPrefix) return false; @@ -3150,6 +3164,7 @@ namespace Google.Protobuf.Reflection { if (CcGenericServices != false) hash ^= CcGenericServices.GetHashCode(); if (JavaGenericServices != false) hash ^= JavaGenericServices.GetHashCode(); if (PyGenericServices != false) hash ^= PyGenericServices.GetHashCode(); + if (PhpGenericServices != false) hash ^= PhpGenericServices.GetHashCode(); if (Deprecated != false) hash ^= Deprecated.GetHashCode(); if (CcEnableArenas != false) hash ^= CcEnableArenas.GetHashCode(); if (ObjcClassPrefix.Length != 0) hash ^= ObjcClassPrefix.GetHashCode(); @@ -3200,6 +3215,10 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(144, 1); output.WriteBool(PyGenericServices); } + if (PhpGenericServices != false) { + output.WriteRawTag(152, 1); + output.WriteBool(PhpGenericServices); + } if (JavaGenerateEqualsAndHash != false) { output.WriteRawTag(160, 1); output.WriteBool(JavaGenerateEqualsAndHash); @@ -3272,6 +3291,9 @@ namespace Google.Protobuf.Reflection { if (PyGenericServices != false) { size += 2 + 1; } + if (PhpGenericServices != false) { + size += 2 + 1; + } if (Deprecated != false) { size += 2 + 1; } @@ -3332,6 +3354,9 @@ namespace Google.Protobuf.Reflection { if (other.PyGenericServices != false) { PyGenericServices = other.PyGenericServices; } + if (other.PhpGenericServices != false) { + PhpGenericServices = other.PhpGenericServices; + } if (other.Deprecated != false) { Deprecated = other.Deprecated; } @@ -3396,6 +3421,10 @@ namespace Google.Protobuf.Reflection { PyGenericServices = input.ReadBool(); break; } + case 152: { + PhpGenericServices = input.ReadBool(); + break; + } case 160: { JavaGenerateEqualsAndHash = input.ReadBool(); break; diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs index f4fac738..fca689dc 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs @@ -44,17 +44,25 @@ namespace Google.Protobuf.WellKnownTypes prefix.EndsWith("/") ? prefix + descriptor.FullName : prefix + "/" + descriptor.FullName; /// <summary> - /// Retrieves the type name for a type URL. This is always just the last part of the URL, - /// after the trailing slash. No validation of anything before the trailing slash is performed. - /// If the type URL does not include a slash, an empty string is returned rather than an exception - /// being thrown; this won't match any types, and the calling code is probably in a better position - /// to give a meaningful error. - /// There is no handling of fragments or queries at the moment. + /// Retrieves the type name for a type URL, matching the <see cref="DescriptorBase.FullName"/> + /// of the packed message type. /// </summary> + /// <remarks> + /// <para> + /// This is always just the last part of the URL, after the final slash. No validation of + /// anything before the trailing slash is performed. If the type URL does not include a slash, + /// an empty string is returned rather than an exception being thrown; this won't match any types, + /// and the calling code is probably in a better position to give a meaningful error. + /// </para> + /// <para> + /// There is no handling of fragments or queries at the moment. + /// </para> + /// </remarks> /// <param name="typeUrl">The URL to extract the type name from</param> /// <returns>The type name</returns> - internal static string GetTypeName(string typeUrl) + public static string GetTypeName(string typeUrl) { + ProtoPreconditions.CheckNotNull(typeUrl, nameof(typeUrl)); int lastSlash = typeUrl.LastIndexOf('/'); return lastSlash == -1 ? "" : typeUrl.Substring(lastSlash + 1); } @@ -81,6 +89,27 @@ namespace Google.Protobuf.WellKnownTypes } /// <summary> + /// Attempts to unpack the content of this Any message into the target message type, + /// if it matches the type URL within this Any message. + /// </summary> + /// <typeparam name="T">The type of message to attempt to unpack the content into.</typeparam> + /// <returns><c>true</c> if the message was successfully unpacked; <c>false</c> if the type name didn't match</returns> + public bool TryUnpack<T>(out T result) where T : IMessage, new() + { + // Note: deliberately avoid writing anything to result until the end, in case it's being + // monitored by other threads. (That would be a bug in the calling code, but let's not make it worse.) + T target = new T(); + if (GetTypeName(TypeUrl) != target.Descriptor.FullName) + { + result = default(T); // Can't use null as there's no class constraint, but this always *will* be null in real usage. + return false; + } + target.MergeFrom(Value); + result = target; + return true; + } + + /// <summary> /// Packs the specified message into an Any message using a type URL prefix of "type.googleapis.com". /// </summary> /// <param name="message">The message to pack.</param> diff --git a/docs/third_party.md b/docs/third_party.md index 3def0035..4c9ffef3 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -116,6 +116,7 @@ GRPC (http://www.grpc.io/) is Google's RPC implementation for Protocol Buffers. * https://github.com/thesamet/rpcz (C++/Python, based on ZeroMQ) * https://github.com/w359405949/libmaid (C++, Python) * https://github.com/madwyn/libpbrpc (C++) +* https://github.com/SeriousMa/grpc-protobuf-validation (Java) ## Other Utilities @@ -140,7 +141,7 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d * http://igor-petruk.github.com/protobuf-maven-plugin/ * http://code.google.com/p/maven-protoc-plugin/ * https://github.com/os72/protoc-jar-maven-plugin -* [Documentation generator plugin (Markdown/HTML/DocBook/...)](https://github.com/estan/protoc-gen-doc) +* [Documentation generator plugin (Markdown/HTML/DocBook/...)](https://github.com/pseudomuto/protoc-gen-doc) * [DocBook generator for .proto files](http://code.google.com/p/protoc-gen-docbook/) * [Protobuf for nginx module](https://github.com/dbcode/protobuf-nginx/) * [RSpec matchers and Cucumber step defs for testing Protocol Buffers](https://github.com/connamara/protobuf_spec) diff --git a/java/core/pom.xml b/java/core/pom.xml index 9c4e1b93..e4f50dd1 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-parent</artifactId> - <version>3.3.0</version> + <version>3.3.2</version> </parent> <artifactId>protobuf-java</artifactId> @@ -34,11 +34,6 @@ <artifactId>easymockclassextension</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>com.google.truth</groupId> - <artifactId>truth</artifactId> - <scope>test</scope> - </dependency> </dependencies> <build> diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 249d7c5e..910f360f 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -30,8 +30,6 @@ package com.google.protobuf; -import static com.google.common.truth.Truth.assertThat; - import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.TextFormat.Parser.SingularOverwritePolicy; @@ -1079,12 +1077,12 @@ public class TextFormatTest extends TestCase { { TestMap.Builder dest = TestMap.newBuilder(); TextFormat.merge(text, dest); - assertThat(dest.build()).isEqualTo(message); + assertEquals(message, dest.build()); } { TestMap.Builder dest = TestMap.newBuilder(); parserWithOverwriteForbidden.merge(text, dest); - assertThat(dest.build()).isEqualTo(message); + assertEquals(message, dest.build()); } } @@ -1096,10 +1094,10 @@ public class TextFormatTest extends TestCase { TestMap.Builder dest = TestMap.newBuilder(); parserWithOverwriteForbidden.merge(text, dest); TestMap message = dest.build(); - assertThat(message.getStringToInt32Field().size()).isEqualTo(2); - assertThat(message.getInt32ToMessageField().size()).isEqualTo(2); - assertThat(message.getStringToInt32Field().get("x")).isEqualTo(10); - assertThat(message.getInt32ToMessageField().get(2).getValue()).isEqualTo(200); + assertEquals(2, message.getStringToInt32Field().size()); + assertEquals(2, message.getInt32ToMessageField().size()); + assertEquals(10, message.getStringToInt32Field().get("x").intValue()); + assertEquals(200, message.getInt32ToMessageField().get(2).getValue()); } public void testMapShortFormEmpty() throws Exception { @@ -1108,8 +1106,8 @@ public class TextFormatTest extends TestCase { TestMap.Builder dest = TestMap.newBuilder(); parserWithOverwriteForbidden.merge(text, dest); TestMap message = dest.build(); - assertThat(message.getStringToInt32Field().size()).isEqualTo(0); - assertThat(message.getInt32ToMessageField().size()).isEqualTo(0); + assertEquals(0, message.getStringToInt32Field().size()); + assertEquals(0, message.getInt32ToMessageField().size()); } public void testMapShortFormTrailingComma() throws Exception { @@ -1119,7 +1117,7 @@ public class TextFormatTest extends TestCase { parserWithOverwriteForbidden.merge(text, dest); fail("Expected parse exception."); } catch (TextFormat.ParseException e) { - assertThat(e).hasMessageThat().isEqualTo("1:48: Expected \"{\"."); + assertEquals("1:48: Expected \"{\".", e.getMessage()); } } @@ -1134,8 +1132,8 @@ public class TextFormatTest extends TestCase { TestMap.Builder builder = TestMap.newBuilder(); defaultParser.merge(text, builder); TestMap map = builder.build(); - assertThat(map.getInt32ToInt32Field().size()).isEqualTo(2); - assertThat(map.getInt32ToInt32Field().get(1).intValue()).isEqualTo(30); + assertEquals(2, map.getInt32ToInt32Field().size()); + assertEquals(30, map.getInt32ToInt32Field().get(1).intValue()); } { @@ -1144,8 +1142,8 @@ public class TextFormatTest extends TestCase { TestMap.Builder builder = TestMap.newBuilder(); defaultParser.merge(text, builder); TestMap map = builder.build(); - assertThat(map.getInt32ToInt32Field().size()).isEqualTo(2); - assertThat(map.getInt32ToInt32Field().get(1).intValue()).isEqualTo(30); + assertEquals(2, map.getInt32ToInt32Field().size()); + assertEquals(30, map.getInt32ToInt32Field().get(1).intValue()); } } diff --git a/java/pom.xml b/java/pom.xml index 81ffc48a..39ed31ab 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,7 +11,7 @@ <groupId>com.google.protobuf</groupId> <artifactId>protobuf-parent</artifactId> - <version>3.3.0</version> + <version>3.3.2</version> <packaging>pom</packaging> <name>Protocol Buffers [Parent]</name> @@ -84,13 +84,7 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>20.0</version> - </dependency> - <dependency> - <groupId>com.google.truth</groupId> - <artifactId>truth</artifactId> - <scope>test</scope> - <version>0.32</version> + <version>19.0</version> </dependency> </dependencies> </dependencyManagement> diff --git a/java/util/pom.xml b/java/util/pom.xml index c72fa650..62394ed7 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-parent</artifactId> - <version>3.3.0</version> + <version>3.3.2</version> </parent> <artifactId>protobuf-java-util</artifactId> diff --git a/jenkins/docker/Dockerfile b/jenkins/docker/Dockerfile index fcebe167..45900262 100644 --- a/jenkins/docker/Dockerfile +++ b/jenkins/docker/Dockerfile @@ -129,7 +129,7 @@ ENV MVN mvn --batch-mode RUN cd /tmp && \ git clone https://github.com/google/protobuf.git && \ cd protobuf && \ - git reset --hard c2b3b3e04e7a023efe06f2107705b45428847800 && \ + git reset --hard 129a6e2aca95dcfb6c3e717d7b9cca1f104fde39 && \ ./autogen.sh && \ ./configure && \ make -j4 && \ @@ -164,6 +164,14 @@ RUN cd php-7.0.18 && ./configure --enable-maintainer-zts --prefix=/usr/local/php RUN cd php-7.0.18 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 && \ make && make install && cd .. +RUN wget http://am1.php.net/get/php-7.1.4.tar.bz2/from/this/mirror +RUN mv mirror php-7.1.4.tar.bz2 +RUN tar -xvf php-7.1.4.tar.bz2 +RUN cd php-7.1.4 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.1-zts && \ + make && make install && cd .. +RUN cd php-7.1.4 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.1 && \ + make && make install && cd .. + RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php composer-setup.php RUN mv composer.phar /usr/bin/composer @@ -190,7 +198,12 @@ RUN cd /tmp && \ ln -sfn /usr/local/php-7.0/bin/php-config /usr/bin/php-config && \ ln -sfn /usr/local/php-7.0/bin/phpize /usr/bin/phpize && \ composer install && \ - mv vendor /usr/local/vendor-7.0 + mv vendor /usr/local/vendor-7.0 && \ + ln -sfn /usr/local/php-7.1/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-7.1/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-7.1/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-7.1 ################## # Go dependencies. diff --git a/jenkins/docker32/Dockerfile b/jenkins/docker32/Dockerfile index d9925d8d..2c9d4165 100644 --- a/jenkins/docker32/Dockerfile +++ b/jenkins/docker32/Dockerfile @@ -57,30 +57,6 @@ RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ ################## # PHP dependencies. -RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -RUN php composer-setup.php -RUN mv composer.phar /usr/bin/composer -RUN php -r "unlink('composer-setup.php');" -RUN cd /tmp && \ - git clone https://github.com/google/protobuf.git && \ - cd protobuf/php && \ - git reset --hard 8d97b3d8b5a33650e822460b3b561802c969e86e && \ - ln -sfn /usr/bin/php5.5 /usr/bin/php && \ - ln -sfn /usr/bin/php-config5.5 /usr/bin/php-config && \ - ln -sfn /usr/bin/phpize5.5 /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-5.5 && \ - ln -sfn /usr/bin/php5.6 /usr/bin/php && \ - ln -sfn /usr/bin/php-config5.6 /usr/bin/php-config && \ - ln -sfn /usr/bin/phpize5.6 /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-5.6 && \ - ln -sfn /usr/bin/php7.0 /usr/bin/php && \ - ln -sfn /usr/bin/php-config7.0 /usr/bin/php-config && \ - ln -sfn /usr/bin/phpize7.0 /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-7.0 - RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror RUN mv mirror php-5.5.38.tar.bz2 RUN tar -xvf php-5.5.38.tar.bz2 @@ -105,6 +81,45 @@ RUN cd php-7.0.18 && ./configure --enable-maintainer-zts --prefix=/usr/local/php RUN cd php-7.0.18 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 && \ make && make install && cd .. +RUN wget http://am1.php.net/get/php-7.1.4.tar.bz2/from/this/mirror +RUN mv mirror php-7.1.4.tar.bz2 +RUN tar -xvf php-7.1.4.tar.bz2 +RUN cd php-7.1.4 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.1-zts && \ + make && make install && cd .. +RUN cd php-7.1.4 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.1 && \ + make && make install && cd .. + +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +RUN php composer-setup.php +RUN mv composer.phar /usr/bin/composer +RUN php -r "unlink('composer-setup.php');" +RUN composer config -g -- disable-tls true +RUN composer config -g -- secure-http false +RUN cd /tmp && \ + git clone https://github.com/google/protobuf.git && \ + cd protobuf/php && \ + git reset --hard 8d97b3d8b5a33650e822460b3b561802c969e86e && \ + ln -sfn /usr/local/php-5.5/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-5.5/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-5.5/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-5.5 && \ + ln -sfn /usr/local/php-5.6/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-5.6/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-5.6/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-5.6 && \ + ln -sfn /usr/local/php-7.0/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-7.0/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-7.0/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-7.0 && \ + ln -sfn /usr/local/php-7.1/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-7.1/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-7.1/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-7.1 + ################## # Python dependencies diff --git a/js/README.md b/js/README.md index f4184621..24386dc7 100644 --- a/js/README.md +++ b/js/README.md @@ -19,7 +19,9 @@ resolve imports at compile time. To use Protocol Buffers with JavaScript, you need two main components: 1. The protobuf runtime library. You can install this with - `npm install google-protobuf`, or use the files in this directory. + `npm install google-protobuf`, or use the files in this directory. + If npm is not being used, as of 3.3.0, the files needed are located in binary subdirectory; + arith.js, constants.js, decoder.js, encoder.js, map.js, message.js, reader.js, utils.js, writer.js 2. The Protocol Compiler `protoc`. This translates `.proto` files into `.js` files. The compiler is not currently available via npm, but you can download a pre-built binary @@ -93,6 +95,12 @@ statements like: var message = proto.my.package.MyMessage(); +If unfamiliar with Closure or it's compiler, consider reviewing Closure documentation +https://developers.google.com/closure/library/docs/tutorial +https://developers.google.com/closure/library/docs/closurebuilder +https://developers.google.com/closure/library/docs/depswriter +At a high level, closurebuilder.py can walk dependencies, and compile your code, and all dependencies for Protobuf into a single .js file. Using depsbuilder.py to generate a dependency file can also be considered for non-production dev environments. + CommonJS imports ---------------- diff --git a/js/package.json b/js/package.json index 14f54b8b..afb223db 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.3.0", + "version": "3.3.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/objectivec/GPBUnknownField.h b/objectivec/GPBUnknownField.h index a135cc20..5b96023b 100644 --- a/objectivec/GPBUnknownField.h +++ b/objectivec/GPBUnknownField.h @@ -42,6 +42,9 @@ NS_ASSUME_NONNULL_BEGIN **/ @interface GPBUnknownField : NSObject<NSCopying> +/** Initialize a field with the given number. */ +- (instancetype)initWithNumber:(int32_t)number; + /** The field number the data is stored under. */ @property(nonatomic, readonly, assign) int32_t number; diff --git a/objectivec/GPBUnknownField_PackagePrivate.h b/objectivec/GPBUnknownField_PackagePrivate.h index 1fbce0f9..2b4c7895 100644 --- a/objectivec/GPBUnknownField_PackagePrivate.h +++ b/objectivec/GPBUnknownField_PackagePrivate.h @@ -36,8 +36,6 @@ @interface GPBUnknownField () -- (instancetype)initWithNumber:(int32_t)number; - - (void)writeToOutput:(GPBCodedOutputStream *)output; - (size_t)serializedSize; diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index b07abfa7..ef3d4cf6 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -474,7 +474,7 @@ static void map_slot_init(void* memory, upb_fieldtype_t type, zval* cache) { *(zval***)memory = holder; #else *(zval**)memory = cache; - // PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1); + PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1); #endif break; } diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index a5d48446..4a524864 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -143,6 +143,7 @@ static zend_function_entry map_field_methods[] = { PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -156,7 +157,10 @@ static void map_field_write_dimension(zval *object, zval *key, // ----------------------------------------------------------------------------- zend_class_entry* map_field_type; +zend_class_entry* map_field_iter_type; + zend_object_handlers* map_field_handlers; +zend_object_handlers* map_field_iter_handlers; static void map_begin_internal(Map *map, MapIter *iter) { iter->self = map; @@ -231,8 +235,8 @@ PHP_PROTO_OBJECT_CREATE_END(Map, map_field) // Init class entry. PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\MapField", Map, map_field) -zend_class_implements(map_field_type TSRMLS_CC, 2, spl_ce_ArrayAccess, - spl_ce_Countable); +zend_class_implements(map_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess, + zend_ce_aggregate, spl_ce_Countable); map_field_handlers->write_dimension = map_field_write_dimension; map_field_handlers->get_gc = map_field_get_gc; PHP_PROTO_INIT_CLASS_END @@ -444,6 +448,15 @@ PHP_METHOD(MapField, count) { RETURN_LONG(upb_strtable_count(&intern->table)); } +PHP_METHOD(MapField, getIterator) { + CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(return_value, + map_field_iter_type); + + Map *intern = UNBOX(Map, getThis()); + MapIter *iter = UNBOX(MapIter, return_value); + map_begin(getThis(), iter TSRMLS_CC); +} + // ----------------------------------------------------------------------------- // Map Iterator // ----------------------------------------------------------------------------- @@ -470,3 +483,79 @@ upb_value map_iter_value(MapIter *iter, int *len) { *len = native_slot_size(iter->self->value_type); return upb_strtable_iter_value(&iter->it); } + +// ----------------------------------------------------------------------------- +// MapFieldIter methods +// ----------------------------------------------------------------------------- +static zend_function_entry map_field_iter_methods[] = { + PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + +// ----------------------------------------------------------------------------- +// MapFieldIter creation/desctruction +// ----------------------------------------------------------------------------- + +// Define object free method. +PHP_PROTO_OBJECT_FREE_START(MapIter, map_field_iter) +PHP_PROTO_OBJECT_FREE_END + +PHP_PROTO_OBJECT_DTOR_START(MapIter, map_field_iter) +PHP_PROTO_OBJECT_DTOR_END + +// Define object create method. +PHP_PROTO_OBJECT_CREATE_START(MapIter, map_field_iter) +intern->self = NULL; +PHP_PROTO_OBJECT_CREATE_END(MapIter, map_field_iter) + +// Init class entry. +PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\MapFieldIter", + MapIter, map_field_iter) +zend_class_implements(map_field_iter_type TSRMLS_CC, 1, zend_ce_iterator); +PHP_PROTO_INIT_CLASS_END + +// ----------------------------------------------------------------------------- +// PHP MapFieldIter Methods +// ----------------------------------------------------------------------------- + +PHP_METHOD(MapFieldIter, rewind) { + MapIter *intern = UNBOX(MapIter, getThis()); + map_begin_internal(intern->self, intern); +} + +PHP_METHOD(MapFieldIter, current) { + MapIter *intern = UNBOX(MapIter, getThis()); + Map *map_field = intern->self; + + int value_length = 0; + upb_value value = map_iter_value(intern, &value_length); + + void* mem = upb_value_memory(&value); + native_slot_get_by_array(map_field->value_type, mem, + ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC); +} + +PHP_METHOD(MapFieldIter, key) { + MapIter *intern = UNBOX(MapIter, getThis()); + Map *map_field = intern->self; + + int key_length = 0; + const char* key = map_iter_key(intern, &key_length); + + native_slot_get_by_map_key(map_field->key_type, key, key_length, + ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC); +} + +PHP_METHOD(MapFieldIter, next) { + MapIter *intern = UNBOX(MapIter, getThis()); + map_next(intern); +} + +PHP_METHOD(MapFieldIter, valid) { + MapIter *intern = UNBOX(MapIter, getThis()); + RETURN_BOOL(!map_done(intern)); +} diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index b8ef9fc0..254640c7 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -115,7 +115,11 @@ static void message_set_property(zval* object, zval* member, zval* value, return; } +#if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0) if (Z_OBJCE_P(object) != EG(scope)) { +#else + if (Z_OBJCE_P(object) != zend_get_executed_scope()) { +#endif // User cannot set property directly (e.g., $m->a = 1) zend_error(E_USER_ERROR, "Cannot access private property."); return; @@ -145,7 +149,11 @@ static zval* message_get_property(zval* object, zval* member, int type, return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL; } +#if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0) if (Z_OBJCE_P(object) != EG(scope)) { +#else + if (Z_OBJCE_P(object) != zend_get_executed_scope()) { +#endif // User cannot get property directly (e.g., $a = $m->a) zend_error(E_USER_ERROR, "Cannot access private property."); return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL; diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index a2a8e066..20a45bc6 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -13,7 +13,7 @@ <date>2017-01-13</date> <time>16:06:07</time> <version> - <release>3.3.0</release> + <release>3.3.2</release> <api>3.3.0</api> </version> <stability> @@ -40,6 +40,7 @@ GA release. <file baseinstalldir="/" name="upb.h" role="src" /> <file baseinstalldir="/" name="utf8.c" role="src" /> <file baseinstalldir="/" name="utf8.h" role="src" /> + <file baseinstalldir="/" name="LICENSE" role="doc" /> </dir> </contents> <dependencies> @@ -103,5 +104,37 @@ Second alpha release. GA release. </notes> </release> + <release> + <version> + <release>3.3.1</release> + <api>3.3.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <date>2017-05-08</date> + <time>15:33:07</time> + <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license> + <notes> +GA release. + </notes> + </release> + <release> + <version> + <release>3.3.2</release> + <api>3.3.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <date>2017-06-21</date> + <time>15:33:07</time> + <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license> + <notes> +GA release. + </notes> + </release> </changelog> </package> diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index 6a848b27..5de9cfe9 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -189,6 +189,7 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { static PHP_MINIT_FUNCTION(protobuf) { map_field_init(TSRMLS_C); + map_field_iter_init(TSRMLS_C); repeated_field_init(TSRMLS_C); repeated_field_iter_init(TSRMLS_C); gpb_type_init(TSRMLS_C); @@ -206,6 +207,7 @@ static PHP_MSHUTDOWN_FUNCTION(protobuf) { PEFREE(repeated_field_handlers); PEFREE(repeated_field_iter_handlers); PEFREE(map_field_handlers); + PEFREE(map_field_iter_handlers); return 0; } diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 406a09a5..33787e86 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.3.0" +#define PHP_PROTOBUF_VERSION "3.3.2" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 @@ -373,6 +373,7 @@ struct MessageLayout; struct RepeatedField; struct RepeatedFieldIter; struct Map; +struct MapIter; struct Oneof; typedef struct DescriptorPool DescriptorPool; @@ -385,6 +386,7 @@ typedef struct MessageLayout MessageLayout; typedef struct RepeatedField RepeatedField; typedef struct RepeatedFieldIter RepeatedFieldIter; typedef struct Map Map; +typedef struct MapIter MapIter; typedef struct Oneof Oneof; // ----------------------------------------------------------------------------- @@ -400,6 +402,7 @@ void enum_descriptor_init(TSRMLS_D); void descriptor_pool_init(TSRMLS_D); void gpb_type_init(TSRMLS_D); void map_field_init(TSRMLS_D); +void map_field_iter_init(TSRMLS_D); void repeated_field_init(TSRMLS_D); void repeated_field_iter_init(TSRMLS_D); void util_init(TSRMLS_D); @@ -637,7 +640,7 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, bool native_slot_set_by_array(upb_fieldtype_t type, const zend_class_entry* klass, void* memory, zval* value TSRMLS_DC); -void native_slot_init(upb_fieldtype_t type, void* memory, void* cache); +void native_slot_init(upb_fieldtype_t type, void* memory, CACHED_VALUE* cache); // For each property, in order to avoid conversion between the zval object and // the actual data type during parsing/serialization, the containing message // object use the custom memory layout to store the actual data type for each @@ -659,6 +662,7 @@ void native_slot_get_default(upb_fieldtype_t type, // ----------------------------------------------------------------------------- extern zend_object_handlers* map_field_handlers; +extern zend_object_handlers* map_field_iter_handlers; PHP_PROTO_WRAP_OBJECT_START(Map) upb_fieldtype_t key_type; @@ -667,10 +671,10 @@ PHP_PROTO_WRAP_OBJECT_START(Map) upb_strtable table; PHP_PROTO_WRAP_OBJECT_END -typedef struct { +PHP_PROTO_WRAP_OBJECT_START(MapIter) Map* self; upb_strtable_iter it; -} MapIter; +PHP_PROTO_WRAP_OBJECT_END void map_begin(zval* self, MapIter* iter TSRMLS_DC); void map_next(MapIter* iter); @@ -709,6 +713,13 @@ PHP_METHOD(MapField, offsetGet); PHP_METHOD(MapField, offsetSet); PHP_METHOD(MapField, offsetUnset); PHP_METHOD(MapField, count); +PHP_METHOD(MapField, getIterator); + +PHP_METHOD(MapFieldIter, rewind); +PHP_METHOD(MapFieldIter, current); +PHP_METHOD(MapFieldIter, key); +PHP_METHOD(MapFieldIter, next); +PHP_METHOD(MapFieldIter, valid); // ----------------------------------------------------------------------------- // Repeated Field. diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index 6318f88c..6c789bcb 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -210,7 +210,7 @@ bool native_slot_set_by_array(upb_fieldtype_t type, return true; } -void native_slot_init(upb_fieldtype_t type, void* memory, void* cache) { +void native_slot_init(upb_fieldtype_t type, void* memory, CACHED_VALUE* cache) { zval* tmp = NULL; switch (type) { case UPB_TYPE_FLOAT: @@ -224,6 +224,9 @@ void native_slot_init(upb_fieldtype_t type, void* memory, void* cache) { break; case UPB_TYPE_STRING: case UPB_TYPE_BYTES: + DEREF(memory, CACHED_VALUE*) = cache; + ZVAL_EMPTY_STRING(CACHED_PTR_TO_ZVAL_PTR(cache)); + break; case UPB_TYPE_MESSAGE: DEREF(memory, CACHED_VALUE*) = cache; break; @@ -355,6 +358,19 @@ void native_slot_get_by_array(upb_fieldtype_t type, const void* memory, } } +void native_slot_get_by_map_key(upb_fieldtype_t type, const void* memory, + int length, CACHED_VALUE* cache TSRMLS_DC) { + switch (type) { + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: { + PHP_PROTO_ZVAL_STRINGL(CACHED_PTR_TO_ZVAL_PTR(cache), memory, length, 1); + return; + } + default: + native_slot_get(type, memory, cache TSRMLS_CC); + } +} + void native_slot_get_default(upb_fieldtype_t type, CACHED_VALUE* cache TSRMLS_DC) { switch (type) { @@ -608,6 +624,21 @@ void layout_init(MessageLayout* layout, void* storage, int cache_index = slot_property_cache(layout, storage, field); CACHED_VALUE* property_ptr = &properties_table[cache_index]; + // Clean up initial value by generated code. In the generated code of + // previous versions, each php field is given an initial value. However, the + // order to initialize these fields may not be consistent with the order of + // upb fields. + if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(property_ptr)) == IS_STRING) { +#if PHP_MAJOR_VERSION < 7 + if (!IS_INTERNED(Z_STRVAL_PP(property_ptr))) { + FREE(Z_STRVAL_PP(property_ptr)); + } +#else + zend_string_release(Z_STR_P(property_ptr)); +#endif + } + ZVAL_NULL(CACHED_PTR_TO_ZVAL_PTR(property_ptr)); + if (upb_fielddef_containingoneof(field)) { memset(memory, 0, NATIVE_SLOT_MAX_SIZE); *oneof_case = ONEOF_CASE_NONE; @@ -731,7 +762,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, } } -static native_slot_merge(const upb_fielddef* field, const void* from_memory, +static void native_slot_merge(const upb_fielddef* field, const void* from_memory, void* to_memory PHP_PROTO_TSRMLS_DC) { upb_fieldtype_t type = upb_fielddef_type(field); zend_class_entry* ce = NULL; @@ -788,7 +819,7 @@ static native_slot_merge(const upb_fielddef* field, const void* from_memory, } } -static native_slot_merge_by_array(const upb_fielddef* field, const void* from_memory, +static void native_slot_merge_by_array(const upb_fielddef* field, const void* from_memory, void* to_memory PHP_PROTO_TSRMLS_DC) { upb_fieldtype_t type = upb_fielddef_type(field); switch (type) { diff --git a/php/phpunit.xml b/php/phpunit.xml index 7cb1e2a3..637467be 100644 --- a/php/phpunit.xml +++ b/php/phpunit.xml @@ -10,6 +10,7 @@ <file>tests/generated_phpdoc_test.php</file> <file>tests/map_field_test.php</file> <file>tests/well_known_test.php</file> + <file>tests/generated_service_test.php</file> </testsuite> </testsuites> </phpunit> diff --git a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php index 636a0ad4..1e3c745e 100644 --- a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php +++ b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php @@ -139,6 +139,7 @@ class Descriptor ->optional('cc_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 16) ->optional('java_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 17) ->optional('py_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 18) + ->optional('php_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 19) ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 23) ->optional('cc_enable_arenas', \Google\Protobuf\Internal\GPBType::BOOL, 31) ->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36) diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php index 0fdaecfc..1d6959b7 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -119,7 +118,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setField(&$var) + public function setField($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->field = $arr; @@ -147,7 +146,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setExtension(&$var) + public function setExtension($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->extension = $arr; @@ -175,7 +174,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setNestedType(&$var) + public function setNestedType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $this->nested_type = $arr; @@ -203,7 +202,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setEnumType(&$var) + public function setEnumType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $this->enum_type = $arr; @@ -231,7 +230,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\DescriptorProto_ExtensionRange[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setExtensionRange(&$var) + public function setExtensionRange($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class); $this->extension_range = $arr; @@ -259,7 +258,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\OneofDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setOneofDecl(&$var) + public function setOneofDecl($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class); $this->oneof_decl = $arr; @@ -287,7 +286,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\MessageOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class); $this->options = $var; @@ -315,7 +314,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\DescriptorProto_ReservedRange[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setReservedRange(&$var) + public function setReservedRange($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class); $this->reserved_range = $arr; @@ -349,7 +348,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message * @param string[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setReservedName(&$var) + public function setReservedName($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->reserved_name = $arr; diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php index bbd34824..51d5d359 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php index 3d613133..b1022d61 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php index 6cdaf2df..816fbae5 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -81,7 +80,7 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\EnumValueDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setValue(&$var) + public function setValue($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class); $this->value = $arr; @@ -109,7 +108,7 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\EnumOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class); $this->options = $var; diff --git a/php/src/Google/Protobuf/Internal/EnumOptions.php b/php/src/Google/Protobuf/Internal/EnumOptions.php index 3c3a9e22..3f598a41 100644 --- a/php/src/Google/Protobuf/Internal/EnumOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -137,7 +136,7 @@ class EnumOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php index 89d6707f..e363220f 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -109,7 +108,7 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\EnumValueOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class); $this->options = $var; diff --git a/php/src/Google/Protobuf/Internal/EnumValueOptions.php b/php/src/Google/Protobuf/Internal/EnumValueOptions.php index 3b5c58e4..db8de174 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumValueOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -95,7 +94,7 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php index ae61be47..10c27593 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -418,7 +417,7 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\FieldOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class); $this->options = $var; diff --git a/php/src/Google/Protobuf/Internal/FieldOptions.php b/php/src/Google/Protobuf/Internal/FieldOptions.php index 157c0f82..3144e670 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -404,7 +403,7 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php index 3b1567d1..9ee222d1 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -187,7 +186,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param string[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setDependency(&$var) + public function setDependency($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->dependency = $arr; @@ -219,7 +218,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param int[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setPublicDependency(&$var) + public function setPublicDependency($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->public_dependency = $arr; @@ -253,7 +252,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param int[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setWeakDependency(&$var) + public function setWeakDependency($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->weak_dependency = $arr; @@ -285,7 +284,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setMessageType(&$var) + public function setMessageType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $this->message_type = $arr; @@ -313,7 +312,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setEnumType(&$var) + public function setEnumType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $this->enum_type = $arr; @@ -341,7 +340,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\ServiceDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setService(&$var) + public function setService($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class); $this->service = $arr; @@ -369,7 +368,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setExtension(&$var) + public function setExtension($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->extension = $arr; @@ -397,7 +396,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\FileOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class); $this->options = $var; @@ -435,7 +434,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\SourceCodeInfo $var * @return $this */ - public function setSourceCodeInfo(&$var) + public function setSourceCodeInfo($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class); $this->source_code_info = $var; diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php index 591e2a81..0b2cf957 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -44,7 +43,7 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\FileDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setFile(&$var) + public function setFile($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class); $this->file = $arr; diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php index 2202102b..c2dd5e08 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -110,6 +109,11 @@ class FileOptions extends \Google\Protobuf\Internal\Message private $py_generic_services = false; private $has_py_generic_services = false; /** + * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code> + */ + private $php_generic_services = false; + private $has_php_generic_services = false; + /** * Is this file deprecated? * Depending on the target platform, this can emit Deprecated annotations * for everything in the file, or it will be completely ignored; in the very @@ -549,6 +553,34 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** + * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code> + * @return bool + */ + public function getPhpGenericServices() + { + return $this->php_generic_services; + } + + /** + * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code> + * @param bool $var + * @return $this + */ + public function setPhpGenericServices($var) + { + GPBUtil::checkBool($var); + $this->php_generic_services = $var; + $this->has_php_generic_services = true; + + return $this; + } + + public function hasPhpGenericServices() + { + return $this->has_php_generic_services; + } + + /** * Is this file deprecated? * Depending on the target platform, this can emit Deprecated annotations * for everything in the file, or it will be completely ignored; in the very @@ -812,7 +844,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php index 35b47526..ae2ad745 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -54,7 +53,7 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setAnnotation(&$var) + public function setAnnotation($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class); $this->annotation = $arr; diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php index c2e22e89..22ac2337 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -74,7 +73,7 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message * @param int[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setPath(&$var) + public function setPath($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->path = $arr; diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php index cb707955..88e6c8b2 100644 --- a/php/src/Google/Protobuf/Internal/MapFieldIter.php +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -91,9 +91,12 @@ class MapFieldIter implements \Iterator public function key() { $key = key($this->container); - // PHP associative array stores bool as integer for key. if ($this->key_type === GPBType::BOOL) { + // PHP associative array stores bool as integer for key. return boolval($key); + } elseif ($this->key_type === GPBType::STRING) { + // PHP associative array stores int string as int for key. + return strval($key); } else { return $key; } diff --git a/php/src/Google/Protobuf/Internal/MessageOptions.php b/php/src/Google/Protobuf/Internal/MessageOptions.php index 3677ca38..99ff3d0e 100644 --- a/php/src/Google/Protobuf/Internal/MessageOptions.php +++ b/php/src/Google/Protobuf/Internal/MessageOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -311,7 +310,7 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php index 69c25b69..ccfce2db 100644 --- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -165,7 +164,7 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\MethodOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class); $this->options = $var; diff --git a/php/src/Google/Protobuf/Internal/MethodOptions.php b/php/src/Google/Protobuf/Internal/MethodOptions.php index 5b2db776..baa806b7 100644 --- a/php/src/Google/Protobuf/Internal/MethodOptions.php +++ b/php/src/Google/Protobuf/Internal/MethodOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -128,7 +127,7 @@ class MethodOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php index 0d4f3bdc..15ff0610 100644 --- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -76,7 +75,7 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\OneofOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class); $this->options = $var; diff --git a/php/src/Google/Protobuf/Internal/OneofOptions.php b/php/src/Google/Protobuf/Internal/OneofOptions.php index aa8c934c..e5b4633d 100644 --- a/php/src/Google/Protobuf/Internal/OneofOptions.php +++ b/php/src/Google/Protobuf/Internal/OneofOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -47,7 +46,7 @@ class OneofOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php index 963cd650..da88e9c4 100644 --- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -81,7 +80,7 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setMethod(&$var) + public function setMethod($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class); $this->method = $arr; @@ -109,7 +108,7 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\ServiceOptions $var * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class); $this->options = $var; diff --git a/php/src/Google/Protobuf/Internal/ServiceOptions.php b/php/src/Google/Protobuf/Internal/ServiceOptions.php index ea649865..3e7214a1 100644 --- a/php/src/Google/Protobuf/Internal/ServiceOptions.php +++ b/php/src/Google/Protobuf/Internal/ServiceOptions.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -95,7 +94,7 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php index 65530586..6ce05ed4 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -170,7 +169,7 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\SourceCodeInfo_Location[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setLocation(&$var) + public function setLocation($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class); $this->location = $arr; diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php index b33013b8..19ed2bc2 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -170,7 +169,7 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * @param int[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setPath(&$var) + public function setPath($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->path = $arr; @@ -210,7 +209,7 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * @param int[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setSpan(&$var) + public function setSpan($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->span = $arr; @@ -368,7 +367,7 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * @param string[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setLeadingDetachedComments(&$var) + public function setLeadingDetachedComments($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->leading_detached_comments = $arr; diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption.php b/php/src/Google/Protobuf/Internal/UninterpretedOption.php index a4fab343..4d342eb3 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** @@ -81,7 +80,7 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message * @param \Google\Protobuf\Internal\UninterpretedOption_NamePart[]|\Google\Protobuf\Internal\RepeatedField $var * @return $this */ - public function setName(&$var) + public function setName($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class); $this->name = $arr; diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php index 69a96d45..c9a6fc3c 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php @@ -8,7 +8,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\InputStream; - use Google\Protobuf\Internal\GPBUtil; /** diff --git a/php/tests/array_test.php b/php/tests/array_test.php index 271389ba..e57f0a7e 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -521,21 +521,23 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase # Test memory leak ######################################################### - public function testCycleLeak() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class); - $arr[] = new TestMessage; - $arr[0]->SetRepeatedRecursive($arr); - - // Clean up memory before test. - gc_collect_cycles(); - $start = memory_get_usage(); - unset($arr); - - // Explicitly trigger garbage collection. - gc_collect_cycles(); - - $end = memory_get_usage(); - $this->assertLessThan($start, $end); - } + // COMMENTED OUT BY @bshaffer + // @see https://github.com/google/protobuf/pull/3344#issuecomment-315162761 + // public function testCycleLeak() + // { + // $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class); + // $arr[] = new TestMessage; + // $arr[0]->SetRepeatedRecursive($arr); + + // // Clean up memory before test. + // gc_collect_cycles(); + // $start = memory_get_usage(); + // unset($arr); + + // // Explicitly trigger garbage collection. + // gc_collect_cycles(); + + // $end = memory_get_usage(); + // $this->assertLessThan($start, $end); + // } } diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index e2912ad4..b43dffb4 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -9,437 +9,445 @@ use Foo\TestEnum; use Foo\TestMessage; use Foo\TestMessage_Sub; use Foo\TestPackedMessage; +use Foo\TestRandomFieldOrder; use Foo\TestUnpackedMessage; class EncodeDecodeTest extends TestBase { -# public function testEncode() -# { -# $from = new TestMessage(); -# $this->expectEmptyFields($from); -# $this->setFields($from); -# $this->expectFields($from); -# -# $data = $from->serializeToString(); -# $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()), -# bin2hex($data)); -# } -# -# public function testDecode() -# { -# $to = new TestMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestMessage()); -# $this->expectFields($to); -# } -# -# public function testEncodeDecode() -# { -# $from = new TestMessage(); -# $this->expectEmptyFields($from); -# $this->setFields($from); -# $this->expectFields($from); -# -# $data = $from->serializeToString(); -# -# $to = new TestMessage(); -# $to->mergeFromString($data); -# $this->expectFields($to); -# } -# -# public function testEncodeDecodeEmpty() -# { -# $from = new TestMessage(); -# $this->expectEmptyFields($from); -# -# $data = $from->serializeToString(); -# -# $to = new TestMessage(); -# $to->mergeFromString($data); -# $this->expectEmptyFields($to); -# } + public function testEncode() + { + $from = new TestMessage(); + $this->expectEmptyFields($from); + $this->setFields($from); + $this->expectFields($from); + + $data = $from->serializeToString(); + $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()), + bin2hex($data)); + } + + public function testDecode() + { + $to = new TestMessage(); + $to->mergeFromString(TestUtil::getGoldenTestMessage()); + $this->expectFields($to); + } + + public function testEncodeDecode() + { + $from = new TestMessage(); + $this->expectEmptyFields($from); + $this->setFields($from); + $this->expectFields($from); + + $data = $from->serializeToString(); + + $to = new TestMessage(); + $to->mergeFromString($data); + $this->expectFields($to); + } + + public function testEncodeDecodeEmpty() + { + $from = new TestMessage(); + $this->expectEmptyFields($from); + + $data = $from->serializeToString(); + + $to = new TestMessage(); + $to->mergeFromString($data); + $this->expectEmptyFields($to); + } public function testEncodeDecodeOneof() { $m = new TestMessage(); -# $m->setOneofInt32(1); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame(1, $n->getOneofInt32()); -# -# $m->setOneofFloat(2.0); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame(2.0, $n->getOneofFloat()); -# -# $m->setOneofString('abc'); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame('abc', $n->getOneofString()); -# -# $sub_m = new TestMessage_Sub(); -# $sub_m->setA(1); -# $m->setOneofMessage($sub_m); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame(1, $n->getOneofMessage()->getA()); + $m->setOneofInt32(1); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame(1, $n->getOneofInt32()); + + $m->setOneofFloat(2.0); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame(2.0, $n->getOneofFloat()); + + $m->setOneofString('abc'); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame('abc', $n->getOneofString()); + + $sub_m = new TestMessage_Sub(); + $sub_m->setA(1); + $m->setOneofMessage($sub_m); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame(1, $n->getOneofMessage()->getA()); // Encode default value -# $m->setOneofEnum(TestEnum::ZERO); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame("oneof_enum", $n->getMyOneof()); -# $this->assertSame(TestEnum::ZERO, $n->getOneofEnum()); + $m->setOneofEnum(TestEnum::ZERO); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame("oneof_enum", $n->getMyOneof()); + $this->assertSame(TestEnum::ZERO, $n->getOneofEnum()); $m->setOneofString(""); $data = $m->serializeToString(); $n = new TestMessage(); $n->mergeFromString($data); $this->assertSame("oneof_string", $n->getMyOneof()); - $this->assertSame("", $n->getOneofString()); - -# $sub_m = new TestMessage_Sub(); -# $m->setOneofMessage($sub_m); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame("oneof_message", $n->getMyOneof()); -# $this->assertFalse(is_null($n->getOneofMessage())); - - } - -# public function testPackedEncode() -# { -# $from = new TestPackedMessage(); -# TestUtil::setTestPackedMessage($from); -# $this->assertSame(TestUtil::getGoldenTestPackedMessage(), -# $from->serializeToString()); -# } -# -# public function testPackedDecodePacked() -# { -# $to = new TestPackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testPackedDecodeUnpacked() -# { -# $to = new TestPackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testUnpackedEncode() -# { -# $from = new TestUnpackedMessage(); -# TestUtil::setTestPackedMessage($from); -# $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(), -# $from->serializeToString()); -# } -# -# public function testUnpackedDecodePacked() -# { -# $to = new TestUnpackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testUnpackedDecodeUnpacked() -# { -# $to = new TestUnpackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testDecodeInt64() -# { -# // Read 64 testing -# $testVals = array( -# '10' => '100a', -# '100' => '1064', -# '800' => '10a006', -# '6400' => '108032', -# '70400' => '1080a604', -# '774400' => '1080a22f', -# '9292800' => '108098b704', -# '74342400' => '1080c0b923', -# '743424000' => '108080bfe202', -# '8177664000' => '108080b5bb1e', -# '65421312000' => '108080a8dbf301', -# '785055744000' => '108080e0c7ec16', -# '9420668928000' => '10808080dd969202', -# '103627358208000' => '10808080fff9c717', -# '1139900940288000' => '10808080f5bd978302', -# '13678811283456000' => '10808080fce699a618', -# '109430490267648000' => '10808080e0b7ceb1c201', -# '984874412408832000' => '10808080e0f5c1bed50d', -# ); -# -# $msg = new TestMessage(); -# foreach ($testVals as $original => $encoded) { -# $msg->setOptionalInt64($original); -# $data = $msg->serializeToString(); -# $this->assertSame($encoded, bin2hex($data)); -# $msg->setOptionalInt64(0); -# $msg->mergeFromString($data); -# $this->assertEquals($original, $msg->getOptionalInt64()); -# } -# } -# -# public function testDecodeToExistingMessage() -# { -# $m1 = new TestMessage(); -# $this->setFields($m1); -# $this->expectFields($m1); -# -# $m2 = new TestMessage(); -# $this->setFields2($m2); -# $data = $m2->serializeToString(); -# -# $m1->mergeFromString($data); -# $this->expectFieldsMerged($m1); -# } -# -# public function testDecodeFieldNonExist() -# { -# $data = hex2bin('c80501'); -# $m = new TestMessage(); -# $m->mergeFromString($data); -# } -# -# public function testEncodeNegativeInt32() -# { -# $m = new TestMessage(); -# $m->setOptionalInt32(-1); -# $data = $m->serializeToString(); -# $this->assertSame("08ffffffffffffffffff01", bin2hex($data)); -# } -# -# public function testDecodeNegativeInt32() -# { -# $m = new TestMessage(); -# $this->assertEquals(0, $m->getOptionalInt32()); -# $m->mergeFromString(hex2bin("08ffffffffffffffffff01")); -# $this->assertEquals(-1, $m->getOptionalInt32()); -# -# $m = new TestMessage(); -# $this->assertEquals(0, $m->getOptionalInt32()); -# $m->mergeFromString(hex2bin("08ffffffff0f")); -# $this->assertEquals(-1, $m->getOptionalInt32()); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidInt32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('08')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSubMessage() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('9A010108')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidInt64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('10')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidUInt32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('18')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidUInt64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('20')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSInt32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('28')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSInt64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('30')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidFixed32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('3D')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidFixed64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('41')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSFixed32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('4D')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSFixed64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('51')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidFloat() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('5D')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidDouble() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('61')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidBool() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('68')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidStringLengthMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('72')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidStringDataMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('7201')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidBytesLengthMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('7A')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidBytesDataMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('7A01')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidEnum() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('8001')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidMessageLengthMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('8A01')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidMessageDataMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('8A0101')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidPackedMessageLength() -# { -# $m = new TestPackedMessage(); -# $m->mergeFromString(hex2bin('D205')); -# } -# -# public function testJsonEncode() -# { -# $from = new TestMessage(); -# $this->setFields($from); -# $data = $from->serializeToJsonString(); -# $to = new TestMessage(); -# $to->mergeFromJsonString($data); -# $this->expectFields($to); -# } + $this->assertSame("", $n->getOneofString()); + + $sub_m = new TestMessage_Sub(); + $m->setOneofMessage($sub_m); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame("oneof_message", $n->getMyOneof()); + $this->assertFalse(is_null($n->getOneofMessage())); + + } + + public function testPackedEncode() + { + $from = new TestPackedMessage(); + TestUtil::setTestPackedMessage($from); + $this->assertSame(TestUtil::getGoldenTestPackedMessage(), + $from->serializeToString()); + } + + public function testPackedDecodePacked() + { + $to = new TestPackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testPackedDecodeUnpacked() + { + $to = new TestPackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testUnpackedEncode() + { + $from = new TestUnpackedMessage(); + TestUtil::setTestPackedMessage($from); + $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(), + $from->serializeToString()); + } + + public function testUnpackedDecodePacked() + { + $to = new TestUnpackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testUnpackedDecodeUnpacked() + { + $to = new TestUnpackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testDecodeInt64() + { + // Read 64 testing + $testVals = array( + '10' => '100a', + '100' => '1064', + '800' => '10a006', + '6400' => '108032', + '70400' => '1080a604', + '774400' => '1080a22f', + '9292800' => '108098b704', + '74342400' => '1080c0b923', + '743424000' => '108080bfe202', + '8177664000' => '108080b5bb1e', + '65421312000' => '108080a8dbf301', + '785055744000' => '108080e0c7ec16', + '9420668928000' => '10808080dd969202', + '103627358208000' => '10808080fff9c717', + '1139900940288000' => '10808080f5bd978302', + '13678811283456000' => '10808080fce699a618', + '109430490267648000' => '10808080e0b7ceb1c201', + '984874412408832000' => '10808080e0f5c1bed50d', + ); + + $msg = new TestMessage(); + foreach ($testVals as $original => $encoded) { + $msg->setOptionalInt64($original); + $data = $msg->serializeToString(); + $this->assertSame($encoded, bin2hex($data)); + $msg->setOptionalInt64(0); + $msg->mergeFromString($data); + $this->assertEquals($original, $msg->getOptionalInt64()); + } + } + + public function testDecodeToExistingMessage() + { + $m1 = new TestMessage(); + $this->setFields($m1); + $this->expectFields($m1); + + $m2 = new TestMessage(); + $this->setFields2($m2); + $data = $m2->serializeToString(); + + $m1->mergeFromString($data); + $this->expectFieldsMerged($m1); + } + + public function testDecodeFieldNonExist() + { + $data = hex2bin('c80501'); + $m = new TestMessage(); + $m->mergeFromString($data); + } + + public function testEncodeNegativeInt32() + { + $m = new TestMessage(); + $m->setOptionalInt32(-1); + $data = $m->serializeToString(); + $this->assertSame("08ffffffffffffffffff01", bin2hex($data)); + } + + public function testDecodeNegativeInt32() + { + $m = new TestMessage(); + $this->assertEquals(0, $m->getOptionalInt32()); + $m->mergeFromString(hex2bin("08ffffffffffffffffff01")); + $this->assertEquals(-1, $m->getOptionalInt32()); + + $m = new TestMessage(); + $this->assertEquals(0, $m->getOptionalInt32()); + $m->mergeFromString(hex2bin("08ffffffff0f")); + $this->assertEquals(-1, $m->getOptionalInt32()); + } + + public function testRandomFieldOrder() + { + $m = new TestRandomFieldOrder(); + $data = $m->serializeToString(); + $this->assertSame("", $data); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidInt32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('08')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSubMessage() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('9A010108')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidInt64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('10')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidUInt32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('18')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidUInt64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('20')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSInt32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('28')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSInt64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('30')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidFixed32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('3D')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidFixed64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('41')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSFixed32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('4D')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSFixed64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('51')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidFloat() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('5D')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidDouble() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('61')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidBool() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('68')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidStringLengthMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('72')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidStringDataMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('7201')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidBytesLengthMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('7A')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidBytesDataMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('7A01')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidEnum() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('8001')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidMessageLengthMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('8A01')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidMessageDataMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('8A0101')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidPackedMessageLength() + { + $m = new TestPackedMessage(); + $m->mergeFromString(hex2bin('D205')); + } + + public function testJsonEncode() + { + $from = new TestMessage(); + $this->setFields($from); + $data = $from->serializeToJsonString(); + $to = new TestMessage(); + $to->mergeFromJsonString($data); + $this->expectFields($to); + } } diff --git a/php/tests/generated_service_test.php b/php/tests/generated_service_test.php new file mode 100644 index 00000000..5407db9a --- /dev/null +++ b/php/tests/generated_service_test.php @@ -0,0 +1,110 @@ +<?php + +require_once('test_base.php'); +require_once('test_util.php'); + +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\MapField; +use Google\Protobuf\Internal\GPBType; +use Foo\Greeter; +use Foo\HelloRequest; +use Foo\HelloReply; + +class GeneratedServiceTest extends TestBase +{ + /** + * @var \ReflectionClass + */ + private $serviceClass; + + /** + * @var \ReflectionClass + */ + private $namespacedServiceClass; + + /** + * @var array + */ + private $methodNames = [ + 'sayHello', + 'sayHelloAgain' + ]; + + public function setUp() + { + parent::setUp(); + + $this->serviceClass = new ReflectionClass('Foo\GreeterInterface'); + + $this->namespacedServiceClass = new ReflectionClass('Bar\OtherGreeterInterface'); + } + + public function testIsInterface() + { + $this->assertTrue($this->serviceClass->isInterface()); + } + + public function testPhpDocForClass() + { + $this->assertContains('foo.Greeter', $this->serviceClass->getDocComment()); + } + + public function testPhpDocForNamespacedClass() + { + $this->assertContains('foo.OtherGreeter', $this->namespacedServiceClass->getDocComment()); + } + + public function testServiceMethodsAreGenerated() + { + $this->assertCount(count($this->methodNames), $this->serviceClass->getMethods()); + foreach ($this->methodNames as $methodName) { + $this->assertTrue($this->serviceClass->hasMethod($methodName)); + } + } + + public function testPhpDocForServiceMethod() + { + foreach ($this->methodNames as $methodName) { + $docComment = $this->serviceClass->getMethod($methodName)->getDocComment(); + $this->assertContains($methodName, $docComment); + $this->assertContains('@param \Foo\HelloRequest $request', $docComment); + $this->assertContains('@return \Foo\HelloReply', $docComment); + } + } + + public function testPhpDocForServiceMethodInNamespacedClass() + { + foreach ($this->methodNames as $methodName) { + $docComment = $this->namespacedServiceClass->getMethod($methodName)->getDocComment(); + $this->assertContains($methodName, $docComment); + $this->assertContains('@param \Foo\HelloRequest $request', $docComment); + $this->assertContains('@return \Foo\HelloReply', $docComment); + } + } + + public function testParamForServiceMethod() + { + foreach ($this->methodNames as $methodName) { + $method = $this->serviceClass->getMethod($methodName); + $this->assertCount(1, $method->getParameters()); + $param = $method->getParameters()[0]; + $this->assertFalse($param->isOptional()); + $this->assertSame('request', $param->getName()); + // ReflectionParameter::getType only exists in PHP 7+, so get the type from __toString + $this->assertContains('Foo\HelloRequest $request', (string) $param); + } + } + + public function testParamForServiceMethodInNamespacedClass() + { + foreach ($this->methodNames as $methodName) { + $method = $this->serviceClass->getMethod($methodName); + $this->assertCount(1, $method->getParameters()); + $param = $method->getParameters()[0]; + $this->assertFalse($param->isOptional()); + $this->assertSame('request', $param->getName()); + // ReflectionParameter::getType only exists in PHP 7+, so get the type from __toString + $this->assertContains('Foo\HelloRequest $request', (string) $param); + } + } +} diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index c5d21264..120b1bde 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -56,6 +56,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { unset($arr['3.1']); unset($arr[MAX_INT32_STRING]); $this->assertEquals(0, count($arr)); + + // Test foreach. + $arr = new MapField(GPBType::INT32, GPBType::INT32); + for ($i = 0; $i < 3; $i++) { + $arr[$i] = $i; + } + $i = 0; + $arr_test = []; + foreach ($arr as $key => $val) { + $this->assertSame($key, $val); + $arr_test[] = $key; + $i++; + } + $this->assertTrue(isset($arr_test[0])); + $this->assertTrue(isset($arr_test[1])); + $this->assertTrue(isset($arr_test[2])); + $this->assertSame(3, $i); } ######################################################### @@ -366,6 +383,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(1, count($arr)); unset($arr[True]); $this->assertEquals(0, count($arr)); + + // Test foreach. + $arr = new MapField(GPBType::STRING, GPBType::STRING); + for ($i = 0; $i < 3; $i++) { + $arr[$i] = $i; + } + $i = 0; + $arr_test = []; + foreach ($arr as $key => $val) { + $this->assertSame($key, $val); + $arr_test[] = $key; + $i++; + } + $this->assertTrue(isset($arr_test['0'])); + $this->assertTrue(isset($arr_test['1'])); + $this->assertTrue(isset($arr_test['2'])); + $this->assertSame(3, $i); } ######################################################### diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index 6572fdd0..faa1833d 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -20,6 +20,7 @@ require_once('generated/Foo/TestMessage_NestedEnum.php'); require_once('generated/Foo/TestMessage_Sub.php'); require_once('generated/Foo/TestPackedMessage.php'); require_once('generated/Foo/TestPhpDoc.php'); +require_once('generated/Foo/TestRandomFieldOrder.php'); require_once('generated/Foo/TestUnpackedMessage.php'); require_once('generated/GPBMetadata/Proto/Test.php'); require_once('generated/GPBMetadata/Proto/TestEmptyPhpNamespace.php'); diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index dada8b48..d81f66f5 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -181,3 +181,9 @@ message TestIncludeNamespaceMessage { TestNamespace namespace_message = 1; TestEmptyNamespace empty_namespace_message = 2; } + +// This will cause upb fields not ordered by the order in the generated code. +message TestRandomFieldOrder { + int64 tag13 = 150; + string tag14 = 160; +} diff --git a/php/tests/proto/test_service.proto b/php/tests/proto/test_service.proto new file mode 100644 index 00000000..a03dbc46 --- /dev/null +++ b/php/tests/proto/test_service.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package foo; + +option php_generic_services = true; + +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply) {} + rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/php/tests/proto/test_service_namespace.proto b/php/tests/proto/test_service_namespace.proto new file mode 100644 index 00000000..719aa484 --- /dev/null +++ b/php/tests/proto/test_service_namespace.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +import "proto/test_service.proto"; + +package foo; + +option php_generic_services = true; +option php_namespace = "Bar"; + +service OtherGreeter { + rpc SayHello (HelloRequest) returns (HelloReply) {} + rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} +} diff --git a/php/tests/test.sh b/php/tests/test.sh index 6c6edd56..b640c143 100755 --- a/php/tests/test.sh +++ b/php/tests/test.sh @@ -8,7 +8,7 @@ set -e phpize && ./configure CFLAGS='-g -O0' && make popd -tests=( array_test.php encode_decode_test.php generated_class_test.php generated_phpdoc_test.php map_field_test.php well_known_test.php ) +tests=( array_test.php encode_decode_test.php generated_class_test.php generated_phpdoc_test.php map_field_test.php well_known_test.php generated_service_test.php ) for t in "${tests[@]}" do diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index 3c5e887b..a124ed7c 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -73,6 +73,10 @@ compiler (protoc). This binary is intended for users who want to use Protocol Buffers in languages other than C++ but do not want to compile protoc themselves. To install, simply place this binary somewhere in your PATH. +If you intend to use the included well known types then don't forget to +copy the contents of the 'include' directory somewhere as well, for example +into '/usr/local/include/'. + Please refer to our official github site for more installation instructions: https://github.com/google/protobuf EOF diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index a06c9998..6003f09d 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ </parent> <groupId>com.google.protobuf</groupId> <artifactId>protoc</artifactId> - <version>3.3.0</version> + <version>3.3.2</version> <packaging>pom</packaging> <name>Protobuf Compiler</name> <description> diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 0375d72d..622dfb3d 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.3.0' +__version__ = '3.3.2' if __name__ != '__main__': try: diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index d02cb091..937285b0 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -532,8 +532,8 @@ class _Parser(object): def _ConvertGenericMessage(self, value, message): """Convert a JSON representation into message with FromJsonString.""" - # Durantion, Timestamp, FieldMask have FromJsonString method to do the - # convert. Users can also call the method directly. + # Duration, Timestamp, FieldMask have a FromJsonString method to do the + # conversion. Users can also call the method directly. message.FromJsonString(value) def _ConvertValueMessage(self, value, message): diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 85aaa46f..49113c7c 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -1055,13 +1055,15 @@ int InternalDeleteRepeatedField( if (PySlice_Check(slice)) { from = to = step = slice_length = 0; - PySlice_GetIndicesEx( #if PY_MAJOR_VERSION < 3 + PySlice_GetIndicesEx( reinterpret_cast<PySliceObject*>(slice), + length, &from, &to, &step, &slice_length); #else + PySlice_GetIndicesEx( slice, -#endif length, &from, &to, &step, &slice_length); +#endif if (from < to) { min = from; max = to - 1; diff --git a/python/google/protobuf/pyext/repeated_composite_container.cc b/python/google/protobuf/pyext/repeated_composite_container.cc index 9cb4e9a1..06a976de 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.cc +++ b/python/google/protobuf/pyext/repeated_composite_container.cc @@ -266,10 +266,11 @@ int AssignSubscript(RepeatedCompositeContainer* self, if (PySlice_Check(slice)) { #if PY_MAJOR_VERSION >= 3 if (PySlice_GetIndicesEx(slice, + length, &from, &to, &step, &slicelength) == -1) { #else if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), -#endif length, &from, &to, &step, &slicelength) == -1) { +#endif return -1; } return PySequence_DelSlice(self->child_messages, from, to); diff --git a/python/google/protobuf/pyext/repeated_scalar_container.cc b/python/google/protobuf/pyext/repeated_scalar_container.cc index 95da85f8..9fedb952 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.cc +++ b/python/google/protobuf/pyext/repeated_scalar_container.cc @@ -305,10 +305,12 @@ static PyObject* Subscript(RepeatedScalarContainer* self, PyObject* slice) { length = Len(self); #if PY_MAJOR_VERSION >= 3 if (PySlice_GetIndicesEx(slice, + length, &from, &to, &step, &slicelength) == -1) { #else if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), -#endif length, &from, &to, &step, &slicelength) == -1) { + +#endif return NULL; } return_list = true; @@ -458,10 +460,11 @@ static int AssSubscript(RepeatedScalarContainer* self, length = reflection->FieldSize(*message, field_descriptor); #if PY_MAJOR_VERSION >= 3 if (PySlice_GetIndicesEx(slice, + length, &from, &to, &step, &slicelength) == -1) { #else if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), -#endif length, &from, &to, &step, &slicelength) == -1) { +#endif return -1; } create_list = true; diff --git a/python/tox.ini b/python/tox.ini index 1600db21..baa96dba 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -9,6 +9,7 @@ setenv = cpp: LD_LIBRARY_PATH={toxinidir}/../src/.libs cpp: DYLD_LIBRARY_PATH={toxinidir}/../src/.libs cpp: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp + python: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python commands = python setup.py -q build_py python: python setup.py -q build diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 836b1dd2..bed835cb 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.3.0" + s.version = "3.3.2" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." diff --git a/ruby/lib/google/protobuf/well_known_types.rb b/ruby/lib/google/protobuf/well_known_types.rb index 547de874..921ddbc0 100644 --- a/ruby/lib/google/protobuf/well_known_types.rb +++ b/ruby/lib/google/protobuf/well_known_types.rb @@ -80,7 +80,7 @@ module Google end def to_f - self.seconds + (self.nanos.to_f / 1_000_000_000) + self.seconds + (self.nanos.quo(1_000_000_000)) end end diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 9b46632b..bd24c328 100644 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -13,10 +13,18 @@ class TestWellKnownTypes < Test::Unit::TestCase assert_equal Time.at(12345), ts.to_time assert_equal 12345, ts.to_i - ts.from_time(Time.at(123456, 654321)) + # millisecond accuracy + time = Time.at(123456, 654321) + ts.from_time(time) assert_equal 123456, ts.seconds assert_equal 654321000, ts.nanos - assert_equal Time.at(123456.654321), ts.to_time + assert_equal time, ts.to_time + + # nanosecond accuracy + time = Time.at(123456, Rational(654321321, 1000)) + ts.from_time(time) + assert_equal 654321321, ts.nanos + assert_equal time, ts.to_time end def test_duration diff --git a/src/Makefile.am b/src/Makefile.am index 45a8a79b..a943f685 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,7 +184,7 @@ nobase_include_HEADERS = \ lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS) -libprotobuf_lite_la_LDFLAGS = -version-info 13:0:0 -export-dynamic -no-undefined +libprotobuf_lite_la_LDFLAGS = -version-info 13:2:0 -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotobuf_lite_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf-lite.map EXTRA_libprotobuf_lite_la_DEPENDENCIES = libprotobuf-lite.map @@ -198,6 +198,8 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/stubs/hash.h \ google/protobuf/stubs/int128.cc \ google/protobuf/stubs/int128.h \ + google/protobuf/stubs/io_win32.cc \ + google/protobuf/stubs/io_win32.h \ google/protobuf/stubs/map_util.h \ google/protobuf/stubs/mathutil.h \ google/protobuf/stubs/once.cc \ @@ -229,7 +231,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/io/zero_copy_stream_impl_lite.cc libprotobuf_la_LIBADD = $(PTHREAD_LIBS) -libprotobuf_la_LDFLAGS = -version-info 13:0:0 -export-dynamic -no-undefined +libprotobuf_la_LDFLAGS = -version-info 13:2:0 -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotobuf_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf.map EXTRA_libprotobuf_la_DEPENDENCIES = libprotobuf.map @@ -250,6 +252,7 @@ libprotobuf_la_SOURCES = \ google/protobuf/extension_set_heavy.cc \ google/protobuf/field_mask.pb.cc \ google/protobuf/generated_message_reflection.cc \ + google/protobuf/generated_message_table_driven.cc \ google/protobuf/map_field.cc \ google/protobuf/message.cc \ google/protobuf/reflection_internal.h \ @@ -318,7 +321,7 @@ libprotobuf_la_SOURCES = \ nodist_libprotobuf_la_SOURCES = $(nodist_libprotobuf_lite_la_SOURCES) libprotoc_la_LIBADD = $(PTHREAD_LIBS) libprotobuf.la -libprotoc_la_LDFLAGS = -version-info 13:0:0 -export-dynamic -no-undefined +libprotoc_la_LDFLAGS = -version-info 13:2:0 -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotoc_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotoc.map EXTRA_libprotoc_la_DEPENDENCIES = libprotoc.map @@ -761,6 +764,7 @@ protobuf_test_SOURCES = \ google/protobuf/stubs/bytestream_unittest.cc \ google/protobuf/stubs/common_unittest.cc \ google/protobuf/stubs/int128_unittest.cc \ + google/protobuf/stubs/io_win32_unittest.cc \ google/protobuf/stubs/once_unittest.cc \ google/protobuf/stubs/statusor_test.cc \ google/protobuf/stubs/status_test.cc \ diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index f1cf6d46..e36ffb5f 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -123,7 +123,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -309,6 +309,7 @@ void Any::SerializeWithCachedSizes( ::google::protobuf::uint8* Any::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index bc05fb35..ad2073a8 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/api.pb.cc index 30dd8dbc..766c7e0d 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -182,7 +182,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -486,6 +486,7 @@ void Api::SerializeWithCachedSizes( ::google::protobuf::uint8* Api::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1254,6 +1255,7 @@ void Method::SerializeWithCachedSizes( ::google::protobuf::uint8* Method::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1868,6 +1870,7 @@ void Mixin::SerializeWithCachedSizes( ::google::protobuf::uint8* Mixin::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 729e4ad1..f857f220 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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/code_generator.h b/src/google/protobuf/compiler/code_generator.h index b917d373..6ea5f18d 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -162,8 +162,8 @@ typedef GeneratorContext OutputDirectory; // "foo=bar,baz,qux=corge" // parses to the pairs: // ("foo", "bar"), ("baz", ""), ("qux", "corge") -extern void ParseGeneratorParameter(const string&, - std::vector<std::pair<string, string> >*); +LIBPROTOC_EXPORT void ParseGeneratorParameter( + const string&, std::vector<std::pair<string, string> >*); } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index df03907d..4d894c82 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -45,10 +45,7 @@ #endif #include <sys/stat.h> #include <fcntl.h> -#ifdef _MSC_VER -#include <io.h> -#include <direct.h> -#else +#ifndef _MSC_VER #include <unistd.h> #endif #include <errno.h> @@ -80,6 +77,7 @@ #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/io/printer.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> @@ -91,22 +89,6 @@ namespace google { namespace protobuf { namespace compiler { -#if defined(_WIN32) -#define mkdir(name, mode) mkdir(name) -#ifndef W_OK -#define W_OK 02 // not defined by MSVC for whatever reason -#endif -#ifndef F_OK -#define F_OK 00 // not defined by MSVC for whatever reason -#endif -#ifndef STDIN_FILENO -#define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -#define STDOUT_FILENO 1 -#endif -#endif - #ifndef O_BINARY #ifdef _O_BINARY #define O_BINARY _O_BINARY @@ -118,6 +100,14 @@ namespace compiler { namespace { #if defined(_WIN32) && !defined(__CYGWIN__) static const char* kPathSeparator = ";"; +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::access; +using google::protobuf::internal::win32::close; +using google::protobuf::internal::win32::mkdir; +using google::protobuf::internal::win32::open; +using google::protobuf::internal::win32::setmode; +using google::protobuf::internal::win32::write; #else static const char* kPathSeparator = ":"; #endif @@ -141,9 +131,9 @@ static bool IsWindowsAbsolutePath(const string& text) { void SetFdToTextMode(int fd) { #ifdef _WIN32 - if (_setmode(fd, _O_TEXT) == -1) { + if (setmode(fd, _O_TEXT) == -1) { // This should never happen, I think. - GOOGLE_LOG(WARNING) << "_setmode(" << fd << ", _O_TEXT): " << strerror(errno); + GOOGLE_LOG(WARNING) << "setmode(" << fd << ", _O_TEXT): " << strerror(errno); } #endif // (Text and binary are the same on non-Windows platforms.) @@ -151,9 +141,9 @@ void SetFdToTextMode(int fd) { void SetFdToBinaryMode(int fd) { #ifdef _WIN32 - if (_setmode(fd, _O_BINARY) == -1) { + if (setmode(fd, _O_BINARY) == -1) { // This should never happen, I think. - GOOGLE_LOG(WARNING) << "_setmode(" << fd << ", _O_BINARY): " << strerror(errno); + GOOGLE_LOG(WARNING) << "setmode(" << fd << ", _O_BINARY): " << strerror(errno); } #endif // (Text and binary are the same on non-Windows platforms.) diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 366e623f..5fbb37a4 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -35,9 +35,7 @@ #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> -#ifdef _MSC_VER -#include <io.h> -#else +#ifndef _MSC_VER #include <unistd.h> #endif #include <memory> @@ -65,27 +63,27 @@ #include <gtest/gtest.h> #include <google/protobuf/stubs/strutil.h> +#include <google/protobuf/stubs/io_win32.h> namespace google { namespace protobuf { namespace compiler { +#if defined(_WIN32) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::access; +using google::protobuf::internal::win32::dup; +using google::protobuf::internal::win32::dup2; +using google::protobuf::internal::win32::close; +using google::protobuf::internal::win32::open; +using google::protobuf::internal::win32::write; +#endif + // Disable the whole test when we use tcmalloc for "draconian" heap checks, in // which case tcmalloc will print warnings that fail the plugin tests. #if !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN -#if defined(_WIN32) -#ifndef STDIN_FILENO -#define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -#define STDOUT_FILENO 1 -#endif -#ifndef F_OK -#define F_OK 00 // not defined by MSVC for whatever reason -#endif -#endif - namespace { bool FileExists(const string& path) { diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc index 0d3fdcbe..960730ca 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc @@ -144,13 +144,13 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { printer->Print(variables_, "} else {\n" " mutable_unknown_fields()->AddVarint(\n" - " $number$, static_cast<::google::protobuf::uint64>(value));\n"); + " $number$, static_cast< ::google::protobuf::uint64>(value));\n"); } else { printer->Print( "} else {\n" " unknown_fields_stream.WriteVarint32($tag$u);\n" " unknown_fields_stream.WriteVarint32(\n" - " static_cast<::google::protobuf::uint32>(value));\n", + " static_cast< ::google::protobuf::uint32>(value));\n", "tag", SimpleItoa(internal::WireFormat::MakeTag(descriptor_))); } printer->Print(variables_, @@ -347,13 +347,13 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { printer->Print(variables_, "} else {\n" " mutable_unknown_fields()->AddVarint(\n" - " $number$, static_cast<::google::protobuf::uint64>(value));\n"); + " $number$, static_cast< ::google::protobuf::uint64>(value));\n"); } else { printer->Print( "} else {\n" " unknown_fields_stream.WriteVarint32(tag);\n" " unknown_fields_stream.WriteVarint32(\n" - " static_cast<::google::protobuf::uint32>(value));\n"); + " static_cast< ::google::protobuf::uint32>(value));\n"); } printer->Print("}\n"); } @@ -412,12 +412,12 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { if (UseUnknownFieldSet(descriptor_->file(), options_)) { printer->Print(variables_, " mutable_unknown_fields()->AddVarint(\n" - " $number$, static_cast<::google::protobuf::uint64>(value));\n"); + " $number$, static_cast< ::google::protobuf::uint64>(value));\n"); } else { printer->Print(variables_, " unknown_fields_stream.WriteVarint32(tag);\n" " unknown_fields_stream.WriteVarint32(\n" - " static_cast<::google::protobuf::uint32>(value));\n"); + " static_cast< ::google::protobuf::uint32>(value));\n"); } printer->Print( " }\n"); @@ -439,7 +439,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const { " ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED,\n" " output);\n" " output->WriteVarint32(\n" - " static_cast<::google::protobuf::uint32>(_$name$_cached_byte_size_));\n" + " static_cast< ::google::protobuf::uint32>(_$name$_cached_byte_size_));\n" "}\n"); } printer->Print(variables_, @@ -467,7 +467,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { " ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED,\n" " target);\n" " target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(" - " static_cast<::google::protobuf::uint32>(\n" + " static_cast< ::google::protobuf::uint32>(\n" " _$name$_cached_byte_size_), target);\n" " target = ::google::protobuf::internal::WireFormatLite::WriteEnumNoTagToArray(\n" " this->$name$_, target);\n" @@ -497,7 +497,7 @@ GenerateByteSize(io::Printer* printer) const { "if (data_size > 0) {\n" " total_size += $tag_size$ +\n" " ::google::protobuf::internal::WireFormatLite::Int32Size(\n" - " static_cast<google::protobuf::int32>(data_size));\n" + " static_cast< ::google::protobuf::int32>(data_size));\n" "}\n" "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n" "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 1f7a66c5..d79a3e73 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -526,11 +526,10 @@ class FileGenerator::ForwardDeclarations { void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // AddDescriptors() is a file-level procedure which adds the encoded // FileDescriptorProto for this .proto file to the global DescriptorPool for - // generated files (DescriptorPool::generated_pool()). It either runs at - // static initialization time (by default) or when default_instance() is - // called for the first time (in LITE_RUNTIME mode with - // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER flag enabled). This procedure also - // constructs default instances and registers extensions. + // generated files (DescriptorPool::generated_pool()). It ordinarily runs at + // static initialization time, but is not used at all in LITE_RUNTIME mode + // except when extensions are used. This procedure also constructs default + // instances and registers extensions. // // Its sibling, AssignDescriptors(), actually pulls the compiled // FileDescriptor from the DescriptorPool and uses it to populate all of @@ -889,19 +888,15 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { " ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);\n" "}\n"); - if (!StaticInitializersForced(file_, options_)) { - printer->Print("#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"); - } - printer->Print( - // With static initializers. - "// Force AddDescriptors() to be called at static initialization time.\n" - "struct StaticDescriptorInitializer {\n" - " StaticDescriptorInitializer() {\n" - " AddDescriptors();\n" - " }\n" - "} static_descriptor_initializer;\n"); - if (!StaticInitializersForced(file_, options_)) { - printer->Print("#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"); + if (StaticInitializersForced(file_, options_)) { + printer->Print( + "// Force AddDescriptors() to be called at dynamic initialization " + "time.\n" + "struct StaticDescriptorInitializer {\n" + " StaticDescriptorInitializer() {\n" + " AddDescriptors();\n" + " }\n" + "} static_descriptor_initializer;\n"); } } diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 1ab87638..33231ae3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -2411,11 +2411,7 @@ GenerateStructors(io::Printer* printer) { printer->Print( "$classname$::$classname$(::google::protobuf::Arena* arena)\n" " : $initializer$ {\n" - // When arenas are used it's safe to assume we have finished - // static init time (protos with arenas are unsafe during static init) - "#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" " $file_namespace$::InitDefaults();\n" - "#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" " SharedCtor();\n" " RegisterArenaDtor(arena);\n" " // @@protoc_insertion_point(arena_constructor:$full_name$)\n" @@ -3717,6 +3713,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) { "classname", classname_); printer->Indent(); + printer->Print("(void)deterministic; // Unused\n"); printer->Print( "// @@protoc_insertion_point(serialize_to_array_start:$full_name$)\n", "full_name", descriptor_->full_name()); diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index 83bc096f..e45f35b3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -382,7 +382,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const { "$number$, " "::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, " "output);\n" - " output->WriteVarint32(static_cast<::google::protobuf::uint32>(\n" + " output->WriteVarint32(static_cast< ::google::protobuf::uint32>(\n" " _$name$_cached_byte_size_));\n"); if (FixedSize(descriptor_->type()) > 0) { @@ -423,7 +423,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { " ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED,\n" " target);\n" " target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(\n" - " static_cast<::google::protobuf::uint32>(\n" + " static_cast< ::google::protobuf::uint32>(\n" " _$name$_cached_byte_size_), target);\n" " target = ::google::protobuf::internal::WireFormatLite::\n" " Write$declared_type$NoTagToArray(this->$name$_, target);\n" @@ -455,7 +455,7 @@ GenerateByteSize(io::Printer* printer) const { "if (data_size > 0) {\n" " total_size += $tag_size$ +\n" " ::google::protobuf::internal::WireFormatLite::Int32Size(\n" - " static_cast<google::protobuf::int32>(data_size));\n" + " static_cast< ::google::protobuf::int32>(data_size));\n" "}\n" "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n" "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 4e44b578..5c54270e 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -134,6 +134,14 @@ class GenerateAndTest { }; TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) { + // Skip this whole test if the csharp directory doesn't exist (i.e., a C++11 + // only distribution). + string descriptor_file_name = + "../csharp/src/Google.Protobuf/Reflection/Descriptor.cs"; + if (!File::Exists(TestSourceDir() + "/" + descriptor_file_name)) { + return; + } + MockErrorCollector error_collector; DiskSourceTree source_tree; Importer importer(&source_tree, &error_collector); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index ebb8fbc2..ecf29ece 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -54,7 +54,7 @@ namespace compiler { namespace csharp { void FieldGeneratorBase::SetCommonFieldVariables( - map<string, string>* variables) { + std::map<string, string>* variables) { // Note: this will be valid even though the tag emitted for packed and unpacked versions of // repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which // never effects the tag size. @@ -92,7 +92,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( } void FieldGeneratorBase::SetCommonOneofFieldVariables( - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["oneof_name"] = oneof_name(); (*variables)["has_property_check"] = oneof_name() + "Case_ == " + oneof_property_name() + diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 4109f3ca..df26853b 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -66,14 +66,14 @@ class FieldGeneratorBase : public SourceGeneratorBase { protected: const FieldDescriptor* descriptor_; const int fieldOrdinal_; - map<string, string> variables_; + std::map<string, string> variables_; void AddDeprecatedFlag(io::Printer* printer); void AddNullCheck(io::Printer* printer); void AddNullCheck(io::Printer* printer, const std::string& name); void AddPublicMemberAttributes(io::Printer* printer); - void SetCommonOneofFieldVariables(map<string, string>* variables); + void SetCommonOneofFieldVariables(std::map<string, string>* variables); std::string oneof_property_name(); std::string oneof_name(); @@ -89,7 +89,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { std::string capitalized_type_name(); private: - void SetCommonFieldVariables(map<string, string>* variables); + void SetCommonFieldVariables(std::map<string, string>* variables); std::string GetStringDefaultValueInternal(); std::string GetBytesDefaultValueInternal(); diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 0f00a438..5ef0e4e8 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -105,7 +105,7 @@ void MessageGenerator::AddDeprecatedFlag(io::Printer* printer) { } void MessageGenerator::Generate(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["class_name"] = class_name(); vars["access_level"] = class_access_level(); @@ -280,7 +280,7 @@ bool MessageGenerator::HasNestedGeneratedTypes() } void MessageGenerator::GenerateCloningCode(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; WriteGeneratedCodeAttributes(printer); vars["class_name"] = class_name(); printer->Print( @@ -333,7 +333,7 @@ void MessageGenerator::GenerateFreezingCode(io::Printer* printer) { } void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["class_name"] = class_name(); // Equality @@ -432,7 +432,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { // Note: These are separate from GenerateMessageSerializationMethods() // because they need to be generated even for messages that are optimized // for code size. - map<string, string> vars; + std::map<string, string> vars; vars["class_name"] = class_name(); WriteGeneratedCodeAttributes(printer); diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc index 844edc1c..71e3c6de 100644 --- a/src/google/protobuf/compiler/importer.cc +++ b/src/google/protobuf/compiler/importer.cc @@ -33,7 +33,7 @@ // Sanjay Ghemawat, Jeff Dean, and others. #ifdef _MSC_VER -#include <io.h> +#include <direct.h> #else #include <unistd.h> #endif @@ -53,19 +53,21 @@ #include <google/protobuf/compiler/parser.h> #include <google/protobuf/io/tokenizer.h> #include <google/protobuf/io/zero_copy_stream_impl.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/strutil.h> -namespace google { -namespace protobuf { -namespace compiler { - #ifdef _WIN32 -#ifndef F_OK -#define F_OK 00 // not defined by MSVC for whatever reason -#endif #include <ctype.h> +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::access; +using google::protobuf::internal::win32::open; #endif +namespace google { +namespace protobuf { +namespace compiler { + // Returns true if the text looks like a Windows-style absolute path, starting // with a drive letter. Example: "C:\foo". TODO(kenton): Share this with // copy in command_line_interface.cc? diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc index f5643abc..56017171 100644 --- a/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/src/google/protobuf/compiler/java/java_message_builder.cc @@ -472,7 +472,7 @@ GenerateCommonBuilderMethods(io::Printer* printer) { "}\n" "public Builder setField(\n" " com.google.protobuf.Descriptors.FieldDescriptor field,\n" - " Object value) {\n" + " java.lang.Object value) {\n" " return (Builder) super.setField(field, value);\n" "}\n" "public Builder clearField(\n" @@ -485,12 +485,12 @@ GenerateCommonBuilderMethods(io::Printer* printer) { "}\n" "public Builder setRepeatedField(\n" " com.google.protobuf.Descriptors.FieldDescriptor field,\n" - " int index, Object value) {\n" + " int index, java.lang.Object value) {\n" " return (Builder) super.setRepeatedField(field, index, value);\n" "}\n" "public Builder addRepeatedField(\n" " com.google.protobuf.Descriptors.FieldDescriptor field,\n" - " Object value) {\n" + " java.lang.Object value) {\n" " return (Builder) super.addRepeatedField(field, value);\n" "}\n"); diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 5007ecee..aad10bb1 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -346,9 +346,9 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { printer->Print( "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n" - "protected final Object dynamicMethod(\n" + "protected final java.lang.Object dynamicMethod(\n" " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n" - " Object arg0, Object arg1) {\n" + " java.lang.Object arg0, java.lang.Object arg1) {\n" " switch (method) {\n" " case NEW_MUTABLE_INSTANCE: {\n" " return new $classname$();\n" diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc index 7666db38..26bc7f85 100644 --- a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc @@ -52,7 +52,7 @@ namespace { // TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of // repeat code between this and the other field types. void SetEnumVariables(const Params& params, - const FieldDescriptor* descriptor, map<string, string>* variables) { + const FieldDescriptor* descriptor, std::map<string, string>* variables) { (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); (*variables)["capitalized_name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.h b/src/google/protobuf/compiler/javanano/javanano_enum_field.h index b94790d6..1be25d10 100644 --- a/src/google/protobuf/compiler/javanano/javanano_enum_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.h @@ -62,7 +62,7 @@ class EnumFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; vector<string> canonical_values_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); @@ -85,7 +85,7 @@ class AccessorEnumFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; vector<string> canonical_values_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AccessorEnumFieldGenerator); @@ -112,7 +112,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { void GenerateRepeatedDataSizeCode(io::Printer* printer) const; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; vector<string> canonical_values_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); diff --git a/src/google/protobuf/compiler/javanano/javanano_extension.cc b/src/google/protobuf/compiler/javanano/javanano_extension.cc index 0b9d1d8d..4c61f915 100644 --- a/src/google/protobuf/compiler/javanano/javanano_extension.cc +++ b/src/google/protobuf/compiler/javanano/javanano_extension.cc @@ -78,7 +78,7 @@ const char* GetTypeConstantName(const FieldDescriptor::Type type) { } // namespace void SetVariables(const FieldDescriptor* descriptor, const Params params, - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["extends"] = ClassName(params, descriptor->containing_type()); (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); bool repeated = descriptor->is_repeated(); diff --git a/src/google/protobuf/compiler/javanano/javanano_extension.h b/src/google/protobuf/compiler/javanano/javanano_extension.h index 4843e296..f4e9eb2d 100644 --- a/src/google/protobuf/compiler/javanano/javanano_extension.h +++ b/src/google/protobuf/compiler/javanano/javanano_extension.h @@ -61,7 +61,7 @@ class ExtensionGenerator { private: const Params& params_; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); }; diff --git a/src/google/protobuf/compiler/javanano/javanano_field.cc b/src/google/protobuf/compiler/javanano/javanano_field.cc index 85257f3f..e31d1177 100644 --- a/src/google/protobuf/compiler/javanano/javanano_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_field.cc @@ -151,7 +151,7 @@ const FieldGenerator& FieldGeneratorMap::get( } void SetCommonOneofVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["oneof_name"] = UnderscoresToCamelCase(descriptor->containing_oneof()); (*variables)["oneof_capitalized_name"] = @@ -169,7 +169,7 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor, } void GenerateOneofFieldEquals(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer) { if (GetJavaType(descriptor) == JAVATYPE_BYTES) { printer->Print(variables, @@ -190,7 +190,7 @@ void GenerateOneofFieldEquals(const FieldDescriptor* descriptor, } void GenerateOneofFieldHashCode(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer) { if (GetJavaType(descriptor) == JAVATYPE_BYTES) { printer->Print(variables, diff --git a/src/google/protobuf/compiler/javanano/javanano_field.h b/src/google/protobuf/compiler/javanano/javanano_field.h index 57c221f4..347c888c 100644 --- a/src/google/protobuf/compiler/javanano/javanano_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_field.h @@ -114,12 +114,12 @@ class FieldGeneratorMap { }; void SetCommonOneofVariables(const FieldDescriptor* descriptor, - map<string, string>* variables); + std::map<string, string>* variables); void GenerateOneofFieldEquals(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer); void GenerateOneofFieldHashCode(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer); } // namespace javanano diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/src/google/protobuf/compiler/javanano/javanano_helpers.cc index 5018250c..1927ba12 100644 --- a/src/google/protobuf/compiler/javanano/javanano_helpers.cc +++ b/src/google/protobuf/compiler/javanano/javanano_helpers.cc @@ -567,7 +567,7 @@ string GenerateDifferentBit(int bit_index) { } void SetBitOperationVariables(const string name, - int bitIndex, map<string, string>* variables) { + int bitIndex, std::map<string, string>* variables) { (*variables)["get_" + name] = GenerateGetBit(bitIndex); (*variables)["set_" + name] = GenerateSetBit(bitIndex); (*variables)["clear_" + name] = GenerateClearBit(bitIndex); diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.h b/src/google/protobuf/compiler/javanano/javanano_helpers.h index 014c85ae..04b2d633 100644 --- a/src/google/protobuf/compiler/javanano/javanano_helpers.h +++ b/src/google/protobuf/compiler/javanano/javanano_helpers.h @@ -181,7 +181,7 @@ string GenerateDifferentBit(int bit_index); // the given name of the bit, to the appropriate Java expressions for the given // bit index. void SetBitOperationVariables(const string name, - int bitIndex, map<string, string>* variables); + int bitIndex, std::map<string, string>* variables); inline bool IsMapEntry(const Descriptor* descriptor) { // TODO(liujisi): Add an option to turn on maps for proto2 syntax as well. diff --git a/src/google/protobuf/compiler/javanano/javanano_map_field.cc b/src/google/protobuf/compiler/javanano/javanano_map_field.cc index 83b2b0ce..a4ab8858 100644 --- a/src/google/protobuf/compiler/javanano/javanano_map_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_map_field.cc @@ -84,7 +84,7 @@ const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) { } void SetMapVariables(const Params& params, - const FieldDescriptor* descriptor, map<string, string>* variables) { + const FieldDescriptor* descriptor, std::map<string, string>* variables) { const FieldDescriptor* key = KeyField(descriptor); const FieldDescriptor* value = ValueField(descriptor); (*variables)["name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_map_field.h b/src/google/protobuf/compiler/javanano/javanano_map_field.h index c01bde38..81e5915d 100644 --- a/src/google/protobuf/compiler/javanano/javanano_map_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_map_field.h @@ -58,7 +58,7 @@ class MapFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator); }; diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc index f81f7f9a..78421887 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message.cc @@ -182,7 +182,7 @@ void MessageGenerator::Generate(io::Printer* printer) { } // oneof - map<string, string> vars; + std::map<string, string> vars; vars["message_name"] = descriptor_->name(); for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { const OneofDescriptor* oneof_desc = descriptor_->oneof_decl(i); diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.cc b/src/google/protobuf/compiler/javanano/javanano_message_field.cc index d1d04b52..2ed8a3aa 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.cc @@ -54,7 +54,7 @@ namespace { // TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of // repeat code between this and the other field types. void SetMessageVariables(const Params& params, - const FieldDescriptor* descriptor, map<string, string>* variables) { + const FieldDescriptor* descriptor, std::map<string, string>* variables) { (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); (*variables)["capitalized_name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.h b/src/google/protobuf/compiler/javanano/javanano_message_field.h index e074735c..0ae8879b 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.h @@ -62,7 +62,7 @@ class MessageFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); }; @@ -85,7 +85,7 @@ class MessageOneofFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator); }; @@ -108,7 +108,7 @@ class RepeatedMessageFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); }; diff --git a/src/google/protobuf/compiler/javanano/javanano_params.h b/src/google/protobuf/compiler/javanano/javanano_params.h index e3b4bb93..3594767d 100644 --- a/src/google/protobuf/compiler/javanano/javanano_params.h +++ b/src/google/protobuf/compiler/javanano/javanano_params.h @@ -47,8 +47,8 @@ enum eMultipleFiles { JAVANANO_MUL_UNSET, JAVANANO_MUL_FALSE, JAVANANO_MUL_TRUE // Parameters for used by the generators class Params { public: - typedef map<string, string> NameMap; - typedef set<string> NameSet; + typedef std::map<string, string> NameMap; + typedef std::set<string> NameSet; private: string empty_; string base_name_; diff --git a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc index 978abf2c..66a0ff05 100644 --- a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc @@ -166,7 +166,7 @@ bool AllAscii(const string& text) { void SetPrimitiveVariables(const FieldDescriptor* descriptor, const Params params, - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); (*variables)["capitalized_name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_primitive_field.h b/src/google/protobuf/compiler/javanano/javanano_primitive_field.h index a01981dd..d7d72d57 100644 --- a/src/google/protobuf/compiler/javanano/javanano_primitive_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_primitive_field.h @@ -65,7 +65,7 @@ class PrimitiveFieldGenerator : public FieldGenerator { void GenerateSerializationConditional(io::Printer* printer) const; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); }; @@ -89,7 +89,7 @@ class AccessorPrimitiveFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AccessorPrimitiveFieldGenerator); }; @@ -111,7 +111,7 @@ class PrimitiveOneofFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveOneofFieldGenerator); }; @@ -137,7 +137,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator { void GenerateRepeatedDataSizeCode(io::Printer* printer) const; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); }; diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 0ddb99e5..8b7a6146 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -55,6 +55,13 @@ #include <google/protobuf/stubs/substitute.h> #include <gtest/gtest.h> +#ifdef major +#undef major +#endif +#ifdef minor +#undef minor +#endif + namespace google { namespace protobuf { namespace compiler { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index 7a774a09..8899a13a 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -46,7 +46,7 @@ namespace objectivec { namespace { void SetEnumVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { string type = EnumName(descriptor->enum_type()); (*variables)["storage_type"] = type; // For non repeated fields, if it was defined in a different file, the @@ -118,7 +118,7 @@ void EnumFieldGenerator::GenerateCFunctionImplementations( } void EnumFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { SingleFieldGenerator::DetermineForwardDeclarations(fwd_decls); // If it is an enum defined in a different file, then we'll need a forward // declaration for it. When it is in our file, all the enums are output diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h index 946faa81..ae56c069 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h @@ -47,7 +47,7 @@ class EnumFieldGenerator : public SingleFieldGenerator { public: virtual void GenerateCFunctionDeclarations(io::Printer* printer) const; virtual void GenerateCFunctionImplementations(io::Printer* printer) const; - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; protected: EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index 73e4b86e..b788d0a3 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -59,7 +59,7 @@ ExtensionGenerator::ExtensionGenerator(const string& root_class_name, ExtensionGenerator::~ExtensionGenerator() {} void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["method_name"] = method_name_; SourceLocation location; if (descriptor_->GetSourceLocation(&location)) { @@ -77,7 +77,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { void ExtensionGenerator::GenerateStaticVariablesInitialization( io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["root_class_and_method_name"] = root_class_and_method_name_; vars["extended_type"] = ClassName(descriptor_->containing_type()); vars["number"] = SimpleItoa(descriptor_->number()); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 9f7e84f2..b6123fad 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -49,7 +49,7 @@ namespace objectivec { namespace { void SetCommonFieldVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { string camel_case_name = FieldName(descriptor); string raw_field_name; if (descriptor->type() == FieldDescriptor::TYPE_GROUP) { @@ -178,7 +178,7 @@ void FieldGenerator::GenerateCFunctionImplementations( } void FieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { // Nothing } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.h b/src/google/protobuf/compiler/objectivec/objectivec_field.h index a3a4b1b6..6bd5db2e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.h @@ -67,7 +67,7 @@ class FieldGenerator { virtual void GenerateCFunctionImplementations(io::Printer* printer) const; // Exposed for subclasses, should always call it on the parent class also. - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; // Used during generation, not intended to be extended by subclasses. void GenerateFieldDescription( @@ -100,7 +100,7 @@ class FieldGenerator { virtual bool WantsHasProperty(void) const = 0; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 7ad127bb..954b2688 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -89,7 +89,7 @@ bool FileContainsExtensions(const FileDescriptor* file) { void PruneFileAndDepsMarkingAsVisited( const FileDescriptor* file, vector<const FileDescriptor*>* files, - set<const FileDescriptor*>* files_visited) { + std::set<const FileDescriptor*>* files_visited) { vector<const FileDescriptor*>::iterator iter = std::find(files->begin(), files->end(), file); if (iter != files->end()) { @@ -105,7 +105,7 @@ void PruneFileAndDepsMarkingAsVisited( void CollectMinimalFileDepsContainingExtensionsWorker( const FileDescriptor* file, vector<const FileDescriptor*>* files, - set<const FileDescriptor*>* files_visited) { + std::set<const FileDescriptor*>* files_visited) { if (files_visited->find(file) != files_visited->end()) { return; } @@ -138,7 +138,7 @@ void CollectMinimalFileDepsContainingExtensionsWorker( void CollectMinimalFileDepsContainingExtensions( const FileDescriptor* file, vector<const FileDescriptor*>* files) { - set<const FileDescriptor*> files_visited; + std::set<const FileDescriptor*> files_visited; for (int i = 0; i < file->dependency_count(); i++) { const FileDescriptor* dep = file->dependency(i); CollectMinimalFileDepsContainingExtensionsWorker(dep, files, @@ -229,12 +229,12 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { "CF_EXTERN_C_BEGIN\n" "\n"); - set<string> fwd_decls; + std::set<string> fwd_decls; for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); iter != message_generators_.end(); ++iter) { (*iter)->DetermineForwardDeclarations(&fwd_decls); } - for (set<string>::const_iterator i(fwd_decls.begin()); + for (std::set<string>::const_iterator i(fwd_decls.begin()); i != fwd_decls.end(); ++i) { printer->Print("$value$;\n", "value", *i); } @@ -325,7 +325,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) { // #import the headers for anything that a plain dependency of this proto // file (that means they were just an include, not a "public" include). - set<string> public_import_names; + std::set<string> public_import_names; for (int i = 0; i < file_->public_dependency_count(); i++) { public_import_names.insert(file_->public_dependency(i)->name()); } @@ -468,7 +468,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) { // File descriptor only needed if there are messages to use it. if (message_generators_.size() > 0) { - map<string, string> vars; + std::map<string, string> vars; vars["root_class_name"] = root_class_name_; vars["package"] = file_->package(); vars["objc_prefix"] = FileClassPrefix(file_); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index bb8170a9..72b5d5f5 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -28,9 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifdef _MSC_VER -#include <io.h> -#else +#ifndef _MSC_VER #include <unistd.h> #endif #include <climits> @@ -49,8 +47,15 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/strutil.h> +#if defined(_WIN32) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::open; +#endif + // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. @@ -980,13 +985,13 @@ namespace { class ExpectedPrefixesCollector : public LineConsumer { public: - ExpectedPrefixesCollector(map<string, string>* inout_package_to_prefix_map) + ExpectedPrefixesCollector(std::map<string, string>* inout_package_to_prefix_map) : prefix_map_(inout_package_to_prefix_map) {} virtual bool ConsumeLine(const StringPiece& line, string* out_error); private: - map<string, string>* prefix_map_; + std::map<string, string>* prefix_map_; }; bool ExpectedPrefixesCollector::ConsumeLine( @@ -1009,7 +1014,7 @@ bool ExpectedPrefixesCollector::ConsumeLine( } bool LoadExpectedPackagePrefixes(const Options &generation_options, - map<string, string>* prefix_map, + std::map<string, string>* prefix_map, string* out_error) { if (generation_options.expected_prefixes_path.empty()) { return true; @@ -1023,7 +1028,7 @@ bool LoadExpectedPackagePrefixes(const Options &generation_options, bool ValidateObjCClassPrefix( const FileDescriptor* file, const string& expected_prefixes_path, - const map<string, string>& expected_package_prefixes, + const std::map<string, string>& expected_package_prefixes, string* out_error) { const string prefix = file->options().objc_class_prefix(); const string package = file->package(); @@ -1033,7 +1038,7 @@ bool ValidateObjCClassPrefix( // Check: Error - See if there was an expected prefix for the package and // report if it doesn't match (wrong or missing). - map<string, string>::const_iterator package_match = + std::map<string, string>::const_iterator package_match = expected_package_prefixes.find(package); if (package_match != expected_package_prefixes.end()) { // There was an entry, and... @@ -1082,7 +1087,7 @@ bool ValidateObjCClassPrefix( // Look for any other package that uses the same prefix. string other_package_for_prefix; - for (map<string, string>::const_iterator i = expected_package_prefixes.begin(); + for (std::map<string, string>::const_iterator i = expected_package_prefixes.begin(); i != expected_package_prefixes.end(); ++i) { if (i->second == prefix) { other_package_for_prefix = i->first; @@ -1150,7 +1155,7 @@ bool ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files, const Options& generation_options, string* out_error) { // Load the expected package prefixes, if available, to validate against. - map<string, string> expected_package_prefixes; + std::map<string, string> expected_package_prefixes; if (!LoadExpectedPackagePrefixes(generation_options, &expected_package_prefixes, out_error)) { @@ -1519,7 +1524,7 @@ void ImportWriter::AddFile(const FileDescriptor* file, ParseFrameworkMappings(); } - map<string, string>::iterator proto_lookup = + std::map<string, string>::iterator proto_lookup = proto_file_to_framework_name_.find(file->name()); if (proto_lookup != proto_file_to_framework_name_.end()) { other_framework_imports_.push_back( @@ -1640,7 +1645,7 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( StringPiece proto_file(proto_file_list, start, offset - start); StringPieceTrimWhitespace(&proto_file); if (proto_file.size() != 0) { - map<string, string>::iterator existing_entry = + std::map<string, string>::iterator existing_entry = map_->find(proto_file.ToString()); if (existing_entry != map_->end()) { std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index c99262a1..daea7609 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -262,20 +262,20 @@ class LIBPROTOC_EXPORT ImportWriter { private: class ProtoFrameworkCollector : public LineConsumer { public: - ProtoFrameworkCollector(map<string, string>* inout_proto_file_to_framework_name) + ProtoFrameworkCollector(std::map<string, string>* inout_proto_file_to_framework_name) : map_(inout_proto_file_to_framework_name) {} virtual bool ConsumeLine(const StringPiece& line, string* out_error); private: - map<string, string>* map_; + std::map<string, string>* map_; }; void ParseFrameworkMappings(); const string generate_for_named_framework_; const string named_framework_to_proto_path_mappings_path_; - map<string, string> proto_file_to_framework_name_; + std::map<string, string> proto_file_to_framework_name_; bool need_to_parse_mapping_file_; vector<string> protobuf_framework_imports_; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc index 0bc9dc10..bcaf5709 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc @@ -162,7 +162,7 @@ void MapFieldGenerator::FinishInitialization(void) { } void MapFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls); const FieldDescriptor* value_descriptor = descriptor_->message_type()->FindFieldByName("value"); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index bc68a682..6664d849 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -51,7 +51,7 @@ class MapFieldGenerator : public RepeatedFieldGenerator { MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options); virtual ~MapFieldGenerator(); - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; private: scoped_ptr<FieldGenerator> value_field_generator_; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 0a554a83..4f22e290 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -233,7 +233,7 @@ void MessageGenerator::GenerateStaticVariablesInitialization( } } -void MessageGenerator::DetermineForwardDeclarations(set<string>* fwd_decls) { +void MessageGenerator::DetermineForwardDeclarations(std::set<string>* fwd_decls) { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); @@ -514,7 +514,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " };\n"); } - map<string, string> vars; + std::map<string, string> vars; vars["classname"] = class_name_; vars["rootclassname"] = root_classname_; vars["fields"] = has_fields ? "fields" : "NULL"; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 0fb78bc0..8f317ac0 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -64,7 +64,7 @@ class MessageGenerator { void GenerateMessageHeader(io::Printer* printer); void GenerateSource(io::Printer* printer); void GenerateExtensionRegistrationSource(io::Printer* printer); - void DetermineForwardDeclarations(set<string>* fwd_decls); + void DetermineForwardDeclarations(std::set<string>* fwd_decls); // Checks if the message or a nested message includes a oneof definition. bool IncludesOneOfDefinition() const; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index d6ccd6d1..699d25b3 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -45,7 +45,7 @@ namespace objectivec { namespace { void SetMessageVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { const string& message_type = ClassName(descriptor->message_type()); (*variables)["type"] = message_type; (*variables)["containing_class"] = ClassName(descriptor->containing_type()); @@ -67,7 +67,7 @@ MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor, MessageFieldGenerator::~MessageFieldGenerator() {} void MessageFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { ObjCObjFieldGenerator::DetermineForwardDeclarations(fwd_decls); // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); @@ -95,7 +95,7 @@ RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {} void RepeatedMessageFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls); // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index d2dba153..50f4b6d4 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -51,7 +51,7 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator { virtual bool WantsHasProperty(void) const; public: - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); @@ -67,7 +67,7 @@ class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { virtual ~RepeatedMessageFieldGenerator(); public: - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h index 3d9df4db..ff353a6c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h @@ -67,7 +67,7 @@ class OneofGenerator { private: const OneofDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofGenerator); }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index d49350f4..aa8ac324 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -118,7 +118,7 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) { } void SetPrimitiveVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { std::string primitive_name = PrimitiveTypeName(descriptor); (*variables)["type"] = primitive_name; (*variables)["storage_type"] = primitive_name; diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 03aebdb9..60e6fce9 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -82,6 +82,10 @@ void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, int is_descriptor); void GenerateEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value); +void GenerateServiceDocComment(io::Printer* printer, + const ServiceDescriptor* service); +void GenerateServiceMethodDocComment(io::Printer* printer, + const MethodDescriptor* method); std::string RenameEmpty(const std::string& name) { if (name == "Empty") { @@ -139,17 +143,9 @@ std::string ClassNamePrefix(const string& classname, return ""; } - template <typename DescriptorType> -std::string FullClassName(const DescriptorType* desc, bool is_descriptor) { - string classname = desc->name(); - const Descriptor* containing = desc->containing_type(); - while (containing != NULL) { - classname = containing->name() + '_' + classname; - containing = containing->containing_type(); - } - classname = ClassNamePrefix(classname, desc) + classname; - +std::string NamespacedName(const string& classname, + const DescriptorType* desc, bool is_descriptor) { if (desc->file()->options().has_php_namespace()) { const string& php_namespace = desc->file()->options().php_namespace(); if (php_namespace != "") { @@ -167,6 +163,24 @@ std::string FullClassName(const DescriptorType* desc, bool is_descriptor) { } } +template <typename DescriptorType> +std::string FullClassName(const DescriptorType* desc, bool is_descriptor) { + string classname = desc->name(); + const Descriptor* containing = desc->containing_type(); + while (containing != NULL) { + classname = containing->name() + '_' + classname; + containing = containing->containing_type(); + } + classname = ClassNamePrefix(classname, desc) + classname; + return NamespacedName(classname, desc, is_descriptor); +} + +std::string FullClassName(const ServiceDescriptor* desc, bool is_descriptor) { + string classname = desc->name(); + classname = ClassNamePrefix(classname, desc) + classname; + return NamespacedName(classname, desc, is_descriptor); +} + std::string PhpName(const std::string& full_name, bool is_descriptor) { if (is_descriptor) { return kDescriptorPackageName; @@ -272,6 +286,17 @@ std::string GeneratedEnumFileName(const EnumDescriptor* en, return result + ".php"; } +std::string GeneratedServiceFileName(const ServiceDescriptor* service, + bool is_descriptor) { + std::string result = FullClassName(service, is_descriptor) + "Interface"; + for (int i = 0; i < result.size(); i++) { + if (result[i] == '\\') { + result[i] = '/'; + } + } + return result + ".php"; +} + std::string IntToString(int32 value) { std::ostringstream os; os << value; @@ -534,12 +559,9 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, // Generate setter. GenerateFieldDocComment(printer, field, is_descriptor, kFieldSetter); printer->Print( - "public function set^camel_name^(^var^)\n" + "public function set^camel_name^($var)\n" "{\n", - "camel_name", UnderscoresToCamelCase(field->name(), true), - "var", (field->is_repeated() || - field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ? - "&$var": "$var"); + "camel_name", UnderscoresToCamelCase(field->name(), true)); Indent(printer); @@ -663,6 +685,16 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { Outdent(printer); } +void GenerateServiceMethod(const MethodDescriptor* method, + io::Printer* printer) { + printer->Print( + "public function ^camel_name^(\\^request_name^ $request);\n\n", + "camel_name", UnderscoresToCamelCase(method->name(), false), + "request_name", FullClassName( + method->input_type(), false) + ); +} + void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, io::Printer* printer) { // Don't generate MapEntry messages -- we use the PHP extension's native @@ -844,7 +876,7 @@ void GenerateUseDeclaration(bool is_descriptor, io::Printer* printer) { "use Google\\Protobuf\\Internal\\GPBType;\n" "use Google\\Protobuf\\Internal\\GPBWire;\n" "use Google\\Protobuf\\Internal\\RepeatedField;\n" - "use Google\\Protobuf\\Internal\\InputStream;\n\n" + "use Google\\Protobuf\\Internal\\InputStream;\n" "use Google\\Protobuf\\Internal\\GPBUtil;\n\n"); } } @@ -1064,6 +1096,58 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, } } +void GenerateServiceFile(const FileDescriptor* file, + const ServiceDescriptor* service, bool is_descriptor, + GeneratorContext* generator_context) { + std::string filename = GeneratedServiceFileName(service, is_descriptor); + scoped_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(filename)); + io::Printer printer(output.get(), '^'); + + GenerateHead(file, &printer); + + std::string fullname = FilenameToClassname(filename); + int lastindex = fullname.find_last_of("\\"); + + if (file->options().has_php_namespace()) { + const string& php_namespace = file->options().php_namespace(); + if (!php_namespace.empty()) { + printer.Print( + "namespace ^name^;\n\n", + "name", php_namespace); + } + } else if (!file->package().empty()) { + printer.Print( + "namespace ^name^;\n\n", + "name", fullname.substr(0, lastindex)); + } + + GenerateServiceDocComment(&printer, service); + + if (lastindex != string::npos) { + printer.Print( + "interface ^name^\n" + "{\n", + "name", fullname.substr(lastindex + 1)); + } else { + printer.Print( + "interface ^name^\n" + "{\n", + "name", fullname); + } + + Indent(&printer); + + for (int i = 0; i < service->method_count(); i++) { + const MethodDescriptor* method = service->method(i); + GenerateServiceMethodDocComment(&printer, method); + GenerateServiceMethod(method, &printer); + } + + Outdent(&printer); + printer.Print("}\n\n"); +} + void GenerateFile(const FileDescriptor* file, bool is_descriptor, GeneratorContext* generator_context) { GenerateMetadataFile(file, is_descriptor, generator_context); @@ -1075,6 +1159,12 @@ void GenerateFile(const FileDescriptor* file, bool is_descriptor, GenerateEnumFile(file, file->enum_type(i), is_descriptor, generator_context); } + if (file->options().php_generic_services()) { + for (int i = 0; i < file->service_count(); i++) { + GenerateServiceFile(file, file->service(i), is_descriptor, + generator_context); + } + } } static string EscapePhpdoc(const string& input) { @@ -1183,6 +1273,16 @@ void GenerateMessageDocComment(io::Printer* printer, "messagename", EscapePhpdoc(message->full_name())); } +void GenerateServiceDocComment(io::Printer* printer, + const ServiceDescriptor* service) { + printer->Print("/**\n"); + GenerateDocCommentBody(printer, service); + printer->Print( + " * Protobuf type <code>^fullname^</code>\n" + " */\n", + "fullname", EscapePhpdoc(service->full_name())); +} + void GenerateFieldDocComment(io::Printer* printer, const FieldDescriptor* field, int is_descriptor, int function_type) { // In theory we should have slightly different comments for setters, getters, @@ -1229,6 +1329,23 @@ void GenerateEnumValueDocComment(io::Printer* printer, "def", EscapePhpdoc(FirstLineOf(value->DebugString()))); } +void GenerateServiceMethodDocComment(io::Printer* printer, + const MethodDescriptor* method) { + printer->Print("/**\n"); + GenerateDocCommentBody(printer, method); + printer->Print( + " * Method <code>^method_name^</code>\n" + " *\n", + "method_name", EscapePhpdoc(UnderscoresToCamelCase(method->name(), false))); + printer->Print( + " * @param \\^input_type^ $request\n", + "input_type", EscapePhpdoc(FullClassName(method->input_type(), false))); + printer->Print( + " * @return \\^return_type^\n" + " */\n", + "return_type", EscapePhpdoc(FullClassName(method->output_type(), false))); +} + bool Generator::Generate(const FileDescriptor* file, const string& parameter, GeneratorContext* generator_context, string* error) const { diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index 3848101d..e8ffbb51 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -36,18 +36,12 @@ #include <set> #ifdef _WIN32 -#include <io.h> #include <fcntl.h> -#ifndef STDIN_FILENO -#define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -#define STDOUT_FILENO 1 -#endif #else #include <unistd.h> #endif +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/plugin.pb.h> @@ -55,6 +49,11 @@ #include <google/protobuf/descriptor.h> #include <google/protobuf/io/zero_copy_stream_impl.h> +#if defined(_WIN32) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::setmode; +#endif namespace google { namespace protobuf { @@ -150,8 +149,8 @@ int PluginMain(int argc, char* argv[], const CodeGenerator* generator) { } #ifdef _WIN32 - _setmode(STDIN_FILENO, _O_BINARY); - _setmode(STDOUT_FILENO, _O_BINARY); + setmode(STDIN_FILENO, _O_BINARY); + setmode(STDOUT_FILENO, _O_BINARY); #endif CodeGeneratorRequest request; diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 87fcc40f..3842ef61 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -201,7 +201,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -430,6 +430,7 @@ void Version::SerializeWithCachedSizes( ::google::protobuf::uint8* Version::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.Version) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -967,6 +968,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( ::google::protobuf::uint8* CodeGeneratorRequest::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorRequest) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1577,6 +1579,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( ::google::protobuf::uint8* CodeGeneratorResponse_File::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse.File) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2101,6 +2104,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( ::google::protobuf::uint8* CodeGeneratorResponse::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index c8ae8774..57e1f77b 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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/profile.pb.cc b/src/google/protobuf/compiler/profile.pb.cc index 223dcc21..bf69f79d 100644 --- a/src/google/protobuf/compiler/profile.pb.cc +++ b/src/google/protobuf/compiler/profile.pb.cc @@ -167,7 +167,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -396,6 +396,7 @@ void FieldAccessInfo::SerializeWithCachedSizes( ::google::protobuf::uint8* FieldAccessInfo::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.FieldAccessInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -892,6 +893,7 @@ void MessageAccessInfo::SerializeWithCachedSizes( ::google::protobuf::uint8* MessageAccessInfo::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.MessageAccessInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1298,6 +1300,7 @@ void AccessInfo::SerializeWithCachedSizes( ::google::protobuf::uint8* AccessInfo::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.AccessInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/compiler/profile.pb.h b/src/google/protobuf/compiler/profile.pb.h index d20b87ed..b4931cf1 100644 --- a/src/google/protobuf/compiler/profile.pb.h +++ b/src/google/protobuf/compiler/profile.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/descriptor.pb.cc index 6e4e4088..04c6b8e1 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -297,6 +297,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, cc_generic_services_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_generic_services_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, py_generic_services_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, php_generic_services_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, deprecated_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, cc_enable_arenas_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, objc_class_prefix_), @@ -310,13 +311,14 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { 8, 9, 10, - 16, + 17, 2, 11, 12, 13, 14, 15, + 16, 3, 4, 5, @@ -488,20 +490,20 @@ static const ::google::protobuf::internal::MigrationSchema schemas[] = { { 124, 132, sizeof(EnumValueDescriptorProto)}, { 135, 143, sizeof(ServiceDescriptorProto)}, { 146, 157, sizeof(MethodDescriptorProto)}, - { 163, 186, sizeof(FileOptions)}, - { 204, 214, sizeof(MessageOptions)}, - { 219, 231, sizeof(FieldOptions)}, - { 238, 244, sizeof(OneofOptions)}, - { 245, 253, sizeof(EnumOptions)}, - { 256, 263, sizeof(EnumValueOptions)}, - { 265, 272, sizeof(ServiceOptions)}, - { 274, 282, sizeof(MethodOptions)}, - { 285, 292, sizeof(UninterpretedOption_NamePart)}, - { 294, 306, sizeof(UninterpretedOption)}, - { 313, 323, sizeof(SourceCodeInfo_Location)}, - { 328, 334, sizeof(SourceCodeInfo)}, - { 335, 344, sizeof(GeneratedCodeInfo_Annotation)}, - { 348, 354, sizeof(GeneratedCodeInfo)}, + { 163, 187, sizeof(FileOptions)}, + { 206, 216, sizeof(MessageOptions)}, + { 221, 233, sizeof(FieldOptions)}, + { 240, 246, sizeof(OneofOptions)}, + { 247, 255, sizeof(EnumOptions)}, + { 258, 265, sizeof(EnumValueOptions)}, + { 267, 274, sizeof(ServiceOptions)}, + { 276, 284, sizeof(MethodOptions)}, + { 287, 294, sizeof(UninterpretedOption_NamePart)}, + { 296, 308, sizeof(UninterpretedOption)}, + { 315, 325, sizeof(SourceCodeInfo_Location)}, + { 330, 336, sizeof(SourceCodeInfo)}, + { 337, 346, sizeof(GeneratedCodeInfo_Annotation)}, + { 350, 356, sizeof(GeneratedCodeInfo)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -729,7 +731,7 @@ void AddDescriptorsImpl() { "\n\013output_type\030\003 \001(\t\022/\n\007options\030\004 \001(\0132\036.g" "oogle.protobuf.MethodOptions\022\037\n\020client_s" "treaming\030\005 \001(\010:\005false\022\037\n\020server_streamin" - "g\030\006 \001(\010:\005false\"\313\005\n\013FileOptions\022\024\n\014java_p" + "g\030\006 \001(\010:\005false\"\360\005\n\013FileOptions\022\024\n\014java_p" "ackage\030\001 \001(\t\022\034\n\024java_outer_classname\030\010 \001" "(\t\022\"\n\023java_multiple_files\030\n \001(\010:\005false\022)" "\n\035java_generate_equals_and_hash\030\024 \001(\010B\002\030" @@ -739,75 +741,76 @@ void AddDescriptorsImpl() { "ackage\030\013 \001(\t\022\"\n\023cc_generic_services\030\020 \001(" "\010:\005false\022$\n\025java_generic_services\030\021 \001(\010:" "\005false\022\"\n\023py_generic_services\030\022 \001(\010:\005fal" - "se\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_enab" - "le_arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_pre" - "fix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014s" - "wift_prefix\030\' \001(\t\022\030\n\020php_class_prefix\030( " - "\001(\t\022\025\n\rphp_namespace\030) \001(\t\022C\n\024uninterpre" - "ted_option\030\347\007 \003(\0132$.google.protobuf.Unin" - "terpretedOption\":\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\027messa" - "ge_set_wire_format\030\001 \001(\010:\005false\022.\n\037no_st" - "andard_descriptor_accessor\030\002 \001(\010:\005false\022" - "\031\n\ndeprecated\030\003 \001(\010:\005false\022\021\n\tmap_entry\030" - "\007 \001(\010\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.g" - "oogle.protobuf.UninterpretedOption*\t\010\350\007\020" - "\200\200\200\200\002J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n\014FieldOptions\022:\n\005ct" - "ype\030\001 \001(\0162#.google.protobuf.FieldOptions" - ".CType:\006STRING\022\016\n\006packed\030\002 \001(\010\022\?\n\006jstype" - "\030\006 \001(\0162$.google.protobuf.FieldOptions.JS" - "Type:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010:\005false\022\031\n\n" - "deprecated\030\003 \001(\010:\005false\022\023\n\004weak\030\n \001(\010:\005f" - "alse\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.go" - "ogle.protobuf.UninterpretedOption\"/\n\005CTy" - "pe\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014STRING_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\014On" - "eofOptions\022C\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_alia" - "s\030\002 \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005false\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\005\020\006" - "\"}\n\020EnumValueOptions\022\031\n\ndeprecated\030\001 \001(\010" - ":\005false\022C\n\024uninterpreted_option\030\347\007 \003(\0132$" + "se\022#\n\024php_generic_services\030\023 \001(\010:\005false\022" + "\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_enable_" + "arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_prefix" + "\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014swif" + "t_prefix\030\' \001(\t\022\030\n\020php_class_prefix\030( \001(\t" + "\022\025\n\rphp_namespace\030) \001(\t\022C\n\024uninterpreted" + "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" + "pretedOption\":\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_format\030\001 \001(\010:\005false\022.\n\037no_stand" + "ard_descriptor_accessor\030\002 \001(\010:\005false\022\031\n\n" + "deprecated\030\003 \001(\010:\005false\022\021\n\tmap_entry\030\007 \001" + "(\010\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.goog" + "le.protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200" + "\200\002J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n\014FieldOptions\022:\n\005ctype" + "\030\001 \001(\0162#.google.protobuf.FieldOptions.CT" + "ype:\006STRING\022\016\n\006packed\030\002 \001(\010\022\?\n\006jstype\030\006 " + "\001(\0162$.google.protobuf.FieldOptions.JSTyp" + "e:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010:\005false\022\031\n\ndep" + "recated\030\003 \001(\010:\005false\022\023\n\004weak\030\n \001(\010:\005fals" + "e\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" + "e.protobuf.UninterpretedOption\"/\n\005CType\022" + "\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014STRING_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\014Oneof" + "Options\022C\n\024uninterpreted_option\030\347\007 \003(\0132$" ".google.protobuf.UninterpretedOption*\t\010\350" - "\007\020\200\200\200\200\002\"{\n\016ServiceOptions\022\031\n\ndeprecated\030" - "! \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 " - "\003(\0132$.google.protobuf.UninterpretedOptio" - "n*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n\ndeprec" - "ated\030! \001(\010:\005false\022_\n\021idempotency_level\030\"" - " \001(\0162/.google.protobuf.MethodOptions.Ide" - "mpotencyLevel:\023IDEMPOTENCY_UNKNOWN\022C\n\024un" - "interpreted_option\030\347\007 \003(\0132$.google.proto" - "buf.UninterpretedOption\"P\n\020IdempotencyLe" - "vel\022\027\n\023IDEMPOTENCY_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" - "\023UninterpretedOption\022;\n\004name\030\002 \003(\0132-.goo" - "gle.protobuf.UninterpretedOption.NamePar" - "t\022\030\n\020identifier_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\014double_value\030\006 \001(\001\022\024\n\014string_valu" - "e\030\007 \001(\014\022\027\n\017aggregate_value\030\010 \001(\t\0323\n\010Name" - "Part\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_extension\030" - "\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010location\030\001 \003" - "(\0132(.google.protobuf.SourceCodeInfo.Loca" - "tion\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004s" - "pan\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_de" - "tached_comments\030\006 \003(\t\"\247\001\n\021GeneratedCodeI" - "nfo\022A\n\nannotation\030\001 \003(\0132-.google.protobu" - "f.GeneratedCodeInfo.Annotation\032O\n\nAnnota" - "tion\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\214\001\n\023com." - "google.protobufB\020DescriptorProtosH\001Z>git" - "hub.com/golang/protobuf/protoc-gen-go/de" - "scriptor;descriptor\242\002\003GPB\252\002\032Google.Proto" - "buf.Reflection" + "\007\020\200\200\200\200\002\"\223\001\n\013EnumOptions\022\023\n\013allow_alias\030\002" + " \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005false\022C\n\024unint" + "erpreted_option\030\347\007 \003(\0132$.google.protobuf" + ".UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\005\020\006\"}\n" + "\020EnumValueOptions\022\031\n\ndeprecated\030\001 \001(\010:\005f" + "alse\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.go" + "ogle.protobuf.UninterpretedOption*\t\010\350\007\020\200" + "\200\200\200\002\"{\n\016ServiceOptions\022\031\n\ndeprecated\030! \001" + "(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003(\013" + "2$.google.protobuf.UninterpretedOption*\t" + "\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n\ndeprecate" + "d\030! \001(\010:\005false\022_\n\021idempotency_level\030\" \001(" + "\0162/.google.protobuf.MethodOptions.Idempo" + "tencyLevel:\023IDEMPOTENCY_UNKNOWN\022C\n\024unint" + "erpreted_option\030\347\007 \003(\0132$.google.protobuf" + ".UninterpretedOption\"P\n\020IdempotencyLevel" + "\022\027\n\023IDEMPOTENCY_UNKNOWN\020\000\022\023\n\017NO_SIDE_EFF" + "ECTS\020\001\022\016\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023Un" + "interpretedOption\022;\n\004name\030\002 \003(\0132-.google" + ".protobuf.UninterpretedOption.NamePart\022\030" + "\n\020identifier_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\014double_value\030\006 \001(\001\022\024\n\014string_value\030\007" + " \001(\014\022\027\n\017aggregate_value\030\010 \001(\t\0323\n\010NamePar" + "t\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_extension\030\002 \002" + "(\010\"\325\001\n\016SourceCodeInfo\022:\n\010location\030\001 \003(\0132" + "(.google.protobuf.SourceCodeInfo.Locatio" + "n\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\021" + "trailing_comments\030\004 \001(\t\022!\n\031leading_detac" + "hed_comments\030\006 \003(\t\"\247\001\n\021GeneratedCodeInfo" + "\022A\n\nannotation\030\001 \003(\0132-.google.protobuf.G" + "eneratedCodeInfo.Annotation\032O\n\nAnnotatio" + "n\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\214\001\n\023com.goo" + "gle.protobufB\020DescriptorProtosH\001Z>github" + ".com/golang/protobuf/protoc-gen-go/descr" + "iptor;descriptor\242\002\003GPB\252\002\032Google.Protobuf" + ".Reflection" }; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - descriptor, 5614); + descriptor, 5651); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/descriptor.proto", &protobuf_RegisterTypes); ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); @@ -817,7 +820,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -1127,6 +1130,7 @@ void FileDescriptorSet::SerializeWithCachedSizes( ::google::protobuf::uint8* FileDescriptorSet::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorSet) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1730,6 +1734,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* FileDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2762,6 +2767,7 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( ::google::protobuf::uint8* DescriptorProto_ExtensionRange::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ExtensionRange) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3101,6 +3107,7 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes( ::google::protobuf::uint8* DescriptorProto_ReservedRange::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ReservedRange) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3644,6 +3651,7 @@ void DescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* DescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -4565,7 +4573,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( set_label(static_cast< ::google::protobuf::FieldDescriptorProto_Label >(value)); } else { mutable_unknown_fields()->AddVarint( - 4, static_cast<::google::protobuf::uint64>(value)); + 4, static_cast< ::google::protobuf::uint64>(value)); } } else { goto handle_unusual; @@ -4585,7 +4593,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( set_type(static_cast< ::google::protobuf::FieldDescriptorProto_Type >(value)); } else { mutable_unknown_fields()->AddVarint( - 5, static_cast<::google::protobuf::uint64>(value)); + 5, static_cast< ::google::protobuf::uint64>(value)); } } else { goto handle_unusual; @@ -4783,6 +4791,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* FieldDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -5725,6 +5734,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* OneofDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -6177,6 +6187,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* EnumDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -6683,6 +6694,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* EnumValueDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -7176,6 +7188,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* ServiceDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -7782,6 +7795,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::uint8* MethodDescriptorProto::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodDescriptorProto) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -8292,6 +8306,7 @@ const int FileOptions::kGoPackageFieldNumber; const int FileOptions::kCcGenericServicesFieldNumber; const int FileOptions::kJavaGenericServicesFieldNumber; const int FileOptions::kPyGenericServicesFieldNumber; +const int FileOptions::kPhpGenericServicesFieldNumber; const int FileOptions::kDeprecatedFieldNumber; const int FileOptions::kCcEnableArenasFieldNumber; const int FileOptions::kObjcClassPrefixFieldNumber; @@ -8451,10 +8466,13 @@ void FileOptions::Clear() { } if (_has_bits_[8 / 32] & 65280u) { ::memset(&java_multiple_files_, 0, static_cast<size_t>( - reinterpret_cast<char*>(&cc_enable_arenas_) - - reinterpret_cast<char*>(&java_multiple_files_)) + sizeof(cc_enable_arenas_)); + reinterpret_cast<char*>(&deprecated_) - + reinterpret_cast<char*>(&java_multiple_files_)) + sizeof(deprecated_)); + } + if (_has_bits_[16 / 32] & 196608u) { + cc_enable_arenas_ = false; + optimize_for_ = 1; } - optimize_for_ = 1; _has_bits_.Clear(); _internal_metadata_.Clear(); } @@ -8513,7 +8531,7 @@ bool FileOptions::MergePartialFromCodedStream( set_optimize_for(static_cast< ::google::protobuf::FileOptions_OptimizeMode >(value)); } else { mutable_unknown_fields()->AddVarint( - 9, static_cast<::google::protobuf::uint64>(value)); + 9, static_cast< ::google::protobuf::uint64>(value)); } } else { goto handle_unusual; @@ -8593,6 +8611,20 @@ bool FileOptions::MergePartialFromCodedStream( break; } + // optional bool php_generic_services = 19 [default = false]; + case 19: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(152u)) { + set_has_php_generic_services(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( + input, &php_generic_services_))); + } else { + goto handle_unusual; + } + break; + } + // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; case 20: { if (static_cast< ::google::protobuf::uint8>(tag) == @@ -8796,7 +8828,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (cached_has_bits & 0x00010000u) { + if (cached_has_bits & 0x00020000u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 9, this->optimize_for(), output); } @@ -8831,13 +8863,18 @@ void FileOptions::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteBool(18, this->py_generic_services(), output); } + // optional bool php_generic_services = 19 [default = false]; + if (cached_has_bits & 0x00004000u) { + ::google::protobuf::internal::WireFormatLite::WriteBool(19, this->php_generic_services(), output); + } + // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; if (cached_has_bits & 0x00000200u) { ::google::protobuf::internal::WireFormatLite::WriteBool(20, this->java_generate_equals_and_hash(), output); } // optional bool deprecated = 23 [default = false]; - if (cached_has_bits & 0x00004000u) { + if (cached_has_bits & 0x00008000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(23, this->deprecated(), output); } @@ -8847,7 +8884,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool cc_enable_arenas = 31 [default = false]; - if (cached_has_bits & 0x00008000u) { + if (cached_has_bits & 0x00010000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(31, this->cc_enable_arenas(), output); } @@ -8921,6 +8958,7 @@ void FileOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* FileOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -8949,7 +8987,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (cached_has_bits & 0x00010000u) { + if (cached_has_bits & 0x00020000u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 9, this->optimize_for(), target); } @@ -8985,13 +9023,18 @@ void FileOptions::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(18, this->py_generic_services(), target); } + // optional bool php_generic_services = 19 [default = false]; + if (cached_has_bits & 0x00004000u) { + target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(19, this->php_generic_services(), target); + } + // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; if (cached_has_bits & 0x00000200u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(20, this->java_generate_equals_and_hash(), target); } // optional bool deprecated = 23 [default = false]; - if (cached_has_bits & 0x00004000u) { + if (cached_has_bits & 0x00008000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(23, this->deprecated(), target); } @@ -9001,7 +9044,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool cc_enable_arenas = 31 [default = false]; - if (cached_has_bits & 0x00008000u) { + if (cached_has_bits & 0x00010000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(31, this->cc_enable_arenas(), target); } @@ -9191,23 +9234,30 @@ size_t FileOptions::ByteSizeLong() const { total_size += 2 + 1; } + // optional bool php_generic_services = 19 [default = false]; + if (has_php_generic_services()) { + total_size += 2 + 1; + } + // optional bool deprecated = 23 [default = false]; if (has_deprecated()) { total_size += 2 + 1; } + } + if (_has_bits_[16 / 32] & 196608u) { // optional bool cc_enable_arenas = 31 [default = false]; if (has_cc_enable_arenas()) { total_size += 2 + 1; } - } - // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (has_optimize_for()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::EnumSize(this->optimize_for()); - } + // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + if (has_optimize_for()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->optimize_for()); + } + } int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = cached_size; @@ -9294,15 +9344,21 @@ void FileOptions::MergeFrom(const FileOptions& from) { py_generic_services_ = from.py_generic_services_; } if (cached_has_bits & 0x00004000u) { - deprecated_ = from.deprecated_; + php_generic_services_ = from.php_generic_services_; } if (cached_has_bits & 0x00008000u) { - cc_enable_arenas_ = from.cc_enable_arenas_; + deprecated_ = from.deprecated_; } _has_bits_[0] |= cached_has_bits; } - if (cached_has_bits & 0x00010000u) { - set_optimize_for(from.optimize_for()); + if (cached_has_bits & 196608u) { + if (cached_has_bits & 0x00010000u) { + cc_enable_arenas_ = from.cc_enable_arenas_; + } + if (cached_has_bits & 0x00020000u) { + optimize_for_ = from.optimize_for_; + } + _has_bits_[0] |= cached_has_bits; } } @@ -9349,6 +9405,7 @@ void FileOptions::InternalSwap(FileOptions* other) { std::swap(cc_generic_services_, other->cc_generic_services_); std::swap(java_generic_services_, other->java_generic_services_); std::swap(py_generic_services_, other->py_generic_services_); + std::swap(php_generic_services_, other->php_generic_services_); std::swap(deprecated_, other->deprecated_); std::swap(cc_enable_arenas_, other->cc_enable_arenas_); std::swap(optimize_for_, other->optimize_for_); @@ -9566,13 +9623,13 @@ void FileOptions::set_java_string_check_utf8(bool value) { // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; bool FileOptions::has_optimize_for() const { - return (_has_bits_[0] & 0x00010000u) != 0; + return (_has_bits_[0] & 0x00020000u) != 0; } void FileOptions::set_has_optimize_for() { - _has_bits_[0] |= 0x00010000u; + _has_bits_[0] |= 0x00020000u; } void FileOptions::clear_has_optimize_for() { - _has_bits_[0] &= ~0x00010000u; + _has_bits_[0] &= ~0x00020000u; } void FileOptions::clear_optimize_for() { optimize_for_ = 1; @@ -9724,15 +9781,39 @@ void FileOptions::set_py_generic_services(bool value) { // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.py_generic_services) } +// optional bool php_generic_services = 19 [default = false]; +bool FileOptions::has_php_generic_services() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +void FileOptions::set_has_php_generic_services() { + _has_bits_[0] |= 0x00004000u; +} +void FileOptions::clear_has_php_generic_services() { + _has_bits_[0] &= ~0x00004000u; +} +void FileOptions::clear_php_generic_services() { + php_generic_services_ = false; + clear_has_php_generic_services(); +} +bool FileOptions::php_generic_services() const { + // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.php_generic_services) + return php_generic_services_; +} +void FileOptions::set_php_generic_services(bool value) { + set_has_php_generic_services(); + php_generic_services_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.php_generic_services) +} + // optional bool deprecated = 23 [default = false]; bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00004000u) != 0; + return (_has_bits_[0] & 0x00008000u) != 0; } void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00004000u; + _has_bits_[0] |= 0x00008000u; } void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00004000u; + _has_bits_[0] &= ~0x00008000u; } void FileOptions::clear_deprecated() { deprecated_ = false; @@ -9750,13 +9831,13 @@ void FileOptions::set_deprecated(bool value) { // optional bool cc_enable_arenas = 31 [default = false]; bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00008000u) != 0; + return (_has_bits_[0] & 0x00010000u) != 0; } void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00008000u; + _has_bits_[0] |= 0x00010000u; } void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00008000u; + _has_bits_[0] &= ~0x00010000u; } void FileOptions::clear_cc_enable_arenas() { cc_enable_arenas_ = false; @@ -10354,6 +10435,7 @@ void MessageOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* MessageOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MessageOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -10774,7 +10856,7 @@ bool FieldOptions::MergePartialFromCodedStream( set_ctype(static_cast< ::google::protobuf::FieldOptions_CType >(value)); } else { mutable_unknown_fields()->AddVarint( - 1, static_cast<::google::protobuf::uint64>(value)); + 1, static_cast< ::google::protobuf::uint64>(value)); } } else { goto handle_unusual; @@ -10836,7 +10918,7 @@ bool FieldOptions::MergePartialFromCodedStream( set_jstype(static_cast< ::google::protobuf::FieldOptions_JSType >(value)); } else { mutable_unknown_fields()->AddVarint( - 6, static_cast<::google::protobuf::uint64>(value)); + 6, static_cast< ::google::protobuf::uint64>(value)); } } else { goto handle_unusual; @@ -10956,6 +11038,7 @@ void FieldOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* FieldOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -11494,6 +11577,7 @@ void OneofOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* OneofOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -11843,6 +11927,7 @@ void EnumOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* EnumOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -12247,6 +12332,7 @@ void EnumValueOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* EnumValueOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -12607,6 +12693,7 @@ void ServiceOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* ServiceOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -12917,7 +13004,7 @@ bool MethodOptions::MergePartialFromCodedStream( set_idempotency_level(static_cast< ::google::protobuf::MethodOptions_IdempotencyLevel >(value)); } else { mutable_unknown_fields()->AddVarint( - 34, static_cast<::google::protobuf::uint64>(value)); + 34, static_cast< ::google::protobuf::uint64>(value)); } } else { goto handle_unusual; @@ -13002,6 +13089,7 @@ void MethodOptions::SerializeWithCachedSizes( ::google::protobuf::uint8* MethodOptions::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodOptions) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -13413,6 +13501,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( ::google::protobuf::uint8* UninterpretedOption_NamePart::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption.NamePart) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -13960,6 +14049,7 @@ void UninterpretedOption::SerializeWithCachedSizes( ::google::protobuf::uint8* UninterpretedOption::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -14703,7 +14793,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( // repeated int32 path = 1 [packed = true]; if (this->path_size() > 0) { ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output); - output->WriteVarint32(static_cast<::google::protobuf::uint32>( + output->WriteVarint32(static_cast< ::google::protobuf::uint32>( _path_cached_byte_size_)); } for (int i = 0, n = this->path_size(); i < n; i++) { @@ -14714,7 +14804,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( // repeated int32 span = 2 [packed = true]; if (this->span_size() > 0) { ::google::protobuf::internal::WireFormatLite::WriteTag(2, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output); - output->WriteVarint32(static_cast<::google::protobuf::uint32>( + output->WriteVarint32(static_cast< ::google::protobuf::uint32>( _span_cached_byte_size_)); } for (int i = 0, n = this->span_size(); i < n; i++) { @@ -14762,6 +14852,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( ::google::protobuf::uint8* SourceCodeInfo_Location::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo.Location) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -14773,7 +14864,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, target); target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray( - static_cast<::google::protobuf::uint32>( + static_cast< ::google::protobuf::uint32>( _path_cached_byte_size_), target); target = ::google::protobuf::internal::WireFormatLite:: WriteInt32NoTagToArray(this->path_, target); @@ -14786,7 +14877,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, target); target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray( - static_cast<::google::protobuf::uint32>( + static_cast< ::google::protobuf::uint32>( _span_cached_byte_size_), target); target = ::google::protobuf::internal::WireFormatLite:: WriteInt32NoTagToArray(this->span_, target); @@ -14849,7 +14940,7 @@ size_t SourceCodeInfo_Location::ByteSizeLong() const { if (data_size > 0) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( - static_cast<google::protobuf::int32>(data_size)); + static_cast< ::google::protobuf::int32>(data_size)); } int cached_size = ::google::protobuf::internal::ToCachedSize(data_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); @@ -14865,7 +14956,7 @@ size_t SourceCodeInfo_Location::ByteSizeLong() const { if (data_size > 0) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( - static_cast<google::protobuf::int32>(data_size)); + static_cast< ::google::protobuf::int32>(data_size)); } int cached_size = ::google::protobuf::internal::ToCachedSize(data_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); @@ -15373,6 +15464,7 @@ void SourceCodeInfo::SerializeWithCachedSizes( ::google::protobuf::uint8* SourceCodeInfo::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -15707,7 +15799,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( // repeated int32 path = 1 [packed = true]; if (this->path_size() > 0) { ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output); - output->WriteVarint32(static_cast<::google::protobuf::uint32>( + output->WriteVarint32(static_cast< ::google::protobuf::uint32>( _path_cached_byte_size_)); } for (int i = 0, n = this->path_size(); i < n; i++) { @@ -15745,6 +15837,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( ::google::protobuf::uint8* GeneratedCodeInfo_Annotation::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo.Annotation) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -15756,7 +15849,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, target); target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray( - static_cast<::google::protobuf::uint32>( + static_cast< ::google::protobuf::uint32>( _path_cached_byte_size_), target); target = ::google::protobuf::internal::WireFormatLite:: WriteInt32NoTagToArray(this->path_, target); @@ -15808,7 +15901,7 @@ size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const { if (data_size > 0) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( - static_cast<google::protobuf::int32>(data_size)); + static_cast< ::google::protobuf::int32>(data_size)); } int cached_size = ::google::protobuf::internal::ToCachedSize(data_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); @@ -16201,6 +16294,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( ::google::protobuf::uint8* GeneratedCodeInfo::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index f64a339c..2aaa9fde 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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. @@ -2290,6 +2290,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p bool py_generic_services() const; void set_py_generic_services(bool value); + // optional bool php_generic_services = 19 [default = false]; + bool has_php_generic_services() const; + void clear_php_generic_services(); + static const int kPhpGenericServicesFieldNumber = 19; + bool php_generic_services() const; + void set_php_generic_services(bool value); + // optional bool deprecated = 23 [default = false]; bool has_deprecated() const; void clear_deprecated(); @@ -2334,6 +2341,8 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p void clear_has_java_generic_services(); void set_has_py_generic_services(); void clear_has_py_generic_services(); + void set_has_php_generic_services(); + void clear_has_php_generic_services(); void set_has_deprecated(); void clear_has_deprecated(); void set_has_cc_enable_arenas(); @@ -2369,6 +2378,7 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p bool cc_generic_services_; bool java_generic_services_; bool py_generic_services_; + bool php_generic_services_; bool deprecated_; bool cc_enable_arenas_; int optimize_for_; @@ -6644,13 +6654,13 @@ inline void FileOptions::set_java_string_check_utf8(bool value) { // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; inline bool FileOptions::has_optimize_for() const { - return (_has_bits_[0] & 0x00010000u) != 0; + return (_has_bits_[0] & 0x00020000u) != 0; } inline void FileOptions::set_has_optimize_for() { - _has_bits_[0] |= 0x00010000u; + _has_bits_[0] |= 0x00020000u; } inline void FileOptions::clear_has_optimize_for() { - _has_bits_[0] &= ~0x00010000u; + _has_bits_[0] &= ~0x00020000u; } inline void FileOptions::clear_optimize_for() { optimize_for_ = 1; @@ -6802,15 +6812,39 @@ inline void FileOptions::set_py_generic_services(bool value) { // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.py_generic_services) } +// optional bool php_generic_services = 19 [default = false]; +inline bool FileOptions::has_php_generic_services() const { + return (_has_bits_[0] & 0x00004000u) != 0; +} +inline void FileOptions::set_has_php_generic_services() { + _has_bits_[0] |= 0x00004000u; +} +inline void FileOptions::clear_has_php_generic_services() { + _has_bits_[0] &= ~0x00004000u; +} +inline void FileOptions::clear_php_generic_services() { + php_generic_services_ = false; + clear_has_php_generic_services(); +} +inline bool FileOptions::php_generic_services() const { + // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.php_generic_services) + return php_generic_services_; +} +inline void FileOptions::set_php_generic_services(bool value) { + set_has_php_generic_services(); + php_generic_services_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.php_generic_services) +} + // optional bool deprecated = 23 [default = false]; inline bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00004000u) != 0; + return (_has_bits_[0] & 0x00008000u) != 0; } inline void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00004000u; + _has_bits_[0] |= 0x00008000u; } inline void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00004000u; + _has_bits_[0] &= ~0x00008000u; } inline void FileOptions::clear_deprecated() { deprecated_ = false; @@ -6828,13 +6862,13 @@ inline void FileOptions::set_deprecated(bool value) { // optional bool cc_enable_arenas = 31 [default = false]; inline bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00008000u) != 0; + return (_has_bits_[0] & 0x00010000u) != 0; } inline void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00008000u; + _has_bits_[0] |= 0x00010000u; } inline void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00008000u; + _has_bits_[0] &= ~0x00010000u; } inline void FileOptions::clear_cc_enable_arenas() { cc_enable_arenas_ = false; diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index c7fbaaf6..70b82a4d 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -351,6 +351,7 @@ message FileOptions { optional bool cc_generic_services = 16 [default=false]; optional bool java_generic_services = 17 [default=false]; optional bool py_generic_services = 18 [default=false]; + optional bool php_generic_services = 19 [default=false]; // Is this file deprecated? // Depending on the target platform, this can emit Deprecated annotations diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 1933c6d2..3892b197 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -123,7 +123,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -151,9 +151,7 @@ Duration::Duration() Duration::Duration(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Duration) @@ -301,6 +299,7 @@ void Duration::SerializeWithCachedSizes( ::google::protobuf::uint8* Duration::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 34873d97..02679c6a 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/empty.pb.cc index 71195056..86a77b61 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -120,7 +120,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -146,9 +146,7 @@ Empty::Empty() Empty::Empty(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Empty) @@ -244,6 +242,7 @@ void Empty::SerializeWithCachedSizes( ::google::protobuf::uint8* Empty::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Empty) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index f28dc19b..306301a4 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/field_mask.pb.cc index d7efd083..faba7a02 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -122,7 +122,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -264,6 +264,7 @@ void FieldMask::SerializeWithCachedSizes( ::google::protobuf::uint8* FieldMask::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 742c1cf9..42110be6 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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/generated_message_table_driven.cc b/src/google/protobuf/generated_message_table_driven.cc index e281266d..f8fda9c6 100644 --- a/src/google/protobuf/generated_message_table_driven.cc +++ b/src/google/protobuf/generated_message_table_driven.cc @@ -74,7 +74,7 @@ inline Arena* GetArena(MessageLite* msg, int64 arena_offset) { template <typename Type> inline Type* AddField(MessageLite* msg, int64 offset) { #if LANG_CXX11 - static_assert(std::is_trivially_copy_assignable<Type>::value, + static_assert(google::protobuf::internal::has_trivial_copy<Type>::value, "Do not assign"); #endif @@ -94,7 +94,7 @@ inline string* AddField<string>(MessageLite* msg, int64 offset) { template <typename Type> inline void AddField(MessageLite* msg, int64 offset, Type value) { #if LANG_CXX11 - static_assert(std::is_trivially_copy_assignable<Type>::value, + static_assert(google::protobuf::internal::has_trivial_copy<Type>::value, "Do not assign"); #endif *AddField<Type>(msg, offset) = value; @@ -118,7 +118,7 @@ template <typename Type> inline void SetField(MessageLite* msg, uint32* has_bits, uint32 has_bit_index, int64 offset, Type value) { #if LANG_CXX11 - static_assert(std::is_trivially_copy_assignable<Type>::value, + static_assert(google::protobuf::internal::has_trivial_copy<Type>::value, "Do not assign"); #endif *MutableField<Type>(msg, has_bits, has_bit_index, offset) = value; diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index a7154b40..c16bd728 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -100,7 +100,7 @@ namespace internal { // choose 16 rather than some other number just in case the compiler would // be confused by an unaligned pointer. #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - static_cast<int>( \ + static_cast< ::google::protobuf::uint32>( \ reinterpret_cast<const char*>( \ &reinterpret_cast<const TYPE*>(16)->FIELD) - \ reinterpret_cast<const char*>(16)) diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 20d86143..9f1cf88c 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -1434,7 +1434,7 @@ inline bool CodedInputStream::IsFlat() const { } // namespace protobuf -#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) +#if defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) #pragma runtime_checks("c", restore) #endif // _MSC_VER && !defined(__INTEL_COMPILER) diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc index 109c55c1..c7372ac2 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -32,9 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#ifdef _MSC_VER -#include <io.h> -#else +#ifndef _MSC_VER #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> @@ -43,9 +41,9 @@ #include <errno.h> #include <iostream> #include <algorithm> - #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/stl_util.h> @@ -58,6 +56,13 @@ namespace io { // Win32 lseek is broken: If invoked on a non-seekable file descriptor, its // return value is undefined. We re-define it to always produce an error. #define lseek(fd, offset, origin) ((off_t)-1) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::access; +using google::protobuf::internal::win32::close; +using google::protobuf::internal::win32::open; +using google::protobuf::internal::win32::read; +using google::protobuf::internal::win32::write; #endif namespace { diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index 235cbca4..f3754087 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -47,9 +47,7 @@ // implementations. -#ifdef _MSC_VER -#include <io.h> -#else +#ifndef _MSC_VER #include <unistd.h> #endif #include <stdlib.h> @@ -72,6 +70,7 @@ #endif #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/testing/googletest.h> #include <google/protobuf/testing/file.h> @@ -84,6 +83,12 @@ namespace { #ifdef _WIN32 #define pipe(fds) _pipe(fds, 4096, O_BINARY) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::access; +using google::protobuf::internal::win32::mkdir; +using google::protobuf::internal::win32::open; +using google::protobuf::internal::win32::close; #endif #ifndef O_BINARY diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 28eaf031..6a88600c 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -862,14 +862,7 @@ class Map { size_type BucketNumber(const Key& k) const { // We inherit from hasher, so one-arg operator() provides a hash function. size_type h = (*const_cast<InnerMap*>(this))(k); - // To help prevent people from making assumptions about the hash function, - // we use the seed differently depending on NDEBUG. The default hash - // function, the seeding, etc., are all likely to change in the future. -#ifndef NDEBUG - return (h * (seed_ | 1)) & (num_buckets_ - 1); -#else return (h + seed_) & (num_buckets_ - 1); -#endif } bool IsMatch(const Key& k0, const Key& k1) const { diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h index 0cfed72f..e317b5ed 100644 --- a/src/google/protobuf/map_field_inl.h +++ b/src/google/protobuf/map_field_inl.h @@ -252,9 +252,9 @@ template <typename Derived, typename Key, typename T, WireFormatLite::FieldType kValueFieldType, int default_enum_value> void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType, default_enum_value>::Swap(MapField* other) { - std::swap(MapFieldBase::repeated_field_, other->repeated_field_); + std::swap(this->MapFieldBase::repeated_field_, other->repeated_field_); impl_.Swap(&other->impl_); - std::swap(MapFieldBase::state_, other->state_); + std::swap(this->MapFieldBase::state_, other->state_); } template <typename Derived, typename Key, typename T, diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index 0469f4ca..cbf9051a 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -37,9 +37,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#ifdef _MSC_VER -#include <io.h> -#else +#ifndef _MSC_VER #include <unistd.h> #endif #include <sstream> @@ -56,6 +54,7 @@ #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/testing/googletest.h> #include <gtest/gtest.h> @@ -63,6 +62,13 @@ namespace google { namespace protobuf { +#if defined(_WIN32) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::close; +using google::protobuf::internal::win32::open; +#endif + #ifndef O_BINARY #ifdef _O_BINARY #define O_BINARY _O_BINARY diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 8ecb2d19..d0c58825 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -123,7 +123,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -269,6 +269,7 @@ void SourceContext::SerializeWithCachedSizes( ::google::protobuf::uint8* SourceContext::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 23cd7f3e..66ee1886 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/struct.pb.cc index 26684c57..28cfd3bd 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -193,7 +193,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -253,9 +253,7 @@ Struct::Struct(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), fields_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Struct) @@ -436,6 +434,7 @@ void Struct::SerializeWithCachedSizes( ::google::protobuf::uint8* Struct::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -651,9 +650,7 @@ Value::Value() Value::Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Value) @@ -952,6 +949,7 @@ void Value::SerializeWithCachedSizes( ::google::protobuf::uint8* Value::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1560,9 +1558,7 @@ ListValue::ListValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), values_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.ListValue) @@ -1684,6 +1680,7 @@ void ListValue::SerializeWithCachedSizes( ::google::protobuf::uint8* ListValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index a37a5652..c70912cd 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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 60874e09..a56f8e89 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -101,7 +101,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3003000 +#define GOOGLE_PROTOBUF_VERSION 3003002 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" @@ -227,10 +227,8 @@ class FatalException : public std::exception { // in some versions of MSVC. // TODO(acozzette): remove these using statements using std::istream; -using std::map; using std::ostream; using std::pair; -using std::set; using std::string; using std::vector; diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index a997e04b..612b5861 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -40,10 +40,9 @@ #define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 -#define GOOGLE_PROTOBUF_HAVE_64BIT_HASH 1 // Use C++11 unordered_{map|set} if available. -#if ((_LIBCPP_STD_VER >= 11) || \ +#if ((defined(_LIBCPP_STD_VER) && _LIBCPP_STD_VER >= 11) || \ (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \ (__GLIBCXX__ > 20090421))) # define GOOGLE_PROTOBUF_HAS_CXX11_HASH @@ -93,8 +92,11 @@ # define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set # endif +// GCC <= 4.1 does not define std::tr1::hash for `long long int` or `long long unsigned int` # if __GNUC__ == 4 && __GNUC__MINOR__ <= 1 -# undef GOOGLE_PROTOBUF_HAVE_64BIT_HASH +# define GOOGLE_PROTOBUF_MISSING_HASH +# include <map> +# include <set> # endif // Version checks for MSC. diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc new file mode 100644 index 00000000..6f0295e1 --- /dev/null +++ b/src/google/protobuf/stubs/io_win32.cc @@ -0,0 +1,362 @@ +// 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: laszlocsomor@google.com (Laszlo Csomor) +// +// Implementation for long-path-aware open/mkdir/etc. on Windows. +// +// These functions convert the input path to an absolute Windows path +// with "\\?\" prefix if necessary, then pass that to _wopen/_wmkdir/etc. +// (declared in <io.h>) respectively. This allows working with files/directories +// whose paths are longer than MAX_PATH (260 chars). +// +// This file is only used on Windows, it's empty on other platforms. + +#if defined(_WIN32) + +// Comment this out to fall back to using the ANSI versions (open, mkdir, ...) +// instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to +// debug failing tests if that's caused by the long path support. +#define SUPPORT_LONGPATHS + +#include <ctype.h> +#include <direct.h> +#include <errno.h> +#include <fcntl.h> +#include <io.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <wctype.h> +#include <windows.h> + +#include <google/protobuf/stubs/io_win32.h> + +#include <cassert> +#include <memory> +#include <sstream> +#include <string> +#include <vector> + +namespace google { +namespace protobuf { +namespace internal { +namespace win32 { +namespace { + +using std::string; +using std::unique_ptr; +using std::wstring; + +template <typename char_type> +struct CharTraits { + static bool is_alpha(char_type ch); +}; + +template <> +struct CharTraits<char> { + static bool is_alpha(char ch) { return isalpha(ch); } +}; + +template <> +struct CharTraits<wchar_t> { + static bool is_alpha(wchar_t ch) { return iswalpha(ch); } +}; + +// Returns true if the path starts with a drive letter, e.g. "c:". +// Note that this won't check for the "\" after the drive letter, so this also +// returns true for "c:foo" (which is "c:\${PWD}\foo"). +// This check requires that a path not have a longpath prefix ("\\?\"). +template <typename char_type> +bool has_drive_letter(const char_type* ch) { + return CharTraits<char_type>::is_alpha(ch[0]) && ch[1] == ':'; +} + +// Returns true if the path starts with a longpath prefix ("\\?\"). +template <typename char_type> +bool has_longpath_prefix(const char_type* path) { + return path[0] == '\\' && path[1] == '\\' && path[2] == '?' && + path[3] == '\\'; +} + +// Returns true if the path starts with a drive specifier (e.g. "c:\"). +template <typename char_type> +bool is_path_absolute(const char_type* path) { + return has_drive_letter(path) && is_separator(path[2]); +} + +template <typename char_type> +bool is_separator(char_type c) { + return c == '/' || c == '\\'; +} + +template <typename char_type> +bool is_drive_relative(const char_type* path) { + return has_drive_letter(path) && (path[2] == 0 || !is_separator(path[2])); +} + +template <typename char_type> +void replace_directory_separators(char_type* p) { + for (; *p; ++p) { + if (*p == '/') { + *p = '\\'; + } + } +} + +string join_paths(const string& path1, const string& path2) { + if (path1.empty() || is_path_absolute(path2.c_str()) || + has_longpath_prefix(path2.c_str())) { + return path2; + } + if (path2.empty()) { + return path1; + } + + if (is_separator(path1.back())) { + return is_separator(path2.front()) ? (path1 + path2.substr(1)) + : (path1 + path2); + } else { + return is_separator(path2.front()) ? (path1 + path2) + : (path1 + '\\' + path2); + } +} + +string normalize(string path) { + if (has_longpath_prefix(path.c_str())) { + path = path.substr(4); + } + + static const string dot("."); + static const string dotdot(".."); + + std::vector<string> segments; + int segment_start = -1; + // Find the path segments in `path` (separated by "/"). + for (int i = 0;; ++i) { + if (!is_separator(path[i]) && path[i] != '\0') { + // The current character does not end a segment, so start one unless it's + // already started. + if (segment_start < 0) { + segment_start = i; + } + } else if (segment_start >= 0 && i > segment_start) { + // The current character is "/" or "\0", so this ends a segment. + // Add that to `segments` if there's anything to add; handle "." and "..". + string segment(path, segment_start, i - segment_start); + segment_start = -1; + if (segment == dotdot) { + if (!segments.empty() && + (!has_drive_letter(segments[0].c_str()) || segments.size() > 1)) { + segments.pop_back(); + } + } else if (segment != dot && !segment.empty()) { + segments.push_back(segment); + } + } + if (path[i] == '\0') { + break; + } + } + + // Handle the case when `path` is just a drive specifier (or some degenerate + // form of it, e.g. "c:\.."). + if (segments.size() == 1 && segments[0].size() == 2 && + has_drive_letter(segments[0].c_str())) { + return segments[0] + '\\'; + } + + // Join all segments. + bool first = true; + std::ostringstream result; + for (const auto& s : segments) { + if (!first) { + result << '\\'; + } + first = false; + result << s; + } + // Preserve trailing separator if the input contained it. + if (is_separator(path.back())) { + result << '\\'; + } + return result.str(); +} + +std::unique_ptr<WCHAR[]> as_wstring(const string& s) { + int len = ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), NULL, 0); + std::unique_ptr<WCHAR[]> result(new WCHAR[len + 1]); + ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), result.get(), len + 1); + result.get()[len] = 0; + return std::move(result); +} + +wstring as_wchar_path(const string& path) { + std::unique_ptr<WCHAR[]> wbuf(as_wstring(path)); + replace_directory_separators(wbuf.get()); + return wstring(wbuf.get()); +} + +bool as_windows_path(const string& path, wstring* result) { + if (path.empty()) { + result->clear(); + return true; + } + if (is_separator(path[0]) || is_drive_relative(path.c_str())) { + return false; + } + + string mutable_path = path; + if (!is_path_absolute(mutable_path.c_str()) && + !has_longpath_prefix(mutable_path.c_str())) { + char cwd[MAX_PATH]; + ::GetCurrentDirectoryA(MAX_PATH, cwd); + mutable_path = join_paths(cwd, mutable_path); + } + *result = as_wchar_path(normalize(mutable_path)); + if (!has_longpath_prefix(result->c_str())) { + // Add the "\\?\" prefix unconditionally. This way we prevent the Win32 API + // from processing the path and "helpfully" removing trailing dots from the + // path, for example. + // See https://github.com/bazelbuild/bazel/issues/2935 + *result = wstring(L"\\\\?\\") + *result; + } + return true; +} + +} // namespace + +int open(const char* path, int flags, int mode) { +#ifdef SUPPORT_LONGPATHS + wstring wpath; + if (!as_windows_path(path, &wpath)) { + errno = ENOENT; + return -1; + } + return ::_wopen(wpath.c_str(), flags, mode); +#else + return ::_open(path, flags, mode); +#endif +} + +int mkdir(const char* path, int _mode) { +#ifdef SUPPORT_LONGPATHS + wstring wpath; + if (!as_windows_path(path, &wpath)) { + errno = ENOENT; + return -1; + } + return ::_wmkdir(wpath.c_str()); +#else // not SUPPORT_LONGPATHS + return ::_mkdir(path); +#endif // not SUPPORT_LONGPATHS +} + +int access(const char* path, int mode) { +#ifdef SUPPORT_LONGPATHS + wstring wpath; + if (!as_windows_path(path, &wpath)) { + errno = ENOENT; + return -1; + } + return ::_waccess(wpath.c_str(), mode); +#else + return ::_access(path, mode); +#endif +} + +int chdir(const char* path) { +#ifdef SUPPORT_LONGPATHS + wstring wpath; + if (!as_windows_path(path, &wpath)) { + errno = ENOENT; + return -1; + } + return ::_wchdir(wpath.c_str()); +#else + return ::_chdir(path); +#endif +} + +int stat(const char* path, struct _stat* buffer) { +#ifdef SUPPORT_LONGPATHS + wstring wpath; + if (!as_windows_path(path, &wpath)) { + errno = ENOENT; + return -1; + } + return ::_wstat(wpath.c_str(), buffer); +#else // not SUPPORT_LONGPATHS + return ::_stat(path, buffer); +#endif // not SUPPORT_LONGPATHS +} + +FILE* fopen(const char* path, const char* mode) { +#ifdef SUPPORT_LONGPATHS + wstring wpath; + if (!as_windows_path(path, &wpath)) { + errno = ENOENT; + return NULL; + } + std::unique_ptr<WCHAR[]> wmode(as_wstring(mode)); + return ::_wfopen(wpath.c_str(), wmode.get()); +#else + return ::fopen(path, mode); +#endif +} + +int close(int fd) { return ::close(fd); } + +int dup(int fd) { return ::_dup(fd); } + +int dup2(int fd1, int fd2) { return ::_dup2(fd1, fd2); } + +int read(int fd, void* buffer, size_t size) { + return ::_read(fd, buffer, size); +} + +int setmode(int fd, int mode) { return ::_setmode(fd, mode); } + +int write(int fd, const void* buffer, size_t size) { + return ::_write(fd, buffer, size); +} + +wstring testonly_path_to_winpath(const string& path) { + wstring wpath; + as_windows_path(path, &wpath); + return wpath; +} + +} // namespace win32 +} // namespace internal +} // namespace protobuf +} // namespace google + +#endif // defined(_WIN32) + diff --git a/src/google/protobuf/stubs/io_win32.h b/src/google/protobuf/stubs/io_win32.h new file mode 100644 index 00000000..daccf16c --- /dev/null +++ b/src/google/protobuf/stubs/io_win32.h @@ -0,0 +1,96 @@ +// 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: laszlocsomor@google.com (Laszlo Csomor) +// +// This file contains the declarations for Windows implementations of +// commonly used POSIX functions such as open(2) and access(2), as well +// as macro definitions for flags of these functions. +// +// By including this file you'll redefine open/access/etc. to +// ::google::protobuf::internal::win32::{open/access/etc.}. +// Make sure you don't include a header that attempts to redeclare or +// redefine these functions, that'll lead to confusing compilation +// errors. It's best to #include this file as the last one to ensure that. +// +// This file is only used on Windows, it's empty on other platforms. + +#ifndef GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ +#define GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ + +#if defined(_WIN32) + +#include <string> + +namespace google { +namespace protobuf { +namespace internal { +namespace win32 { + +FILE* fopen(const char* path, const char* mode); +int access(const char* path, int mode); +int chdir(const char* path); +int close(int fd); +int dup(int fd); +int dup2(int fd1, int fd2); +int mkdir(const char* path, int _mode); +int open(const char* path, int flags, int mode = 0); +int read(int fd, void* buffer, size_t size); +int setmode(int fd, int mode); +int stat(const char* path, struct _stat* buffer); +int write(int fd, const void* buffer, size_t size); +std::wstring testonly_path_to_winpath(const std::string& path); + +} // namespace win32 +} // namespace internal +} // namespace protobuf +} // namespace google + +#ifndef W_OK +#define W_OK 02 // not defined by MSVC for whatever reason +#endif + +#ifndef F_OK +#define F_OK 00 // not defined by MSVC for whatever reason +#endif + +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + +#endif // defined(_WIN32) + +#endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ + + diff --git a/src/google/protobuf/stubs/io_win32_unittest.cc b/src/google/protobuf/stubs/io_win32_unittest.cc new file mode 100644 index 00000000..90bd9c96 --- /dev/null +++ b/src/google/protobuf/stubs/io_win32_unittest.cc @@ -0,0 +1,367 @@ +// 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: laszlocsomor@google.com (Laszlo Csomor) +// +// Unit tests for long-path-aware open/mkdir/access on Windows. +// +// This file is only used on Windows, it's empty on other platforms. + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#include <errno.h> +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <wchar.h> +#include <windows.h> + +#include <google/protobuf/stubs/io_win32.h> +#include <google/protobuf/testing/googletest.h> +#include <gtest/gtest.h> + +#include <memory> +#include <sstream> +#include <string> + +namespace google { +namespace protobuf { +namespace internal { +namespace win32 { +namespace { + +using std::string; +using std::unique_ptr; +using std::wstring; + +class IoWin32Test : public ::testing::Test { + public: + void SetUp() override; + void TearDown() override; + + protected: + bool CreateAllUnder(wstring path); + bool DeleteAllUnder(wstring path); + + string test_tmpdir; + wstring wtest_tmpdir; +}; + +#define ASSERT_INITIALIZED \ + { \ + EXPECT_FALSE(test_tmpdir.empty()); \ + EXPECT_FALSE(wtest_tmpdir.empty()); \ + } + +void IoWin32Test::SetUp() { + test_tmpdir = string(TestTempDir()); + wtest_tmpdir.clear(); + if (test_tmpdir.empty()) { + const char* test_tmpdir_env = getenv("TEST_TMPDIR"); + if (test_tmpdir_env != nullptr && *test_tmpdir_env) { + test_tmpdir = string(test_tmpdir_env); + } + + // Only Bazel defines TEST_TMPDIR, CMake does not, so look for other + // suitable environment variables. + if (test_tmpdir.empty()) { + for (const char* name : {"TEMP", "TMP"}) { + test_tmpdir_env = getenv(name); + if (test_tmpdir_env != nullptr && *test_tmpdir_env) { + test_tmpdir = string(test_tmpdir_env); + break; + } + } + } + + // No other temp directory was found. Use the current director + if (test_tmpdir.empty()) { + char buffer[MAX_PATH]; + // Use GetCurrentDirectoryA instead of GetCurrentDirectoryW, because the + // current working directory must always be shorter than MAX_PATH, even + // with + // "\\?\" prefix (except on Windows 10 version 1607 and beyond, after + // opting in to long paths by default [1]). + // + // [1] https://msdn.microsoft.com/en-us/library/windows/ \ + // desktop/aa365247(v=vs.85).aspx#maxpath + DWORD result = ::GetCurrentDirectoryA(MAX_PATH, buffer); + if (result > 0) { + test_tmpdir = string(buffer); + } else { + // Using assertions in SetUp/TearDown seems to confuse the test + // framework, so just leave the member variables empty in case of + // failure. + GOOGLE_CHECK_OK(false); + return; + } + } + } + + while (test_tmpdir.back() == '/' || test_tmpdir.back() == '\\') { + test_tmpdir.pop_back(); + } + test_tmpdir += "\\io_win32_unittest.tmp"; + + // CreateDirectoryA's limit is 248 chars, see MSDN. + // https://msdn.microsoft.com/en-us/library/windows/ \ + // desktop/aa363855(v=vs.85).aspx + wtest_tmpdir = testonly_path_to_winpath(test_tmpdir); + if (!DeleteAllUnder(wtest_tmpdir) || !CreateAllUnder(wtest_tmpdir)) { + GOOGLE_CHECK_OK(false); + test_tmpdir.clear(); + wtest_tmpdir.clear(); + } +} + +void IoWin32Test::TearDown() { + if (!wtest_tmpdir.empty()) { + DeleteAllUnder(wtest_tmpdir); + } +} + +bool IoWin32Test::CreateAllUnder(wstring path) { + // Prepend UNC prefix if the path doesn't have it already. Don't bother + // checking if the path is shorter than MAX_PATH, let's just do it + // unconditionally. + if (path.find(L"\\\\?\\") != 0) { + path = wstring(L"\\\\?\\") + path; + } + if (::CreateDirectoryW(path.c_str(), NULL) || + GetLastError() == ERROR_ALREADY_EXISTS || + GetLastError() == ERROR_ACCESS_DENIED) { + return true; + } + if (GetLastError() == ERROR_PATH_NOT_FOUND) { + size_t pos = path.find_last_of(L'\\'); + if (pos != wstring::npos) { + wstring parent(path, 0, pos); + if (CreateAllUnder(parent) && CreateDirectoryW(path.c_str(), NULL)) { + return true; + } + } + } + return false; +} + +bool IoWin32Test::DeleteAllUnder(wstring path) { + static const wstring kDot(L"."); + static const wstring kDotDot(L".."); + + // Prepend UNC prefix if the path doesn't have it already. Don't bother + // checking if the path is shorter than MAX_PATH, let's just do it + // unconditionally. + if (path.find(L"\\\\?\\") != 0) { + path = wstring(L"\\\\?\\") + path; + } + // Append "\" if necessary. + if (path.back() != '\\') { + path.push_back('\\'); + } + + WIN32_FIND_DATAW metadata; + HANDLE handle = ::FindFirstFileW((path + L"*").c_str(), &metadata); + if (handle == INVALID_HANDLE_VALUE) { + return true; // directory doesn't exist + } + + bool result = true; + do { + wstring childname = metadata.cFileName; + if (kDot != childname && kDotDot != childname) { + wstring childpath = path + childname; + if ((metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { + // If this is not a junction, delete its contents recursively. + // Finally delete this directory/junction too. + if (((metadata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 && + !DeleteAllUnder(childpath)) || + !::RemoveDirectoryW(childpath.c_str())) { + result = false; + break; + } + } else { + if (!::DeleteFileW(childpath.c_str())) { + result = false; + break; + } + } + } + } while (::FindNextFileW(handle, &metadata)); + ::FindClose(handle); + return result; +} + +TEST_F(IoWin32Test, AccessTest) { + ASSERT_INITIALIZED; + + string path = test_tmpdir; + while (path.size() < MAX_PATH - 30) { + path += "\\accesstest"; + EXPECT_EQ(mkdir(path.c_str(), 0644), 0); + } + string file = path + "\\file.txt"; + int fd = open(file.c_str(), O_CREAT | O_WRONLY, 0644); + if (fd > 0) { + EXPECT_EQ(close(fd), 0); + } else { + EXPECT_TRUE(false); + } + + EXPECT_EQ(access(test_tmpdir.c_str(), F_OK), 0); + EXPECT_EQ(access(path.c_str(), F_OK), 0); + EXPECT_EQ(access(path.c_str(), W_OK), 0); + EXPECT_EQ(access(file.c_str(), F_OK | W_OK), 0); + EXPECT_NE(access((file + ".blah").c_str(), F_OK), 0); + EXPECT_NE(access((file + ".blah").c_str(), W_OK), 0); + + EXPECT_EQ(access(".", F_OK), 0); + EXPECT_EQ(access(".", W_OK), 0); + EXPECT_EQ(access((test_tmpdir + "/accesstest").c_str(), F_OK | W_OK), 0); + ASSERT_EQ(access((test_tmpdir + "/./normalize_me/.././accesstest").c_str(), + F_OK | W_OK), + 0); + EXPECT_NE(access("io_win32_unittest.AccessTest.nonexistent", F_OK), 0); + EXPECT_NE(access("io_win32_unittest.AccessTest.nonexistent", W_OK), 0); + + ASSERT_EQ(access("c:bad", F_OK), -1); + ASSERT_EQ(errno, ENOENT); + ASSERT_EQ(access("/tmp/bad", F_OK), -1); + ASSERT_EQ(errno, ENOENT); + ASSERT_EQ(access("\\bad", F_OK), -1); + ASSERT_EQ(errno, ENOENT); +} + +TEST_F(IoWin32Test, OpenTest) { + ASSERT_INITIALIZED; + + string path = test_tmpdir; + while (path.size() < MAX_PATH) { + path += "\\opentest"; + EXPECT_EQ(mkdir(path.c_str(), 0644), 0); + } + string file = path + "\\file.txt"; + int fd = open(file.c_str(), O_CREAT | O_WRONLY, 0644); + if (fd > 0) { + EXPECT_EQ(write(fd, "hello", 5), 5); + EXPECT_EQ(close(fd), 0); + } else { + EXPECT_TRUE(false); + } + + ASSERT_EQ(open("c:bad.txt", O_CREAT | O_WRONLY, 0644), -1); + ASSERT_EQ(errno, ENOENT); + ASSERT_EQ(open("/tmp/bad.txt", O_CREAT | O_WRONLY, 0644), -1); + ASSERT_EQ(errno, ENOENT); + ASSERT_EQ(open("\\bad.txt", O_CREAT | O_WRONLY, 0644), -1); + ASSERT_EQ(errno, ENOENT); +} + +TEST_F(IoWin32Test, MkdirTest) { + ASSERT_INITIALIZED; + + string path = test_tmpdir; + do { + path += "\\mkdirtest"; + ASSERT_EQ(mkdir(path.c_str(), 0644), 0); + } while (path.size() <= MAX_PATH); + + ASSERT_EQ(mkdir("c:bad", 0644), -1); + ASSERT_EQ(errno, ENOENT); + ASSERT_EQ(mkdir("/tmp/bad", 0644), -1); + ASSERT_EQ(errno, ENOENT); + ASSERT_EQ(mkdir("\\bad", 0644), -1); + ASSERT_EQ(errno, ENOENT); +} + +TEST_F(IoWin32Test, ChdirTest) { + char owd[MAX_PATH]; + EXPECT_GT(::GetCurrentDirectoryA(MAX_PATH, owd), 0); + string path("C:\\"); + EXPECT_EQ(access(path.c_str(), F_OK), 0); + ASSERT_EQ(chdir(path.c_str()), 0); + EXPECT_TRUE(::SetCurrentDirectoryA(owd)); + + // Do not try to chdir into the test_tmpdir, it may already contain directory + // names with trailing dots. + // Instead test here with an obviously dot-trailed path. If the win32_chdir + // function would not convert the path to absolute and prefix with "\\?\" then + // the Win32 API would ignore the trailing dot, but because of the prefixing + // there'll be no path processing done, so we'll actually attempt to chdir + // into "C:\some\path\foo." + path = test_tmpdir + "/foo."; + EXPECT_EQ(mkdir(path.c_str(), 644), 0); + EXPECT_EQ(access(path.c_str(), F_OK), 0); + ASSERT_NE(chdir(path.c_str()), 0); +} + +TEST_F(IoWin32Test, AsWindowsPathTest) { + DWORD size = GetCurrentDirectoryW(0, NULL); + unique_ptr<wchar_t[]> cwd_str(new wchar_t[size]); + EXPECT_GT(GetCurrentDirectoryW(size, cwd_str.get()), 0); + wstring cwd = wstring(L"\\\\?\\") + cwd_str.get(); + + ASSERT_EQ(testonly_path_to_winpath("relative_mkdirtest"), + cwd + L"\\relative_mkdirtest"); + ASSERT_EQ(testonly_path_to_winpath("preserve//\\trailing///"), + cwd + L"\\preserve\\trailing\\"); + ASSERT_EQ(testonly_path_to_winpath("./normalize_me\\/../blah"), + cwd + L"\\blah"); + std::ostringstream relpath; + for (wchar_t* p = cwd_str.get(); *p; ++p) { + if (*p == '/' || *p == '\\') { + relpath << "../"; + } + } + relpath << ".\\/../\\./beyond-toplevel"; + ASSERT_EQ(testonly_path_to_winpath(relpath.str()), + wstring(L"\\\\?\\") + cwd_str.get()[0] + L":\\beyond-toplevel"); + + // Absolute unix paths lack drive letters, driveless absolute windows paths + // do too. Neither can be converted to a drive-specifying absolute Windows + // path. + ASSERT_EQ(testonly_path_to_winpath("/absolute/unix/path"), L""); + // Though valid on Windows, we also don't support UNC paths (\\UNC\\blah). + ASSERT_EQ(testonly_path_to_winpath("\\driveless\\absolute"), L""); + // Though valid in cmd.exe, drive-relative paths are not supported. + ASSERT_EQ(testonly_path_to_winpath("c:foo"), L""); + ASSERT_EQ(testonly_path_to_winpath("c:/foo"), L"\\\\?\\c:\\foo"); +} + +} // namespace +} // namespace win32 +} // namespace internal +} // namespace protobuf +} // namespace google + +#endif // defined(_WIN32) + diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index 470512ed..a1850e44 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -38,24 +38,28 @@ #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN // yeah, right #include <windows.h> // Find*File(). :( -#include <io.h> -#include <direct.h> +// #include <direct.h> #else #include <dirent.h> #include <unistd.h> #endif #include <errno.h> +#include <google/protobuf/stubs/io_win32.h> + namespace google { namespace protobuf { #ifdef _WIN32 -#define mkdir(name, mode) mkdir(name) // Windows doesn't have symbolic links. #define lstat stat -#ifndef F_OK -#define F_OK 00 // not defined by MSVC for whatever reason -#endif +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::access; +using google::protobuf::internal::win32::chdir; +using google::protobuf::internal::win32::fopen; +using google::protobuf::internal::win32::mkdir; +using google::protobuf::internal::win32::stat; #endif bool File::Exists(const string& name) { @@ -113,6 +117,9 @@ void File::WriteStringToFileOrDie(const string& contents, const string& name) { } bool File::CreateDir(const string& name, int mode) { + if (!name.empty()) { + GOOGLE_CHECK_OK(name.back() != '.'); + } return mkdir(name.c_str(), mode) == 0; } diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index d45706b6..c6fb00d4 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -33,14 +33,14 @@ #include <google/protobuf/testing/googletest.h> #include <google/protobuf/testing/file.h> +#include <google/protobuf/stubs/io_win32.h> #include <google/protobuf/stubs/strutil.h> #include <sys/stat.h> #include <sys/types.h> #include <errno.h> #include <stdlib.h> #ifdef _MSC_VER -#include <io.h> -#include <direct.h> +// #include <direct.h> #else #include <unistd.h> #endif @@ -53,7 +53,13 @@ namespace google { namespace protobuf { #ifdef _WIN32 -#define mkdir(name, mode) mkdir(name) +// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::internal::win32::close; +using google::protobuf::internal::win32::dup2; +using google::protobuf::internal::win32::dup; +using google::protobuf::internal::win32::mkdir; +using google::protobuf::internal::win32::open; #endif #ifndef O_BINARY @@ -111,14 +117,32 @@ string GetTemporaryDirectoryName() { char b[L_tmpnam + 1]; // HPUX multithread return 0 if s is 0 string result = tmpnam(b); #ifdef _WIN32 + // Avoid a trailing dot by changing it to an underscore. On Win32 the names of + // files and directories can, but should not, end with dot. + // + // In MS-DOS and FAT16 filesystem the filenames were 8dot3 style so it didn't + // make sense to have a name ending in dot without an extension, so the shell + // silently ignored trailing dots. To this day the Win32 API still maintains + // this behavior and silently ignores trailing dots in path arguments of + // functions such as CreateFile{A,W}. Even POSIX API function implementations + // seem to wrap the Win32 API functions (e.g. CreateDirectoryA) and behave + // this way. + // It's possible to avoid this behavior and create files / directories with + // trailing dots (using CreateFileW / CreateDirectoryW and prefixing the path + // with "\\?\") but these will be degenerate in the sense that you cannot + // chdir into such directories (or navigate into them with Windows Explorer) + // nor can you open such files with some programs (e.g. Notepad). + if (result.back() == '.') { + result[result.size() - 1] = '_'; + } // On Win32, tmpnam() returns a file prefixed with '\', but which is supposed // to be used in the current working directory. WTF? if (HasPrefixString(result, "\\")) { result.erase(0, 1); } - // The Win32 API accepts forward slashes as a path delimiter even though - // backslashes are standard. Let's avoid confusion and use only forward - // slashes. + // The Win32 API accepts forward slashes as a path delimiter as long as the + // path doesn't use the "\\?\" prefix. + // Let's avoid confusion and use only forward slashes. result = StringReplace(result, "\\", "/", true); #endif // _WIN32 return result; diff --git a/src/google/protobuf/testing/googletest.h b/src/google/protobuf/testing/googletest.h index c0d99e69..bf8bf282 100644 --- a/src/google/protobuf/testing/googletest.h +++ b/src/google/protobuf/testing/googletest.h @@ -85,7 +85,7 @@ class ScopedMemoryLog { const vector<string>& GetMessages(LogLevel error); private: - map<LogLevel, vector<string> > messages_; + std::map<LogLevel, vector<string> > messages_; LogHandler* old_handler_; static void HandleLog(LogLevel level, const char* filename, int line, diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 80ddc5bf..a8c3a1b4 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -123,7 +123,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -151,9 +151,7 @@ Timestamp::Timestamp() Timestamp::Timestamp(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftimestamp_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Timestamp) @@ -301,6 +299,7 @@ void Timestamp::SerializeWithCachedSizes( ::google::protobuf::uint8* Timestamp::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 98478540..9ce2c96a 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/type.pb.cc index 8a53d76a..f07bb0c6 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -244,7 +244,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -406,9 +406,7 @@ Type::Type(::google::protobuf::Arena* arena) fields_(arena), oneofs_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Type) @@ -670,6 +668,7 @@ void Type::SerializeWithCachedSizes( ::google::protobuf::uint8* Type::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1170,9 +1169,7 @@ Field::Field(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Field) @@ -1538,6 +1535,7 @@ void Field::SerializeWithCachedSizes( ::google::protobuf::uint8* Field::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2243,9 +2241,7 @@ Enum::Enum(::google::protobuf::Arena* arena) _internal_metadata_(arena), enumvalue_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Enum) @@ -2478,6 +2474,7 @@ void Enum::SerializeWithCachedSizes( ::google::protobuf::uint8* Enum::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2882,9 +2879,7 @@ EnumValue::EnumValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.EnumValue) @@ -3062,6 +3057,7 @@ void EnumValue::SerializeWithCachedSizes( ::google::protobuf::uint8* EnumValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3377,9 +3373,7 @@ Option::Option() Option::Option(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Option) @@ -3545,6 +3539,7 @@ void Option::SerializeWithCachedSizes( ::google::protobuf::uint8* Option::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 5ac80bb9..1138988d 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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.cc b/src/google/protobuf/wrappers.pb.cc index 245f7653..9cd95c41 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -240,7 +240,7 @@ void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -267,9 +267,7 @@ DoubleValue::DoubleValue() DoubleValue::DoubleValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.DoubleValue) @@ -392,6 +390,7 @@ void DoubleValue::SerializeWithCachedSizes( ::google::protobuf::uint8* DoubleValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -531,9 +530,7 @@ FloatValue::FloatValue() FloatValue::FloatValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.FloatValue) @@ -656,6 +653,7 @@ void FloatValue::SerializeWithCachedSizes( ::google::protobuf::uint8* FloatValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -795,9 +793,7 @@ Int64Value::Int64Value() Int64Value::Int64Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Int64Value) @@ -920,6 +916,7 @@ void Int64Value::SerializeWithCachedSizes( ::google::protobuf::uint8* Int64Value::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1061,9 +1058,7 @@ UInt64Value::UInt64Value() UInt64Value::UInt64Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.UInt64Value) @@ -1186,6 +1181,7 @@ void UInt64Value::SerializeWithCachedSizes( ::google::protobuf::uint8* UInt64Value::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1327,9 +1323,7 @@ Int32Value::Int32Value() Int32Value::Int32Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Int32Value) @@ -1452,6 +1446,7 @@ void Int32Value::SerializeWithCachedSizes( ::google::protobuf::uint8* Int32Value::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1593,9 +1588,7 @@ UInt32Value::UInt32Value() UInt32Value::UInt32Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.UInt32Value) @@ -1718,6 +1711,7 @@ void UInt32Value::SerializeWithCachedSizes( ::google::protobuf::uint8* UInt32Value::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -1859,9 +1853,7 @@ BoolValue::BoolValue() BoolValue::BoolValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.BoolValue) @@ -1984,6 +1976,7 @@ void BoolValue::SerializeWithCachedSizes( ::google::protobuf::uint8* BoolValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2123,9 +2116,7 @@ StringValue::StringValue() StringValue::StringValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.StringValue) @@ -2260,6 +2251,7 @@ void StringValue::SerializeWithCachedSizes( ::google::protobuf::uint8* StringValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2460,9 +2452,7 @@ BytesValue::BytesValue() BytesValue::BytesValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.BytesValue) @@ -2589,6 +2579,7 @@ void BytesValue::SerializeWithCachedSizes( ::google::protobuf::uint8* BytesValue::InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue) ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 4202541b..7495aa68 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3003000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003002 < GOOGLE_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. @@ -63,6 +63,7 @@ build_cpp_distcheck() { # List all files that should be included in the distribution package. git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\)" |\ grep -v ".gitignore" | grep -v "java/compatibility_tests" |\ + grep -v "cmake/protobuf.*\.pc\.cmake" |\ grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst # Unzip the dist tar file. DIST=`ls *.tar.gz` @@ -346,7 +347,7 @@ generate_php_test_proto() { # Generate test file rm -rf generated mkdir generated - ../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto proto/test_prefix.proto proto/test_php_namespace.proto proto/test_empty_php_namespace.proto + ../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto proto/test_prefix.proto proto/test_php_namespace.proto proto/test_empty_php_namespace.proto proto/test_service.proto proto/test_service_namespace.proto pushd ../../src ./protoc --php_out=../php/tests/generated google/protobuf/empty.proto ./protoc --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto @@ -544,16 +545,51 @@ build_php_compatibility() { php/tests/compatibility_test.sh } +build_php7.1() { + use_php 7.1 + pushd php + rm -rf vendor + cp -r /usr/local/vendor-7.1 vendor + wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit + phpunit + popd + pushd conformance + # TODO(teboring): Add it back + # make test_php + popd +} + +build_php7.1_c() { + use_php 7.1 + wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit + cd php/tests && /bin/bash ./test.sh && cd ../.. + pushd conformance + # make test_php_c + popd +} + +build_php7.1_zts_c() { + use_php_zts 7.1 + wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit + cd php/tests && /bin/bash ./test.sh && cd ../.. + pushd conformance + # make test_php_c + popd +} + build_php_all_32() { build_php5.5 build_php5.6 build_php7.0 + build_php7.1 build_php5.5_c build_php5.6_c build_php7.0_c + build_php7.1_c build_php5.5_zts_c build_php5.6_zts_c build_php7.0_zts_c + build_php7.1_zts_c } build_php_all() { @@ -600,6 +636,8 @@ Usage: $0 { cpp | php7.0 | php7.0_c | php_compatibility | + php7.1 | + php7.1_c | php_all) " exit 1 |